標籤:系統最佳化 shell optimize centos 檢測 指令碼
緊承上文《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 Jerry12356 on May 16th, 2016#####################################################################################. /etc/init.d/functionscheck_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_iptablescheck_selinuxcheck_adduserscheck_installcheck_reposcheck_timecheck_servicescheck_historycheck_kernelcheck_hostname
本文出自 “IT小二郎” 部落格,請務必保留此出處http://jerry12356.blog.51cto.com/4308715/1839284
CentOS 6 系統最佳化檢測指令碼