shell脚本:一键优化CentOS系统

主要优化内容有:

创新互联为企业级客户提高一站式互联网+设计服务,主要包括网站建设、做网站成都App定制开发微信平台小程序开发、宣传片制作、LOGO设计等,帮助客户快速提升营销能力和企业形象,创新互联各部门都有经验丰富的经验,可以确保每一个作品的质量和创作周期,同时每年都有很多新员工加入,为我们带来大量新的创意。 

关闭系统不必要的服务;关闭selinux,关闭iptables;关闭ctrl+alt+del重启;设置ssh端口,关闭DNS解析;设置系统最大文件描述符;设置系统关键文件权限;配置安装ntp;安装vim;配置安装阿里云yum源和epel源;

脚本如下:

[root@localhost ~]# cat youhua.sh
#!/bin/bash
#written by mofansheng@2015-11-03
#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
}
 
cat<-----------------------------------------------------------------------
|                    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 http://mirrors.aliyun.com/repo/Centos-6.repo &>/dev/null
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo &>/dev/null
yum clean all &>/dev/null
yum makecache &>/dev/null
check_ok
action  "yum repos update is ok" /bin/true

本文题目:shell脚本:一键优化CentOS系统
URL地址:http://www.stwzsj.com/qtweb/news31/1031.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联