linux系統優化指令碼

wang_0720發表於2013-11-05
#!/bin/bash
#Author: Andy
#operation system initial
#set ulimit
#最大開啟檔案數設定
limit()
{
echo "ulimit -SHn 65535" >>/etc/rc.local
sed "/End of file/i * - nofile 65535" -i /etc/security/limits.conf
}
#set locale
#字符集設定
locale()
{
true>/etc/sysconfig/i18n
cat>>/etc/sysconfig/i18n< LANG="en_US.UTF-8"
SUPPORTED="zh_CN.GBK:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"
LC_ALL="en_US.UTF-8"
EOF
source /etc/sysconfig/i18n
}
#set sysctl
#核心引數
sysctl()
{
true>/etc/sysctl.conf
cat >>/etc/sysctl.conf< 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_users_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
/sbin/sysctl -p
echo "sysctl set ok!"
}

initab()
{
sed -i "s/id:5:initdefault:/id:3:initdefault:/" /etc/inittab
sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab
}
#禁止更改重要檔案
purview()
{
chattr +i /etc/passwd
chattr +i /etc/shadow
chattr +i /etc/group
chattr +i /etc/gshadow
}
#disable ipv6
#禁用ipv6
disipv6()
{
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"
}
#disable selinux
#禁用selinux
diselinux()
{
sed -i "/SELINUX/s/enabled/disabled/" /etc/selinux/config
echo "selinux is disabled,you must reboot system"
}
#init ssh
ssh()
{
sed -i "s/#UseDNS yes/UseDNS no/" /etc/ssh/sshd_config
}
#關閉不常用服務
#chkser
chkser()
{
for server in `ls /etc/rc3.d/S*`;do
 
       curserver=`echo ${server}|cut -c 15-`
        echo ${curserver}
        case ${curserver} in
                        crond|irqbalance|microcode_ctl|network|random|sshd|syslog|local)
                        echo "basic service,skip"
                        ;;
                        *)
                        echo "set ${curserver} off"
                        chkconfig --level 235 ${curserver} off
                        service ${curserver} stop
                        ;;
        esac
done
}
#==================
limit
locale
sysctl
initab
purview
disipv6
diselinux
ssh
chkser

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27181165/viewspace-775750/,如需轉載,請註明出處,否則將追究法律責任。

相關文章