#!/bash/bin
#基础优化
system_name=`uname -n`
#关闭selinux,要重启动服务器
selinux_conf(){
sed -i "s%SELINUX=enforcing%SELINUX=disabled%g" /etc/selinux/config
}
#增加系统文件描述符
file_op6_conf(){
cat << EOF >>/etc/security/limits.conf
* - nofile 65535
EOF
echo "unset MAILCHECK" >> /etc/profile
sed -i 's%1024%4096%g' /etc/security/limits.d/90-nproc.conf
}
file_op7_conf(){
cat << EOF >>/etc/security/limits.conf
* - nofile 65535
EOF
echo "unset MAILCHECK" >> /etc/profile
}
#删除系统原来的open-jdk
jdk_e(){
rpm -e --nodeps `rpm -qa|grep java`
}
#精简系统服务和开机进程
service_centos6_conf(){
for serv in ` $CHKCONFIG --list |grep 3:on|awk '{print $1}'`;do $CHKCONFIG --level 3 $serv off;done
for serv in crond network rsyslog sshd iptables udev-post sysstat;do $CHKCONFIG --level 3 $serv on;done
}
service_centos7_conf(){
for serv in ` systemctl list-unit-files | grep enabled|awk '{print $1}'`;do systemctl disable $serv ;done
for serv in [email protected] crond.service [email protected] irqbalance.service kdump.service microcode.service rsyslog.service sshd.service sysstat.service systemd-readahead-collect.service systemd-readahead-drop.service systemd-readahead-replay.service tuned.service lvm2-lvmetad.socket lvm2-lvmpolld.socket default.target multi-user.target runlevel2.target runlevel3.target runlevel4.target ;do systemctl enable $serv;done
}
if [ $system_name=centos6.* ] ;then
service_centos6_conf && file_op6_conf
fi
if [ $system_name=centos7.* ] ;then
service_centos7_conf && file_op7_conf
fi
jdk_e
selinux_conf
if [ $? -eq 0 ];then
reboot
fi