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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
| #!/bin/sh
#mysql密码
mysqlps=123
#nagios账户密码
nagiospa=123
#nagiosadmin账户密码
nagadps=123
#获取本机IP
hostip=` ip a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|sed "s%/24%%g" `
#安装LAMP
yum -y install httpd mariadb-server mariadb php php-mysql php-gd php-pear
systemctl start httpd
systemctl enable httpd
systemctl start mariadb
systemctl enable mariadb
expect <<EOF
set timeout -1
spawn mysql_secure_installation
expect {
"*(enter for none):" { send "\r"; exp_continue }
"*password:" { send "${mysqlps}\r"; exp_continue }
"*password:" { send "${mysqlps}\r"; exp_continue }
"*users?" { send "Y\r"; exp_continue }
"*remotely?" { send "Y\r"; exp_continue }
"*it?" { send "Y\r"; exp_continue }
"*now?" { send "Y\r"; exp_continue }
}
expect eof
EOF
#安装Nagios
yum install -y gd gd-devel gcc glibc glibc-common openssl openssl-devel openssl-perl unzip wget
useradd -m nagios
expect <<EOF
set timeout -1
spawn passwd nagios
expect {
"*password:" { send "${nagiospa}\r";exp_continue }
"*password:" { send "${nagiospa}\r" }
}
expect eof
EOF
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
cd /tmp
wget https://assets.nagios.com/downlo ... nagios-4.1.1.tar.gz
tar xzf nagios-4.1.1.tar.gz
cd nagios-4.1.1
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
make install-exfoliation
make install-classicui
#安装nagios-plugins、nrpe
yum install -y nagios-plugins* nrpe*
echo -e "#'check_nrpe' command definition
define command{
\tcommand_name check_nrpe
\tcommand_line \$USER1\$/check_nrpe -H \$HOSTADDRESS\$ -c \$ARG1\$
}">>/usr/local/nagios/etc/objects/commands.cfg
sed -i "s/nrpe_user=nrpe/nrpe_user=nagios/g" /etc/nagios/nrpe.cfg
sed -i "s/nrpe_group=nrpe/nrpe_group=nagcmd/g" /etc/nagios/nrpe.cfg
sed -i "s%/usr/local/nagios/libexec%/usr/lib64/nagios/plugins%g" /usr/local/nagios/etc/resource.cfg
#设置nagios Web 访问密码
expect <<EOF
set timeout -1
spawn htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
expect {
"*password:" { send "${nagadps}\r";exp_continue }
"*password:" { send "${nagadps}\r" }
}
expect eof
EOF
#修复假报警
touch /var/www/html/index.html
#重启服务
systemctl restart httpd
ln -s /usr/local/nagios/bin/nagios /usr/bin/
nagios -v /usr/local/nagios/etc/nagios.cfg
systemctl start nrpe
systemctl enable nrpe
systemctl start nagios
chkconfig nagios on
systemctl restart httpd
systemctl status -l nrpe
systemctl status -l nagios
systemctl status -l httpd
echo "请访问http://${hostip}/nagios验证配置!!"
|