nagios服務端配置及客戶的安裝配置

來源:互聯網
上載者:User

1.上面我講了一些nagios服務端的安裝和簡單的配置,現在來講一下服務端監控多台伺服器的以及被監控端的安裝配置。

2.nagios 服務端的配置

(1).首先預設安裝好後,nagios就建立好了一個分組和一些服務,這個檔案就是localhost.cfg檔案。現在我們要建立自己的檔案

     把nagios.cfg裡面的定義localhost.cfg這個注釋掉,然後在開啟hostgroup.cfg,host.cfg,services.cfg這三個檔案。我把這三個檔案

放在conf目錄下便於管理。

註:這些檔案及相關目錄原先是沒有的,要自己建立並授權給它們

(2).要建立自己的組就先要在contacts.cfg裡面定一個自己的連絡人。

Linux-servers是我自己建的連絡人各聯絡組。

註:如果不建這個連絡人和組,在後面的hostgroup.cfg裡面不能定義自己的主機群組員。

(3).現在來建自己的監控主機、監控服務,監控組。

先講一下他們三者的關係,監控組(hostgroup.cfg)包含了監控主機(host.cfg)包含了監控服務(services.cfg)

hostgroup.cfg->host.cfg->services.cfg

只要有一個不在就會報錯。

檢查nagios.cfg這個檔案的報錯資訊是

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

可以看到你哪裡配置錯了,我也是通過這個來排錯的。

 

     1.hostgroup.cfg

define hostgroup {
hostgroup_name  Linux-servers
alias           Linux-servers
members         CentOS
}

     2.host.cfg

define host {
host_name               CentOS
alias                   server,host-pnp
address                 192.168.1.8
contact_groups          Linux-servers
check_command           check-host-alive
max_check_attempts      5
notification_interval   10
notification_period     24x7
notification_options    d,u,r
}

    3.services.cfg

define service {
        host_name               CentOS
        use                     local-service,srv-pnp
        service_description     CPU
        check_period            24x7
        max_check_attempts      4
        normal_check_interval   1
        retry_check_interval    1
        contact_groups          Linux-servers
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        check_command           check_nrpe!check_cpu
       }
define service {
        host_name               CentOS
        use                     local-service,srv-pnp
        service_description     CPU_load
        check_period            24x7
        max_check_attempts      4
        normal_check_interval   1
        retry_check_interval    1
        contact_groups          Linux-servers
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        check_command           check_nrpe!check_load
       }

//services.cfg 這裡只給出了兩個,其它的按自己的需要添加就行了。

重啟nagios之後先檢查一下有沒有錯誤了,沒有的話就重啟一下

service nagios restart

上面的圖是我配好後的結果,現在來配置被監控端。

3.nagios 被監控端的配置。

(1).安裝nagios-plugins

如果後面的configure沒有檢查到mysql這一項,看一下mysql-devel有沒有安裝,沒有安裝一下。

tar –xvf nagios-plugins-1.4.15.tar.gz

cd nagios-plugins-1.4.15

./configure

make && make install

(2).安裝nrpe

tar –xvf nrpe-2.12.tar.gz

cd nrpe-2.12

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

make install-xinetd //這個是用xinetd來管理nrpe的啟動和關閉的,可以加上也可以不加上。

(3).到些被監控的軟體裝好了,還要裝一下snmp來收集資料,安裝和配置net-snmp我已經在前面說過了,這裡就不說了。

現在來配置一下監控項(nrpe.cnf)

log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=192.168.1.7

dont_blame_nrpe=1
debug=1
command_timeout=30
connection_timeout=300

command[check_http]=/usr/local/nagios/libexec/check_http -I localhost -u /index.php -t 60
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 5% -c 3% -A -i '/dev/shm'
command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C nagios -H localhost -I 2 -w 12,30 -c 15,35 -M -b -6
command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh
command[check_mem]=/usr/local/nagios/libexec/check_mem.sh
command[check_ips]=/usr/local/nagios/libexec/ip_conn.sh  400 600
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,8 -c 30,25,20
command[check_ftp]=/usr/local/nagios/libexec/check_ftp 127.0.0.1 -w 10 -c 60

這裡有幾個是沒有的要自己去網上找,然後下載下來放到/usr/local/nagios/libexec/下面並給執行許可權,擁有者nagios。(check_traffic.sh,check_cpu.sh,

check_mem.sh,ip_conn.sh)

(4)監控mysql資料庫和遠程主機還需要在服務端的"commands.cfg"配置一下。

define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

define command {
       command_name     check_mysql
       command_line     $USER1$/check_mysql -H $HOSTADDRESS$ -unagdb -pwww -d nagdb
       }

define command{
      command_name      check_mysql_health
      command_line      $USER1$/check_mysql_health -hostname $HOSTADDRESS$ -username nagdb -password www -warning  $ARG1$ -critical $ARG2$ -mode threads-connected
      }

隨便找一個位置放到commands.cfg檔案裡就行了。

到此就配置完了

 

摘自 HY_51CEO 的BLOG

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.