在实际工作中,服务部署安装程序之前总是要进行服务器的基础配置,手动配置呢既麻烦又浪费时间,这里编写一个shell脚本来完成,主要完成工作:
(1)修改服务器的最大连接数为65535
(2)关闭selinux
(3)关闭防火墙
(4)修改服务器字符集–已注释代码
(5)配置hostname
#!/bin/bash
#create skyfans
#version v1.0
#注意:49行请修改你时间的网卡的名字
function pluge()
{
#修改文件最大连接数为65534
check_limit=`grep "65534" /etc/security/limits.conf|wc -l`
#关闭selinux
check_SELINUX=`grep "SELINUX=disabled" /etc/sysconfig/selinux |wc -l`
#根据实际要求修改字符集,这里默认为UTF-8,所有注释掉
#check_LANG=`grep "zh_CN.GB18030" /etc/sysconfig/i18n|wc -l `
# if [ $check_LANG -lt 1 ]
# then
# sed -i 's/en_US.UTF-8/zh_CN.GB18030/' /etc/sysconfig/i18n
# source /etc/sysconfig/i18n
# echo $LANG
# else
# echo "LANG alreay pluge"
# fi
if [ $check_limit -lt 1 ]
then
cat >>/etc/security/limits.conf<<EOF
* soft nofile 65534
* hard nofile 65534
EOF
tail /etc/security/limits.conf
else
echo "limits already pluge"
fi
if [ $check_SELINUX -lt 1 ]
then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
else
echo "SELINUX alreay pluge"
fi
#关闭防火墙
service iptables stop
chkconfig iptables off
service ip6tables stop
chkconfig ip6tables off
setenforce 0
echo "iptables already closed,please input 'service iptables status ' check"
}
function pluge_nameserver() {
#注意修改服务器实际的网卡地址
getIp=`ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'`
gethostname=`hostname`
check_nameserver=`grep $getIp /etc/hosts |wc -l`
if [ $check_nameserver -lt 0 ]
then
echo "$getIp $gethostname " >> /etc/hosts
else
echo "nameserver alreay pluge"
fi
}
function check_nameserver(){
gethostname=`hostname`
ping $gethostname -c 4
if [ $? -eq 0 ]
then
echo "nameserver pluge susccess"
else
echo "nameserver pluge failed"
fi
}
pluge
pluge_nameserver
check_nameserver