===================================服务端安装nagios=======================================
1.关闭selinx
vim /etc/selinux/config

setenforce 0

2.关闭防火墙
iptables -F
iptables -X
/bin/systemctl save iptables.service

3.安装依赖包
yum -y install make perl gcc glibc glibc-common httpd php gd gd-devel openssl-devel xinetd openssh-clients vim openssl-devel

4.添加账户
useradd -m nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache

5.开始编译安装
./configure --with-command-group=nagcmd --prefix=/usr/local/nagios
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
htpasswd  -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

6.启动服务
chkconfig --add nagios
chkconfig nagios on
chown -R nagios.nagios /usr/local/nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service httpd restart


7.#It appears as though you do not have permission to view information for any of the hosts you requested...
vim /usr/local/nagios/etc/cgi.cfg
use_authentication=0

至此nagios安装完毕

===================================服务端安装插件nagios-plugins==============================

8.安装插件
tar xzvf tar xzf nagios-plugins.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

9.编辑填上自己email
vim /usr/local/nagios/etc/objects/contacts.cfg
email     nagios@localhost   ; **** CHANGE THIS TO YOUR EMAIL

10.启动
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
chown -R nagios.nagios /usr/local/nagios
service nagios restart


11.编辑
vim /usr/local/nagios/etc/nagios.cfg 
cfg_dir=/usr/local/nagios/etc/monitor
mkdir -p /usr/local/nagios/etc/monitor
chown nagios.nagios monitor -R

配置 commands.cfg
vim /usr/local/nagios/etc/objects/commands.cfg
在最后一行添加
#check nrpe

define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios restart

===================================服务端安装插件nrpe==============================
1.

安装nrpe-2.12
cd nrpe-2.12
./configure --prefix=/usr/local/nagios

安装nrpe 插件
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd

vim  /etc/services最后加入

nrpe      5666/tcp       #NRPE随后重启 xinetd 服务

/bin/systemctl  restart xinetd.service
netstat -ant |grep 5666


2.测试插件与客户端是否能正常通信

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

NRPE v2.12


三. 测试脚本没有问题

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

cd /usr/local/nagios/var/rw
chmod 777 nagios.cmd
vim /usr/local/nagios/etc/nrpe.cfg

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_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 250 -c 300
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20 -c 10

四. 重启 nagios

/etc/init.d/nagios restart
五. 连接web 测试

http://192.168.6.103/nagios


========================================================================

一.Nagios 监控客户端

1.在客户端安装监控插件
useradd nagios
groupadd nagcmd

useradd -s /usr/sbin/nologin nagios

tar zxvf nagios-plugins-1.4.14.tar.gz

cd nagios-plugins-1.4.14

./configure

make

make install设置插件目录权限

chown nagios.nagios /usr/local/nagios

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

2.安装 nrpe daemon

tar zxvf nrpe-2.12.tar.gz

cd nrpe-2.12
./configure --prefix=/usr/local/nagios
./configure

make all

make install-plugin

make install-daemon

make install-daemon-config作为 xinetd 服务nrpe守护进程

make install-xinetd配置 xinetd nrpe 只能由监控服务器监控

vim /etc/xinetd.d/nrpe

only_from       = 127.0.0.1 <改为nagios服务器IP地址>添加nrpe守护进程

vim  /etc/services最后加入

nrpe      5666/tcp       #NRPE随后重启 xinetd 服务

/bin/systemctl  restart xinetd.service

3.查看服务器是否起来了

netstat -ant |grep 5666

tcp        0      0 0.0.0.0:5666            0.0.0.0:*               LISTEN看到 5666 端口已经开始监听了,说明没问题

测试本地是否可以通信

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

NRPE v2.12

 

==============================================================================
重启nrpe

先停止nrpe

[root@client nagios]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[root@client nagios]# cat /var/run/nrpe.pid
29116


[root@localhost bin]# cat /var/run/nrpe.pid
25316
[root@localhost bin]#kill 25316

后启动
[root@localhost bin]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
netstat -an | grep 5666

设置自动启动
vi /etc/rc.local  在其中加入此行:
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
被监控端设置完成