歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> nagios服務端配置及客戶的安裝配置步驟分享[圖文]

nagios服務端配置及客戶的安裝配置步驟分享[圖文]

日期:2017/3/1 18:06:03   编辑:Linux技術

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

2.nagios 服務端的配置

(1).首先默認安裝好後,nagios就創建好了一個分組和一些服務,這個文件就是localhost.cfg文件。現在我們要創建自己的文件

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

放在conf目錄下便於管理。

55

注:這些文件及相關目錄原先是沒有的,要自己創建並授權給它們

(2).要創建自己的組就先要在contacts.cfg裡面定一個自己的聯系人。

image

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

image

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

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)

66

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"配置一下。

77

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文件裡就行了。

到此就配置完了。

Copyright © Linux教程網 All Rights Reserved