监控软件 Nagios 安装与配置

打印 上一主题 下一主题

主题 880|帖子 880|积分 2644

监控软件 Nagios 安装与配置


homepage: http://www.nagios.org/
5.4.1. Install

5.4.1.1. Nagios core

Nagios 是一种开放源代码监督软件,它可以扫描主机、服务、网络方面存在的问题。Nagios 与其他类似的包之间的重要区别在于,Nagios 将全部的信息简化为“工作(working)”、“可疑的(questionable)”和“故障(failure)”状态,并且 Nagios 支持由插件构成的非常丰富的“生态系统”。这些特性使得用户能够举行有效安装,在此过程中无需过多地关心细节内容,只提供他们所需的信息即可。
install
  1. $ sudo apt-get install nagios3 nagios-nrpe-plugin
  2.                
复制代码
add user nagiosadmin for nagios
  1. $ sudo htpasswd -c /etc/nagios2/htpasswd.users nagiosadmin
  2. New password:
  3. Re-type new password:
  4. Adding password for user nagiosadmin
  5.                
复制代码
Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.
  1. $ groupadd nagcmd
  2. $ sudo usermod -a -G nagcmd nagios
  3. $ sudo usermod -a -G nagcmd www-data
  4. $ cat /etc/group
  5. nagcmd:x:1003:nagios,www-data
  6.                
复制代码
reload apache
  1. $ sudo /etc/init.d/apache2 reload
  2. * Reloading web server config apache2                    [ OK ]
  3.                
复制代码
5.4.1.2. Monitor Client nrpe

  1.                
  2. nagios-nrpe-server --------> nagios core (nagios-nrpe-plugin)
  3.                
  4.                
复制代码
nagios-nrpe-server 的功能是向服务器发送监控数据, 而服务器端通过nagios-nrpe-plugin接收监控数据。
  1. sudo apt-get install nagios-nrpe-server nagios-plugins
  2.                
复制代码
/etc/nagios/nrpe.cfg
/etc/nagios/nrpe_local.cfg
  1. $ sudo vim /etc/nagios/nrpe_local.cfg
  2. allowed_hosts=172.16.1.2
  3. command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
  4. command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
  5. command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
  6. command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
  7. command[check_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
  8. command[check_swap]=/usr/lib/nagios/plugins/check_swap -w 20% -c 10%
  9. command[check_all_disks]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -e
  10. command[check_disk_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
  11. command[check_disk_home]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /home
  12. command[check_sda_iostat]=/usr/lib/nagios/plugins/check_iostat -d sda -w 100 -c 200
  13. command[check_sdb_iostat]=/usr/lib/nagios/plugins/check_iostat -d sdb -w 100 -c 200
  14. # command[check_uri_user]=/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -p 80 -u http://example.com/test/ok.php
  15. # command[check_mysql]=/usr/lib/nagios/plugins/check_mysql -H localhost -u root -ppassword test -P 3306
  16.                
复制代码
重启后生效
  1. /etc/init.d/nagios-nrpe-server restart
  2.                
复制代码
5.4.1.3. Monitoring Windows Machines

Nagios 可以监控windows服务器,必要安装下面软件。
NSClient++
http://sourceforge.net/projects/nscplus
5.4.1.4. PNP4Nagios 图表插件

http://www.pnp4nagios.org/
5.4.2. nagios

Install Nagios & Plugins
  1. [root@database ~]# yum -y install nagios nagios-plugins-all nagios-plugins-nrpe
  2.                
复制代码
Create the default Nagios web access user & set a password
  1. # htpasswd -c /etc/nagios/passwd nagiosadmin
  2.                
复制代码
Verify default config files
  1. nagios -v /etc/nagios/nagios.cfg               
  2.                
复制代码
Start Nagios
  1. Start Nagios
  2.                
复制代码
Configure it to start on boot
  1. chkconfig --levels 345 nagios on
  2.                
复制代码
http://localhost/nagios/
5.4.3. nrpe node

  1. # yum install nrpe nagios-plugins-all
  2. allowed_hosts=172.16.1.2
  3. command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
  4. command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
  5. command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
  6. command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
  7. command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200
  8. command[check_http]=/usr/lib64/nagios/plugins/check_http -I 127.0.0.1 -p 80 -u http://www.example.com/index.html
  9. command[check_swap]=/usr/lib64/nagios/plugins/check_swap -w 20% -c 10%
  10. command[check_all_disks]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -e
  11. # chkconfig nrpe on
  12. # service nrpe start
  13.                
复制代码
实在没有须要安装全部的监控插件
  1. yum install nrpe -y
  2. yum install nagios-plugins-disk  nagios-plugins-load nagios-plugins-ping nagios-plugins-procs nagios-plugins-swap nagios-plugins-users -y               
  3.                
复制代码
5.4.4. 配置 Nagios

  1. $ sudo vim /etc/nagios3/nagios.cfg
  2. cfg_dir=/etc/nagios3/hosts
  3. cfg_dir=/etc/nagios3/servers
  4. cfg_dir=/etc/nagios3/switches
  5. cfg_dir=/etc/nagios3/routers
  6. admin_email=nagios, neo.chen@example.com
  7.                
复制代码
5.4.4.1. authorized

add user neo for nagios
  1. $ sudo htpasswd /etc/nagios3/htpasswd.users neo
  2. New password:
  3. Re-type new password:
  4. Adding password for user neo
  5.                        
复制代码

  1. # grep default_user_name cgi.cfg
  2. #default_user_name=guest
  3. # grep authorized cgi.cfg
  4. authorized_for_system_information=nagiosadmin
  5. authorized_for_configuration_information=nagiosadmin
  6. authorized_for_system_commands=nagiosadmin
  7. authorized_for_all_services=nagiosadmin
  8. authorized_for_all_hosts=nagiosadmin
  9. authorized_for_all_service_commands=nagiosadmin
  10. authorized_for_all_host_commands=nagiosadmin
  11. #authorized_for_read_only=user1,user2
  12.                        
复制代码

  1. $ sudo vim /etc/nagios3/cgi.cfg
  2. authorized_for_all_services=nagiosadmin,neo
  3. authorized_for_all_hosts=nagiosadmin,neo
  4.                        
复制代码
5.4.4.2. contacts

  1. $ sudo vim /etc/nagios3/conf.d/contacts_nagios2.cfg
  2. ###############################################################################
  3. # contacts.cfg
  4. ###############################################################################
  5. define contact{
  6.         contact_name                    neo
  7.         alias                           Neo
  8.         service_notification_period     24x7
  9.         host_notification_period        24x7
  10.         service_notification_options    w,u,c,r
  11.         host_notification_options       d,r
  12.         service_notification_commands   notify-service-by-email
  13.         host_notification_commands      notify-host-by-email
  14.         email                           neo.chen@example.com
  15.         }
  16. ###############################################################################
  17. ###############################################################################
  18. #
  19. # CONTACT GROUPS
  20. #
  21. ###############################################################################
  22. ###############################################################################
  23. # We only have one contact in this simple configuration file, so there is
  24. # no need to create more than one contact group.
  25. define contactgroup{
  26.         contactgroup_name       admins
  27.         alias                   Nagios Administrators
  28.         members                 root, neo
  29.         }
  30.                        
复制代码
当服务出现w—报警(warning),u—未知(unkown),c—严峻(critical),r—从异常规复到正常,在这四种环境下通知接洽人
当主机出现d-当机(down),u—返回不可达(unreachable),r—从异常环境规复正常,在这3种环境下通知接洽人
确认 contact_groups 已经设置
  1. neo@monitor:/etc/nagios3$ grep admins conf.d/generic-host_nagios2.cfg
  2.                 contact_groups                  admins
  3. neo@monitor:/etc/nagios3$ grep admins conf.d/generic-service_nagios2.cfg
  4.                 contact_groups                  admins
  5.                        
复制代码
</


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

刘俊凯

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表