设为首页 收藏本站
查看: 4929|回复: 0

LNMP+Nagios server一键安装脚本

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-5-12 08:50:11 | 显示全部楼层 |阅读模式
以下是LNMP+Nagios Server端的安装脚本,脚本预计需要执行半小时,当脚本执行完毕后你的基于LNMP的Nagios Server端就装好啦 j_0058.jpg


下面是效果图:

QQ截图20150512084911.png
QQ截图20150512084959.png
QQ截图20150512084930.png

下面是脚本代码: keai.jpg (写的不太好,求大神们指点 kelian.jpg

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



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-66113-1-1.html 上篇帖子: nagios监控redis端口、监控url接口告警脚本 下篇帖子: NAGIOS安装配置文档 server
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表