5、服务端配置告警
vim /etc/nagios/objects/contacts.cfg
#添加内容
define contact{
contact_name David ;联系人名称
use generic-contact ;引用templates.cfg定义
alias 12 ;联系人名称
email 463245818@qq.com ;联系人邮箱
}
define contact{
contact_name Nance
use generic-contact
alias 13
email 463245818@qq.com
}
define contactgroup{
contactgroup_name common ;组名称
alias 112
members David,Nance ;组成员
}
#然后打开
vim /etc/nagios/conf.d/192.168.134.132.cfg
#在比较重要的服务增加
define service{
use generic-service
host_name 192.168.134.132
service_description check_load
check_command check_nrpe!check_load
max_check_attempts 5
normal_check_interval 1
contact_groups common
notifications_enabled 1
notification_period 24x7
notification_options w,u,c,r
}
#其中
notifications_enabled 1 ;是否开启提醒功能。1为开启,0为禁用。一般,这个选项会在主配置文件(nagios.cfg)中定义,效果相同。
notification_period 24x7 ;发送提醒的时间段。非常重要的主机(服务)我定义为7×24,一般的主机(服务)就定义为上班时间。如果不在定义的时间段内,无论什么问题发生,都不>会发送提醒。
notification_options:w,u,c,r ;这个是service的状态。w为waning, u为unknown, c为critical, r为recover(恢复了),类似的还有一个 host对应的状态:d,u,r d = 状态为DOWN, u = 状态为UNREACHABLE, r = 状态恢复为OK,需要加入到host的定义配置里。
有错误看日志
cd /usr/local/src
yum install -y unzip #编译nagios需要的包
#这里使用nagios4..x在安装pnp4nagios存在不兼容问题所以建议下载nagios3.x
wget http://nchc.dl.sourceforge.net/p ... nagios-3.5.1.tar.gz
wget http://nchc.dl.sourceforge.net/p ... nagios-4.2.1.tar.gz
wget https://nagios-plugins.org/downl ... 56335937.1476780657
wgethttp://nchc.dl.sourceforge.net/p ... 15/nrpe-2.15.tar.gz
tar -zxvf nagios-3.5.1.tar.gz
cd nagios
./configure --prefix=/usr/local/nagios
make all #编译主程序
make install #对主程序,CGI以及HTML网页进行安装
make install-init #在/etc/rc.d/init.d目录产生nagios启动脚本
make install-commandmode #安装和配置外部命令对nagios主路径操作的权限。(这里所谓的外部命令主要是指apache通过CGI来对nagios的进行的操作,用户通过web以执行CGI程序脚本的方式来对nagios的检测结果进行读取和调用)
make install-config #将会在/usr/local/nagios/etc这个nagios编译安装的主配置路径下安装示例配置模板 (二)安装nagios-pluginscd /usr/local/src
tar -zxvf nagios-plugins-2.1.2.tar.gz
cd nagios-plugins-2.1.2
./configure --prefix=/usr/local/nagios #在/usr/local/nagios生成libexec目录,都是检测脚本
make install
基本安装完成,现在配置apache,让它可以用web界面访问
vim /usr/local/apache2/conf/httpd.conf
#添加一行
Include conf/extra/nagios.conf
#修改主和组
User nagios
Group nagios
(三)服务端安装插件nrpeyum install -y openssl openssl-devel #./configure需要的包
cd /usr/local/src/
tar -zxvf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure
make all
make install-plugin #安装nrpe插件check-nrpe
(四)在被监控主机安装nagios-plugins、nrpe要想在被监控的主机安装nrpe,首先要在被监控主机删安装nagios插件
useradd -s /sbin/nologin nagios
cd /usr/local/src
wget https://nagios-plugins.org/downl ... 56335937.1476780657
wget http://nchc.dl.sourceforge.net/p ... 15/nrpe-2.15.tar.gz
tar -zxvf nagios-plugins-2.1.2.tar.gz
cd nagios-plugins-2.1.2
./configure --prefix=/usr/local/nagios--with-nagios-user=nagios --with-nagios-group=nagios #在/usr/local/nagios生成libexec目录,都是检测脚本
make install
ls /usr/local/nagios/ #查看一下,共有三个目录
yum install -y openssl openssl-devel #./configure需要的包
tar -zxvf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure --enable-command-args #如果要给nrpe传递参数,在安装配置加上该参数
make all
make install-plugin #安装nrpe插件check_nrpe
make install-daemon #安装nrpe命令/usr/local/nagios/bin/nrpe
make install-daemon-config #安装nrpe配置文件nrpe.cfg
#跳过 版本为v3.0.1 操作这步makeinstall-config #安装nrpe配置文件nrpe.cfg
允许被别的主机监控,并自制命令
vim /usr/local/nagios/etc/nrpe.cfg
#修改
allowed_hosts=127.0.0.1,192.168.134.132
dont_blame_nrpe=1
command[check_sda1]=/usr/local/nagios/libexec/check_disk-w 20% -c 10% -p /dev/sda1
command[check_sda3]=/usr/local/nagios/libexec/check_disk-w 20% -c 10% -p /dev/sda3
/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d #启动nrpe服务
上面选项的解释
# -c <config_file> = Name of configfile to use
#-d = Run as a standalone daemon
/usr/local/nagios/libexec/check_nrpe -H127.0.0.1 #检查本机check_nrpe和nrpe daemon通信是否正常
停止nrpe服务可以杀死它的pid
ps -aux|grep nrpe #查看pid
(五)服务器端监控远程主机#把/usr/local/nagios/include下的文件读入nagios.cfg
vim /usr/local/nagios/etc/nagios.cfg
#添加一行
cfg_dir=/usr/local/nagios/include