基于Nginx平台安装Nagios监控系统

环境:CentOS 6.5(最小化安装)

Nginx:1.6.2

Nagios:3.3.1

安装基本环境:

[[email protected] software]# yum -y install gcc gcc-c++

[[email protected] software]# yum -y install perl-devel perl

源码安装PHP:

[[email protected] software]# yum -y install mysql mysql-devel

[[email protected] software]# yum -y install gd-2.0.35-11.el6.x86_64.rpm gd-devel-2.0.35-11.el6.x86_64.rpm

[[email protected] software]# yum -y install libxml2 libxml2-devel

[[email protected] software]# tar -jxvf php-5.3.8.tar.bz2 &>/dev/null

[[email protected] software]# tar -zxvf zlib-1.2.7.tar.gz &>/dev/null

[[email protected] software]# cd zlib-1.2.7

[[email protected] zlib-1.2.7]# ./configure -prefix=/usr/local/zlib  &&make &&make install

[[email protected] software]# tar -zxvf libmcrypt-2.5.7.tar.gz &>/dev/null

[[email protected] software]# cd libmcrypt-2.5.7

[[email protected] libmcrypt-2.5.7]# ./configure &&make &&make install

[[email protected] software]# useradd -s /sbin/nologin www

[[email protected] software]# cd php-5.3.8

[[email protected] 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

[[email protected] php-5.3.8]# make &&make install

[[email protected] ~]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[[email protected] ~]# sed -i ‘/run\/php-fpm.pid/s/^;//g‘ /usr/local/php/etc/php-fpm.conf

[[email protected] ~]# sed -i ‘/^;pm.min_spare_servers/s/^;//g‘ /usr/local/php/etc/php-fpm.conf

[[email protected] ~]# sed -i ‘/^;pm.max_spare_servers/s/^;//g‘ /usr/local/php/etc/php-fpm.conf

[[email protected] ~]# sed -i ‘/^;pm.start_servers/s/^;//g‘ /usr/local/php/etc/php-fpm.conf

[[email protected] ~]# /usr/local/php/sbin/php-fpm

[[email protected] ~]# echo ‘/usr/local/php/sbin/php-fpm‘>>/etc/rc.local

[[email protected] ~]# netstat -tunlp |grep php

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

[[email protected] ~]# 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

[[email protected] ~]#

php启动错误解决方法:http://yfshare.blog.51cto.com/8611708/1635679

安装Nginx:

[[email protected] software]# tar -jxvf pcre-8.12.tar.bz2 &>/dev/null

[[email protected] software]# cd pcre-8.12

[[email protected] pcre-8.12]# ./configure &&make &&make install

zlib上面安装php时已安装

[[email protected] software]# tar -zxvf openssl-1.0.1c.tar.gz &>/dev/null

[[email protected] software]# cd openssl-1.0.1c

[[email protected] openssl-1.0.1c]# ./config &&make &&make install

[[email protected] software]# tar -zxvf nginx-1.6.2.tar.gz &>/dev/null

[[email protected] software]# cd nginx-1.6.2

[[email protected] 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

[[email protected] nginx-1.6.2]# make &&make install

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

[[email protected] nginx-1.6.2]# /etc/init.d/nginx start

Starting nginx:                                            [  OK  ]

[[email protected] nginx-1.6.2]#

[[email protected] nginx-1.6.2]# chkconfig --add nginx

[[email protected] nginx-1.6.2]# chkconfig nginx on

[[email protected] conf]# ln -s /usr/local/nagios/share /usr/local/nginx/html/nagios

[[email protected] 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

[[email protected] conf]#

给Nginx添加对Perl的CGI支持(默认不支持):

安装FCGI模块:

[[email protected] software]# tar -zxvf FCGI-0.73.tar.gz &>/dev/null

[[email protected] software]# cd FCGI-0.73

[[email protected] FCGI-0.73]# perl Makefile.PL &&make &&make install

[[email protected] software]# tar -zxvf FCGI-ProcManager-0.25.tar.gz &>/dev/null

[[email protected] software]# cd FCGI-ProcManager-0.25

[[email protected] FCGI-ProcManager-0.25]# perl Makefile.PL &&make &&make install

[[email protected] software]# tar -zxvf IO-1.25.tar.gz &>/dev/null

[[email protected] software]# cd IO-1.25

[[email protected] IO-1.25]# perl Makefile.PL &&make &&make install

[[email protected] software]# tar -zxvf IO-All-0.39.tar.gz &>/dev/null

[[email protected] software]# cd IO-All-0.39

[[email protected] IO-All-0.39]# perl Makefile.PL &&make &&make install

[[email protected] software]# tar -zxvf spawn-fcgi-1.6.3.tar.gz &>/dev/null

[[email protected] software]# cd spawn-fcgi-1.6.3

[[email protected] spawn-fcgi-1.6.3]# ./configure &&make &&make install

[[email protected] software]# unzip perl-fcgi.zip

[[email protected] software]# cp perl-fcgi.pl /usr/local/nginx/

[[email protected] software]# chmod 755 /usr/local/nginx/perl-fcgi.pl

[[email protected] software]# cd /usr/local/nginx/

[[email protected] nginx]# chmod 755 start_perl_cgi.sh

编写start_perl_cgi.sh脚本

[[email protected] nginx]# ./start_perl_cgi.sh start

start perl-fcgi done

[[email protected] 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

[[email protected] nginx]# echo "/bin/sh /usr/local/nginx/start_perl_cgi.sh start" >>/etc/rc.local

安装Nagios:

[[email protected] software]# yum -y install libgd2-noxpm libgd2-noxpm-dev

[[email protected] software]# yum -y install php-gd

[[email protected] software]# groupadd nagcmd

[[email protected] software]# useradd -G nagcmd nagios

[[email protected] software]# usermod -G nagcmd www

[[email protected] software]# tar -zxvf nagios-3.3.1.tar.gz &>/dev/null

[[email protected] software]# cd nagios

[[email protected] nagios]# ./configure --with-command-group=nagcmd --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-nc=/usr/include

[[email protected] nagios]# make all &&make install &&make install-init &&make install-config &&make install-commandmode

[[email protected] nagios]# yum -y install httpd-tools

[[email protected] nagios]# cd /usr/local/nagios/etc/

[[email protected] etc]# htpasswd -cm htpasswd.users yfshare

[[email protected] etc]# sed -i ‘/authorized\_for\_/s/nagiosadmin/&\,yfshare/g‘ cgi.cfg

[[email protected] etc]# cd /usr/local/nginx/conf/

[[email protected] etc]# mkdir /usr/local/nagios/logs

[[email protected] etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg |grep ^Total

Total Warnings: 0

Total Errors:   0

[[email protected] etc]# /etc/init.d/nagios start

Starting nagios: done.

[[email protected] etc]# chkconfig --add nagios

[[email protected] etc]# chkconfig nagios on

也可通过访问http://www.4webhelp.net/us/password.php生成htpasswd.users

[[email protected] etc]# /etc/init.d/nagios restart

Running configuration check...done.

Stopping nagios: done.

Starting nagios: done.

[[email protected] etc]#

[[email protected] 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  ]

[[email protected] conf]#

安装Nagios-plugin:

[[email protected] software]# tar -zxvf nagios-plugins-1.4.15.tar.gz &>/dev/null

[[email protected] software]# cd nagios-plugins-1.4.15

[[email protected] nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules

[[email protected] nagios-plugins-1.4.15]# make &&make install

[[email protected] software]# ls /usr/local/nagios/libexec/|wc -l

58

[[email protected] software]#

安装NRPE:

[[email protected] software]# yum -y install openssl openssl-devel

[[email protected] software]# tar -zxvf nrpe-2.13.tar.gz &>/dev/null

[[email protected] software]# cd nrpe-2.13

[[email protected] nrpe-2.13]# ./configure

[[email protected] nrpe-2.13]# make all &&make install-plugin &&make install-daemon &&make install-daemon-config

[[email protected] nrpe-2.13]# cd /usr/local/nagios/etc/

[[email protected] etc]# sed -i ‘/allowed_host/s/127.0.0.1/&,192.168.10.99/g‘ nrpe.cfg

[[email protected] etc]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

[[email protected] etc]# echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local

[[email protected] etc]# /usr/local/nagios/libexec/check_nrpe -H localhost

NRPE v2.13

[[email protected] etc]#

访问:http://192.168.10.99/nagios

但是,打开页面时,其他选项卡都是显示的502 Bad Gateway

[[email protected] ~]# chown nagios:nagcmd /usr/local/nagios/ -R

[[email protected] ~]# chown www:nagcmd /usr/local/nginx/ -R

[[email protected] ~]# cd /usr/local/nginx/

[[email protected] nginx]# ./start_perl_cgi.sh start

ERROR PID file /usr/local/nginx/logs/perl-fcgi.pid already exists

start perl-fcgi done

[[email protected] nginx]#

因为perl-fcgi进程意外中断,但是进程未退出变成了孤儿进程,所以就变成这样了

修改下脚本start_perl_cgi.sh

[[email protected] nginx]# ./start_perl_cgi.sh start

start perl-fcgi done

[[email protected] nginx]#

[[email protected] nginx]# /etc/init.d/nagios restart

Running configuration check...done.

Stopping nagios: done.

Starting nagios: done.

[[email protected] 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  ]

[[email protected] nginx]#

OK,在Nginx上安装Nagios成功

如果出现上面的问题,解决方法:

[[email protected] ~]# sed -i ‘/use_authentication/s/1/0/g‘ /usr/local/nagios/etc/cgi.cfg

[[email protected] ~]# /etc/init.d/nagios restart

Running configuration check...done.

Stopping nagios: done.

Starting nagios: done.

[[email protected] ~]# /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  ]

[[email protected] ~]#

访问http://192.168.10.99/nagios/

OK,Successful

时间: 2024-10-02 21:33:38

基于Nginx平台安装Nagios监控系统的相关文章

Cacti+Nagios监控系统(五):Nagios监控windows(基于check_nt)

一.工作原理 Nagios服务器使用check_nt工具与客户端程序通讯,客户端程序NSCP使用命令来获取本地客户端的信息并返回给check_nt. check_nt只是NSCP其中一项服务,Nagios还可以通过check命令(如check_http检查WEB服务).check_nrpe.NSCA.WMI来监控windows客户端. 二.下载客户端程序 下载地址:  http://nsclient.org/nscp/downloads 64位系统下载:NSCP-0.4.1.105-x64.ms

Cacti+Nagios监控系统(二):安装Cacti

一.设置mysql,创建Cacti数据库和账号 mysql -u root -p mysql> create database cactidb; mysql> GRANT ALL ON cactidb.* TO [email protected] IDENTIFIED BY '123456'; mysql> flush privileges; mysql> quit 二.安装rrdtool yum -y install rrdtool  rrdtool-devel  rrdtool

Cacti+Nagios监控系统(三):安装Nagios

一.添加用户 groupadd nagcmd useradd -G nagcmd nagios passwd nagios 123456 usermod -a -G nagcmd apache 二.安装nagios cd /root/download wget http://jaist.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.7/nagios-4.0.7.tar.gz 也可以从这里下载:http://www.nagios.o

Cacti+Nagios监控系统(五):Cacti安装插件

Cacti插件说明及下载地址:http://docs.cacti.net/plugins 一.Settings插件 cd /root/download wget http://docs.cacti.net/_media/plugin:settings-v0.7-1.tgz mv plugin:settings-v0.7-1.tgz settings-v0.7-1.tgz tar zxvf settings-v0.7-1.tgz -C /var/www/html/cacti/plugins/ 二.

Nagios 监控系统架设全攻略

Nagios 全名为(Nagios Ain’t Goona Insist on Saintood),最初项目名字是 NetSaint.它是一款免费的开源 IT 基础设施监控系统,其功能强大,灵活性强,能有效监控 Windows .Linux.VMware 和 Unix 主机状态,交换机.路由器等网络设置等.一旦主机或服务状态出现异常时,会发出邮件或短信报警第一时间通知 IT 运营人员,在状态恢复后发出正常的邮件或短信通知.Nagios 结构简单,可维护性强,越来越受中小企业青睐,以及运维和管理人

centos 搭建 nagios 监控系统.

linux下搭建nagios监控 一.什么是nagios 1.nagios 简介 Nagios是一个监视系统运行状态和网络信息的监视系统. Nagios能监视所指定的本地或远程主机以及服务,同时提供异常通知功能等. Nagios可运行在Linux/Unix平台之上,同时提供一个可选的基于浏览器的WEB界面以方便系统管理人员查看网络状态, 各种系统问题,以及日志等等. Nagios是十分受欢迎的.开源且免费的计算机及网络系统监控软件. Nagios是"Nagios Ain't Gonna Insi

Nagios 监控系统架设全攻略(一)

最近一段时间在研究Nagios监控系统,然后网上搜索查看很多的资料,借鉴与各位大虾的经验,整理记录一下自己安装记录. Nagios 全名为(Nagios Ain’t Goona Insist on Saintood),最初项目名字是 NetSaint.它是一款免费的开源 IT 基础设施监控系统,其功能强大,灵活性强,能有效监控 Windows .Linux.VMware 和 Unix 主机状态,交换机.路由器等网络设置等.一旦主机或服务状态出现异常时,会发出邮件或短信报警第一时间通知 IT 运营

Nagios监控系统

一.Nagios监控系统简介 1.Nagios工作原理 Nagios本身不包括监控主机和服务的功能.所有的监控.监测功能都是通过各种插件来完成的.安装完nagios之后,在nagios主目录下的/libexex里面放有nagios自带的插件,如:check_disk是检查磁盘空间的插件,check_load是检查cpu负载的插件,每一个插件可以通过运行./check_xxx -h命令来检查其使用方法和功能. 1.Nagios的四种监控状态 Nagios可以识别四种状态返回信息.0(OK)表示状态

ubuntu16.04安装部署监控系统zabbix2.4

Ubuntu16.04安装部署监控系统Zabbix2.4 第一部分,php+mysql+nginx组件安装 1.系统更新 sudo apt-get update && sudo apt-get upgrade 2.安装php-fpm 检索系统当前自带的PHP版本:apt-cache search php-fpm 安装依赖包:sudo apt-get install make  bison g++ build-essential libncurses5-dev cmake 安装php-fpm