ITPub博客

首页 > Linux操作系统 > Linux操作系统 > linux系统优化脚本

linux系统优化脚本

原创 Linux操作系统 作者:wang_0720 时间:2013-11-05 20:22:25 0 删除 编辑
#!/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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-11-05

  • 博文量
    111
  • 访问量
    913546