linux 安装优化脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux 安装优化脚本相关的知识,希望对你有一定的参考价值。
linux 服务器安装后需要优化
cat >>/server/scripts/youhua.sh<<END
#!/bin/bash
#selinux off
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config
setenforce 0
#iptables off
/etc/init.d/iptables stop
chkconfig iptables off
#add users
useradd alvin
echo "142857"|passwd --stdin alvin
\cp /etc/sudoers /etc/sudoers.ori
echo "alvin ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
tail -l /etc/sudoers
visudo -c
#services
#chkconfig egrep -v "crond|sshd|network|rsyslog|sysstat"|awk‘{print"chkconfig",$1,"off"}‘|bash
LANG=en
for alvin in `chkconfig --list|grep 3:on|awk ‘{print $1}‘`;do chkconfig --level 3 $alvin off;done
for alvin in crond network rsyslog sshd sysstat ;do chkconfig --level 3 $alvin on; done
chkconfig --list|grep 3:on
#ntpdate
ntpdate times.aliyun.com
echo ‘#time sync‘ >>/var/spool/cron/root
echo ‘*/5 * * * * /usr/sbin/ntpdate times.aliyun.com >/dev/null 2>&1‘ >>/var/spool/cron/root
crontab -l
#ulimit
echo ‘* - nofile 65535‘ >>/etc/security/limits.conf
tail -l /etc/security/limits.conf
#kernel
cat >>/etc/sysctl.conf << EOF
net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.ip_local_port_range = 4000 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
net.ipv4.tcp_max_orphans = 16384
#iptables
net.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
EOF
#yumrepo
mv /etc/yum.repos.d/CentOS-Base.repo \
/etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo \
http://mirrors.aliyun.com/repo/Centos-6.repo
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
wget -O /etc/yum.repos.d/epel.repo \
http://mirrors.aliyun.com/repo/epel-6.repo
#install command
yum install tree telnet dos2unix sysstat lrzsz nc nmap -y
#update system
cd /etc/pki/rpm-gpg
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum update -y
END
本文出自 “知识改变命运” 博客,请务必保留此出处http://ahtornado.blog.51cto.com/4826737/1891313
以上是关于linux 安装优化脚本的主要内容,如果未能解决你的问题,请参考以下文章