#!/bin/bash
echo "-------Just for centos5.X-----------------"
echo "-------if not centos5.X,pleast ctrl+c-----"
#test whether root
if [ $(id -u) != 0 ];then
echo "error,You must be root to be run this script"
exit
fi
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo ""
echo "Press any key to start..."
char=`get_char`
for i in `ls /etc/rc3.d/S*`
do
CURSRV=`echo $i|cut -c 15-`
echo $CURSRV
case $CURSRV in
atd | auditd | cpuspeed | crond | haldaemon | iptables | irqbalance | iscsi | iscsid | lvm2-monitor | messagebus | microcode_ctl | mysql | network | nginx | php-fpm | portmap | rawdevices | readahead_early | smartd | sshd | syslog | local )
echo "Base services, Skip!"
;;
*)
echo "change $CURSRV to off"
chkconfig --level 235 $CURSRV off
service $CURSRV stop
;;
esac
done
echo "----------service are setted-----------------"
#tty optimization
sed -i 's/3\:2345/\#&/' /etc/inittab
sed -i 's/4\:2345/\#&/' /etc/inittab
sed -i 's/5\:2345/\#&/' /etc/inittab
sed -i 's/6\:2345/\#&/' /etc/inittab
echo "----------tty are setted---------------------"
#disable the ipv6
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
/sbin/chkconfig --level 35 ip6tables off
sed -i '/NETWORKING_IPV6/d' /etc/sysconfig/network
sed -i '/IPV6INIT/d' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i '/IPV6_AUTOCONF/d' /etc/sysconfig/network-scripts/ifcfg-eth0
echo "NETWORKING_IPV6=off" >> /etc/sysconfig/network
echo "IPV6INIT = no" >>/etc/sysconfig/network-scripts/ifcfg-eth0
echo "----------ipv6 is setted---------------------"
#set locale
cat > /etc/sysconfig/i18n <<EOF
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
EOF
#disable selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
echo "----------selinus is setted------------------"
#set timezone
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum install -y ntp
ntpdate 210.72.145.44
echo "----------time is setted---------------------"
#user resource limit
sed -i '/^ulimit/d' /etc/profile
cat >> /etc/profile <<EOF
ulimit -SHn 60000
EOF
echo "----------user limit is setted---------------"
# kernel parameter optimization
true > /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 = 6000
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 = 1200
net.ipv4.ip_local_port_range = 1024 65535
EOF
sysctl -p
echo "----------kernel parameter is setted----------"
#file open limit
cat >> /etc/security/limits.conf <<EOF
* soft noproc 60240
* hard noproc 60240
* soft nofile 60240
* hard nofile 60240
EOF
echo "----------file open limit is setted------------"
#disabled icmp ping
sed -i '/icmp_echo_ignore_all/d' /etc/rc.local
cat >> /etc/rc.local <<EOF
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
EOF
echo "----------icmp is setted-----------------------"
#sshd init
ssh_cf="/etc/ssh/sshd_config"
sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf
#sed -i "s/#Port 22/Port 65535/" $ssh_cf
sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf
#client
sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf
service sshd restart
echo "----------ssh init is ok-----------------------"
echo "----------pleash reboot you system ------------"
centos系統初始化腳本
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
SpringBoot 填坑 (一) | CentOS7.4 環境下,表時間字段默認值設置失效
一個優秀的廢人
2019-02-24 15:33:55
Error response from daemon: OCI runtime create failed
uiz
2019-02-24 13:44:10
CentOS7更換yum源
駙馬葉子
2019-02-23 20:02:48
原來實現GCP用客戶端登錄這麼簡單啊
simon
2019-02-23 17:42:51
Linux 服務器常見報錯
zinejo
2019-02-23 13:50:26
VMware centos6.5克隆網卡配置
張斌66
2019-02-23 13:44:28
Rhel5利用centos5 yum 源及第三方軟件倉庫
jfchl
2019-02-23 13:35:33
CentOS6 配置源及安裝常用軟件
loip125
2019-02-23 13:29:06
CentOS下部署Spacewalk
soda119
2019-02-23 13:17:03
centos使用命令行測試網絡帶寬
braoshan
2019-02-23 13:15:20
redhat中設置環境變量PATH的方法
410502505
2019-02-23 13:09:08
CentOS 6 系統優化 Shell 腳本
冰魚客
2019-02-23 00:43:08
U盤安裝Centos後拔除U盤無法啓動問題解決方法
Allon_
2019-02-23 00:40:03
源碼編譯安裝LNMP
coolner
2019-02-23 00:39:39
centos使用yum安裝gcc
xunmengaa
2019-02-23 00:34:23