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

基于Nginx平台部署Nagios监控系统

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-4-22 09:07:08 | 显示全部楼层 |阅读模式
环境:CentOS 6.5(最小化安装)
Nginx:1.6.2
Nagios:3.3.1

安装基本环境:
1
2
[iyunv@localhost software]# yum -y install gcc gcc-c++
[iyunv@localhost software]# yum -y install perl-devel perl



源码安装PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[iyunv@localhost software]# yum -y install mysql mysql-devel
[iyunv@localhost software]# yum -y install gd-2.0.35-11.el6.x86_64.rpm gd-devel-2.0.35-11.el6.x86_64.rpm
[iyunv@localhost software]# yum -y install libxml2 libxml2-devel
[iyunv@localhost software]# tar -zxvf zlib-1.2.7.tar.gz &>/dev/null
[iyunv@localhost software]# cd zlib-1.2.7
[iyunv@localhost zlib-1.2.7]# ./configure -prefix=/usr/local/zlib  &&make &&make install
[iyunv@localhost software]# tar -zxvf libmcrypt-2.5.7.tar.gz &>/dev/null
[iyunv@localhost software]# cd libmcrypt-2.5.7
[iyunv@localhost libmcrypt-2.5.7]# ./configure &&make &&make install
[iyunv@localhost software]# useradd -s /sbin/nologin www
[iyunv@localhost software]# tar -jxvf php-5.3.8.tar.bz2 &>/dev/null
[iyunv@localhost software]# cd php-5.3.8
[iyunv@localhost php-5.3.8]# ./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
[iyunv@localhost php-5.3.8]# make &&make install
[iyunv@localhost ~]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[iyunv@localhost ~]# sed -i '/run\/php-fpm.pid/s/^;//g' /usr/local/php/etc/php-fpm.conf
[iyunv@localhost ~]# sed -i '/^;pm.min_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
[iyunv@localhost ~]# sed -i '/^;pm.max_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
[iyunv@localhost ~]# sed -i '/^;pm.start_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
[iyunv@localhost ~]# /usr/local/php/sbin/php-fpm
[iyunv@localhost ~]# echo '/usr/local/php/sbin/php-fpm'>>/etc/rc.local



[iyunv@localhost ~]# netstat -tunlp |grep php

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      1592/php-fpm        

[iyunv@localhost ~]# ps -ef|grep php|grep -v grep
root       1592      1  0 12:36 ?        00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
www        1593   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1594   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1595   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1596   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1597   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1598   1592  0 12:36 ?        00:00:00 php-fpm: pool www
www        1599   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1600   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1601   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1602   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1603   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1604   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1605   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1606   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1607   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1608   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1609   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1610   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1611   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
www        1612   1592  0 12:36 ?        00:00:00 php-fpm: pool www         
[iyunv@localhost ~]#

安装Nginx:

1
2
3
4
5
6
7
8
9
10
11
[iyunv@localhost software]# tar -jxvf pcre-8.12.tar.bz2 &>/dev/null
[iyunv@localhost software]# cd pcre-8.12
[iyunv@localhost pcre-8.12]# ./configure &&make &&make install
zlib上面安装php时已安装
[iyunv@localhost software]# tar -zxvf openssl-1.0.1c.tar.gz &>/dev/null
[iyunv@localhost software]# cd openssl-1.0.1c
[iyunv@localhost openssl-1.0.1c]# ./config &&make &&make install
[iyunv@localhost software]# tar -zxvf nginx-1.6.2.tar.gz &>/dev/null
[iyunv@localhost software]# cd nginx-1.6.2
[iyunv@localhost nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-pcre=/software/pcre-8.12 --with-zlib=/software/zlib-1.2.7 --with-openssl=/software/openssl-1.0.1c --with-http_stub_status_module
[iyunv@localhost nginx-1.6.2]# make &&make install



编写/etc/init.d/nginx文件

[iyunv@localhost nginx-1.6.2]# /etc/init.d/nginx start

Starting nginx:                                            [  OK  ]

[iyunv@localhost nginx-1.6.2]#

1
2
3
[iyunv@localhost nginx-1.6.2]# chkconfig --add nginx
[iyunv@localhost nginx-1.6.2]# chkconfig nginx on
[iyunv@localhost conf]# ln -s /usr/local/nagios/share /usr/local/nginx/html/nagios



[iyunv@localhost conf]# ll /usr/local/nginx/html/

total 8

-rw-r--r-- 1 root root 537 Apr 18 10:59 50x.html

-rw-r--r-- 1 root root 612 Apr 18 10:59 index.html

lrwxrwxrwx 1 root root  23 Apr 18 12:43 nagios -> /usr/local/nagios/share

还需要自己编写nginx.conf、fastcgi.conf、cgi.conf、start_perl_cgi.sh、perl-fcgi.pl

[iyunv@localhost conf]#

给Nginx添加对Perl的CGI支持(默认不支持):
安装FCGI模块:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[iyunv@localhost software]# tar -zxvf FCGI-0.73.tar.gz &>/dev/null
[iyunv@localhost software]# cd FCGI-0.73
[iyunv@localhost FCGI-0.73]# perl Makefile.PL &&make &&make install
[iyunv@localhost software]# tar -zxvf FCGI-ProcManager-0.25.tar.gz &>/dev/null
[iyunv@localhost software]# cd FCGI-ProcManager-0.25
[iyunv@localhost FCGI-ProcManager-0.25]# perl Makefile.PL &&make &&make install
[iyunv@localhost software]# tar -zxvf IO-1.25.tar.gz &>/dev/null
[iyunv@localhost software]# cd IO-1.25
[iyunv@localhost IO-1.25]# perl Makefile.PL &&make &&make install
[iyunv@localhost software]# tar -zxvf IO-All-0.39.tar.gz &>/dev/null
[iyunv@localhost software]# cd IO-All-0.39
[iyunv@localhost IO-All-0.39]# perl Makefile.PL &&make &&make install
[iyunv@localhost software]# tar -zxvf spawn-fcgi-1.6.3.tar.gz &>/dev/null
[iyunv@localhost software]# cd spawn-fcgi-1.6.3
[iyunv@localhost spawn-fcgi-1.6.3]# ./configure &&make &&make install
[iyunv@localhost software]# unzip perl-fcgi.zip
[iyunv@localhost software]# cp perl-fcgi.pl /usr/local/nginx/
[iyunv@localhost software]# chmod 755 /usr/local/nginx/perl-fcgi.pl
[iyunv@localhost software]# cd /usr/local/nginx/
[iyunv@localhost nginx]# chmod 755 start_perl_cgi.sh



编写start_perl_cgi.sh脚本
1
[iyunv@localhost nginx]# ./start_perl_cgi.sh start



start perl-fcgi done
[iyunv@localhost nginx]# ll /usr/local/nginx/logs/perl-fcgi.sock
srwxr-xr-x 1 www www 0 Apr 18 11:02 /usr/local/nginx/logs/perl-fcgi.sock
[iyunv@localhost nginx]# echo "/bin/sh /usr/local/nginx/start_perl_cgi.sh start" >>/etc/rc.local
安装Nagios:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[iyunv@localhost software]# yum -y install libgd2-noxpm libgd2-noxpm-dev
[iyunv@localhost software]# yum -y install php-gd
[iyunv@localhost software]# groupadd nagcmd
[iyunv@localhost software]# useradd -G nagcmd nagios
[iyunv@localhost software]# usermod -G nagcmd www
[iyunv@localhost software]# tar -zxvf nagios-3.3.1.tar.gz &>/dev/null
[iyunv@localhost software]# cd nagios
[iyunv@localhost nagios]# ./configure --with-command-group=nagcmd --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-nc=/usr/include
[iyunv@localhost nagios]# make all &&make install &&make install-init &&make install-config &&make install-commandmode
[iyunv@localhost nagios]# yum -y install httpd-tools
[iyunv@localhost nagios]# cd /usr/local/nagios/etc/
[iyunv@localhost etc]# htpasswd -cm htpasswd.users yfshare
[iyunv@localhost etc]# sed -i '/authorized\_for\_/s/nagiosadmin/&\,yfshare/g' cgi.cfg
[iyunv@localhost etc]# cd /usr/local/nginx/conf/
[iyunv@localhost etc]# mkdir /usr/local/nagios/logs



[iyunv@localhost etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg |grep ^Total
Total Warnings: 0
Total Errors:   0
[iyunv@localhost etc]# /etc/init.d/nagios start
Starting nagios: done.
1
2
[iyunv@localhost etc]# chkconfig --add nagios
[iyunv@localhost etc]# chkconfig nagios on



也可通过访问http://www.4webhelp.net/us/password.php生成htpasswd.users
QQ截图20150422090437.png
[iyunv@localhost etc]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[iyunv@localhost etc]#
[iyunv@localhost conf]# /etc/init.d/nginx restart
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[iyunv@localhost conf]#
安装Nagios-plugin:
1
2
3
4
5
6
7
[iyunv@localhost software]# tar -zxvf nagios-plugins-1.4.15.tar.gz &>/dev/null
[iyunv@localhost software]# cd nagios-plugins-1.4.15
[iyunv@localhost nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
[iyunv@localhost nagios-plugins-1.4.15]# make &&make install
[iyunv@localhost software]# ls /usr/local/nagios/libexec/|wc -l
58
[iyunv@localhost software]#




安装NRPE:
1
2
3
4
5
6
7
8
9
[iyunv@localhost software]# yum -y install openssl openssl-devel
[iyunv@localhost software]# tar -zxvf nrpe-2.13.tar.gz &>/dev/null
[iyunv@localhost software]# cd nrpe-2.13
[iyunv@localhost nrpe-2.13]# ./configure
[iyunv@localhost nrpe-2.13]# make all &&make install-plugin &&make install-daemon &&make install-daemon-config
[iyunv@localhost nrpe-2.13]# cd /usr/local/nagios/etc/
[iyunv@localhost etc]# sed -i '/allowed_host/s/127.0.0.1/&,192.168.10.99/g' nrpe.cfg
[iyunv@localhost etc]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[iyunv@localhost etc]# echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local



[iyunv@localhost etc]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.13
[iyunv@localhost etc]#

QQ截图20150422090447.png
但是,打开页面时,其他选项卡都是显示的502 Bad Gateway
[iyunv@localhost ~]# chown nagios:nagcmd /usr/local/nagios/ -R
[iyunv@localhost ~]# chown www:nagcmd /usr/local/nginx/ -R
[iyunv@localhost ~]# cd /usr/local/nginx/


[iyunv@localhost nginx]# ./start_perl_cgi.sh start
ERROR PID file /usr/local/nginx/logs/perl-fcgi.pid already exists
start perl-fcgi done
[iyunv@localhost nginx]#
因为perl-fcgi进程意外中断,但是进程未退出变成了孤儿进程,所以就变成这样了
修改下脚本start_perl_cgi.sh
[iyunv@localhost nginx]# ./start_perl_cgi.sh start
start perl-fcgi done
[iyunv@localhost nginx]#
[iyunv@localhost nginx]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[iyunv@localhost nginx]# /etc/init.d/nginx restart
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[iyunv@localhost nginx]#
QQ截图20150422090455.png
OK,在Nginx上安装Nagios成功
如果出现上面的问题,解决方法:
1
[iyunv@localhost ~]# sed -i '/use_authentication/s/1/0/g' /usr/local/nagios/etc/cgi.cfg



[iyunv@localhost ~]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[iyunv@localhost ~]# /etc/init.d/nginx restart
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[iyunv@localhost ~]#
访问http://192.168.10.99/nagios/
QQ截图20150422090504.png
OK,Successful

运维网声明 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-59470-1-1.html 上篇帖子: Nagios 监控服务器剩余内存 下篇帖子: 监控服务器Nagios之一 概述及安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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