1. 程式人生 > 實用技巧 >nagios 監控linux 主機

nagios 監控linux 主機

1.解決時間同步問題

當然前提是你的伺服器已經安裝了ntp的程式,如果沒有安裝可以: yum -y install ntp /usr/sbin/ntpdate pool.ntp.org

uptime

2.安裝Nagios所需要的基礎包

yum -y install gcc glibc glibc-common yum -y install gd gd-devdel

yum -y install openssl-devel

3.建立nagios 使用者

useradd nagios

4.下載安裝最新nagios外掛

wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz

tar zxvf nagios-plugins-1.5.tar.gz

cd nagios-plugins-1.5

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make && make install

5.更改目錄許可權:

chown nagios.nagios /usr/local/nagios

chown -R nagios.nagios /usr/local/nagios/libexec

6.安裝nrpe外掛

wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz/download

tar zxvf nrpe-2.15.tar.gz

cd nrpe-2.15

./configure

150236626.jpg

make all

make install-plugin

make install-daemon

make install-daemon-config


7.將NRPE deamon作為xinetd 下的一個服務執行

yum -y install xinetd

make install-xinetd

顯示如下

150758110.jpg

可以看到建立了這個檔案/etc/xinetd.d/nrpe,編輯這個指令碼:

vim /etc/xinetd.d/nrpe

151001131.jpg

8.編輯/etc/services這個檔案,新增nrpe服務

vim /etc/services

在最後新增如下:

#Local services

nrpe 5666/tcp #nrpe



重啟xinetd的服務:

service xinetd restart

檢視nrpe是否已經啟動:

[[email protected] nrpe-2.15]# netstat -at |grep nrpe

tcp 0 0 *:nrpe *:* LISTEN

[[email protected] nrpe-2.15]# netstat -an |grep 5666

tcp 0 0 :::5666 :::* LIST

檢視nrpe 是否正常工作 

/usr/local/nagios/libexec/check_nrpe -H localhost


8.檢視nrpe的監控命令:

vim /usr/local/nagios/etc/nrpe.cfg

163932486.jpg

上面這5行定義的命令分別是檢測登陸使用者數,cpu負載,sda1的容量,殭屍程序,總程序數


9.配置監控端:

先安裝openssl-devel

yum -y install openssl-devel

安裝nrpe

tar -zxvf nrpe-2.8.1.tar.gz

cd nrpe-2.8.1

./configure --enable-ssl --with-ssl-lib=/usr/lib/

make all

make install-plugin

只執行之一步就行了,因為只需要check_nrpe這個外掛

測試與被監控機的通訊:

/usr/local/nagios/libexec/check_nrpe -H 192.168.1.243

返回nrpe的版本說明通訊正常


10.在command.cfg裡新增外部構件nrpe

vi /usr/local/nagios/etc/objects/commands.cfg
新增
#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

配置被監控主機:

vim /usr/local/nagios/etc/nagios.cfg

新增:

cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg

11.配置mylinux.cfg

cd /usr/local/nagios/etc/objects/

touch mylinux.cfg

chown nagios.nagios mylinux.cfg

vim mylinux.cfg

寫入如下:

define host{
use linux-server
host_name mylinux
alias mylinux
address 192.168.1.243
}
define service{
use generic-service
host_name mylinux
service_description HTTP
check_command check_http
}
define service{
use generic-service
host_name mylinux
service_description SSH
check_command check_ssh
}
define service{
use generic-service
host_name mylinux
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name mylinux
service_description check-load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name mylinux
service_description check-disk
check_command check_nrpe!check_disk
}
define service{
use generic-service
host_name mylinux
service_description check-users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name mylinux
service_description otal_procs
check_command check_nrpe!check_total_procs
}

檢查配置檔案是否錯誤:

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

112604631.jpg

12.重啟nagios: service nagios restart

13.檢視web

112733939.jpg

完成!







轉載於:https://blog.51cto.com/snbolinux/1329456