阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Nagios平台从Apache迁移到Nginx

99次阅读
没有评论

共计 4873 个字符,预计需要花费 13 分钟才能阅读完成。

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://www.linuxidc.com/Linux/2009-08/21405p6.htm
● 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.gz

tar xf spawn-fcgi-1.6.3.tar.gz

cd  /usr/local/src/spawn-fcgi-1.6.3

./configure  –prefix=/usr/local/spawn-fcgi

make && make install

安装 fcgi 库

wget http://dl.Fedoraproject.org/pub/epel/6/x86_64/fcgi-2.4.0-10.el6.x86_64.rpm

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/fcgi-devel-2.4.0-10.el6.x86_64.rpm

rpm -ivh fcgi-2.4.0-10.el6.x86_64.rpm

rpm -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/fcgiwrap

make && 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 daemon

 

chmod +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-fcgi

 

C_SCRIPT=/usr/local/bin/c-fcgi.sh

 

RETVAL=0

 

case “$1” in

start)

echo “Starting fastcgi”

$C_SCRIPT

RETVAL=$?

;;

stop)

echo “Stopping fastcgi”

killall -9 fcgiwrap

RETVAL=$?

;;

restart)

echo “Restarting fastcgi”

killall -9 fcgiwrap

$C_SCRIPT

RETVAL=$?

;;

*)

echo “Usage: c-fastcgi {start|stop|restart}”

exit 1

;;

esac

exit $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 -tulnp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address              Foreign Address            State      PID/Program name

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                  LISTEN      32629/php-cgi

tcp        0      0 127.0.0.1:10000            0.0.0.0:*                  LISTEN      20039/fcgiwrap

 

 

#ps -ef | grep fcgiwrap | grep -v grep

 

daemon      20039    1  0 15:20 ?        00:00:00 /usr/local/bin/fcgiwrap

daemon      20040    1  0 15:20 ?        00:00:00 /usr/local/bin/fcgiwrap

daemon      20041    1  0 15:20 ?        00:00:00 /usr/local/bin/fcgiwr

 

#ps -ef | grep php-cgi | grep -v grep

 

nginx    22046    1  0 Jul10 ?        00:00:00 /usr/bin/php-cgi

nginx    22047 22046  0 Jul10 ?        00:00:00 /usr/bin/php-cgi

nginx    22048 22046  0 Jul10 ?        00:00:00 /usr/bin/php-cgi

nginx    22049 22046  0 Jul10 ?        00:00:00 /usr/bin/php-cgi

nginx    22050 22046  0 Jul10 ?        00:00:00 /usr/bin/php-cgi

nginx    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 admin

cat /etc/nginx/conf.d/htpasswd

admin:QqbxsY3jdkOpQ

若没有 htpasswd 命令,请安装 httpd-tools 包

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx 搭建视频点播服务器(仿真专业流媒体软件)http://www.linuxidc.com/Linux/2012-08/69151.htm

Nginx 的详细介绍 :请点这里
Nginx 的下载地址 :请点这里

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计4873字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中