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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
| #!/bin/bash
#date:2015-5-10
#author:yfshare
#mail:838554604@qq.com
function check_service() {
a=`netstat -tunlp |grep ${1} |wc -l`
b=`ps -ef|grep ${1}|grep -v grep|wc -l`
while true
do
if [ ${a} -ge 1 ] || [ ${b} -ge 1 ];then
echo -e "${1} started successfully"
break
else
echo -e "${1} failed to start"
/bin/sh $2
sleep 2
fi
done
}
aa="/dev/null"
read -p 'please input software path:' path
yum -y install httpd-tools &>${aa}
echo ''
echo -e 'Please input the password for user admin:'
htpasswd -cm $path/conf/htpasswd.users admin
cd $path
yum -y install gcc gcc-c++ perl perl-devel mysql mysql-devel libxml2 libxml2-devel unzip &>${aa}
yum -y install gd-2.0.35-11.el6.x86_64.rpm gd-devel-2.0.35-11.el6.x86_64.rpm &>${aa}
echo -e ''
echo -e 'Nginx+Nagios software install...'
#install php
tar -zxvf zlib-1.2.7.tar.gz -C $path &>${aa}
cd $path/`tar -zxvf ${path}/zlib-1.2.7.tar.gz|head -n 1|awk -F/ '{print $1}'`
./configure -prefix=/usr/local/zlib &>${aa} &&make &>${aa} &&make install &>${aa}
tar -zxvf ${path}/libmcrypt-2.5.7.tar.gz -C $path >${aa}
cd $path/`tar -zxvf ${path}/libmcrypt-2.5.7.tar.gz|head -n 1|awk -F/ '{print $1}'`
./configure &>${aa} &&make &>${aa} &&make install &>${aa}
useradd -s /sbin/nologin www >${aa}
groupadd nagcmd &&useradd -G nagcmd nagios &&usermod -G nagcmd www
tar -jxvf $path/php-5.3.8.tar.bz2 -C $path &>${aa}
cd $path/`tar -jxvf ${path}/php-5.3.8.tar.bz2|head -n 1|awk -F/ '{print $1}'`
./configure --prefix=/usr/local/php --enable-mbstring --enable-soap --enable-wddx=shared --enable-xml --with-gd --with-gettext --with-regex=system --with-zlib-dir=/usr/local/zlib --enable-fpm --with-jpeg-dir --with-fpm-user=www --with-fpm-group=www --enable-shmop --with-mcrypt --with-mysqli=mysqlnd &>${aa} &&make &>${aa} &&make install &>${aa}
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
sed -i '/run\/php-fpm.pid/s/^;//g' /usr/local/php/etc/php-fpm.conf
sed -i '/^;pm.min_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
sed -i '/^;pm.max_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
sed -i '/^;pm.start_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
/usr/local/php/sbin/php-fpm >${aa}
echo '/usr/local/php/sbin/php-fpm'>>/etc/rc.local
check_service php "/usr/local/php/sbin/php-fpm"
#install nginx
tar -jxvf $path/pcre-8.12.tar.bz2 -C $path &>${aa}
cd $path/`tar -jxvf $path/pcre-8.12.tar.bz2|head -n 1|awk -F/ '{print $1}'`
./configure &>${aa} &&make &>${aa} &&make install &>${aa}
tar -zxvf $path/openssl-1.0.1c.tar.gz -C $path &>${aa}
cd $path/`tar -zxvf $path/openssl-1.0.1c.tar.gz|head -n 1|awk -F/ '{print $1}'`
./config &>${aa} &&make &>${aa} &&make install &>${aa}
tar -zxvf $path/nginx-1.6.2.tar.gz -C $path &>${aa}
cd $path/`tar -zxvf $path/nginx-1.6.2.tar.gz|head -n 1|awk -F/ '{print $1}'`
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-pcre=${path}/pcre-8.12 --with-zlib=${path}/zlib-1.2.7 --with-openssl=${path}/openssl-1.0.1c --with-http_stub_status_module &>${aa} &&make &>${aa} &&make install &>${aa}
cp $path/conf/etc_init.d_nginx /etc/init.d/nginx >${aa}
chown www:www /usr/local/nginx -R
chmod 775 /etc/init.d/nginx &&/etc/init.d/nginx start >${aa}
chkconfig --add nginx >${aa} && chkconfig nginx on >${aa}
check_service nginx "/etc/init.d/nginx start"
cat $path/conf/nginx.conf >/usr/local/nginx/conf/nginx.conf
cat $path/conf/fastcgi.conf >/usr/local/nginx/conf/fastcgi.conf
cat $path/conf/fcgi.conf >/usr/local/nginx/conf/fcgi.conf
cat $path/conf/start_perl_cgi.sh > /usr/local/nginx/start_perl_cgi.sh
chmod 775 /usr/local/nginx/start_perl_cgi.sh
#install FCGI
tar -zxvf $path/FCGI-0.73.tar.gz -C $path &>${aa}
cd $path/`tar -zxvf $path/FCGI-0.73.tar.gz|head -n 1|awk -F/ '{print $1}'`
perl Makefile.PL &>${aa} &&make &>${aa} &&make install &>${aa}
tar -zxvf $path/FCGI-ProcManager-0.25.tar.gz -C $path &>${aa}
cd $path/`tar -zxvf $path/FCGI-ProcManager-0.25.tar.gz|head -n 1|awk -F/ '{print $1}'`
perl Makefile.PL &>${aa} &&make &>${aa} &&make install &>${aa}
tar -zxvf $path/IO-1.25.tar.gz -C $path &>${aa}
cd $path/`tar -zxvf $path/IO-1.25.tar.gz|head -n 1|awk -F/ '{print $1}'`
perl Makefile.PL &>${aa} &&make &>${aa} &&make install &>${aa}
tar -zxvf $path/IO-All-0.39.tar.gz -C $path &>${aa}
cd $path/`tar -zxvf $path/IO-All-0.39.tar.gz|head -n 1|awk -F/ '{print $1}'`
perl Makefile.PL &>${aa} &&make &>${aa} &&make install &>${aa}
tar -zxvf $path/spawn-fcgi-1.6.3.tar.gz -C $path &>${aa}
cd $path/`tar -zxvf $path/spawn-fcgi-1.6.3.tar.gz|head -n 1|awk -F/ '{print $1}'`
./configure &>${aa} &&make &>${aa} &&make install &>${aa}
cd $path &&unzip $path/perl-fcgi.zip &>${aa}
cp $path/perl-fcgi.pl /usr/local/nginx/ >${aa}
chmod 755 /usr/local/nginx/perl-fcgi.pl
/usr/local/nginx/start_perl_cgi.sh start >${aa}
echo "/bin/sh /usr/local/nginx/start_perl_cgi.sh start" >>/etc/rc.local
c=`ls /usr/local/nginx/logs/|grep "perl-fcgi.sock"|wc -l`
while true
do
if [ $c -eq 1 ];then
echo -e 'start perl-fcgi done'
break
else
echo -e 'perl-fcgi failed to start'
/usr/local/nginx/start_perl_cgi.sh start >${aa}
fi
done
#install Nagios
yum -y install php-gd &>${aa}
tar -zxvf $path/nagios-3.3.1.tar.gz -C $path &>${aa}
cd $path/`tar -zxvf $path/nagios-3.3.1.tar.gz|head -n 1|awk -F/ '{print $1}'`
./configure --with-command-group=nagcmd --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-nc=/usr/include &>${aa} &&make all &>${aa} &&make install &>${aa} &&make install-init &>${aa} &&make install-config &>${aa} &&make install-commandmode &>${aa}
sed -i '/authorized\_for\_/s/nagiosadmin/&\,admin/g' /usr/local/nagios/etc/cgi.cfg
mv $path/conf/htpasswd.users /usr/local/nagios/etc/
mkdir /usr/local/nagios/logs
sed -i '/use_authentication/s/1/0/g' /usr/local/nagios/etc/cgi.cfg
sed -i '/requiretty$/s/^Defaults/#&/g' /etc/sudoers
chown nagios:nagcmd /usr/local/nagios -R
chkconfig --add nagios &&chkconfig nagios on
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg |grep ^Total >${aa}
/etc/init.d/nagios start >${aa}
check_service nagios "/etc/init.d/nagios start"
#install Nagios-plugin
tar -zxvf $path/nagios-plugins-1.4.15.tar.gz -C $path &>${aa}
cd $path/`tar -zxvf $path/nagios-plugins-1.4.15.tar.gz|head -n 1|awk -F/ '{print $1}'`
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules &>${aa}
make &>${aa} &&make install &>${aa}
d=`ls /usr/local/nagios/libexec/|wc -l`
echo -e "nagios/libexec:${d}"
#install NRPE
yum -y install openssl-devel &>${aa}
tar -zxvf ${path}/nrpe-2.13.tar.gz -C $path &>${aa}
cd $path/`tar -zxvf ${path}/nrpe-2.13.tar.gz|head -n 1|awk -F/ '{print $1}'`
./configure &>${aa} &&make all &>${aa} &&make install-plugin &>${aa} &&make install-daemon &>${aa} &&make install-daemon-config &>${aa}
e=`ifconfig eth0|grep "inet addr"|awk '{print $2}'|awk -F: '{print $2}'`
sed -i "/allowed_host/s/127.0.0.1/&,${e}/g" /usr/local/nagios/etc/nrpe.cfg
echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local
chown nagios:nagcmd /usr/local/nagios -R
ln -s /usr/local/nagios/share /usr/local/nginx/html/nagios
/usr/local/nagios/libexec/check_nrpe -H localhost >${aa}
sed -i '/^:OUTPUT/a\-A INPUT \-m state \-\-state NEW \-m tcp \-p tcp \-\-dport 80 \-j ACCEPT' /etc/sysconfig/iptables
sed -i '/^:OUTPUT/a\-A INPUT \-m state \-\-state NEW \-m tcp \-p tcp \-\-dport 5666 \-j ACCEPT' /etc/sysconfig/iptables
sed -i '/^:OUTPUT/a\-A INPUT \-m state \-\-state NEW \-m tcp \-p tcp \-\-dport 9000 \-j ACCEPT' /etc/sysconfig/iptables
sed -i '/WorldWideWeb/s/http/#&/g' /etc/services
sed -i '/HyperText/s/http/#&/g' /etc/services
sed -i '/cslistener/s/cslistener/#&/g' /etc/services
sed -i "/WorldWideWeb/anginx\t 80\/tcp\nnginx\t80\/udp\nnginx\t80\/sctp" /etc/services
sed -i "9770 a php\-fpm\t9000\/tcp\nphp\-fpm\t9000\/udp" /etc/services
sed -i "/sfm-db-server/anrpe\t5666\/tcp\nnrpe\t5666\/udp" /etc/services
/etc/init.d/iptables restart >${aa} &&chkconfig iptables on
/etc/init.d/nagios restart
echo -e ''
/etc/init.d/nginx reload
|