Linux系统初始化脚本

Linux系统初始化脚本如下:


#!/bin/bash
#gcc install
yum install -y gcc
#vim install
yum install -y vim
#Development Tools
yum groupinstall -y "Development Libraries" "Development Tools"
# close iptables
yum -y install iptables
/etc/init.d/iptables stop
/sbin/iptables -F
service iptables save
/etc/init.d/iptables stop
chkconfig iptables off

# disable ipv6
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
/sbin/chkconfig --level 35 ip6tables off
echo "ipv6 is disabled!"

#yum install
yum install -y lrzsz
yum -y install xfsdump
yum -y install wget
yum -y install redhat-lsb

#disable selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
echo "selinux is disabled,you must reboot!"


#modify timezone
echo 'y'| cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

#sync time
yum install -y ntp
/usr/sbin/ntpdate ntp.api.bz > /dev/null 2>&1
echo "/usr/sbin/ntpdate ntp.api.bz > /dev/null 2>&1" >> /etc/rc.local
echo "modprobe ip_conntrack > /dev/null 2>&1" >> /etc/rc.local
#tunoff services
for i in `ls /etc/rc3.d/S*`
do
CURSRV=`echo $i | cut -c 15-`
echo $CURSRV
case $CURSRV in
crond | irqbalance | microcode_ctl | network | random | sendmail | sshd | syslog | local )
echo "Base services,skip!"
;;
*)
echo "change $CURSRV to off"
chkconfig --level 235 $CURSRV off
service $CURSRV stop
;;
esac
done

echo "ulimit -SHn 65535" >> /etc/profile
echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "* hard nofile 65536" >> /etc/security/limits.conf
echo ''>/etc/sysctl.conf
cat >>/etc/sysctl.conf<<eof
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 60000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000
fs.file-max = 102400
net.ipv4.ip_conntrack_max = 1048576
net.ipv4.netfilter.ip_conntrack_max = 131072
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 216000
eof
modprobe ip_conntrack
sysctl -p
#修改ssh默认dns解析
sed -i '/AddressFamily/ a\UseDNS no' /etc/ssh/sshd_config

#添加默认lib库文件
touch /etc/ld.so.conf.d/default.conf
echo "/usr/lib" >> /etc/ld.so.conf.d/default.conf
echo "/usr/lib64" >> /etc/ld.so.conf.d/default.conf
echo "/usr/local/lib" >> /etc/ld.so.conf.d/default.conf
echo "/usr/local/lib64" >> /etc/ld.so.conf.d/default.conf
ldconfig
echo "初始化系统没有完成!"

 

原文地址:http://azhuang.blog.51cto.com/9176790/1550438

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>