nagios监控系统

本文发布时间: 2019-Mar-22
一、系统环境[root@host3 ~]# cat /etc/redhat-releaseCentOS release 5.5 (Final)[root@host3 ~]# uname -aLinux host3.zc.com 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:14 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux软件包存放目录/data所需软件包nagios-3.2.3.tar.gznagios-cn-3.2.3.tar.bz2nagios-plugins-1.4.9.tar.gznrpe-2.12.tar.gz监控端:host3ip:192.168.1.220被监控端:host4ip:192.168.1.221二、Nagios的快速安装监控机host3上安装:1、准备软件包在做安装之前确认要对该机器拥有root权限。确认你安装好的linux系统上已经安装如下软件包再继续。ApachephpGCC编译器GD库与开发库mysql(可选,为以后nagios扩展做准备)可以用yum命令来安装这些软件包,键入命令:[root@host3 ~]# yum -y install httpd php mysql mysql-server php-mysql httpd-manual php-adodb openphp-gd openssl gcc* openssl-devel xinetd2、建立nagios账号创建一个用户组名为nagcmd用于从Web接口执行外部命令。将nagios用户和apache用户都加到这个组中。[root@host3 ~]# useradd -s /sbin/nologin nagios[root@host3 ~]# groupadd nagcmd[root@host3 ~]# usermod -G nagcmd nagios[root@host3 ~]# usermod -G nagcmd apache3、nagios源码软件包安装解包、配置、编译安装nagios[root@host3 ~]# cd /data/[root@host3 data]# tar -zxf nagios-3.2.3.tar.gz[root@host3 data]# cd nagios-3.2.3[root@host3 nagios-3.2.3]# ./configure --with-command-group=nagcmd[root@host3 nagios-3.2.3]# make all //输出如下信息[root@host3 nagios-3.2.3]# make install //安装主程序,CGI和HTML文件[root@host3 nagios-3.2.3]# make install-init //在/etc/rc.d/init.d安装启动脚本[root@host3 nagios-3.2.3]# make install-config //配置目录权限[root@host3 nagios-3.2.3]# make install-commandmode //来安装示例配置文件[root@host3 nagios-3.2.3]# make install-webconf //生成web接口验证程序是否被正确安装。切换目录到安装路径(这里是/usr/local/nagios),看是否存在etc、bin、sbin、share、var这五个目录,如果存在则可以表明程序被正确的安装到系统了。后表是五个目录功能的简要说明:bin Nagios执行程序所在目录,nagios文件即为主程序etc Nagios配置文件位置,初始安装完后,只有几个*.cfg-sample文件sbin NagiosCgi文件所在目录,也就是执行外部命令所需文件所在的目录Share Nagios网页文件所在的目录Var Nagios日志文件、spid等文件所在的目录var/archives Emptydirectoryfor thearchivedlogsvar/rw Emptydirectoryfor theexternalcommandfile4、安装Nagios汉化插件[root@host3 nagios-3.2.3]# cd /data/[root@host3 data]# tar -jxf nagios-cn-3.2.3.tar.bz2[root@host3 data]# cd nagios-cn-3.2.3[root@host3 nagios-cn-3.2.3]# ./configure[root@host3 nagios-cn-3.2.3]# make all[root@host3 nagios-cn-3.2.3]# make install[root@host3 nagios-cn-3.2.3]# cd5、增加用户验证[root@host3 ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadminNewpassword:(输入redhat)Re-typenewpassword:(再输入一次密码redhat)nagiosadmin系统默认管理用户,拥有对nagios有完全控制权限。密码:redhat(注意:也可自定义用户,或增加用户,但必须从以下文件中设置)[root@host3 ~]# vim /usr/local/nagios/etc/cgi.cfgauthorized_for_system_information=nagiosadminauthorized_for_configuration_information=nagiosadminauthorized_for_system_commands=nagiosadminauthorized_for_all_services=nagiosadminauthorized_for_all_hosts=nagiosadmin,testauthorized_for_all_service_commands=nagiosadmin,testauthorized_for_all_host_commands=nagiosadmin6、启动nagios,httpd把Nagios加入到服务列表中以使之在系统启动时自动启动[root@host3 ~]# chkconfig --add nagios[root@host3 ~]# chkconfig nagios on验证Nagios的样例配置文件[root@host3 ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg如果没有报错,可以启动Nagios服务和apache服务[root@host3 ~]# /etc/init.d/nagios start[root@host3 ~]# /etc/init.d/httpd start7、测试登录http://ip/nagios输入用户名nagiosadmin密码redhat就可以正常登陆了三、增加本机监控项1、监控机(本机)中安装插件[root@host3 ~]# cd /data/[root@host3 data]# tar -zxf nagios-plugins-1.4.9.tar.gz[root@host3 data]# cd nagios-plugins-1.4.9[root@host3 nagios-plugins-1.4.9]# ./configure --prefix=/usr/local/nagios/[root@host3 nagios-plugins-1.4.9]# make[root@host3 nagios-plugins-1.4.9]# make install在libexec目录中生成了多个监控脚本[root@host3 nagios-plugins-1.4.9]# cd /usr/local/nagios/libexec/[root@host3 libexec]# lscheck_apt check_file_age check_mailq check_pop check_upscheck_breeze check_flexlm check_mrtg check_procs check_userscheck_by_ssh check_ftp check_mrtgtraf check_real check_wavecheck_clamd check_http check_nagios check_rpc negatecheck_cluster check_icmp check_nntp check_sensors urlizecheck_dhcp check_ifoperstatus check_nt check_smtp utils.pmcheck_dig check_ifstatus check_ntp check_ssh utils.shcheck_disk check_imap check_nwstat check_swapcheck_disk_smb check_ircd check_oracle check_tcpcheck_dns check_load check_overcr check_timecheck_dummy check_log check_ping check_udp[root@host3 libexec]#./check_ping --help 可以大多可查看到帮助信息2、增加监控项Nagios自己定义了一套规则用于配置文件,其中最重要的概念就是”对象”----object.在Nagios里面定义了一些基本的对象,一般用到的有:联系人 contact 出了问题像谁报告?一般当然是系统管理员了监控时间段 timeperiod 7X24小时不间断还是周一至周五,或是自定义的其他时间段被监控主机 host 所需要监控的服务器,当然可以是监控机自己监控命令 command nagios发出的哪个指令来执行某个监控,这也是自己定义的被监控的服务 service 例如主机是否存活,80端口是否开,磁盘使用情况或者自定义的服务等另外,多个被监控主机可以定义为一个主机组,多个联系人可以被定义为一个联系人组,多个服务还能定义成一个服务组呢。我们定义一个被监控的服务,当然就要指定被监控的主机,需要监控的时间段,要用哪个命令来完成这个监控操作,出了问题向哪个联系人报告。主配置文件选项Nagios的主配置文件为/usr/local/nagios/etc/nagios.cfg重要配置说明如下:nagios_user=nagiosnagios用户nagios_group=nagiosnagios组cfg_file=/usr/local/nagios/etc/objects/contacts.cfg//联系人/组配置文件cfg_file=/usr/local/nagios/etc/objects/localhost.cfg //本机配置文件cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg//监视时段配置文件cfg_file=/usr/local/nagios/etc/objects/commands.cfg//监视脚本配置cfg_file=/usr/local/nagios/etc/objects/templates.cfg//监视服务,报警配置cfg_file=/usr/local/nagios/etc/objects/switch.cfg//监视路由cfg_file=/usr/local/nagios/etc/objects/windows.cfg//监视微软打开本机localhost.cfg模版如下:definehost{声明主机use linux-server引入模版linux-serverhost_name localhost主机名alias localhostaddress 127.0.0.1所对应的ip地址}definehostgroup{声明主机组hostgroup_name linux-servers引入模版linux-serversalias LinuxServersmembers localhost将哪些主机加入此组,如有多台主机以,号隔开}defineservice{声明监控服务项use local-service引入模版local-service哪些主机host_name localhost要使用此监控项若有多个,以,号隔开。service_description PING此监控项的描述check_command check_ping!100.0,20%!500.0,60%此监控项监控脚本名称及设置相关选项或阈值}打开模版:vim /usr/local/nagios/etc/objects/ templates.cfgdefinehost{name linux-serveruse generic-hostcheck_period 24x7 //监测时间check_interval 5 //检测时间间隔retry_interval 1 //再次间隔时间max_check_attempts 10 //最大尝试次数check_command check-host-alive //主机检查使用命令notification_period workhours //报警通知时间notification_interval 120 //通知间隔时间notification_options d,u,r // 通知级别 #d-down,u-unreacheable,r-recoverycontact_groups admins //设置报警组register 0}四、增加被监控机host4的监控项1、监控机host3上安装[root@host3 ~]# cd /data/[root@host3 data]# tar -zxf nrpe-2.12.tar.gz[root@host3 data]# cd nrpe-2.12[root@host3 nrpe-2.12]# ./configure[root@host3 nrpe-2.12]# make all[root@host3 nrpe-2.12]# make install-plugin[root@host3 nrpe-2.12]# make install-daemon[root@host3 nrpe-2.12]# make install-daemon-config[root@host3 nrpe-2.12]# make install-xinetd2、被监控机host4上配置[root@host4 ~]# yum -y install gcc* openssl-devel xinetd[root@host4 ~]# cd /data/[root@host4 data]# useradd -s /sbin/nologin nagios1)安装监控脚本插件[root@host4 data]# tar -zxf nagios-plugins-1.4.9.tar.gz[root@host4 data]# cd nagios-plugins-1.4.9[root@host4 nagios-plugins-1.4.9]# ./configure --prefix=/usr/local/nagios[root@host4 nagios-plugins-1.4.9]# make[root@host4 nagios-plugins-1.4.9]# make install2)安装nrpe[root@host4 nagios-plugins-1.4.9]# cd /data/[root@host4 data]# tar -zxf nrpe-2.12.tar.gz[root@host4 data]# cd nrpe-2.12[root@host4 nrpe-2.12]# ./configure[root@host4 nrpe-2.12]# make all[root@host4 nrpe-2.12]# make install-plugin[root@host4 nrpe-2.12]# make install-daemon[root@host4 nrpe-2.12]# make install-daemon-config[root@host4 nrpe-2.12]# make install-xinetd3、监控机和被监控机上启动NRPE,并进行测试被监控端[root@host4 nrpe-2.12]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d#启动nrpe服务[root@host4 nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H localhost#查看nrpe版本NRPE v2.12[root@host4 nrpe-2.12]# netstat -anpt | grep nrpetcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 22941/nrpe添加nrpe开机启动:[root@host4 nrpe-2.12]# vi /etc/xinetd.d/nrpeonly_from = 127.0.0.1 192.168.1.220#添加监控端ip[root@host4 nrpe-2.12]# vi /etc/servicesnrpe 5666/tcp # nrpe#末行添加[root@host4 nrpe-2.12]# pkill nrpe#关闭之前开启的nrpe进程如不关闭,下面监控端做测试的时候会提示,CHECK_NRPE: Error - Could not complete SSL handshake.[root@host4 nrpe-2.12]# /etc/init.d/xinetd restart停止 xinetd: [失败]启动 xinetd: [确定]监控端[root@host3 nrpe-2.12]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d#启动nrpe服务[root@host3 nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H localhost#查看nrpe版本NRPE v2.12[root@host3 nrpe-2.12]# netstat -anpt | grep nrpetcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 1970/nrpe添加nrpe开机启动[root@host3 nrpe-2.12]# vi /etc/servicesnrpe 5666/tcp # nrpe #末行添加[root@host3 nrpe-2.12]# /etc/init.d/xinetd restart停止 xinetd: [失败]启动 xinetd: [确定][root@host3 nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.221#查看被监控端的nrpe版本NRPE v2.124、添加被监控主机监控端host3配置[root@host3 nrpe-2.12]# cd /usr/local/nagios/etc/objects/[root@host3 objects]# cat 192.168.1.221.cfg #以下所有模版都是通过调用/usr/local/nagios/libexec/templates.cfg文件中对模版的定义define host{ use linux-server #引用linux-server模版 host_name 192.168.1.221#主机名 alias 192.168.1.221#别名 address 192.168.1.221#被监控端ip地址 }define service{ use local-service #引用local-service模版 host_name 192.168.1.221 service_description PING#对监控服务内容的描述 check_command check_ping!100.0,20%!500.0,60%#指定检查的命令,check_ping命令在commands.cfg中定义,后跟两个参数,命令与参数间用!分割 }define service{ use local-service host_name 192.168.1.221 service_description Root Partition check_command check_local_disk!20%!10%!/ }define service{ use local-service host_name 192.168.1.221 service_description Current Users check_command check_local_users!20!50 }define service{ use local-service host_name 192.168.1.221 service_description Total Processes check_command check_local_procs!250!400!RSZDT }define service{ use local-service host_name 192.168.1.221 service_description Current Load check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0 }define service{ use local-service host_name 192.168.1.221 service_description Swap Usage check_command check_local_swap!20!10 }define service{ use local-service host_name 192.168.1.221 service_description SSH check_command check_ssh notifications_enabled 0 }define service{ use local-service host_name 192.168.1.221 service_description HTTP check_command check_http notifications_enabled 0 }cfg_file=/usr/local/nagios/etc/objects/commands.cfg#定义命令cfg_file=/usr/local/nagios/etc/objects/contacts.cfg#定义联系人和联系人组cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg#定义监控时间段cfg_file=/usr/local/nagios/etc/objects/templates.cfg#定义模版本文出自 “linux” 博客


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:11pm
栏目列表