Nagios监控Linux与Windows主机

来源:本站原创 Linux 超过753 views围观 0条评论

nagios监控linux与windows主机

经过一段时间的整理,结合个人在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安装

tar –xvzf nagios-2.9.tar.gz   mkdir /usr/local/nagios   useradd nagios –d /usr/local/nagios   chmod 755 /usr/local/nagios   cd nagios-2.9   ./configure –prefix=/usr/local/nagios –with-gd-lib=/usr/local/lib   –with-gd-inc=/usr/local/include   make all   make install   make install-init ##This installs the init script in /usr/local/etc/rc.d   make install-commandmode   make install-config ##将初始的配置文件安装到/usr/local/nagios/etc   注:在make install-init 这一步的时候可能会进行不下去,这时只要加个root组即可。

2、nagios-plugins的安装

tar –xvzf nagios-plugins-1.4.7.tar.gz   mkdir /usr/local/nagios-plugins   cd nagios-plugins-1.4.7   ./configure –prefix=/usr/local/nagios-plugins   make all   make install   安装完成以后在/usr/local/nagios-plugins会产生一个libexec的目录,将该目录全部移动到/usr/local/nagios目录下

mv /usr/local/nagios-plugins/libexec /usr/local/nagios   3、imagepak-base的安装

tar –xvzf imagepak-base.tar.gz

解压以后是base目录

cp –R base /usr/local/nagios/share/images/logos   4、安装过程全部结束

 

三、Nagios的设定:

(1)、配置apache

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

ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/   AllowOverride AuthConfig   Options ExecCGI   Order allow,deny   Allow from all   Alias /nagios/ /usr/local/nagios/share/   Options None   AllowOverride AuthConfig   Order allow,deny   Allow from all   (2)、设置访问权限

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

vi .htaccess   AuthName “Nagios Access”   AuthType Basic   AuthUserFile /usr/local/nagios/etc/.htpasswd   require valid-user   2、在/usr/local/nagios/sbin目录下

vi .htpasswd   AuthName “Nagios Access”   AuthType Basic   AuthUserFile /usr/local/nagios/etc/.htpasswd   require valid-user   3、/usr/local/apache/bin/htpasswd –c /usr/local/nagios/etc/.htpasswd nagios

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

四、配置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配置完成。

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

nrpe 安装与使用

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

1、安装openssl

#./config –prefix=/usr/local/nagios/openssl   #make   #make install   2、安装nrpe与配置

#./configure –enable-ssl –with-ssl-lib=/usr/local/nagios/openssl/lib   –with-kerberos-inc=/usr/local/nagios/openssl/include –enable-command-args   #make all   #mkdir /usr/local/nagios/etc   #mkdir /usr/local/nagios/bin   #mkdir /usr/local/nagios/libexec   #chown -R nagios:nagios /usr/local/nagios   #cp nrpe.cfg /usr/local/nagios/etc   #cp src/nrpe /usr/local/nagios/bin   #cp src/check_nrpe /usr/local/nagios/libexec   #vi /usr/local/nagios/etc/nrpe.cfg   改成你允许的IP

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

改成你准备监视的服务

command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1___FCKpd___9nbsp;-c $ARG2___FCKpd___9nbsp;-p $ARG3$   检查磁盘,当 / 剩余$ARG1$%报警(浅黄色),剩余$ARG2$%“出错”(红色)-p 后为指定分区

3、启动nrpe,端口为5666

/usr/local/nagios/bin/nrpe -c /etc/nrpe.cfg -d   4、安装监测的模块

nagios-plugins的安装

tar –xvzf nagios-plugins-1.4.7.tar.gz   mkdir /usr/local/nagios-plugins   cd nagios-plugins-1.4.7   ./configure –prefix=/usr/local/nagios-plugins   make all   make install   安装完成以后在/usr/local/nagios-plugins会产生一个libexec的目录,将该目录全部移动到/usr/local/nagios目录下

mv /usr/local/nagios-plugins/libexec /usr/local/nagios   (二)服务器上的配置

1、安装openssl

#./config –prefix=/usr/local/nagios/openssl   #make   #make install   2、安装nrpe(主要是使用check_nrpe模块)

#./configure –enable-ssl –with-ssl-lib=/usr/local/nagios/openssl/lib   –with-kerberos-inc=/usr/local/nagios/openssl/include –enable-command-args   #make all   #cp src/check_nrpe /usr/local/nagios/libexec   3、nagios文件的配置

vi commands.cfg

定义check_nrpe命令

# ‘check_nrpe’ command definition   define command{   command_name check_nrpe   command_line $USER1$/check_nrpe -H $HOSTADDRESS___FCKpd___15nbsp;-c $ARG1$   }   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

加入以代码:

define command{   command_name check_ping   command_line $USER1$/check_ping -H $HOSTADDRESS___FCKpd___16nbsp;-p $ARG1___FCKpd___16nbsp;$ARG2$   }   [root@db4 etc]#cfg=”cfg_file=/usr/local/nagios/etc/lgweb.cfg”   [root@db4   [email=root@db4][/email]   etc]#echo “$cfg” >> /usr/local/nagios/etc/nagios.cfg   [root@db4 etc]#/etc/init.d/nagios start 

六、安装监控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配置

#cd /usr/local/nagios/etc   #vi 201web.cfg(具体内容见配置文件)   #vi commands.cfg(添加相应的命令,见配置文件)   #echo “cfg=/usr/local/nagios/etc/201web.cfg” >> /usr/local/nagios/etc/nagios.cfg   #/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg(若无错误就可进行下步)   #service nagios start   访问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中的以下几个参数前的注释去掉:

default_user_name=nagios  authorized_for_system_information=nagiosadmin,nagios   authorized_for_configuration_information=nagiosadmin,nagios   authorized_for_system_commands=nagiosadmin,nagios   authorized_for_all_services=nagiosadmin,nagios   authorized_for_all_hosts=nagiosadmin,nagios   authorized_for_all_service_commands=nagiosadmin,nagios   authorized_for_all_host_commands=nagiosadmin,nagios  

关于监控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)

#mysql -uroot -pxukixu   mysql>grant all privileges on *.* to      identified by ‘xukixu’;   mysql>flush privileges;   mysql>quit; 

文章转载自网管之家:http://www.bitscn.com/os/linux/201103/192939_6.html

文章转载自网管之家:http://www.bitscn.com/os/linux/201103/192939.html

文章出自:CCIE那点事 http://www.jdccie.com/ 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。 禁止全文转载。
本文链接:http://www.jdccie.com/?p=158转载请注明转自CCIE那点事
如果喜欢:点此订阅本站
  • 相关文章
  • 为您推荐
  • 各种观点

暂时还木有人评论,坐等沙发!
发表评论

您必须 [ 登录 ] 才能发表留言!