手机版
你好,游客 登录 注册
背景:
阅读新闻

Nagios远程监控软件的安装与配置详解

[日期:2011-09-14] 来源:evolution.blog.51cto.com  作者:evolution [字体:大 中 小]

Windows 监控端配置

安装NSClient,进入安装目录修改配置文件NSC.ini,将[module]下所有库文件的注释删去。运行nsclient。

Linux 监控端配置

1.添加nagios用户

  1. useradd nagios  

2.编译安装nagios-plugin

  1. tar zxf nagios-plugins-1.4.15.tar.gz  
  2. cd nagios-plugins-1.4.15 
  3. ./configure --with-nagios-user=nagios --with-nagios-group=nagios 
  4. make && make install 

3.编译安装nrpe 

  1. yum install openssl-devel 
  2. #先安装openssl解决依赖 
  3. tar -zxvf nrpe-2.12.tar.gz 
  4. cd nrpe-2.12.tar.gz 
  5. ./configure --enable-ssl --with-ssl-lib=/usr/lib/ 
  6. make all && make install-plugin && make install-daemon && make install-daemon-config 
  7. #编译安装 

4.配置并启用nrpe 

  1. vim /usr/local/nagios/etc/nrpe.cfg 
  2. allowed_hosts=192.168.0.71 
  3. #监控端的IP 
  4. /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d 
  5. #开启进程 

 监控端重启nagios服务 

  1. service nagiso restart 

浏览器刷新页面,即出现windows和linux被监控主机 

监控服务的添加

下面就添加被监控主机mysql服务为例进行说明

 1.被监控机(192.168.0.72)安装mysql并创建监控用户

  1. yum install mysql mysql-server 
  2. #简单起见yum安装mysql 
  3. service mysqld start 
  4. #启动mysql 
  5. mysqladmin -uroot -p password '123456' 
  6. #给root用户创建mysql密码 
  7. mysql -uroot -p 
  8. #进入mysql 
  9. mysql> create database nagios;  
  10. #创建数据库 
  11. mysql> grant select on nagios.* to nagios@'%' identified by 'RedHat';  
  12. #给nagios用户赋予查询权限 
  13. mysql> flush privileges;  
  14. #刷新特权表 

2.监控机(192.168.0.71)修改相关配置文件 

  1. vim /usr/local/nagios/etc/objects/command.cfg 
  2. #check mysql  
  3. define command{  
  4. command_name check_mysql  
  5. command_line $USER1$/check_mysql -H 192.168.0.72 -u nagios -d nagios -p redhat  
  6. }  
  7. #在命令配置文件中添加这些字段 
  1. vim /usr/local/nagios/etc/objects/mylinux.cfg  
  2. define service{ 
  3.         use                    generic-service 
  4.         host_name           mylinux 
  5.         service_description  check_mysql 
  6.         check_command     check_mysql 
  7. }         
  8. #在linux主机配置文件中定义服务 

 重启服务

  1. service nagios restart 

刷新浏览器页面

异常报警

这里选用飞信作为异常报警手段,异常事件出发直接以短信形式通知运维人员

1.飞信的安装

  1. unzip fetion.zip
  2. cd ../fetion 
  3. mv fetion /usr/bin/ 
  4. #将飞信脚本放在/usr/lib 
  5. chmod +x /usr/bin/fetion 
  6. #添加执行权限 
  7. mv ./* /usr/lib 
  8. #将剩余所有库文件移动到/usr/lib  

Ps:飞信程序下载地址:

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /pub/2011/09/14/Nagios远程监控软件的安装与配置详解/

2.修改nagios相关配置文件

  1. vim /usr/local/nagios/etc/templates.cfg 
  2. define contact{ 
  3.         name                            generic-contact         
  4.         service_notification_period     24x7                     
  5.         host_notification_period        24x7                    
  6.         service_notification_options    w,u,c,r,f,s           
  7.         host_notification_options       d,u,r,f,s               
  8.         service_notification_commands   notify-service-by-fetion 
  9.         host_notification_commands      notify-host-by-fetion     
  10.         register                        0                       
  11.         } 
  12. #修改成上面字段 
  13.  
  14. vim /usr/local/nagios/etc/commands.cfg 
  15.  commands.cfg 
  16. define command{ 
  17.         command_name notify-service-by-fetion 
  18.         command_line      /usr/bin/fetion --mobile 您的手机号 --pwd 您的飞信密码 --to 您的手机号 --msg-tpye=0  --msg-utf8 $HOSTNAME 
  19. } 
  20.   #添加这些字段 

重启服务使配置文件生效    

关于nagios的配置流程以及应用添加就先写到这里,以上内容在您实现过程中出现的任何问题,欢迎在此交流; 并请各位高手前辈大神达人予以批评指正,谢谢!
linux
相关资讯       Nagios 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款