CentOS 6 系统优化检测脚本

紧承上文《CentOS 6系统优化脚本》,因为有时候一台虚拟机已经刷过了优化脚本,但是可能因为别的原因,这台虚拟机暂时搁置了。等过了一段时间之后,突然要用又不知道这台虚拟机是否已经优化过了,而重新使用cobbler刷一次系统又会耗费一定的时间,所以这个检测系统是否刷过优化脚本的shell脚本就诞生了。脚本不是特别准确,但是能针对上次的优化脚本做一个检查,如果已经刷过脚本,就会通过运行该脚本知道系统已经优化过了,可以立即投入使用,避免浪费时间重新再刷一次系统。如果是一个完全重新安装的CentOS 6.x,那结果也可以看出该虚拟机并未优化过,那么执行优化脚本优化一次即可。

#!/bin/bash
#####################################################################################
#The script is used to check whether the optimize script had been run on CentOS 6.x
#Created by shengwei
#####################################################################################
/etc/init .d /functions
 
check_iptables(){
      /etc/init .d /iptables  status  > /dev/null  2>&1
      [ $? - ne  0 ] && action  "Optimize iptables: "  /bin/true  || action  "Optimize iptables: "  /bin/false
}
 
check_selinux(){
      selinux_status=`getenforce`
      [ $selinux_status ==  'Disabled'  ] && action  "Optimize selinux: "  /bin/true  || action  "Optimize selinux: "  /bin/false
}
 
check_addusers(){
      egrep  "admin|nginx|zabbix"  /etc/passwd   >> /dev/null  2>&1
      [ $? - eq  0 ] && action  "Add users: "  /bin/true  || action  "Add users: "  /bin/false
}
 
check_install(){
      rpm -qa| egrep  "gcc|gcc-c++|openssh-clients|wget|make|cmake|curl|finger|nmap|tcp_wrappers|expect|lrzsz|unzip|zip|xz|ntpdate|lsof|telnet|vim|tree"  > /dev/null  2>&1 
      [ $? - eq  0 ] && action  "Install softwares: "  /bin/true  || action  "Install softwares: "  /bin/false
}
 
check_repos(){
      [ -d  /etc/yum .repos.d /bak  ] && action  "Update repos: "  /bin/true  || action  "Update repos: "  /bin/false
}
 
check_time(){
      date  -R | grep  +0800 > /dev/null  2>&1
      [ $? - eq  0 ] && action  "Setting timezone: "  /bin/true  || action  "Setting timezone: "  /bin/false
      crond_num=` crontab  -l| grep  ntpdate| wc  -l`
      [ $crond_num - ge  1 ] && action  "Sync time: "  /bin/true  || action  "Sync time: "  /bin/false
}
 
check_services(){
      service_num=`chkconfig --list | grep  3:on| egrep  "crond|network|rsyslog|sshd" | wc  -l`
      [ $service_num - eq  4 ] && action  "Optimize services: "  /bin/true  || action  "Optimize services: "  /bin/false
}
 
check_history(){
      [ $HISTSIZE - eq  10000 ] && action  "Setting history: "  /bin/true  || action  "Setting history: "  /bin/false
 
check_kernel(){
      conn_num=` ulimit  -n`
      [ $conn_num - eq  2097152 ] && action  "Optimize kernel: "  /bin/true  || action  "Optimize kernel: "  /bin/false
}
 
check_hostname(){
      [ $HOSTNAME !=  'localhost.localdomain'  ] && action  "Change hostname: "  /bin/true  || action  "Change hostname: "  /bin/false
}
 
 
 
check_iptables
check_selinux
check_addusers
check_install
check_repos
check_time
check_services
check_history
check_kernel
check_hostname
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值