一个内核参数优化的shell脚本

#优化
cp /etc/sysctl.conf /etc/sysctl.conf.bak
egrep -q “nf_conntrack” /etc/modprobe.d/modprobe.conf >/dev/null 2>&1 || echo “options nf_conntrack hashsize=1048576″ >> /etc/modprobe.d/modprobe.conf
egrep -q -c “#__XXX_XX__” /etc/sysctl.conf >/dev/null 2>&1 || echo “#__XXX_XX__
net.ipv4.ip_forward = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_retrans_collapse = 0
net.ipv4.ip_local_port_range = 10000 50000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 50000
net.ipv4.tcp_timestamps = 0
net.nf_conntrack_max = 2621440
net.netfilter.nf_conntrack_tcp_timeout_established = 655360
net.ipv4.tcp_rmem = 4096
net.ipv4.tcp_wmem = 4096
net.core.rmem_max = 8388608
net.core.wmem_max = 8388608
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
” >> /etc/sysctl.conf && modprobe nf_conntrack >/dev/null 2>&1 && sysctl -p >/dev/null 2>&1
#Ulimits
## echo “ulimits config…”
egrep ” – nofile 65535″ /etc/security/limits.conf >/dev/null 2>&1 || echo ‘* – nofile 65535′ >> /etc/security/limits.conf
egrep ” – nproc 65535″ /etc/security/limits.conf >/dev/null 2>&1 || echo ‘* – nproc 65535′ >> /etc/security/limits.conf
egrep ” soft nofile 65535″ /etc/security/limits.conf >/dev/null 2>&1 || echo ‘* soft nofile 65535′ >> /etc/security/limits.conf
egrep ” hard nofile 65535″ /etc/security/limits.conf >/dev/null 2>&1 || echo ‘* hard nofile 65535′ >> /etc/security/limits.conf
egrep ” soft nproc 65535″ /etc/security/limits.conf >/dev/null 2>&1 || echo ‘* soft nproc 65535′ >> /etc/security/limits.conf
egrep ” hard nproc 65535″ /etc/security/limits.conf >/dev/null 2>&1 || echo ‘* hard nproc 65535′ >> /etc/security/limits.conf
sed -i ‘s/* soft nproc 1024/#* soft nproc 1024/g’ /etc/security/limits.d/90-nproc.conf
#Setting in MM
sed -i “s/kernel.msgmnb = 65536/kernel.msgmnb = 67108864/g” /etc/sysctl.conf
echo ”
##Disable IPV6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
” >> /etc/sysctl.conf
cat /etc/sysctl.conf
#使生效
sysctl -p
cat /etc/security/limits.conf
#设置history环境变量
if ! grep “HISTTIMEFORMAT” ~/.bashrc >/dev/null 2>&1; then echo ‘
export HISTSIZE=1000
export HISTFILESIZE=10000
export HISTTIMEFORMAT=”[%F %T] ”
‘ >> ~/.bashrc;fi
source ~/.bashrc
#全局设置history环境变量
echo ‘
export HISTTIMEFORMAT=”%F %T ”
export HISTSIZE=1000
export HISTFILESIZE=10000′ >>/etc/profile.d/history.sh

发表评论

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

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