|
紧承上文《CentOS 6系统优化脚本》,因为有时候一台虚拟机已经刷过了优化脚本,但是可能因为别的原因,这台虚拟机暂时搁置了。等过了一段时间之后,突然要用又不知道这台虚拟机是否已经优化过了,而重新使用cobbler刷一次系统又会耗费一定的时间,所以这个检测系统是否刷过优化脚本的shell脚本就诞生了。脚本不是特别准确,但是能针对上次的优化脚本做一个检查,如果已经刷过脚本,就会通过运行该脚本知道系统已经优化过了,可以立即投入使用,避免浪费时间重新再刷一次系统。如果是一个完全重新安装的CentOS 6.x,那结果也可以看出该虚拟机并未优化过,那么执行优化脚本优化一次即可。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
| #!/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/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
|
|
|