Nagios遠程監控

來源:互聯網
上載者:User

標籤:遠程監控   使用者   

1.添加使用者

[[email protected] ~]# useradd nagios
2.安裝nagios-plugins

[[email protected] ~]# tar zxf nagios-plugins-2.0.3.tar.gz
[[email protected] nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with
     --with-apt-get-command:
              --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: /usr/bin/mysql_config
                    --with-openssl: yes
                     --with-gnutls: no
               --enable-extra-opts: yes
                       --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
[[email protected] nagios-plugins-2.0.3]# make && make install

[[email protected] nagios]# pwd
/usr/local/nagios
[[email protected] nagios]# chown -R nagios.nagios *

3.安裝 NRPE

[[email protected] ~]# tar zxf nrpe-2.15.tar.gz

[[email protected] nrpe-2.15]# ./configure

General Options:
 -------------------------
 NRPE port:    5666
 NRPE user:    nagios
 NRPE group:   nagios
 Nagios user:  nagios
 Nagios group: nagios

[[email protected] nrpe-2.15]# make all

4.安裝外掛程式、daemon和樣本設定檔

#安裝nrpe-plugin外掛程式
[[email protected] nrpe-2.15]# make install-plugin

#安裝nrpe daemon

[[email protected] nrpe-2.15]# make install-daemon
#安裝daemon設定檔

[[email protected] nrpe-2.15]# make install-daemon-config

#安裝xinetd指令碼,NRPE daemon是作為xinetd下的一個服務來啟動並執行,所以先安裝好xinetd

[[email protected] nrpe-2.15]# yum install -y xinetd 

[[email protected] nrpe-2.15]# make install-xinetd

4.修改設定檔

[[email protected] nrpe-2.15]# vim /etc/xinetd.d/nrpe   #添加nagios服務端的地址

    only_from       = 172.25.16.2        #nagios 主機 ip 地址

[[email protected] ~]# vim /usr/local/nagios/etc/nrpe.cfg

    allowed_hosts=172.25.16.2    #允許監測主機的IP

5.編輯/etc/services檔案,增加NRPE服務

nrpe            5666/tcp                 #nrpe

6.重啟服務

[[email protected] nrpe-2.15]# /etc/init.d/xinetd restart

[[email protected] nrpe-2.15]# netstat -antlp | grep 5666   #NRPE已經啟動
tcp        0      0 :::5666                     :::*                        LISTEN      22872/xinetd    


#在監控主機上

1.安裝NRPE,只需要check_nrpe外掛程式,可直接從被監測端copy

[[email protected] libexec]# scp check_nrpe 172.25.16.2:/usr/local/nagios/libexec/

[[email protected] libexec]# chown nagios.nagios check_nrpe
[[email protected] libexec]# ll check_nrpe
-rwxr-xr-x. 1 nagios nagios 76769 Aug 29 23:36 check_nrpe
[[email protected] libexec]# ./check_nrpe -H 172.25.16.3  #輸出nrpe的版本,說明監測機check_nrpe與被監測主機啟動並執行nrpe daemon之間建立聯絡
NRPE v2.15
[[email protected] libexec]# vim /usr/local/nagios/etc/objects/commands.cfg

    # ‘check_nrpe‘
    define command{
            command_name    check_nrpe
            command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c "$ARG1$"  #-c後面的參數是傳給被監測端nrpe daemon要執行的監測命令,這些命令在nrpe.cfg中要求已經定義

       }
[[email protected] ~]# grep -v ‘^#‘ /usr/local/nagios/etc/nrpe.cfg | sed ‘/^$/d‘
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=172.25.16.2
 dont_blame_nrpe=0
allow_bash_command_substitution=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 

[[email protected] libexec]# vim /usr/local/nagios/etc/objects/services.cfg  #在這個裡面定義的服務命令完全根據在被監控端nrpe.cfg中內建命令定義的,如上面命令所示

define service{
        use generic-service
        host_name server3.example.com
        service_description CPU Load
        check_command check_nrpe!check_load
        }
define service{
        use generic-service
        host_name server3.example.com
        service_description Current Users
        check_command check_nrpe!check_users
}

define service{
        use generic-service
        host_name server3.example.com
        service_description  / Free Space
        check_command check_nrpe!check_disk
}
define service{
        use generic-service
        host_name server3.example.com
        service_description Total Processes
        check_command  check_nrpe!check_total_procs
}

define service{
        use generic-service
        host_name server3.example.com
        service_description  Zombie Processes
        check_command check_nrpe!check_zombie_procs
}

#監測是否有語法錯誤並測試

[[email protected] libexec]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[[email protected] objects]#/usr/local/nagios/libexec/check_nrpe -H 172.25.16.3 -c check_load

OK - load average: 0.08, 0.02, 0.01|load1=0.080;15.000;30.000;0; load5=0.020;10.000;25.000;0; load15=0.010;5.000;20.000;0;

[[email protected] objects]# /usr/local/nagios/libexec/check_nrpe -H 172.25.16.3 -c check_users
USERS OK - 1 users currently logged in |users=1;5;10;0

本文出自 “8397752” 部落格,請務必保留此出處http://8407752.blog.51cto.com/8397752/1701452

Nagios遠程監控

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.