Nagios安装配置和基于NRPE监控远程Linux主机
实验平台:LInux-5.8,yum源已配置好,SeLinux处于关闭状态监控端:172.16.14.15
被监控端:172.16.14.14
一:安装配置Nagios
这个过程在监控端172.16.14.15实现:
1、解决安装Nagios的依赖关系:
Nagios基本组件的运行依赖于httpd、gcc和gd
[*]# yum -y install httpd gcc glibc glibc-common gd gd-devel \
[*] php php-mysql mysql mysql-devel mysql-server
2、添加nagios运行所需要的用户和组:
[*]# groupaddnagcmd
[*]# useradd -G nagcmd nagios
[*]# passwd nagios
把apache加入到nagcmd组,以便于在通过web Interface操作nagios时能够具有足够的权限:
[*]# usermod -a -G nagcmd apache
3、编译安装nagios:
[*]# tar zxf nagios-3.3.1.tar.gz
[*]# cd nagios
[*]# ./configure--with-command-group=nagcmd --enable-event-broker
[*]##--sysconfdir=/etc/nagios 自己可以指定nagios的配置文件路径
[*]##--with-command-group=nagcmd使用前面创建的组
[*]##--enable-event-broker 为使用NDOutils做准备的
[*]
[*]# make all
[*]# make install ##安装nagios
[*]# make install-init##安装nagios的init脚本,即/etc/rc.d/init.d/nagios
[*]# make install-commandmode##安装命令模式
[*]# make install-config##安装生成配置文件
[*]
[*]# make install-webconf ##安装web接口的,识别nagios程序位置/usr/local/nagios/share
[*]##然后进入/etc/httpd/conf.d,会发现多了nagios.conf文件,为访问
[*]##nagios的web页面定义了一个别名,当访问172.16.14.15/nagios时就可
[*]##以访问/usr/local/nagios/share的文件了
我们的nagios web页面不能随便让人访问吧,所以需创建一个登录nagios
web程序的用户,只有通过认证的用户才能访问:
[*]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
重新启动httpd:
[*]# service httpd restart
4、编译安装nagios-plugins
nagios的所有监控工作都是通过插件完成的,因此,在启动nagios之前
还需要为其安装官方提供的插件。
[*]# tar zxf nagios-plugins-1.4.15.tar.gz
[*]# cd nagios-plugins-1.4.15
[*]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[*]# make
[*]# make install
5、配置并启动Nagios
[*](1)把nagios添加为系统服务并将之加入到自动启动服务队列:
[*]# chkconfig --add nagios
[*]# chkconfig nagios on
[*]
[*](2)检查其主配置文件的语法是否正确:
[*]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[*]
[*](3)如果上面的语法检查没有问题,接下来就可以正式启动nagios服务了:
[*]# service nagios start
接下来就可以访问nagios了,提示输入用户名和密码:
输入前面设定的用户和密码后,进入nagios的界面:
查看hosts信息:
各服务意思:
[*]current Load:CPU的负载情况,当前显示是Ok的
[*]Current Users:用户数
[*]HTTP:显示HTTP服务事物信息的,当前显示WARNING是因为没有提供web页面
[*]PING:用来ping主机的
[*]Root Partition:显示根分区信息的
[*]SSH:显示SSH的状态的
[*]Swap Usage:显示交换分区使用情况的
[*]Total Processes:总进程数状态
[*]
[*]在右上角还有一个各项状态汇总图
二:基于NRPE监控远程Linux主机
NRPE(Nagios Remote Plugin Executor)是用于在远端服务器上运行检测命令的守护进程,
它用于让Nagios监控端基于安装的方式触发远端主机上的检测命令,并将检测结果输出至监控端
监控端:172.16.14.15
被监控端:172.16.14.14
[*]安装开发包组:
[*]yum-y groupinstall "Development Libraries" "Development Tools"
1、安装配置被监控端
1)先添加nagios用户
[*]# useradd -s /sbin/nologin nagios
2)NRPE依赖于nagios-plugins,因此,需要先安装之
[*]# tar zxf nagios-plugins-1.4.15.tar.gz
[*]# cd nagios-plugins-1.4.15
[*]# ./configure --with-nagios-user=nagios --with-nagios-
[*]
[*]group=nagios
[*]# make all
[*]# make install
3)安装NRPE
[*]# tar -zxvf nrpe-2.13.tar.gz
[*]# cd nrpe-2.13.tar.gz
[*]# ./configure --with-nrpe-user=nagios \ ##添加nrpe用户
[*] --with-nrpe-group=nagios \ ##nrpe组
[*] --with-nagios-user=nagios \ ##nagios用户名
[*] --with-nagios-group=nagios \ ##nagios组名
[*] --enable-command-args \ ##向命令传递参数的
[*] --enable-ssl ##默认选项,监控端和被监控端传递信息需要ssl加密
[*]
[*]# make all
[*]# make install-plugin ##安装插件
[*]# make install-daemon ##将nrpe安装成守护进程
[*]# make install-daemon-config ##安装守护进程的配置文件
4)配置NRPE:
[*]# vim /usr/local/nagios/etc/nrpe.conf
[*]
[*]log_facility=daemon ##日志文件的设施
[*]pid_file=/var/run/nrpe.pid ##pid文件路径,自己可以定义
[*]server_address=172.16.14.14##监听的地址
[*]server_port=5666 ##端口号
[*]nrpe_user=nagios ##nrpe用户
[*]nrpe_group=nagios##nrpe组名
[*]allowed_hosts=172.16.14.15##定义本机所允许的监控端的IP地址。
[*]
[*]command_timeout=60 ##定义命令的超时时间
[*]connection_timeout=300 ##链接的超时时间
[*]debug=0##调试功能没打开
5)启动NRPE:
[*]# /usr/local/nagios/bin/nrpe -c
[*]
[*]/usr/local/nagios/etc/nrpe.cfg –d
为了便于NRPE服务的启动,可以将如下内容定义为/etc/init.d/nrped脚本:
[*]#!/bin/bash
[*]# chkconfig: 2345 88 12
[*]# description: NRPE DAEMON
[*]
[*]NRPE=/usr/local/nagios/bin/nrpe
[*]NRPECONF=/usr/local/nagios/etc/nrpe.cfg
[*]
[*]case "$1" in
[*] start)
[*] echo -n "Starting NRPE daemon..."
[*] $NRPE -c $NRPECONF -d
[*] echo " done."
[*] ;;
[*] stop)
[*] echo -n "Stopping NRPE daemon..."
[*] pkill -u nagios nrpe
[*] echo " done."
[*] ;;
[*] restart)
[*] $0 stop
[*] sleep 2
[*] $0 start
[*] ;;
[*] *)
[*] echo "Usage: $0 start|stop|restart"
[*] ;;
[*] esac
[*]exit 0
赋予执行权限:
[*]# chmod +x /etc/init.d/nrped
添加至服务列表:
[*]# chkconfig --add nrped
[*]# chkconfig --list nrped
6)启动nrped服务和查看端口:
[*]# service nrped start
[*]
[*]# netstat -tnlp | grep 5666
[*]tcp 0 0 172.16.14.14:5666 0.0.0.0:* LISTEN \
[*] 24909/nrpe
7)配置允许远程主机监控的对象:
在/usr/local/nagios/etc/nrpe.cfg中添加:
[*]command=/usr/local/nagios/libexec/check_users -w 5 -c 10
[*]command=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
[*]command=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
[*]command=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2
[*]command=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda3
[*]command=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
[*]command=/usr/local/nagios/libexec/check_procs -w 150 -c 200
2、配置监控端:
1)安装NRPE
[*]# tar -zxvf nrpe-2.13.tar.gz
[*]# cd nrpe-2.13.tar.gz
[*]# ./configure --with-nrpe-user=nagios \
[*] --with-nrpe-group=nagios \
[*] --with-nagios-user=nagios \
[*] --with-nagios-group=nagios \
[*] --enable-command-args \
[*] --enable-ssl
[*]# make all
[*]# make install-plugin
安装完成后在/usr/local/nagios/libexec/下会生成一个check_nrpe插件
[*]# cd /usr/local/nagios/libexec/
[*]# ./check_nrpe -H 172.16.14.14
[*]NRPE v2.13 ##说明监控端与被监控端可以通信了
2)定义如何监控远程主机及服务:
[*]在commands.cfg 定义check_nrpe命令:
[*] define command
[*] {
[*] command_name check_nrpe
[*] command_line $USER1$/check_nrpe –H $HOSTADDRESS$ -c $ARG1$
[*]}
[*]
3)在/usr/local/nagios/etc/objects下定义Linux主机linhost.cfg
定义的对象要与被监控端nrpe.conf文件中允许被监控的对象对应:
[*]# vim linhost.cfg
[*]
[*]define host{
[*] use linux-server
[*] host_name linhost
[*] alias My Linux Host
[*] address 172.16.14.14
[*]}
[*]
[*]define service{
[*] use generic-service
[*] host_name linhost
[*] service_description CHECK USERS
[*] check_command check_nrpe!check_users
[*] }
[*]
[*]define service{
[*] use generic-service
[*] host_name linhost
[*] service_description Load
[*] check_command check_nrpe!check_load
[*] }
[*]
[*]define service{
[*] use generic-service
[*] host_name linhost
[*] service_description SDA1
[*] check_command check_nrpe!check_sda1
[*] }
[*]
[*]define service{
[*] use generic-service
[*] host_name linhost
[*] service_description SDA2
[*] check_command check_nrpe!check_sda2
[*] }
[*]
[*]define service{
[*] use generic-service
[*] host_name linhost
[*] service_description SDA3
[*] check_command check_nrpe!check_sda3
[*] }
[*]
[*]define service{
[*] use generic-service
[*] host_name linhost
[*] service_description Zombie
[*] check_command check_nrpe!check_zombie_procs
[*] }
[*]
[*]define service{
[*] use generic-service
[*] host_name linhost
[*] service_description Total procs
[*] check_command check_nrpe!check_total_procs
4)将linuxhost.cfg包含进主配置文件中:
[*]# vim /usr/local/nagios/etc/nagios.cfg
[*]cfg_file=/usr/local/nagios/etc/objects/linhost.cfg
5)检查语法正确性:
[*]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[*]Total Warnings: 0
[*]Total Errors: 0
[*]Things look okay - No serious problems were detected during the pre-flight check
一定要记得重启服务啊,我在做时忘了重启服务了,排错好长时间,也为前面步骤错了呢,惭愧!
# service nagios restart
3、查看web nagios页面,显示自己定义的linhost信息:
这样就实现了对Linux主机进行远程监控了
有道理。。。 听君一席话,省我十本书! 锻炼肌肉,防止挨揍! 我本非随便的人,但如果你想随便,那我就随你的便好啦! 在一辆拥挤的公车上,一位女郎忽然叫了起来:别挤啦!别挤啦!把人家的奶都挤出来啦!(她拿着酸奶呢)。 我真想亲口管你爷爷叫声:爹!
页:
[1]