搭建环境
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