nginx+nagios在ubuntu下搭建过程全程指导

今天终于把nginx+nagios在我自己的ubuntu机器下搭建起来,特此写一个教程,有2个目的,1作为备忘录留为己用,2作为新手教程指导。 

1.安装nginx,在ubuntu下apt-cache search nginx可以搜索到nginx包,我安装的是0.7.65版本。
fcgiwrap - simple server to run CGI applications over FastCGI
collectd-core - statistics collection and monitoring daemon (core system)
nginx - small, but very powerful and efficient web server and mail proxy
nginx-dbg - Debugging symbols for nginx
php5-fpm - server-side, HTML-embedded scripting language (FPM binary)


2.此处列出了fagiwrap包以及php5-fpm包均是以后需要安装的包,如果搜索得到即可立即安装否则等待下面的步骤进行安装。安装方法: 
sudo apt-get install nginx


3.nginx部署nagios需要安装fagiwrap以及php5-fpm,可以先进行安装,我安装的nagios3.2.0版本是不带有这2个ubuntu包的。 


4.fagiwrap以及php5-fpm的安装方法:参考我的另一篇文章 


5.启动fcgiwrap以及php5-fpm服务,这里要记得修改2个包的配置文件,将运行方式修改为sock方式则可以在如下目录生成相应的socket文件unix:/var/run/fcgiwrap.socket,unix:/var/run/php5-fpm.sock,另fastcgi内包含大量的脚本文件cgi,这些脚本会在/etc/nginx/fastcgi_params目录下,如果你安装的fastcgi版本低,则该目录下是一个.conf的文件,修改php5-fpm的监听方式修改/etc/php5/fpm/php5-fpm.conf文件,找到如下位置并修改成这个样子 
listen = /var/run/php5-fpm.sock 
;listen = 127.0.0.1:9000 

6.给nagios访问添加验证服务,创建一个nagiosadmin的用户用于Nagios的WEB接口登录。记下你所设置的登录口令,一会儿你会用到它 
这里要借助于apche的htpasswd,在有apache机器上执行下列命令 

    /usr/local/apache2/bin/htpasswd -c /usr/local/server/nginx/conf/htppasswd nagiosadmin 


7.修改nginx配置:
user www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

        server {
        listen       9999;
        server_name  10.18.105.110;
        auth_basic            "Restricted Nagios Area!";
        auth_basic_user_file  /opt/nagios/etc/htpasswd.users;
        charset utf-8;
        root   /usr/share/nagios3/htdocs ;
        index  index.html index.htm index.php;

        location /nagios3/stylesheets {
                alias /etc/nagios3/stylesheets;
        }


        location /nagios3/images {
                 alias /usr/share/nagios3/htdocs/images;
        }

        location ~ \.cgi$ {
                root /usr/lib/cgi-bin/nagios3;

                rewrite ^/cgi-bin/nagios3/(.*)$ /$1;

                include /etc/nginx/fastcgi_params;

                fastcgi_param AUTH_USER $remote_user;
                fastcgi_param REMOTE_USER $remote_user;
                fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/nagios3$fastcgi_script_name;

                fastcgi_pass unix:/var/run/fcgiwrap.socket;
        }

        location ~ \.php$ {
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }}
}

8.配置文件内着重注意的地方1,root   /usr/share/nagios3/htdocs ,nagios首页页面所在位置,不要定位到example的index页面上去,2,样式以及图片的过滤路径,有可能找不到需要你去配置,3.找不到cgi脚本报脚本名或者document root错误,4,fastcgi参数有include /etc/nginx/fastcgi_params;老版本可能是一个配置文件,而不是一个文件夹,5,fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/nagios3$fastcgi_script_name; 这里最好重新定位一下你的脚本在哪里,否则fastcgi自带的配置文件仍然报找不到脚本 


参考文档: 

在nginx上搭建nagios 
ubuntu php5-fpm安装 
Nagios with NginX in Ubuntu 
How to serve nagios with nginx 
上一篇:【.Net Micro Framework PortingKit – 11】NandFlash驱动开发


下一篇:Dataworks调度能力升级——分支节点