Nagios监控Linux与Windows主机

运维 系统运维
Nagios监控Linux与Windows主机:Nagios是一个监控系统运行状态和网络信息的监控系统。Nagios能监控所指定的本地或远程主机以及服务,同时提供异常通知功能等。这篇文章讲述的是Nagios监控Linux与Windows主机。

  nagios监控linuxwindows主机

  经过一段时间的整理,结合个人在linux与windows服务器上的测试,写出这篇blog,希望更多地人关注nagios,虽然cacti也具有这样的功能但缺泛像nagios的警报功能。Naigos的安装:

  一、 所需软件

  nagios-2.9.tar.gz

  nagios-plugins-1.4.7.tar.gz

  imagepak-base.tar.gz

  nsclient_201.zip

  二、 安装

  1、nagios安装

  1.   tar –xvzf nagios-2.9.tar.gz  
  2.  
  3.   mkdir /usr/local/nagios  
  4.  
  5.   useradd nagios –d /usr/local/nagios  
  6.  
  7.   chmod 755 /usr/local/nagios  
  8.  
  9.   cd nagios-2.9  
  10.  
  11.   ./configure –prefix=/usr/local/nagios –with-gd-lib=/usr/local/lib  
  12.  
  13.   –with-gd-inc=/usr/local/include  
  14.  
  15.   make all  
  16.  
  17.   make install  
  18.  
  19.   make install-init ##This installs the init script in /usr/local/etc/rc.d  
  20.  
  21.   make install-commandmode  
  22.  
  23.   make install-config ##将初始的配置文件安装到/usr/local/nagios/etc  
  24.  

  注:在make install-init 这一步的时候可能会进行不下去,这时只要加个root组即可。

  2、nagios-plugins的安装

  1.   tar –xvzf nagios-plugins-1.4.7.tar.gz  
  2.  
  3.   mkdir /usr/local/nagios-plugins  
  4.  
  5.   cd nagios-plugins-1.4.7  
  6.  
  7.   ./configure –prefix=/usr/local/nagios-plugins  
  8.  
  9.   make all  
  10.  
  11.   make install  
  12.  

  安装完成以后在/usr/local/nagios-plugins会产生一个libexec的目录,将该目录全部移动到/usr/local/nagios目录下

  1.   mv /usr/local/nagios-plugins/libexec /usr/local/nagios  
  2.  

  3、imagepak-base的安装

  tar –xvzf imagepak-base.tar.gz

  解压以后是base目录

  1.   cp –R base /usr/local/nagios/share/images/logos  
  2.  

  4、安装过程全部结束

#p#

  三、Nagios的设定:

  (1)、配置apache

  在apache的配置文件httpd.conf中追加

  1.   ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/  
  2.  
  3.   AllowOverride AuthConfig  
  4.  
  5.   Options ExecCGI  
  6.  
  7.   Order allow,deny  
  8.  
  9.   Allow from all  
  10.  
  11.   Alias /nagios/ /usr/local/nagios/share/  
  12.  
  13.   Options None  
  14.  
  15.   AllowOverride AuthConfig  
  16.  
  17.   Order allow,deny  
  18.  
  19.   Allow from all  
  20.  

  (2)、设置访问权限

  1、在/usr/local/nagios/share目录下

  1.   vi .htaccess  
  2.  
  3.   AuthName “Nagios Access”  
  4.  
  5.   AuthType Basic  
  6.  
  7.   AuthUserFile /usr/local/nagios/etc/.htpasswd  
  8.  
  9.   require valid-user  
  10.  

  2、在/usr/local/nagios/sbin目录下

  1.   vi .htpasswd  
  2.  
  3.   AuthName “Nagios Access”  
  4.  
  5.   AuthType Basic  
  6.  
  7.   AuthUserFile /usr/local/nagios/etc/.htpasswd  
  8.  
  9.   require valid-user  
  10.  

  3、/usr/local/apache/bin/htpasswd –c /usr/local/nagios/etc/.htpasswd nagios

  这个apache目录根据安装目录的不同而不同,主要所以用.htpasswd这个命令生成用户名和密码

#p#

  四、配置nagios

  1、在/usr/local/nagios/etc下是nagios的配置模板文件.cfg-sample,把.cfg-sample文件全部拷贝成.cfg

  例如:cp nagios.cfg-sample nagios.cfg

  mkdir /usr/local/nagios/etc/sample

  cp *.cfg-sample !$

  全部拷贝完成即可.

  1、修改cgi.cfg

  vi /etc/cgi.cfg

  修改use_authentication=1为use_authentication=0,即不用验证.不然有一些页面不会显示。

  2、然后检查配置文件是否出错

  /usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg

  出现Total Warnings: 0

  Total Errors: 0

  为正常

  出错的话,就是.cfg文件有问题

  3、启动后台进程

  /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

  /usr/local/etc/rc.d/nagios start

  4、(如果有些页面看不到的话.可以在cgi.cfg文件中把带有authorized的选项前的#号去掉即可)这些配置完以后,基本的nagios配置完成。

#p#

  五、安装监控linux类服务器的nrpe

  nrpe 安装与使用

  (一)远程主机的配置(192.168.0.206 linux)

  1、安装openssl

  1.   #./config –prefix=/usr/local/nagios/openssl  
  2.  
  3.   #make  
  4.  
  5.   #make install  
  6.  

  2、安装nrpe与配置

  1.   #./configure –enable-ssl –with-ssl-lib=/usr/local/nagios/openssl/lib  
  2.  
  3.   –with-kerberos-inc=/usr/local/nagios/openssl/include –enable-command-args  
  4.  
  5.   #make all  
  6.  
  7.   #mkdir /usr/local/nagios/etc  
  8.  
  9.   #mkdir /usr/local/nagios/bin  
  10.  
  11.   #mkdir /usr/local/nagios/libexec  
  12.  
  13.   #chown -R nagios:nagios /usr/local/nagios  
  14.  
  15.   #cp nrpe.cfg /usr/local/nagios/etc  
  16.  
  17.   #cp src/nrpe /usr/local/nagios/bin  
  18.  
  19.   #cp src/check_nrpe /usr/local/nagios/libexec  
  20.  
  21.   #vi /usr/local/nagios/etc/nrpe.cfg  
  22.  

  改成你允许的IP

  allowed_hosts=127.0.0.1,192.168.0.207(207是nagios服务器)

  改成你准备监视的服务

  1.   command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$  
  2.  

  检查磁盘,当 / 剩余$ARG1$%报警(浅黄色),剩余$ARG2$%“出错”(红色)-p 后为指定分区

  3、启动nrpe,端口为5666

  1.   /usr/local/nagios/bin/nrpe -c /etc/nrpe.cfg -d  
  2.  

  4、安装监测的模块

  nagios-plugins的安装

  1.   tar –xvzf nagios-plugins-1.4.7.tar.gz  
  2.  
  3.   mkdir /usr/local/nagios-plugins  
  4.  
  5.   cd nagios-plugins-1.4.7  
  6.  
  7.   ./configure –prefix=/usr/local/nagios-plugins  
  8.  
  9.   make all  
  10.  
  11.   make install  
  12.  

  安装完成以后在/usr/local/nagios-plugins会产生一个libexec的目录,将该目录全部移动到/usr/local/nagios目录下

  1.   mv /usr/local/nagios-plugins/libexec /usr/local/nagios  
  2.  

  (二)服务器上的配置

  1、安装openssl

  1.   #./config –prefix=/usr/local/nagios/openssl  
  2.  
  3.   #make  
  4.  
  5.   #make install  
  6.  

  2、安装nrpe(主要是使用check_nrpe模块)

  1.   #./configure –enable-ssl –with-ssl-lib=/usr/local/nagios/openssl/lib  
  2.  
  3.   –with-kerberos-inc=/usr/local/nagios/openssl/include –enable-command-args  
  4.  
  5.   #make all  
  6.  
  7.   #cp src/check_nrpe /usr/local/nagios/libexec  
  8.  

  3、nagios文件的配置

  vi commands.cfg

  定义check_nrpe命令

  1.   # ‘check_nrpe’ command definition  
  2.  
  3.   define command{  
  4.  
  5.   command_name check_nrpe  
  6.  
  7.   command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$  
  8.  
  9.   }  
  10.  

  4、重启nagios服务

  /etc/rc.d/init.d/nagios restart (linux)

  在 Nagios主机上192.168.0.207:

  [root@207 etc]#vi /usr/local/nagios/etc/commads.cfg

  加入以代码:

  1.   define command{  
  2.  
  3.   command_name check_ping  
  4.  
  5.   command_line $USER1$/check_ping -H $HOSTADDRESS$ -p $ARG1$ $ARG2$  
  6.  
  7.   }  
  8.  
  9.   [root@db4 etc]#cfg=”cfg_file=/usr/local/nagios/etc/lgweb.cfg”  
  10.  
  11.   [root@db4  
  12.  
  13.   [email=root@db4][/email]  
  14.  
  15.   etc]#echo “$cfg” >> /usr/local/nagios/etc/nagios.cfg  
  16.  
  17.   [root@db4 etc]#/etc/init.d/nagios start  
  18.  

#p#

  六、安装监控windows NT服务器的nsclient

  1、客户端192.168.0.201配置

  下载nsclient包

  nsclient_201.zip

  解压包到c:\nsclient

  打开cmd命令行提示符输入:

  c:

  cd c:\nsclient

  pNSClient.exe /install

  net start nsclient

  安装完成

  2、服务端192.168.0.207配置

  1.   #cd /usr/local/nagios/etc  
  2.  
  3.   #vi 201web.cfg(具体内容见配置文件)  
  4.  
  5.   #vi commands.cfg(添加相应的命令,见配置文件)  
  6.  
  7.   #echo “cfg=/usr/local/nagios/etc/201web.cfg” >> /usr/local/nagios/etc/nagios.cfg  
  8.  
  9.   #/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg(若无错误就可进行下步)  
  10.  
  11.   #service nagios start  
  12.  

  访问nagios监控的web界面:

  http://192.168.0.207/nagios/index.html

  故障排除

  问:将use_authentication=1设为1时会出现如下错误:

  It appears as though you do not have permission to view information for any of the hosts you requested…

  答:方法一,只需将/usr/local/nagios/etc/cgi.cfg中的以下几个参数前的注释去掉:

  1.   default_user_name=nagios 
  2.  
  3.   authorized_for_system_information=nagiosadmin,nagios  
  4.  
  5.   authorized_for_configuration_information=nagiosadmin,nagios  
  6.  
  7.   authorized_for_system_commands=nagiosadmin,nagios  
  8.  
  9.   authorized_for_all_services=nagiosadmin,nagios  
  10.  
  11.   authorized_for_all_hosts=nagiosadmin,nagios  
  12.  
  13.   authorized_for_all_service_commands=nagiosadmin,nagios  
  14.  
  15.   authorized_for_all_host_commands=nagiosadmin,nagios  
  16.  

#p#

  关于监控linux主机mysql相关注意点:

  1、server(nagios服务端192.168.0.132)

  #/usr/local/nagios/libexec/check_mysql -H 192.168.0.207 -u root -p xukixu

  此时可能会出现错误:Host ‘192.168.0.132′ is not allowed to connect to this MySQL server

  因此只要在客户端做个mysql授权用户访问即可

  2、client(客户端192.168.0.207)

  1.   #mysql -uroot -pxukixu  
  2.  
  3.   mysql>grant all privileges on *.* to  
  4.  
  5.   root@192.168.0.132  
  6.  
  7.   identified by ‘xukixu’;  
  8.  
  9.   mysql>flush privileges;  
  10.  
  11.   mysql>quit;  

 

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

2011-03-21 13:10:13

NagiosWindows

2014-09-28 10:37:45

LinuxNagiosNRPE

2011-03-28 17:35:44

NagiosNRPE监控

2011-03-23 10:17:25

Nagios监控

2011-03-21 14:53:27

Nagios监控Linux

2011-03-24 10:59:11

NagiosWindows监控

2011-03-25 14:25:38

NagiosWindows监控

2011-07-01 10:26:15

NagiosWindows Ser

2011-03-23 09:11:40

Nagios监控

2011-03-21 15:42:14

LinuxNagios

2011-04-06 14:24:27

Nagios监控Linux

2011-04-01 15:42:13

CactiNagios

2011-04-06 14:24:21

Nagios监控Linux

2011-03-21 14:53:27

Nagios监控Linux

2011-03-21 14:53:36

Nagios监控Linux

2011-04-06 14:24:20

Nagios监控Linux

2011-08-22 11:33:48

nagios

2011-03-25 11:05:39

Nagioswindows

2011-03-22 09:07:13

Nagios监控Linux

2011-03-24 10:08:39

Nagios监控oracle
点赞
收藏

51CTO技术栈公众号