排版不太好,沒有圖文詳解有的地方可能比較難理解,會不定期的更新詳解,等我有空了
注意:nagios插件nagios-plugins+nrpe安裝在被監控linux主機上,否則,不能被監控.別外因爲它們間的通信是加密的SSL,所以在 編譯安裝時都要加上選項, ./configure --enable-ssl --with-ssl-lib=/lib/,否則也會出錯.
1、 環境搭建
Server: nagios nagios-plugins nrpe 192.168.1.20
client: nagios-plugins nrpe 192.168.1.21
nagios服務器端(監控端192.168.1.20)
yum install httpd gettext mysql mysql-server mysql-devel php php-mysql php-pear glibc glibc-common gd gd-devel
在線下載nagios程序和插件,我個人是把nagios,nagios-plugins,nrpe下載到win7上通過winscp上傳到linux主機上進行編譯的,下面的這兩個地址可以使用,版本和我使用的不太一樣,請耐心
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
wget http://sourceforge.net/projects/nagios-cn/files/sourcecode/zh_CN%203.2.3/nagios-cn-3.2.3.tar.bz2/download
[root@localhost src]# useradd nagios
[root@localhost src]# groupadd nagcmd
[root@localhost src]# usermod -G nagcmd nagios
[root@localhost src]# usermod -G nagcmd apache
tar zxvf nagios-3.5.0.tar.gz
cd nagios
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
tar zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib=/usr/lib/
make all
make install-plugin
make install-daemon
make install-daemon-config
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
十、配置本機監控
根據如下配置,完成本機監控的配置,能實現nagios對本機的監控支持。
1、新建monitor文件夾,拷貝示例配置文件到該文件夾下
cd /usr/local/nagios/etc
cp -rf ./objects/* monitor
2、刪除不需要得配置文件
cd /usr/local/nagios/etc/monitor
rm windows.cfg switch.cfg printer.cfg
3、修改contacts.cfg(聯繫人配置文件)
define contact{
contact_name nagios
use generic-contact
alias nagios
email [email protected]
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagios
}
4、修改cgi.cfg
default_user_name=nagios
5、修改nagios.cfg
將所有cfg_file=都註釋掉添加如下一行
cfg_dir=/usr/local/nagios/etc/monitor
6、使用命令:/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg檢查配置是否有誤
7、重啓nagios:/etc/init.d/nagios start
一定要記得啓動http
/etc/init.d/httpd start
此時登錄到nagios的web界面,就能查看到監控界面左側的主機和服務中有我們配置好的本地監控的信息啦
nagios安裝完後,使用check_http報HTTP WARNING: HTTP/1.1 403 Forbidden - 5240 bytes in 0.001 second response time |time=0.001260s;;;0.000000 size=5240B;;;0
原因是因爲在webserver的發佈目錄中,沒有找到index.html的文件
touch /var/www/html/index.html
在nagios的etc目錄中增加check_nrpe檢測
vim /usr/local/nagios/etc/monitor/commands.cfg
#'check_nrpe' command definition
define command{
command_name check_nrpe
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
增加21.cfg監控192.168.1.21服務器,這個配置在nagios服務端(監控端192.168.1.20端)
define host{
use linux-server
host_name test-1
alias test-1
address 192.168.1.21
}
define service{
use generic-service
host_name test-1
service_description ping
check_command check_nrpe!check_ping
}
define service{
use generic-service
host_name test-1
service_description check-disk
check_command check_nrpe!check_disk
}
define service{
use generic-service
host_name test-1
service_description check-users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name test-1
service_description check-procs
check_command check_nrpe!check_procs
}
define service{
use generic-service
host_name test-1
service_description check-load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name test-1
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name test-1
service_description check-ssh
check_command check_nrpe!check_ssh
}
vim /usr/local/nagios/etc/nrpe.cfg
allowed_host=192.168.1.21,127.0.0.1
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
lsof -i :5666
/usr/local/nagios/libexec/check_nrpe -H localhost
/etc/init.d/nagios restart
/etc/init.d/httpd restart
/etc/init.d/mysqld start(可以啓動也可以不用啓動)
有的時候多重啓服務是沒有錯的,也許是某一個服務沒有打開導致打不開監控頁面
配置被監控服務器(被監控端192.168.1.21)
yum install openssl-devel
useradd nagios
tar zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib=/usr/lib/
make all
make install-plugin
make install-daemon
make install-daemon-config
vim /usr/local/nagios/etc/nrpe.cfg
allowed_host=192.168.1.20,127.0.0.1
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 /dev/sda1 /dev/sda3
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
command[check_ssh]=/usr/local/nagios/libexec/check_ssh -4 127.0.0.1
command[check_ping]=/usr/local/nagios/libexec/check_ping -H 192.168.1.20 -w 40,20% -c 100,50% -p 3 -t 2
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
如果什麼地方有錯,請指正,我會改的