成就夢想

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            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支持執(zhí)行我們nagios下的cgi。nginx基于安全性等考慮不讓直接執(zhí)行cgi,但支持fastcgi,所以我們要用到一個fastcig的warp來封裝cgi

          github上開源的項(xiàng)目 fcgiwarp https://github.com/gnosek/fcgiwrap


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

          autoreconf -i
          ./configure
          make
          make instal
          ps:
          如果aotoreconf執(zhí)行不了,請自行安裝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 做成服務(wù)執(zhí)行即可。


          第二種方法是用fastcgi的進(jìn)程管理器來啟動。

          還是GitHub上開源的牛逼項(xiàng)目
          spawn-fcgi   https://github.com/lighttpd/spawn-fcgi

          我們寫一個啟動腳本 

           

          spawn-fcgi -f /usr/local/sbin/fcgiwrap -p 9009                       這個端口自己根據(jù)機(jī)器的端口使用情況自己來寫



          最后貼一個nginx簡單的配置。

          vim /etc/nginx/conf.d/nagios.conf  #根據(jù)自己的nginx啟動位置自行調(diào)整


          server {
                  server_name nagios.tony.com;  #自己的域名
                  access_log /var/log/nginx/nagios-access.log;
                  error_log /var/log/nginx/nagios-error.log; #日志位置,發(fā)現(xiàn)nagios不能在瀏覽器展示,請看日志,看日志,

          #       auth_basic "Private";
          #
                 auth_basic_user_file /etc/nagios/htpasswd.users;   #把認(rèn)證先去掉。跑起來在說在。 要把 /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 閱讀(237) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 民乐县| 诏安县| 桐梓县| 武汉市| 万载县| 兰溪市| 永济市| 昂仁县| 邳州市| 建湖县| 绥德县| 武邑县| 昌图县| 新密市| 丰都县| 兴仁县| 德清县| 通化县| 福安市| 开原市| 绩溪县| 隆化县| 邻水| 汾阳市| 富阳市| 黑山县| 榆社县| 兴仁县| 南宁市| 宝山区| 若羌县| 威信县| 乡宁县| 万荣县| 宜宾市| 霞浦县| 四川省| 天气| 芦溪县| 普安县| 阳原县|