本脚本使用范围:
[root@lb01 src]# cat /etc/redhat-release
CentOS release 6.7
[root@lb01 src]# vim initialization.sh
#!/bin/bash
###########################################
# this script function is :
# systemctl initialization
# USER YYYY-MM-DD - ACTION
# bruce fu 20017-08-08 - Created
# mail 270064522@qq.com
############################################
#添加epel和rpmforge的外部yum扩展源
url_yum=https://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm
cd /usr/local/src
wget "$url_yum"
rpm -ivh epel-release-latest-6.noarch.rpm
#安装gcc基础库文件以及sysstat工具
yum -y install gcc gcc-c++ vim-enhanced unzip unrar sysstat
#配置ntpdate自动对时
yum install lrzsz ntpdate sysstat -y
echo '*/5 * * * * /usr/sbin/ntpdate time.windows.com >/dev/null 2 >&1' >>/var/spool/cron/root
echo '*/10 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
#设置字符集
sed-i 's#LANG="en_US.UTF-8"#LANG="zh_CN.GB18030"#'/etc/sysconfig/i18n
source/etc/sysconfig/i18n
service crond restart
#ulimit key
ulimit -SHn 65535
echo "ulimit -SHn 65535" >> /etc/rc.local
cat >> /etc/security/limits.conf << EOF
* soft nofile 60000
* hard nofile 65535
EOF
#tune kernel parametres(内核参数优化)
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.ipv4.ip_conntrack_max = 25000000
net.ipv4.netfilter.ip_conntrack_max = 25000000
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 180
net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 120
net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait = 60
net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait = 120
EOF
/sbin/sysctl -p
#forbid control-alt-delete
sed -i 's@ca::ctrlaltdel:/sbin/shutdown -t3 -r now@#ca::ctrlaltdel:/sbin/shutdown -t3 -r now@' /etc/inittab
#关闭SElinux
sed -i 's@SELINUX=enforcing@SELINUX=disabled@' /etc/selinux/config
#forbid ipv6 address
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
echo "install ipv6 /bin/true" >> /etc/modprobe.conf
echo "IPV6INIT=no" >> /etc/sysconfig/network
sed -i 's@NETWORKING_IPV6=yes@NETWORKING_IPV6=no@' /etc/sysconfig/network
chkconfig ip6tables off
#vim initialization
echo "syntax on" >> /root/.vimrc
echo "set nohlsearch" >> /root/.vimrc
#stop systemctl service
chkconfig bluetooth off
chkconfig sendmail off
chkconfig kudzu off
chkconfig nfslock off
chkconfig portmap off
chkconfig iptables off
chkconfig autofs off
chkconfig yum-updatesd off
chkconfig postfix off
chkconfig pcscd off
chkconfig alsasound off
chkconfig smb off
#系统敏感权限设置
chmod 400 /etc/crontab
chmod 400 /etc/securetty
chmod 600 /boot/grub/grub.conf
chmod 600 /etc/inittab
chmod 600 /etc/login.defs
#forbid USB
echo "install usb-storage /bin/true" >> /etc/modprobe.d/usb-storage.conf
#重启服务器
reboot
本文出自 “一杯水” 博客,请务必保留此出处http://yibeishui.blog.51cto.com/6518161/1954592