標籤:遷移 nagios 監控 cgi
nginx的效能遠遠優於apache,但由於nagios的web介面中包含php和c-cgi程式,因此需要兩套fcgi管理工具(並非必須)和兩套解譯器(必須)。php用php-cgi跑就可以,c-cgi我選用fcgiwrap。下面介紹安裝/配置步驟。
php-fpm:是為PHP打的一個FastCGI管理補丁,可以平滑變更php.ini配置而無需重啟php-cgi
Spawn-fcgi:是lighttpd的一個分支項目,是一個cgi進程的管理器
● php 打php-fpm補丁,編譯時間啟用--enable-fastcgi --enable-fpm 參數,使用php-fpm管理php-cgi。php安裝詳細步驟參見 張宴文章:http://blog.s135.com/nginx_php_v5/
● c-cgi 使用 Spawn-fcgi 管理 ,利用fcgiwrap驅動。fcgiwrap 介紹參見http://nginx.localdomain.pl/wiki/FcgiWrap
php-cgi 監聽 127.0.0.1:9000
fcgiwrap 監聽 127.0.0.1:10000
nagios 安裝配置不是本文重點,略過。web 目錄如下:
/usr/local/nagios/share
安裝spawn-fcgi
wget http://download.lighttpd.net/spawn-fcgi/releases-1.6.x/spawn-fcgi-1.6.3.tar.gztar xf spawn-fcgi-1.6.3.tar.gzcd /usr/local/src/spawn-fcgi-1.6.3 ./configure --prefix=/usr/local/spawn-fcgimake && make install
安裝fcgi庫
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/fcgi-2.4.0-10.el6.x86_64.rpmwget http://dl.fedoraproject.org/pub/epel/6/x86_64/fcgi-devel-2.4.0-10.el6.x86_64.rpmrpm -ivh fcgi-2.4.0-10.el6.x86_64.rpmrpm -ivh fcgi-devel-2.4.0-10.el6.x86_64.rpm
【注:以上fcgi軟體的rpm為RHEL6對應版本的,如果是5系列請安裝RHEL5對應版本的fcgi庫,RHEL5軟體如下:
fcgi: http://flexbox.sourceforge.net/centos/5/x86_64/fcgi-2.4.0-10.el5.x86_64.rpm
fcgi-devel:http://flexbox.sourceforge.net/centos/5/x86_64/fcgi-devel-2.4.0-10.el5.x86_64.rpm
】
安裝fcgiwrap
fcgiwrap wiki --> http://nginx.localdomain.pl/wiki/FcgiWrap
最新版本為gnosek-fcgiwrap-1.1.0-0-g333ff99.tar.gz
cd gnosek-fcgiwrap-333ff99/autoreconf -i./configure --prefix=/usr/local/fcgiwrapmake && make install
建立一個shell指令碼來用spawn-fcgi 啟動fcgiwrap執行個體
vi /usr/local/bin/c-fcgi.sh#!/bin/sh/usr/local/spawn-fcgi/bin/spawn-fcgi -f /usr/local/fcgiwrap/bin/fcgiwrap -a 127.0.0.1 -p 10000-F 3 -P /var/run/fastcgi-c.pid -u daemon -g daemonchmod +x /usr/local/bin/c-fcgi.sh
參數含義如下:
-f <fcgiapp> 指定調用FastCGI的進程的執行程式位置
-a <addr> 綁定到地址addr
-p <port> 綁定到連接埠port
-s <path> 綁定到unixsocket的路徑path
-C < children> 指定產生的FastCGI的進程數(僅用於PHP)
-F <children> 指定產生的FastCGI的進程數
-P <path> 指定產生的進程的PID檔案路徑
-u和-g FastCGI使用什麼身份(-u使用者-g使用者組)運行,這裡使用nginx的使用者和組daemon運行
建立一個系統啟動進程,方便使用service 和chkconfig 命令管
vi /etc/init.d/c-fcgi#!/bin/bash# c-fcgi - this script starts and stops the fcgiwrap instance## chkconfig: - 96 28# description: c-fcgi# processname: c-fcgiC_SCRIPT=/usr/local/bin/c-fcgi.shRETVAL=0case "$1" instart)echo "Starting fastcgi"$C_SCRIPTRETVAL=$?;;stop)echo "Stopping fastcgi"killall -9 fcgiwrapRETVAL=$?;;restart)echo "Restarting fastcgi"killall -9 fcgiwrap$C_SCRIPTRETVAL=$?;;*)echo "Usage: c-fastcgi {start|stop|restart}"exit 1;;esacexit $RETVAL# <span style="color: #0000ff;">chkconfig --add c-fcgi</span># <span style="color: #0000ff;">chkconfig c-fcgi on</span># <span style="color: #0000ff;">service c-fcgi start</span>
驗證啟動,是否提供了相應的連接埠
#netstat -tulnpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 32629/php-cgitcp 0 0 127.0.0.1:10000 0.0.0.0:* LISTEN 20039/fcgiwrap
#ps -ef | grep fcgiwrap | grep -v grepdaemon 20039 1 0 15:20 ? 00:00:00 /usr/local/bin/fcgiwrapdaemon 20040 1 0 15:20 ? 00:00:00 /usr/local/bin/fcgiwrapdaemon 20041 1 0 15:20 ? 00:00:00 /usr/local/bin/fcgiwr
#ps -ef | grep php-cgi | grep -v grepnginx 22046 1 0 Jul10 ? 00:00:00 /usr/bin/php-cginginx 22047 22046 0 Jul10 ? 00:00:00 /usr/bin/php-cginginx 22048 22046 0 Jul10 ? 00:00:00 /usr/bin/php-cginginx 22049 22046 0 Jul10 ? 00:00:00 /usr/bin/php-cginginx 22050 22046 0 Jul10 ? 00:00:00 /usr/bin/php-cginginx 22051 22046 0 Jul10 ? 00:00:00 /usr/bin/php-cgi
配置nginx相關nagios設定
server { listen 80; server_name nagios.icoffer.cn; root /usr/local/nagios/share; index index.php; auth_basic "Welcome to Jobkoo Nagios Monitor System!"; auth_basic_user_file ./htpasswd; location /nagios{ alias /usr/local/nagios/share/; } location ~ .*\.cgi?$ { root /usr/local/nagios/sbin; rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break; fastcgi_pass 127.0.0.1:10000; fastcgi_index index.cgi; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_read_timeout 500; include fastcgi_params; fastcgi_buffers 8 128k; }}
配置Nagios Nginxweb認證
htpasswd -c /etc/nginx/conf.d/htpasswd admincat /etc/nginx/conf.d/htpasswdadmin:QqbxsY3jdkOpQ
若沒有htpasswd命令,請安裝httpd-tools包
nagios平台從apache遷移到nginx