监控软件 Nagios 安装与配置
homepage: http://www.nagios.org/
5.4.1. Install
5.4.1.1. Nagios core
Nagios 是一种开放源代码监督软件,它可以扫描主机、服务、网络方面存在的问题。Nagios 与其他类似的包之间的重要区别在于,Nagios 将全部的信息简化为“工作(working)”、“可疑的(questionable)”和“故障(failure)”状态,并且 Nagios 支持由插件构成的非常丰富的“生态系统”。这些特性使得用户能够举行有效安装,在此过程中无需过多地关心细节内容,只提供他们所需的信息即可。
install
- $ sudo apt-get install nagios3 nagios-nrpe-plugin
-
复制代码 add user nagiosadmin for nagios
- $ sudo htpasswd -c /etc/nagios2/htpasswd.users nagiosadmin
- New password:
- Re-type new password:
- Adding password for user nagiosadmin
-
复制代码 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.
- $ groupadd nagcmd
- $ sudo usermod -a -G nagcmd nagios
- $ sudo usermod -a -G nagcmd www-data
- $ cat /etc/group
- nagcmd:x:1003:nagios,www-data
-
复制代码 reload apache
- $ sudo /etc/init.d/apache2 reload
- * Reloading web server config apache2 [ OK ]
-
复制代码 5.4.1.2. Monitor Client nrpe
-
- nagios-nrpe-server --------> nagios core (nagios-nrpe-plugin)
-
-
复制代码 nagios-nrpe-server 的功能是向服务器发送监控数据, 而服务器端通过nagios-nrpe-plugin接收监控数据。
- sudo apt-get install nagios-nrpe-server nagios-plugins
-
复制代码 /etc/nagios/nrpe.cfg
/etc/nagios/nrpe_local.cfg
- $ sudo vim /etc/nagios/nrpe_local.cfg
- allowed_hosts=172.16.1.2
- command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
- command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
- command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
- command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
- command[check_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
- command[check_swap]=/usr/lib/nagios/plugins/check_swap -w 20% -c 10%
- command[check_all_disks]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -e
- command[check_disk_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
- command[check_disk_home]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /home
- command[check_sda_iostat]=/usr/lib/nagios/plugins/check_iostat -d sda -w 100 -c 200
- command[check_sdb_iostat]=/usr/lib/nagios/plugins/check_iostat -d sdb -w 100 -c 200
- # command[check_uri_user]=/usr/lib/nagios/plugins/check_http -I 127.0.0.1 -p 80 -u http://example.com/test/ok.php
- # command[check_mysql]=/usr/lib/nagios/plugins/check_mysql -H localhost -u root -ppassword test -P 3306
-
复制代码 重启后生效
- /etc/init.d/nagios-nrpe-server restart
-
复制代码 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
- [root@database ~]# yum -y install nagios nagios-plugins-all nagios-plugins-nrpe
-
复制代码 Create the default Nagios web access user & set a password
- # htpasswd -c /etc/nagios/passwd nagiosadmin
-
复制代码 Verify default config files
- nagios -v /etc/nagios/nagios.cfg
-
复制代码 Start Nagios
Configure it to start on boot
- chkconfig --levels 345 nagios on
-
复制代码 http://localhost/nagios/
5.4.3. nrpe node
- # yum install nrpe nagios-plugins-all
- allowed_hosts=172.16.1.2
- command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
- command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
- command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
- command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
- command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200
- command[check_http]=/usr/lib64/nagios/plugins/check_http -I 127.0.0.1 -p 80 -u http://www.example.com/index.html
- command[check_swap]=/usr/lib64/nagios/plugins/check_swap -w 20% -c 10%
- command[check_all_disks]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -e
- # chkconfig nrpe on
- # service nrpe start
-
复制代码 实在没有须要安装全部的监控插件
- yum install nrpe -y
- yum install nagios-plugins-disk nagios-plugins-load nagios-plugins-ping nagios-plugins-procs nagios-plugins-swap nagios-plugins-users -y
-
复制代码 5.4.4. 配置 Nagios
- $ sudo vim /etc/nagios3/nagios.cfg
- cfg_dir=/etc/nagios3/hosts
- cfg_dir=/etc/nagios3/servers
- cfg_dir=/etc/nagios3/switches
- cfg_dir=/etc/nagios3/routers
- admin_email=nagios, neo.chen@example.com
-
复制代码 5.4.4.1. authorized
add user neo for nagios
- $ sudo htpasswd /etc/nagios3/htpasswd.users neo
- New password:
- Re-type new password:
- Adding password for user neo
-
复制代码
- # grep default_user_name cgi.cfg
- #default_user_name=guest
- # grep authorized cgi.cfg
- authorized_for_system_information=nagiosadmin
- authorized_for_configuration_information=nagiosadmin
- authorized_for_system_commands=nagiosadmin
- authorized_for_all_services=nagiosadmin
- authorized_for_all_hosts=nagiosadmin
- authorized_for_all_service_commands=nagiosadmin
- authorized_for_all_host_commands=nagiosadmin
- #authorized_for_read_only=user1,user2
-
复制代码
- $ sudo vim /etc/nagios3/cgi.cfg
- authorized_for_all_services=nagiosadmin,neo
- authorized_for_all_hosts=nagiosadmin,neo
-
复制代码 5.4.4.2. contacts
- $ sudo vim /etc/nagios3/conf.d/contacts_nagios2.cfg
- ###############################################################################
- # contacts.cfg
- ###############################################################################
- define contact{
- contact_name neo
- alias Neo
- service_notification_period 24x7
- host_notification_period 24x7
- service_notification_options w,u,c,r
- host_notification_options d,r
- service_notification_commands notify-service-by-email
- host_notification_commands notify-host-by-email
- email neo.chen@example.com
- }
- ###############################################################################
- ###############################################################################
- #
- # CONTACT GROUPS
- #
- ###############################################################################
- ###############################################################################
- # We only have one contact in this simple configuration file, so there is
- # no need to create more than one contact group.
- define contactgroup{
- contactgroup_name admins
- alias Nagios Administrators
- members root, neo
- }
-
复制代码 当服务出现w—报警(warning),u—未知(unkown),c—严峻(critical),r—从异常规复到正常,在这四种环境下通知接洽人
当主机出现d-当机(down),u—返回不可达(unreachable),r—从异常环境规复正常,在这3种环境下通知接洽人
确认 contact_groups 已经设置
- neo@monitor:/etc/nagios3$ grep admins conf.d/generic-host_nagios2.cfg
- contact_groups admins
- neo@monitor:/etc/nagios3$ grep admins conf.d/generic-service_nagios2.cfg
- contact_groups admins
-
复制代码 </
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |