【皇家国际娱乐】一键优化CentOS系统,最小安装

在设想机上设置CentOS
6.4,比起第壹次安装境遇各样主题材料种种Google,此次好不轻巧弹无虚发了。本着做一件事超越四次就自动化的标准,把起初设置的写成脚本运营。

shell脚本:一键优化CentOS系统

和煦参谋了系统优化的点,写了贰个一键优化脚本,适用于CentOS6.x版本,种种项已经独立举行测验通过。适用于CentOS6.x系统最小化安装施行,能够依据自身的需要开始展览增添或涂改完善。

最首要优化内容有:

关闭系统不须求的劳务;关闭selinux,关闭iptables;关闭ctrl+alt+del重启;设置ssh端口,关闭DNS深入分析;设置系统最大文件汇报符;设置系统首要性文件权限;配置安装ntp;安装vim;配置安装Ali云yum源和epel源;

剧本如下:

[[email protected]
~]# cat youhua.sh
#!/bin/bash
#written by
[email protected]
#system optimization script
#The fllow apply to CentOS 6.x
. /etc/init.d/functions
 
function check_ok(){
  if [ $? -eq 0 ]
  then
    echo “”
    continue
  else
    echo “pls check error”
    exit
  fi
}
 

首先配置网络,小编那边运用的是静态IP,脚本中sed加-i参数能够将扭转写入到文件。

cat<<EOF

#!/bin/bash
#皇家国际娱乐,static
cd /etc/sysconfig/network-scripts
sed -i ‘s/ONBOOT=no/ONBOOT=yes/g’ ifcfg-eth0
sed -i ‘s/dhcp/static/g’ ifcfg-eth0
echo IPADDR=10.14.112.*** >> ifcfg-eth0
echo NETMASK=255.255.255.0 >> ifcfg-eth0
echo GATEWAY=10.14.112.1 >> ifcfg-eth0
echo DNS1=10.10.0.** >> ifcfg-eth0
service network restart

|                    system optimization                            |

EOF
 
#close unimportant system services
echo “===Close unimportant system services,it will take serval
mintinues===”
for s in `chkconfig –list|grep 3:on|awk ‘{print $1}’|grep -Ev
“crond|sshd|sysstat|rsyslog|network”`
do
  chkconfig $s off
done
check_ok
action “Close unimportant system services” /bin/true
 
 
#close selinux
echo “===close SELINUX===”
if [ `getenforce` != “Disabled” ]
then
 sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
 echo “selinux is disabled,you must reboot!”
else
 action “SELINUX is closed” /bin/true
fi
check_ok
action “Close SELINUX” /bin/true
 
 
#close ctrl+alt+del
mv /etc/init/control-alt-delete.conf
/etc/init/control-alt-delete.conf.bak
 
 
#close iptables
echo “===close iptables===”
iptables-save >/etc/sysconfig/iptables_$(date +%s)
iptables -F
service iptables save
check_ok
action “iptables is closed” /bin/true
 
 
#set ulimit
echo “ulimit -SHn 65535” >>/etc/rc.local
 
#set SSH
sed -i ‘s/#UseDNS yes/UseDNS no/g’ /etc/ssh/sshd_config
sed -i ‘s/#Port 22/Port 65500/g’ /etc/ssh/sshd_config
service sshd restart
 
 
#set system files permission
chmod 600 /etc/passwd
chmod 600 /etc/group
chmod 600 /etc/shadow
chmod 600 /etc/gshadow
 
 
#set ntp
yum install ntpdate -y
ntpdate ntp.fudan.edu.cn
echo “* 3 * * * /usr/sbin/ntpdate ntp.fudan.edu.cn >/dev/null
2>&1” >>/etc/crontab
service crond restart
check_ok
action “ntpdate is installed and add in crontab” /bin/true
 
 
#set vim
echo “===install vim,it will take serval mintinues===”
yum install vim-enhanced -y &>/dev/null
alias vi=vim
echo “alias vi=vim” >>/root/.bashrc
check_ok
action “vim is installed” /bin/true
 
 
#set yum repos
echo “===update yum repos,it will take serval mintinues===”
yum install wget -y
mv /etc/yum.repos.d/CentOS-Base.repo
/etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo
&>/dev/null
wget -O /etc/yum.repos.d/epel.repo
&>/dev/null
yum clean all &>/dev/null
yum makecache &>/dev/null
check_ok
action  “yum repos update is ok” /bin/true

本身参考了系统优化的点,写了三个一键优化脚本,适用于CentOS6.x版本,各类项已经独自进行测量检验通过。适用…

接着配置yum源,使用的是校内源。

#!/bin/bash
#
SHELL_HOME=`cd $RELATIVE_PATH;pwd`
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.backup
cp ${SHELL_HOME}/CentOS-Base-zju.repo CentOS-Base.repo
sed -i ‘s/enabled=1/enabled=0/g’
/etc/yum/pluginconf.d/fastestmirror.conf
yum makecache
yum update -y

运作过那三个本子,基本就足以利用了。当然还要设置vim等常用软件。
上边是谷歌(Google)来的,一般还索要安装的常用软件:

安装
nslookup、traceroute、wget、man、sudo、ntp、ntpdate组件,安装screen、patch、make
gcc、gcc-c++、flex、bison

发表评论

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

网站地图xml地图