配置Nagios监控服务器(图)

运维 系统运维
部署Nagios监控服务器:什么是Nagios呢? Linux下的系统监控Nagios是怎样进行运行的呢?Nagios能够运行在Linux/Unix平台上,同时提供一个可选的基于WEB界面以方便系统管理人员查看网络状态,各种系统问题,以及日志等等。本文讲述的是部署Nagios监控服务器。

  部署Nagios监控服务器:

  (一)下载所需软件包

  1.nagios.3.2.0.tar.gz Nagios的主程序

  1.   [root@UnixHot src]# wget http://prdownloads.sourceforge.n ... nagios.3.2.0.tar.gz  
  2.  

  2.nagios-plugins-1.4.13.tar.gz Nagios 的插件

  1.   [root@UnixHot src]# wget http://prdownloads.sourceforge.n ... ugins-1.4.13.tar.gz  
  2.  

  3.nrpe-2.12.tar.gz 代理检测程序

  1.   [root@UnixHot src]# wget http://prdownloads.sourceforge.n ... os/nrpe-2.12.tar.gz  
  2.  
  3.   [root@UnixHot src]# ls  
  4.  
  5.   nagios-3.2.0.tar.gz nagios-plugins-1.4.13.tar.gz nrpe-2.12.tar.gz  
  6.  

  (二)安装Nagios

  官方的安装文档:http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html

  1.安装前的依赖检查

  1.   [root@UnixHot ~]# rpm -q httpd php gcc glibc glibc-common gd gd-devel  
  2.  

  2.创建Nagios账户和组

  1.   [root@UnixHot src]# useradd -m nagios  
  2.  
  3.   [root@UnixHot src]#groupadd nagcmd  
  4.  
  5.   [root@UnixHot src]# usermod -a -G nagcmd nagios  
  6.  
  7.   [root@UnixHot src]#usermod -a -G nagcmd apache  
  8.  

  3.编译安装

  1.   [root@UnixHot src]# tar xvf nagios-3.2.0.tar.gz  
  2.  
  3.   [root@UnixHot src]# cd nagios-3.2.0  
  4.  

  至于每一步的具体意思,我不再详述,因为运行完毕后,提示信息会明确的告诉你,它干了什么,是怎么干的。当然,还有一个***的办法,就是看Makefile文件,里面都会有注释的。

  参考Makefile文件

  1.   [root@UnixHot nagios-3.2.0]# less Makefile  
  2.  
  3.   [root@UnixHot nagios-3.2.0]# ./configure --with-command-group=nagcmd \  
  4.  
  5.   --with-nagios-user=nagios \  
  6.  
  7.   --with-nagios-group=nagios  
  8.  
  9.   [root@UnixHot nagios-3.2.0]# make all  
  10.  
  11.   [root@UnixHot nagios-3.2.0]# make install  
  12.  
  13.   [root@UnixHot nagios-3.2.0]# make install-init (生成init启动脚本)  
  14.  
  15.   [root@UnixHot nagios-3.2.0]# make install-config (生成一些模板配置文件)  
  16.  
  17.   [root@UnixHot nagios-3.2.0]# make install-commandmode (设置相应的权限)  
  18.  
  19.   [root@UnixHot nagios-3.2.0]# make install-webconf (生成Apache配置文件nagios.conf)  
  20.  

  4.为Nagios设置Web验证的密码

  (注意***次添加用户用-c选项,以后再添加千万别在用这个选项了,会覆盖以前的所有用户的,这个在RHCE考前冲刺我已经讲了。)

  1.   [root@UnixHot nagios-3.2.0]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin  
  2.  

  5.设置Nagios的开机启动

  1.   [root@UnixHot ~]# chkconfig --add nagios  
  2.  
  3.   [root@UnixHot ~]# chkconfig nagios on  
  4.  

  6.修改SELinux

  两种方法:

  ***种最直接,关闭SELinux,对于SELinux不是很熟悉的用户,请选择此。

  1.   [root@UnixHot nagios-3.2.0]# cat /etc/sysconfig/selinux  
  2.  
  3.   SELINUX=disabled 
  4.  

  第二种给打上正确的安全脉络。

  1.   chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/  
  2.  
  3.   chcon -R -t httpd_sys_content_t /usr/local/nagios/share/  
  4.  

  (三)安装Nagios的插件nagios-plugin

  插件是Nagios扩展功能的强大武器,一般好的软件,都支持插件扩展,你可以根据实际的应用,自己开发插件。

  1.   [root@UnixHot src]# tar xvf nagios-plugins-1.4.13.tar.gz  
  2.  
  3.   [root@UnixHot src]# cd nagios-plugins-1.4.13  
  4.  
  5.   [root@UnixHot nagios-plugins-1.4.13]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios  
  6.  
  7.   [root@UnixHot nagios-plugins-1.4.13]# make && make install  
  8.  

  (四)配置检测主机是否存活

  1.配置文件概述

  如果安装上面的步骤,安装完成后,配置文件在安装时放在了/usr/local/nagios/etc/目录下

  1.   [root@UnixHot ~]# cd /usr/local/nagios/etc  
  2.  
  3.   [root@UnixHot etc]# ls -l  
  4.  
  5.   -rw-rw-r-- 1 nagios nagios 11408 08-30 11:55 cgi.cfg (CGI配置文件)  
  6.  
  7.   -rw-r--r-- 1 root root 26 08-30 11:56 htpasswd.users (Apache的验证密码文件)  
  8.  
  9.   -rw-rw-r-- 1 nagios nagios 43776 08-30 11:55 nagios.cfg (主配置文件)  
  10.  
  11.   drwxrwxr-x 2 nagios nagios 4096 08-30 11:55 objects (对象定义文件目录)  
  12.  
  13.   -rw-rw---- 1 nagios nagios 1340 08-30 11:55 resource.cfg (资源配置文件)  
  14.  

  我们修要修改的的是nagios.cfg 和 objects 目录下的文件,来检测主机是否存活。

  2.主配置文件nagios.cfg的配置

  主配置文件的内容很多,对于这个版本,我们需要修改和添加的主要是对象配置文件,即:cfg_file=

  1.   cfg_file=/usr/local/nagios/etc/objects/commands.cfg (命令定义文件)  
  2.  
  3.   cfg_file=/usr/local/nagios/etc/objects/contacts.cfg (联系人信息定义文件)  
  4.  
  5.   cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg (添加此行联系人组定义文件)  
  6.  
  7.   cfg_file=/usr/local/nagios/etc/objects/hosts.cfg (添加此行 主机定义文件)  
  8.  
  9.   cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg (添加此行 主机组定义文件)  
  10.  
  11.   cfg_file=/usr/local/nagios/etc/objects/services.cfg (添加此行 服务定义文件)  
  12.  
  13.   cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg (时间周期定义文件)  
  14.  
  15.   cfg_file=/usr/local/nagios/etc/objects/templates.cfg  
  16.  
  17.   # Definitions for monitoring the local (Linux) host  
  18.  
  19.   #cfg_file=/usr/local/nagios/etc/objects/localhost.cfg (注释掉此行)  
  20.  

  3.主机定义文件的配置

  1.   [root@UnixHot etc]# vi objects/hosts.cfg  
  2.  
  3.   define host{  
  4.  
  5.   host_name Nagios-Server  
  6.  
  7.   alias Nagios Server  
  8.  
  9.   address 192.168.0.206  
  10.  
  11.   check_command check-host-alive  
  12.  
  13.   check_interval 5  
  14.  
  15.   retry_interval 1  
  16.  
  17.   max_check_attempts 5  
  18.  
  19.   check_period 24x7  
  20.  
  21.   process_perf_data 0  
  22.  
  23.   retain_nonstatus_information 0  
  24.  
  25.   contact_groups sagroup  
  26.  
  27.   notification_interval 30  
  28.  
  29.   notification_period 24x7  
  30.  
  31.   notification_options d,u,r  
  32.  
  33.   }  
  34.  
  35.   define host{  
  36.  
  37.   host_name Java-Server  
  38.  
  39.   alias Java Server  
  40.  
  41.   address 192.168.0.157  
  42.  
  43.   check_command check-host-alive  
  44.  
  45.   check_interval 5  
  46.  
  47.   retry_interval 1  
  48.  
  49.   max_check_attempts 5  
  50.  
  51.   check_period 24x7  
  52.  
  53.   process_perf_data 0  
  54.  
  55.   retain_nonstatus_information 0  
  56.  
  57.   contact_groups sagroup  
  58.  
  59.   notification_interval 30  
  60.  
  61.   notification_period 24x7  
  62.  
  63.   notification_options d,u,r  
  64.  
  65.   }  
  66.  
  67.   define host{  
  68.  
  69.   host_name Oracle-Server  
  70.  
  71.   alias Oracle Server  
  72.  
  73.   address 192.168.0.155  
  74.  
  75.   check_command check-host-alive  
  76.  
  77.   check_interval 5  
  78.  
  79.   retry_interval 1  
  80.  
  81.   max_check_attempts 5  
  82.  
  83.   check_period 24x7  
  84.  
  85.   process_perf_data 0  
  86.  
  87.   retain_nonstatus_information 0  
  88.  
  89.   contact_groups sagroup  
  90.  
  91.   notification_interval 30  
  92.  
  93.   notification_period 24x7  
  94.  
  95.   notification_options d,u,r  
  96.  
  97.   }  
  98.  
  99.   define host{  
  100.  
  101.   host_name MySQL-Server  
  102.  
  103.   alias MySQL Server  
  104.  
  105.   address 192.168.0.100  
  106.  
  107.   check_command check-host-alive  
  108.  
  109.   check_interval 5  
  110.  
  111.   retry_interval 1  
  112.  
  113.   max_check_attempts 5  
  114.  
  115.   check_period 24x7  
  116.  
  117.   process_perf_data 0  
  118.  
  119.   retain_nonstatus_information 0  
  120.  
  121.   contact_groups sagroup  
  122.  
  123.   notification_interval 30  
  124.  
  125.   notification_period 24x7  
  126.  
  127.   notification_options d,u,r  
  128.  
  129.   }  
  130.  

  4.主机组定义文件的配置

  1.   [root@UnixHot etc]# vi objects/hostgroups.cfg  
  2.  
  3.   define hostgroup {  
  4.  
  5.   hostgroup_name System-Admin  
  6.  
  7.   alias system Admin  
  8.  
  9.   members Nagios-Server,Oracle-Server,Java-Server,MySQL-Server  
  10.  
  11.   }  
  12.  

  5.服务定义文件的配置

  1.   [root@UnixHot etc]# vi objects/services.cfg  
  2.  
  3.   define service {  
  4.  
  5.   host_name Nagios-Server  
  6.  
  7.   service_description check-host-alive  
  8.  
  9.   check_period 24x7  
  10.  
  11.   max_check_attempts 4  
  12.  
  13.   normal_check_interval 3  
  14.  
  15.   retry_check_interval 2  
  16.  
  17.   contact_groups sagroup  
  18.  
  19.   notification_interval 10  
  20.  
  21.   notification_period 24x7  
  22.  
  23.   notification_options w,u,c,r  
  24.  
  25.   check_command check-host-alive  
  26.  
  27.   }  
  28.  
  29.   define service {  
  30.  
  31.   host_name Oracle-Server  
  32.  
  33.   service_description check-host-alive  
  34.  
  35.   check_period 24x7  
  36.  
  37.   max_check_attempts 4  
  38.  
  39.   normal_check_interval 3  
  40.  
  41.   retry_check_interval 2  
  42.  
  43.   contact_groups sagroup  
  44.  
  45.   notification_interval 10  
  46.  
  47.   notification_period 24x7  
  48.  
  49.   notification_options w,u,c,r  
  50.  
  51.   check_command check-host-alive  
  52.  
  53.   }  
  54.  
  55.   define service {  
  56.  
  57.   host_name Java-Server  
  58.  
  59.   service_description check-host-alive  
  60.  
  61.   check_period 24x7  
  62.  
  63.   max_check_attempts 4  
  64.  
  65.   normal_check_interval 3  
  66.  
  67.   retry_check_interval 2  
  68.  
  69.   contact_groups sagroup  
  70.  
  71.   notification_interval 10  
  72.  
  73.   notification_period 24x7  
  74.  
  75.   notification_options w,u,c,r  
  76.  
  77.   check_command check-host-alive  
  78.  
  79.   }  
  80.  
  81.   define service {  
  82.  
  83.   host_name MySQL-Server  
  84.  
  85.   service_description check-host-alive  
  86.  
  87.   check_period 24x7  
  88.  
  89.   max_check_attempts 4  
  90.  
  91.   normal_check_interval 3  
  92.  
  93.   retry_check_interval 2  
  94.  
  95.   contact_groups sagroup  
  96.  
  97.   notification_interval 10  
  98.  
  99.   notification_period 24x7  
  100.  
  101.   notification_options w,u,c,r  
  102.  
  103.   check_command check-host-alive  
  104.  
  105.   }  
  106.  

  6.联系组定义文件配置

  1.   [root@UnixHot etc]# vi objects/contactgroups.cfg  
  2.  
  3.   define contactgroup {  
  4.  
  5.   contactgroup_name sagroup  
  6.  
  7.   alias system administrator group  
  8.  
  9.   members nagiosadmin  
  10.  
  11.   }  
  12.  

  7.修改目录的所有者

  1.   [root@UnixHot etc]# chown -R nagios:nagios objects/  
  2.  

  8.检测配置文件是否正确

  1.   [root@UnixHot etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg  
  2.  
  3.   Total Warnings: 0  
  4.  
  5.   Total Errors: 0  
  6.  

  如果都是0说明配置成功了,如果有错误,好好检查一下。

  9.启动Nagios服务

  1.   [root@UnixHot etc]# /etc/init.d/httpd restart  
  2.  
  3.   [root@UnixHot etc]# /etc/init.d/nagios start  
  4.  

  (五)***部分功能测试

  在浏览器输入网址:http://192.168.0.206/nagios/

  

 

  ***部分的功能已经实现了,就是简单的监控四台服务器是否存活,当然,对于系统监控来说,这是远远不够的。配置Nagios监控服务器OK

【编辑推荐】

Ubuntu安装运行Nagios

运维监控Nagios

验证Nagios的工作状态(图)

责任编辑:zhaolei 来源: deepin
相关推荐

2011-03-25 14:40:33

Nagios监控

2011-03-23 15:13:08

Nagios监控Oracle

2011-03-23 10:17:26

2011-03-21 14:53:27

Nagios监控Linux

2011-04-06 14:24:21

Nagios监控Linux

2011-03-22 15:17:14

Nagios安装

2011-03-22 09:07:13

Nagios监控Linux

2011-03-23 13:29:46

Debian安装Nagios

2011-03-24 10:59:10

Nagios监控mysql

2011-08-22 11:33:48

nagios

2011-03-23 15:13:08

Nagios监控oracle

2011-03-25 15:24:40

Nagios监控

2011-08-22 12:25:08

nagios

2011-04-06 14:24:28

nagios监控Linux

2011-04-06 15:05:56

nagios监控Linux

2011-03-28 16:37:38

2011-03-23 12:44:06

Nagios监控

2011-08-22 11:00:17

nagios

2011-03-22 15:17:13

Nagios监控

2011-03-22 15:17:14

Nagios安装
点赞
收藏

51CTO技术栈公众号