环境:CentOS 6.5(最小化安装)
Nginx:1.6.2
Nagios:3.3.1
安装基本环境:
[root@localhost software]# yum -y install gcc gcc-c++ [root@localhost software]# yum -y install perl-devel perl
源码安装PHP:
[root@localhost software]# yum -y install mysql mysql-devel [root@localhost software]# yum -y install gd-2.0.35-11.el6.x86_64.rpm gd-devel-2.0.35-11.el6.x86_64.rpm [root@localhost software]# yum -y install libxml2 libxml2-devel [root@localhost software]# tar -zxvf zlib-1.2.7.tar.gz &>/dev/null [root@localhost software]# cd zlib-1.2.7 [root@localhost zlib-1.2.7]# ./configure -prefix=/usr/local/zlib &&make &&make install [root@localhost software]# tar -zxvf libmcrypt-2.5.7.tar.gz &>/dev/null [root@localhost software]# cd libmcrypt-2.5.7 [root@localhost libmcrypt-2.5.7]# ./configure &&make &&make install [root@localhost software]# useradd -s /sbin/nologin www [root@localhost software]# tar -jxvf php-5.3.8.tar.bz2 &>/dev/null [root@localhost software]# cd php-5.3.8 [root@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 [root@localhost php-5.3.8]# make &&make install [root@localhost ~]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [root@localhost ~]# sed -i '/run\/php-fpm.pid/s/^;//g' /usr/local/php/etc/php-fpm.conf [root@localhost ~]# sed -i '/^;pm.min_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf [root@localhost ~]# sed -i '/^;pm.max_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf [root@localhost ~]# sed -i '/^;pm.start_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf [root@localhost ~]# /usr/local/php/sbin/php-fpm [root@localhost ~]# echo '/usr/local/php/sbin/php-fpm'>>/etc/rc.local
[root@localhost ~]# netstat -tunlp |grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1592/php-fpm
[root@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
[root@localhost ~]#
php启动错误解决方法:http://yfshare.blog.51cto.com/8611708/1635679
安装Nginx:
[root@localhost software]# tar -jxvf pcre-8.12.tar.bz2 &>/dev/null [root@localhost software]# cd pcre-8.12 [root@localhost pcre-8.12]# ./configure &&make &&make install zlib上面安装php时已安装 [root@localhost software]# tar -zxvf openssl-1.0.1c.tar.gz &>/dev/null [root@localhost software]# cd openssl-1.0.1c [root@localhost openssl-1.0.1c]# ./config &&make &&make install [root@localhost software]# tar -zxvf nginx-1.6.2.tar.gz &>/dev/null [root@localhost software]# cd nginx-1.6.2 [root@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 [root@localhost nginx-1.6.2]# make &&make install
编写/etc/init.d/nginx文件
[root@localhost nginx-1.6.2]# /etc/init.d/nginx start
Starting nginx: [ OK ]
[root@localhost nginx-1.6.2]#
[root@localhost nginx-1.6.2]# chkconfig --add nginx [root@localhost nginx-1.6.2]# chkconfig nginx on [root@localhost conf]# ln -s /usr/local/nagios/share /usr/local/nginx/html/nagios
[root@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
[root@localhost conf]#
给Nginx添加对Perl的CGI支持(默认不支持):
安装FCGI模块:
[root@localhost software]# tar -zxvf FCGI-0.73.tar.gz &>/dev/null [root@localhost software]# cd FCGI-0.73 [root@localhost FCGI-0.73]# perl Makefile.PL &&make &&make install [root@localhost software]# tar -zxvf FCGI-ProcManager-0.25.tar.gz &>/dev/null [root@localhost software]# cd FCGI-ProcManager-0.25 [root@localhost FCGI-ProcManager-0.25]# perl Makefile.PL &&make &&make install [root@localhost software]# tar -zxvf IO-1.25.tar.gz &>/dev/null [root@localhost software]# cd IO-1.25 [root@localhost IO-1.25]# perl Makefile.PL &&make &&make install [root@localhost software]# tar -zxvf IO-All-0.39.tar.gz &>/dev/null [root@localhost software]# cd IO-All-0.39 [root@localhost IO-All-0.39]# perl Makefile.PL &&make &&make install [root@localhost software]# tar -zxvf spawn-fcgi-1.6.3.tar.gz &>/dev/null [root@localhost software]# cd spawn-fcgi-1.6.3 [root@localhost spawn-fcgi-1.6.3]# ./configure &&make &&make install [root@localhost software]# unzip perl-fcgi.zip [root@localhost software]# cp perl-fcgi.pl /usr/local/nginx/ [root@localhost software]# chmod 755 /usr/local/nginx/perl-fcgi.pl [root@localhost software]# cd /usr/local/nginx/ [root@localhost nginx]# chmod 755 start_perl_cgi.sh
编写start_perl_cgi.sh脚本
[root@localhost nginx]# ./start_perl_cgi.sh start
start perl-fcgi done
[root@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
[root@localhost nginx]# echo "/bin/sh /usr/local/nginx/start_perl_cgi.sh start" >>/etc/rc.local
安装Nagios:
[root@localhost software]# yum -y install libgd2-noxpm libgd2-noxpm-dev [root@localhost software]# yum -y install php-gd [root@localhost software]# groupadd nagcmd [root@localhost software]# useradd -G nagcmd nagios [root@localhost software]# usermod -G nagcmd www [root@localhost software]# tar -zxvf nagios-3.3.1.tar.gz &>/dev/null [root@localhost software]# cd nagios [root@localhost nagios]# ./configure --with-command-group=nagcmd --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-nc=/usr/include [root@localhost nagios]# make all &&make install &&make install-init &&make install-config &&make install-commandmode [root@localhost nagios]# yum -y install httpd-tools [root@localhost nagios]# cd /usr/local/nagios/etc/ [root@localhost etc]# htpasswd -cm htpasswd.users yfshare [root@localhost etc]# sed -i '/authorized\_for\_/s/nagiosadmin/&\,yfshare/g' cgi.cfg [root@localhost etc]# cd /usr/local/nginx/conf/ [root@localhost etc]# mkdir /usr/local/nagios/logs
[root@localhost etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg |grep ^Total
Total Warnings: 0
Total Errors: 0
[root@localhost etc]# /etc/init.d/nagios start
Starting nagios: done.
[root@localhost etc]# chkconfig --add nagios [root@localhost etc]# chkconfig nagios on
也可通过访问http://www.4webhelp.net/us/password.php生成htpasswd.users
[root@localhost etc]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[root@localhost etc]#
[root@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 ]
[root@localhost conf]#
安装Nagios-plugin:
[root@localhost software]# tar -zxvf nagios-plugins-1.4.15.tar.gz &>/dev/null [root@localhost software]# cd nagios-plugins-1.4.15 [root@localhost nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules [root@localhost nagios-plugins-1.4.15]# make &&make install [root@localhost software]# ls /usr/local/nagios/libexec/|wc -l 58 [root@localhost software]#
安装NRPE:
[root@localhost software]# yum -y install openssl openssl-devel [root@localhost software]# tar -zxvf nrpe-2.13.tar.gz &>/dev/null [root@localhost software]# cd nrpe-2.13 [root@localhost nrpe-2.13]# ./configure [root@localhost nrpe-2.13]# make all &&make install-plugin &&make install-daemon &&make install-daemon-config [root@localhost nrpe-2.13]# cd /usr/local/nagios/etc/ [root@localhost etc]# sed -i '/allowed_host/s/127.0.0.1/&,192.168.10.99/g' nrpe.cfg [root@localhost etc]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d [root@localhost etc]# echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local
[root@localhost etc]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.13
[root@localhost etc]#
访问:http://192.168.10.99/nagios
但是,打开页面时,其他选项卡都是显示的502 Bad Gateway
[root@localhost ~]# chown nagios:nagcmd /usr/local/nagios/ -R
[root@localhost ~]# chown www:nagcmd /usr/local/nginx/ -R
[root@localhost ~]# cd /usr/local/nginx/
[root@localhost nginx]# ./start_perl_cgi.sh start
ERROR PID file /usr/local/nginx/logs/perl-fcgi.pid already exists
start perl-fcgi done
[root@localhost nginx]#
因为perl-fcgi进程意外中断,但是进程未退出变成了孤儿进程,所以就变成这样了
修改下脚本start_perl_cgi.sh,把这个脚本写成服务或者加入开机脚本(关闭sudo的tty)
[root@localhost nginx]# ./start_perl_cgi.sh start
start perl-fcgi done
[root@localhost nginx]#
[root@localhost nginx]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[root@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 ]
[root@localhost nginx]#
OK,在Nginx上安装Nagios成功
如果出现上面的问题,解决方法:
[root@localhost ~]# sed -i '/use_authentication/s/1/0/g' /usr/local/nagios/etc/cgi.cfg
[root@localhost ~]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[root@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 ]
[root@localhost ~]#
访问http://192.168.10.99/nagios/
OK,Successful