Nagios是一个监视系统运行状态和网络信息的监视系统。Nagios能监视所指定的本地或远程主机以及服务,同时提供异常通知功能,可运行在Linux/Unix平台之上,同时提供一个可选的基于浏览器的WEB界面以方便系统管理人员查看网络状态,各种系统问题,以及日志等。
工作原理图(取自网上)
配置图
一、配置前准备:
1、同步两台机子时间
ntpdate ntpdate time.nist.gov
添加定时任务,每10分钟同步一次网络时间
[[email protected] ~]# crontab -l
0-59/10 * * * * /usr/sbin/ntpdate time.nist.gov
2、环境安装
安装gcc编译工具
[[email protected] ~]# yum install gcc glibc glibc-common
安装gd库
yum install gd gd-devel
安装lamp
yum install php*
yum install httpd
安装mysql
yum install mysql mysql-server mysql-devel
3、添加nagios 所需的组及用户
useradd nagios
passwd nagios
groupadd nagios
usermod -a -G nagios nagios
usermod -a -G nagios apache
检查组信息
id apache
id -n -G nagios
二、
nagios-server端配置
1、下载所需安装包
nagios、nagios-plugins、nrpe
解压
tar -zxf nagios-3.3.1.tar.gz
tar -zxf nagios-plugins-1.4.14.tar.gz
tar -zxf nrpe-1.8.tar.gz
创建目录并将解压文件移至目录下
[[email protected] ~]# mkdir /var/application/nagios -p
[[email protected] ~]# mv nagios /var/application/nagios/
[[email protected] ~]# mv nagios-plugins-1.4.14 /var/application/nagios/
[[email protected] ~]# mv nrpe-1.8 /var/application/nagios/
2、编辑安装nagios
进入nagios目录
cd /var /application/nagios/nagios
编译
./configure --with-command-group=nagios --enable-even-broker
make all
make install
make install-init
make install-commandmode
make install-config
安装nagios web配置文件
make install-webconf
创建web登陆用户nagiosadmin
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
cat /usr/local/nagios/etc/htpasswd.users
添加监控报警接收email地址
vi /usr/local/nagios/etc/objects/contacts.cfg +35
需要启动postfix
[[email protected] nagios]# service postfix start
Starting postfix: [ OK ]
启动httpd
service httpd start
添加服务自启动
chkconfig --add nagios
chkconfig --level 3 nagios
检查配置文件语法
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios checkconfig
启动nagios
/etc/init.d/nagios start
ps -ef |grep nagios |grep -v grep
在win下测试登陆,如下表示安装成功
3、编译安装nagios-plugins
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
make
make install
检查插件个数
ls /usr/local/nagios/libexec/ |wc -l
4、编译安装nrpe
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
注意nrpe启动依赖于xinetd服务,若没有需先安装
[[email protected] nrpe-1.8]# service xinted start
xinted: unrecognized service
解决: [[email protected] nrpe-1.8]# yum -y install xinetd
[[email protected] nrpe-1.8]# service xinetd restart
Stopping xinetd: [FAILED]
Starting xinetd: [ OK ]
nrpe端口为5666,检查启动
5、本机测试nrpe
[[email protected] nrpe-1.8]# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
OK - load average: 0.06, 0.08, 0.16|load1=0.060;15.000;30.000;0; load5=0.080;10.000;25.000;0; load15=0.160;5.000;20.000;0;
三、nagios-client端配置
1、编译安装nagios-plugins(同服务端安装)
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
make
make install
ls /usr/local/nagios/libexec/ |wc -l
2、编译安装nrpe
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
四、Server端实现监控Client端
1、nagios-server编辑nrpe配置文件
vi /etc/xinetd.d/nrpe
编辑nagios配置文件,添加监控实例
[[email protected] ~]# vi /usr/local/nagios/etc/nagios.cfg
# Definitions for monitoring the Linux host
cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg
复制localhost.cfg 成实例文件mylinux.cfg
cp -r /usr/local/nagios/etc/objects/localhost.cfg /usr/local/nagios/etc/objects/mylinux.cfg
修改实例文件mylinux.cfg
vi /usr/local/nagios/etc/objects/mylinux.cfg
....部分监控内容省略,内容可以根据需求调整。
2、naggios-client编辑nrpe.cfg
完成后,重启:
pkill nrpe
[[email protected] ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
3、Server主机测试
/usr/local/nagios/libexec/check_nrpe -H 192.168.6.129 -c check_total_procs
[[email protected] ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.6.129 -c check_total_procs
PROCS OK: 79 processes
五、测试
通过web页面测试
至此简单nagios监控配置完成。