给ubuntu9.10下的nginx安装nagios监控

1 开权限

root@njava:~# sudo -s
root@njava:~# useradd -m -s /bin/bash nagios
root@njava:~# passwd nagios
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@njava:~# groupadd nagios
groupadd: group 'nagios' already exists
root@njava:~# usermod -G nagios nagios
root@njava:~# groupadd nagcmd
root@njava:~# usermod -a -G nagcmd nagios
root@njava:~# usermod -a -G nagcmd www-data
root@njava:~# 

2 下软件

root@njava:~# axel http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
root@njava:~# axel http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.14.tar.gz
root@njava:~# tar -xzvf nagios-3.2.1.tar.gz 

3 编译设置

root@njava:~# cd nagios-3.2.1
root@njava:~/nagios-3.2.1# ./configure --with-command-group=nagcmd
root@njava:~/nagios-3.2.1# make all
root@njava:~/nagios-3.2.1# make install
root@njava:~/nagios-3.2.1# make install-init
root@njava:~/nagios-3.2.1# make install-config
root@njava:~/nagios-3.2.1# make install-commandmode

4 安装apache配置,对nagios无用

root@njava:~/nagios-3.2.1# make install-webconf

5 配置nginx

root@njava:~/nagios-plugins-1.4.14# cat /etc/nginx/sites-available/nagios 
server {
	listen   80;
	server_name nagios.njava.com;
        
	access_log  /var/log/nginx/nagios.access.log;

	location / {
		root   /usr/local/nagios/share;
		index  index.php;
        }

        location ~ \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                set $path_info "/";
                set $real_script_name $fastcgi_script_name;
                if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                    set $real_script_name $1;
                    set $path_info $2;
                }
               fastcgi_param SCRIPT_FILENAME /usr/local/nagios/share/$real_script_name;
               fastcgi_param script_name $real_script_name;
               fastcgi_param path_info $path_info;
               include /etc/nginx/fastcgi_params;
        }
       location /nagios/images {
                alias /usr/local/nagios/share/images;
        }
                   
        location /nagios/stylesheets {
                alias /usr/local/nagios/share/stylesheets;
          }


         location /cgi-bin {
                 alias /usr/local/nagios/sbin;

    }

    location ~ \.cgi$ {

        root           /usr/local/nagios/sbin;

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

        fastcgi_index  index.cgi;

        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

        include        nginx_fcgi_params;

        fastcgi_read_timeout    5m;

        fastcgi_pass   unix:/var/run/nginx-fcgi.sock;

    }

6 安装Nagios Plugins

root@njava:~# tar -xzvf nagios-plugins-1.4.14.tar.gz
root@njava:~# cd nagios-plugins-1.4.14
root@njava:~/nagios-plugins-1.4.14# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
...
...            --with-apt-get-command: /usr/bin/apt-get
              --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
               --with-ping-command: /bin/ping -n -U -w %d -c %d %s
                       --with-ipv6: yes
                      --with-mysql: no
                    --with-openssl: yes
                     --with-gnutls: no
               --enable-extra-opts: no
                       --with-perl: /usr/bin/perl
             --enable-perl-modules: no
                     --with-cgiurl: /nagios/cgi-bin
               --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
                   --enable-libtap: no
root@njava:~/nagios-plugins-1.4.14# make && make install

7 启动nagios相关设置

root@njava:~/nagios-plugins-1.4.14# ln -s /etc/init.d/nagios /etc/rcS.d/
S99nagios

9 nagios设置
用户登录验证

root@njava:~/nagios-plugins-1.4.14#vi /usr/local/nagios/etc/cgi.cfg
    use_authentication=0

CGI工作目录

root@njava:~/nagios-plugins-1.4.14#vi /usr/local/nagios/share/config.inc.php
$cfg['cgi_base_url']='/cgi-bin';

8 效验nagios执行nagios

root@njava:~/nagios-plugins-1.4.14# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Things look okay - No serious problems were detected during the pre-flight check
root@njava:~/nagios-plugins-1.4.14# /etc/init.d/nagios start

参考:
1 http://nagios.sourceforge.net/docs/3_0/quickstart-ubuntu.html

Tags: , , ,

星期一, 三月 22nd, 2010 服务器

Leave a Reply

1LMooBmUE153Wnd3zDryWvDyXxQudbFxDr