nagios安装与配置

 Nagios是一款开源的免费网络监视工具,其功能强大,灵活性强。能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。
本文档主要实现nagios监控windows主机,nagios监控windows系统有三种实现方式:SNMP、NSClient++、NRPE.
安装过程出问题可到http://www.itnms.net/discuz/forumdisplay.php?fid=10&page=1请求帮忙
  nagios服务器端ip:202.168.25.XXX
被监控windows端ip:233.24.25.xxx    
被监控linux端ip:125.40.5.xxx

一.Nagios的安装

      1,nagios需要apache,gcc,glibc,gd库等套件才能运行.
yum install httpd yum install gcc yum install glibc glibc-common yum install gd gd-devel 
 2,创建帐号及组
/usr/sbin/useradd -m nagios passwd nagios /usr/sbin/groupadd nagios /usr/sbin/usermod -a -G nagios nagios
 3.安装nagios 
tar -zxvf nagios-3.2.1.tar.gz cd nagios-3.2.1.tar.gz ./configure --prefix=/usr/local/nagios --with-command-group=nagios --with-gd-lib=/usr/lib/ --with-gd-inc=/usr/include/ make all make install make install-init #在/etc/rc.d/init.d安装启动脚本 make install-config #在/usr/local/nagios/etc安装示例配置文件 make install-commandmode #配置目录权限 /usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users robbie 输入密码(这一步很重要)
 
 4.安装nagios-plugins插件
tar zxvf nagios-plugins-1.4.15.tar.gz cd nagios-plugins-1.4.15.tar.gz ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround make make install 

     5.其它设置

chkconfig --add nagios #配置机器启动时自动启动Nagios chkconfig nagios on /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #检查Nagios配置文件 vi /etc/selinux/config #关闭SELinux SELINUX=disabled service iptables stop #关闭SELinux,或打开80,5666端口 如果没有报错,可以启动Nagios服务 service nagios start

 6,编辑apache 的httpd.conf 并重启apache
vi /etc/httpd/conf/http.conf最后面加入 ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin <Directory "/usr/local/nagios/sbin"> Options ExecCGI AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd Require valid-user </Directory> Alias /nagios /usr/local/nagios/share <Directory "/usr/local/nagios/share"> Options None AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd Require valid-user </Directory> 
 7,登陆web
输入http://localhost/nagios 可以看到nagios界面 安装完成
 
 

二.监控windows 系统

 nagios监控windows系统有三种实现方式:SNMP,NSClient++,NRPE,后面两种方式都需要在windows上安装agent本文档只介绍使用NSClient++方式来监控Windows

 1.windows设置

把nsclient++0.3.3.zip解压到C盘然后进入命今窗口安装 C:/>cd "NSClient++-Win32-0.3.5" C:/NSClient++-Win32-0.3.5>nsclient++ /install l /NSClient++.cpp(193) Service installed!  

编辑NES.ini [modules] #去掉注释符号”;”除了CheckWMI.dll和RemoteConfiguration.dll FileLogger.dll CheckSystem.dll CheckDisk.dll NSClientListener.dll [Settings] allowd_host=202.168.25.XXX #此处为nagios服务的IP [NSClient] port=12489 #去掉注释就可以了!

 

重启服务并勾选登陆

 

 

最后检查端口

C:/NSClient++-0.3.8-Win32>netstat -an | more Active Connections Proto Local Address Foreign Address State TCP 0.0.0.0:445 0.0.0.0:0 LISTENING TCP 0.0.0.0:5666 0.0.0.0:0 LISTENING TCP 0.0.0.0:12489 0.0.0.0:0 LISTENING

 

 2.nagios设置

 

 

vi /usr/local/nagios/etc/nagios.cfg # Definitions for monitoring the local (Linux) host cfg_file=/usr/local/nagios/etc/objects/localhost.cfg # Definitions for monitoring a Windows machine cfg_file=/usr/local/nagios/etc/objects/windows.cfg #去掉这句话的注释 
 打开模块后配置windows.cfg
vi /usr/local/nagios/etc/objects/windows.cfg define host{ use windows-server host_name winserver #被监控主机名 alias My Windows Server address 233.24.25.xxx ; 被监控的windows地址 #把下面的host_name都改成winserver define service{ use generic-service host_name winserver service_description CPU Load check_command check_nt!CPULOAD!-l 5,80,90 #监控CPU使用 } define service{ use generic-service host_name winserver service_description Memory Usage check_command check_nt!MEMUSE!-w 80 -c 90 #监控内存 } 
下面重启nagios然后看一下监控结果


 

  因为nagios是模块化调用,先到配置文件打开windows相关模块
 

三.监控linux系统

1,被监控端(被监控的服务器)安装nagios-nrpe_2.12.tar.gz和插件nagios-plugins-1.4.13.tar.gz
useradd nagios passwd nagios tar -zxvf nagios-plugins-1.4.13.tar.gz cd nagios-plugins-1.4.13 ./configure make make install

安装完成后会在/usr/local/nagios/下生成两个目录libexec和share

接下来授予 /usr/local/nagios给nagios用户和组
chown nagios.nagios /usr/local/nagios

然后安装nagios-nrpe_2.12.tar.gz
tar -zxvf nagios-nrpe_2.12.tar.gz cd nagios-nrpe_2.12 ./configure make all make install-plugin make install-daemon make install-daemon-config

vi /usr/local/nagios/etc/nrpe.cfg
将allowed_hosts=127.0.0.1 改成allowed_hosts=127.0.0.1,202.168.25.XXX (注意逗号不能有空格,此IP是nagios服务器IP)

启动nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

netstat -an|grep 5666
察看是否在5666端口上监听
注意:防火墙 释放端口5666,很重要

 /usr/local/nagios/libexec/check_nrpe -H localhost
察看是否能返回nrpv版本号,返回则正常!

vi /usr/local/nagios/etc/nrpe.cfg
可以看到里面监控对象
# The following examples use hardcoded command arguments...
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 /dev/sda     #sda是我要监测的硬盘
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 150 -c 200
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%     #添加check_swap

然后再启动nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d (注意:用该命令启动的,如果要重启,得先kill,再启动)
现在,监控端已经是设置完了!!!

2,接下来设置nagios服务器端的设置

安装nagios-nrpe_2.12.tar.gz
这里安装过程比上面再被监控服务安装少两部
tar -zxvf nagios-nrpe_2.12.tar.gz cd nagios-nrpe_2.12 ./configure make all make install-plugin

然后测试下连通性
/usr/local/nagios/libexec/check_nrpe -H 被监控端ip
如果返回nrpe版本号,那么正常!
如果返回拒绝连接!那么telnet ip 5666看是否正常

配置:
由于nrpe外构组件,所以必须在commands.cfg中定义

vi /usr/local/nagios/etc/objects/commands.cfg
最下面添加
#check nrpe
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

vi /usr/local/nagios/etc/nagios.cfg
中间添加
cfg_file=/usr/local/nagios/etc/objects/linuxserver.cfg
  linuxserver.cfg你们可以自己改

新建linuxserver.cfg
vi /usr/local/nagios/etc/objects/linuxserver.cfg
添加

define host{ use linux-server host_name linuxserver alias linuxserver address 125.40.5.xxx (被监控端IP) } define service{ use generic-service host_name linuxserver service_description HTTP check_command check_http } define service{ use generic-service host_name linuxserver service_description FTP check_command check_ftp } define service{ use generic-service host_name linuxserver service_description SSH check_command check_ssh } define service{ use generic-service host_name linuxserver service_description SMTP check_command check_smtp } define service{ use generic-service host_name linuxserver service_description POP3 check_command check_pop } define service{ use generic-service host_name linuxserver service_description check-swap check_command check_nrpe!check_swap } define service{ use generic-service host_name linuxserver service_description check-load check_command check_nrpe!check_load } define service{ use generic-service host_name linuxserver service_description check-disk check_command check_nrpe!check_had1 } define service{ use generic-service host_name linuxserver service_description zombie_procs check_command check_nrpe!check_zombie_procs } define service{ use generic-service host_name linuxserver service_description check-users check_command check_nrpe!check_users } define service{ use generic-service host_name linuxserver service_description total_procs check_command check_nrpe!check_total_procs }

运行 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
检测下是不是都正确!
正确的话,那么我们重新启动nagios

nagios安装与配置_第1张图片

此时web页面上多了个linuxserver了,成功了

你可能感兴趣的:(nagios安装与配置)