成就梦想

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  21 随笔 :: 22 文章 :: 6 评论 :: 0 Trackbacks


1,nagios install 参考官方 

https://assets.nagios.com/downloads/nagioscore/docs/Installing_Nagios_Core_From_Source.pdf#_ga=1.136427443.2075387674.1488266439

上面只是参考,请自行安装最新版本的nagios,并自行忽略掉Apache的配置,我们来配置nginx支持nagios。

2,理解什么是cgi。fastcgi。写的非常棒。要多棒有多棒。

参考文章:http://www.cnblogs.com/skynet/p/4173450.html





3,上文理解了,就好办了。我们的目的就是让nginx支持执行我们nagios下的cgi。nginx基于安全性等考虑不让直接执行cgi,但支持fastcgi,所以我们要用到一个fastcig的warp来封装cgi

github上开源的项目 fcgiwarp https://github.com/gnosek/fcgiwrap


git clone https://github.com/gnosek/fcgiwrap.git

autoreconf -i
./configure
make
make instal
ps:
如果aotoreconf执行不了,请自行安装autoreconf。


然后就是怎么使用fcgiwarp ,作者提到了2种使用方法(针对这2种方法在nginx配置稍微不同):

usage

Most probably you will want fcgiwrap be launched by www-servers/spawn-fcgi. Or you could use the author's Perl launcher - see the homepage for that.



第1种是作者自己写的perl 的启动器:作者说在他的主页呢。。。。copy一下放在下面
#!/usr/bin/perl

use strict;
use warnings FATAL => qw( all );

use IO::Socket::UNIX;

my $bin_path = '/usr/local/bin/fcgiwrap';
my $socket_path = $ARGV[0] || '/tmp/cgi.sock';
my $num_children = $ARGV[1] || 1;

close STDIN;

unlink $socket_path;
my $socket = IO::Socket::UNIX->new(
    Local => $socket_path,
    Listen => 100,
);

die "Cannot create socket at $socket_path: $!\n" unless $socket;

for (1 .. $num_children) {
    my $pid = fork;
    die "Cannot fork: $!" unless defined $pid;
    next if $pid;

    exec $bin_path;
    die "Failed to exec $bin_path: $!\n";
}

我们把这个文件保存成 /etc/init.d/fcgiwrap 做成服务执行即可。


第二种方法是用fastcgi的进程管理器来启动。

还是GitHub上开源的牛逼项目
spawn-fcgi   https://github.com/lighttpd/spawn-fcgi

我们写一个启动脚本 

 

spawn-fcgi -f /usr/local/sbin/fcgiwrap -p 9009                       这个端口自己根据机器的端口使用情况自己来写



最后贴一个nginx简单的配置。

vim /etc/nginx/conf.d/nagios.conf  #根据自己的nginx启动位置自行调整


server {
        server_name nagios.tony.com;  #自己的域名
        access_log /var/log/nginx/nagios-access.log;
        error_log /var/log/nginx/nagios-error.log; #日志位置,发现nagios不能在浏览器展示,请看日志,看日志,

#       auth_basic "Private";
#
       auth_basic_user_file /etc/nagios/htpasswd.users;   #把认证先去掉。跑起来在说在。 要把 /usr/local/nagios/etc/cgi.cfg  中的use_ssl_authentication=0


        root /usr/local/nagios/share; #/usr/local/nagios   nagios安装目录
        index index.php index.html;

    #php 的配置,请自行去解决。
         location ~ \.php$ {  
            include /etc/nginx/fastcgi_params;
            fastcgi_pass  127.0.0.1:9000; #php-fpm 
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
                                    }
        location /nagios {
             alias /usr/local/nagios/share;
                                }

         location ~ \.cgi$ {
                root /usr/local/nagios/sbin;
                rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
                include /etc/nginx/fastcgi_params;

                fastcgi_param AUTH_USER $remote_user;
                fastcgi_param REMOTE_USER $remote_user;
                fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin/$fastcgi_script_name;
                fastcgi_pass  unix:/tmp/cgi.sock; #这是上面第一种方式的配置。
                #fastcgi_pass  127.0.0.1:9009; #这是上面第二种方式的配置。
                                }
}
posted on 2017-03-01 11:35 iamct 阅读(213) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: