搭建環境
centos-6.5(x64)
軟體包
nagios-3.4.1.tar.gz
nagios-plugins-1.4.16.tar.gz
nrpe-2.13.tar.gz
軟體安裝
yum install -y wget* httpd* php make* net-snmp* gcc* glibc* gd* xinetd* openssl* openssh*
useradd nagios && groupadd nagcmd
usermod -a -g nagcmd nagios
tar zxvf nagios-3.4.1.tar.gz
tar zxvf nagios-plugins-1.4.15.tar.gz
cd nagios
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
cp -r contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -r nagios:nagios /usr/local/nagios/libexec/eventhandlers
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios start
htpasswd –c /usr/local/nagios/etc/htpasswd.users nagios
cd nagios-plugins-1.4.15
./configure --with-user=nagios --with-group=nagios
make
chkconfig --add nagios
chkconfig --level 35 nagios on
tar zxvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
service xinetd restart
vim /etc/xinetd.d/nrpe
only_from = 127.0.0.1 服務端ip
vim/usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,服務端ip
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
netstat -tuplna | grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* listen 20863/nrpe
http://伺服器ip/nagios
驗證成功 使用者名 nagios 密碼 nagiosadmin (自行設定)
linux用戶端安裝
usermod -a -g nagcmd nagios
yum -y install xinetd* openssl* openssh*
./configure --with-user=nagios--with-group=nagcmd
make -j4 && make install
chown -r nagios:nagios /usr/local/nagios && chown -r nagios:nagios/usr/local/nagios/libexec/
make install-deemon-config
only_from = 127.0.0.1 服務端ip
allowed_hosts=127.0.0.1,服務端ip
tcp 0 0 0.0.0.0:5666 0.0.0.0:* listen 20863/nrpe
/usr/local/nagios/libexec/check_nrpe -h 服務端ip 服務端檢查用戶端nrpe插件版本
nrpe v2.13
/usr/local/nagios/libexec/check_nrpe -h 用戶端ip 用戶端檢查服務端nrpe插件版本
pkill nrpe;
/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d
服務端添加主機
vim/usr/local/nagios/etc/objects/commands.cfg
# 'check_nrpe' command definition
definecommand{
command_name check_nrpe
command_line $user1$/check_nrpe-h $hostaddress$ -c $arg1$
} 最後一行添加預設配置檔案預設沒有此配置
vim /usr/local/nagios/etc/nagios.cfg
#cfg_dir=/usr/local/nagios/etc/servers 去掉#
mkdir -p /usr/local/nagios/etc/servers
cd /usr/local/nagios/etc/servers
touch 10.58.130.172.cfg
define host{
use linux-server
host_name 10.58.130.172
alias 10.58.130.172
address 10.58.130.172
}
define service{
use generic-service
service_description check_ping
check_command check_ping!100.0,20%!200.0,50%
max_check_attempts 5
normal_check_interval 1
}
host_name 10.58.130.172
service_description check_ftp
check_command check_ftp!21
max_check_attempts 5
defineservice{
use generic-service
host_name 10.58.130.172
service_description check_ssh
check_command check_ssh
max_check_attempts 5
normal_check_interval 1
service_description check_http
check_command check_http
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
total warnings: 0
total errors: 0 看到提示就是配置沒有錯誤
service nagios restart (service nagios reload)
running configuration check...done.
stopping nagios: done.
starting nagios: done