基於Apache搭建Nagios圖形監控

基於apache 的稍微簡單一點麼?實驗一會兒就OK了。。。php

環境:html

System:linux

[root@losnau etc]# cat /etc/issue
Red Hat Enterprise Linux Server release 6.5 (Santiago)
Kernel \r on an \m

ios

IP:192.168.1.5web

 防火牆關閉(service iptabes stop): Firewall is not running.
 vim /etc/sysconfig/selinux  SELINUX=disabledapache

 

要監控服務:監控本機CPu負載、當天用戶登陸數量、是否開啓80端口、是否活動、/分區使用狀況、swap分區使用狀況、總進程數vim


實驗開始:瀏覽器

安裝基礎套件
[root@dep5 ~]# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-develssh

安裝Apache和PHPide

[root@dep5 ~]# yum install -y httpd* php

建立Nagios用戶和組
[root@dep5 ~]# useradd -s /sbin/nologin nagios
[root@dep5 ~]# mkdir /usr/local/nagios
[root@dep5 ~]# chown nagios:nagios /usr/local/nagios/

編譯安裝Nagios
[root@dep5 ~]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.3.tar.gz
[root@dep5 ~]# tar zxvf nagios-3.4.3.tar.gz
[root@dep5 ~]# cd nagios
[root@dep5 nagios]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
[root@dep5 nagios]# make all && make install && make install-init && make install-commandmode && make install-config && chkconfig --add nagios && chkconfig --level 35 nagios on && chkconfig --list nagios

檢測是否安裝正確
# cd /usr/local/nagios
 
(查看是否有/usr/local/nagios/etc、bin、sbin、share、var、libexec這六個目錄,若是有,表示安裝成功)

安裝Nagios插件
#wget http://pkgs.fedoraproject.org/repo/pkgs/nagios-plugins/nagios-plugins-1.4.16.tar.gz/862f5e44fb5bc65ce7e5d86d654d4da0/nagios-plugins-1.4.16.tar.gz

[root@dep5 ~]# tar zxvf nagios-plugins-1.4.16.tar.gz
[root@dep5 ~]# cd nagios-plugins-1.4.16
[root@dep5 nagios-plugins-1.4.16]# ./configure --prefix=/usr/local/nagios
[root@dep5 nagios-plugins-1.4.16]# make && make install


4.七、安裝NRPE


[root@dep5 ~]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz
[root@dep5 ~]# tar zxvf nrpe-2.13.tar.gz
[root@dep5 ~]# cd nrpe-2.13
[root@dep5 nrpe-2.13]# ./configure
[root@dep5 nrpe-2.13]# make all
[root@dep5 nrpe-2.13]# make install-plugin
主監控機須要安裝check_nrpe 這個插件,被監控機並不須要,咱們在這裏安裝它只是爲了測試目的。

安裝配置Apache和PHP
Apache 和Php 不是安裝nagios 所必須的,可是nagios提供了web監控界面,經過web監控界面能夠清晰的看到被監控主機、資源的運行狀態,所以,安裝一個web服務是很必要.
[root@dep5 ~] usermod -G nagios apache       #則會出現notifications for this service have been disabled
[root@dep5 ~] touch /etc/httpd/conf.d/nagios.conf    建立nagios.conf web配置文件
[root@dep5 ~] vim /etc/httpd/conf.d/nagios.conf      輸入如下內容

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
     AuthType Basic
     Options ExecCGI
     AllowOverride None
     Order allow,deny 
     Allow from all 
     AuthName "Nagios Access"
     AuthUserFile /usr/local/nagios/etc/htpasswd.users
#            //用於此目錄訪問身份驗證的文件 
     Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
     AuthType Basic
     Options None
     AllowOverride None
     Order allow,deny 
     Allow from all 
     AuthName "nagios Access"
     AuthUserFile /usr/local/nagios/etc/htpasswd.users
     Require valid-user
</Directory>

# htpasswd -c  /usr/local/nagios/etc/htpasswd.users nagiosadmin  加入認證
# grep nagiosadmin /usr/local/nagios/etc/cgi.cfg  驗證

在IE裏面輸入http://192.168.1.5/nagios
輸入帳號nagiosadmin 密碼就是你剛剛改過的密碼


完了麼?不不不,前面只是讓Apache跟Ngios創建聯繫

重要的如今纔剛剛開始呢?

 

[root@losnau ~]# /usr/local/nagios/etc/objects

[root@losnau objects]# mv localhost.cfg localhost.cfg.bak #備份一下,萬一之後用得着呢?

[root@losnau objects]# vim localhost.cfg

添加一下內容

define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        }
define hostgroup{
        hostgroup_name  linux-servers ; The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         localhost     ; Comma separated list of hosts that belong to this group
        }
;==================================================================================================
;check ping
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        notifications_enabled           1
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            2
        check_period                    24x7
        notification_interval           5
        notification_period             24x7
        notification_options            w,u,c,r
        contact_groups                  admins
        }
;check / space
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             / Parttion
        check_command                   check_local_disk!20%!10%!/
        notifications_enabled           1
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            2
        check_period                    24x7
        notification_interval           5
        notification_period             24x7
        notification_options            w,u,c,r
        contact_groups                  admins

        }
;check /opt space
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             /opt Parttion
        check_command                   check_local_disk!30%!15%!/opt
        notifications_enabled           1
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            2
        check_period                    24x7
        notification_interval           5
        notification_period             24x7
        notification_options            w,u,c,r
        contact_groups                  admins
        }
;check users
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             Current Users
        check_command                   check_local_users!20!50
        notifications_enabled           1
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            2
        check_period                    24x7
        notification_interval           5
        notification_period             24x7
        notification_options            w,u,c,r
        contact_groups                  admins
        }
;check Toal Processes
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             Total Processes
        check_command                   check_local_procs!250!400!RSZDT
        notifications_enabled           1
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            2
        check_period                    24x7
        notification_interval           5
        notification_period             24x7
        notification_options            w,u,c,r
        contact_groups                  admins
        }
;check cpu load
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             Current Load
        check_command                   check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
        notifications_enabled           1
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            2
        check_period                    24x7
        notification_interval           5
        notification_period             24x7
        notification_options            w,u,c,r
        contact_groups                  admins
        }
;check swap space
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             Swap Usage
        check_command                   check_local_swap!20!10
        notifications_enabled           1
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            2
        check_period                    24x7
        notification_interval           5
        notification_period             24x7
        notification_options            w,u,c,r
        contact_groups                  admins

        }
;check ssh
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           1
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            2
        check_period                    24x7
        notification_interval           5
        notification_period             24x7
        notification_options            w,u,c,r
        contact_groups                  admins
        }

檢查配置文件是否正確
[root@losnau objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

啓動nagios
[root@losnau objects]# /etc/init.d/nagios restart

啓動nagios
[root@losnau objects]# /etc/init.d/httpd  restart

打開瀏覽器輸入:192.168.1.5/nagios

輸入登陸的賬號密碼

若出現如下界面,恭喜你成了搭建了簡單的基於Apache的Ngios監控

 

 

 

上面那個只是監控本機,監控多臺,還有警報那些還沒弄好,慢慢來嘛,有待學習

原理那些請參考:http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html

這裏就再也不重複啦,上面那個博客貌似給出的更加詳細一些,貌似本身作的時候出了一點小錯誤,不過已經從坑裏爬出來了,哈哈

相關文章
相關標籤/搜索