标签:nagios
Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。
在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。
作为老牌的监控软件,大家应该学习,本文介绍使用配置的方法。
监控服务端和客户端安装省略。
#准备阶段
信息列表
服务器名称 | 服务器IP |
nagios server | 10.89.1.2 |
samba | 10.89.1.3 |
web-lnmp | 10.89.1.34 |
#1.nagios的监控模式定义及监控模式的选择
1.1.主动模式,由nagios服务器端发出的请求主动探测就可以得到数据的监控模式,也就是说不需要再
客户端安装任何插件(适合对 端口 URL http ssh mysql rsync等监控)。当然主动模式也可以配置为被动模式探测
1.2.半被动模式,我们把负载,内存,硬盘,虚拟内存,磁盘IO,温度,风扇等
对于这些本地资源性能的监控,一般使用半被动模式(通过调用nrpe,snmp)
1.3.被动模式
主动模式:和nrpe无关了,就是利用服务端本地插件直获取信息
被动模式:主程序通过check_nrpe插件,和客户端nrpe进程沟通,调用本地插件获取数据
#2.配置服务端
[root@nagios tools]# ll /usr/local/nagios/
total 32
drwxrwxr-x 2 nagios nagios 4096 Jul 14 23:25 bin #命令的目录
drwxrwxr-x 3 nagios nagios 4096 Jul 14 23:25 etc #配置文件的目录
drwxr-xr-x 2 root root 4096 Jul 14 23:24 include
drwxrwxr-x 2 nagios nagios 4096 Jul 14 23:25 libexec #插件
drwxr-xr-x 5 root root 4096 Jul 14 23:24 perl
drwxrwxr-x 2 nagios nagios 4096 Jul 14 23:21 sbin #cgi 的程序
drwxrwxr-x 11 nagios nagios 4096 Jul 14 23:24 share #web程序,nagios界面展示的php程序
drwxrwxr-x 5 nagios nagios 4096 Jul 16 10:03 var #日志和数据
[root@nagios tools]# cd /usr/local/nagios/etc
[root@nagios etc]# ls -l
total 76
-rw-rw-r-- 1 nagios nagios 11669 Jul 14 23:21 cgi.cfg
-rw-r--r-- 1 root root 21 Jul 14 23:22 htpasswd.users #密码验证文件
-rw-rw-r-- 1 nagios nagios 44710 Jul 14 23:21 nagios.cfg #nagios主配置文件
-rw-r--r-- 1 nagios nagios 7207 Jul 14 23:25 nrpe.cfg
drwxrwxr-x 2 nagios nagios 4096 Jul 14 23:21 objects
-rw-rw---- 1 nagios nagios 1340 Jul 14 23:21 resource.cfg
#生成hosts.cfg文件
[root@nagios etc]# cd objects/
[root@nagios objects]# head -51 localhost.cfg >hosts.cfg
[root@nagios objects]# chown nagios.nagios /usr/local/nagios/etc/objects/hosts.cfg
#生成 services.cfg文件
[root@nagios objects]# touch services.cfg
[root@nagios objects]# chown nagios.nagios /usr/local/nagios/etc/objects/services.cfg
[root@nagios objects]# ll
total 52
-rw-rw-r-- 1 nagios nagios 7716 Jul 14 23:21 commands.cfg #存放nagios 命令相关配置,实现nagios命令和linux系统命令关联
-rw-rw-r-- 1 nagios nagios 2166 Jul 14 23:21 contacts.cfg #存放报警联系人的相关配置文件
-rw-r--r-- 1 nagios nagios 1870 Jul 16 12:00 hosts.cfg #新增,存放具体被监控主机相关配置
-rw-rw-r-- 1 nagios nagios 5403 Jul 14 23:21 localhost.cfg
-rw-rw-r-- 1 nagios nagios 3124 Jul 14 23:21 printer.cfg
-rw-r--r-- 1 nagios nagios 0 Jul 16 12:03 services.cfg #新增,存放具体被监控服务相关配置
-rw-rw-r-- 1 nagios nagios 3293 Jul 14 23:21 switch.cfg
-rw-rw-r-- 1 nagios nagios 10812 Jul 14 23:21 templates.cfg #模板配置文件
-rw-rw-r-- 1 nagios nagios 3208 Jul 14 23:21 timeperiods.cfg #存放报警周期时间等相关配置
-rw-rw-r-- 1 nagios nagios 4019 Jul 14 23:21 windows.cfg
#修改 nagios.cfg 文件前,备份/etc 目录防止改错
[root@nagios etc]# cd ..
[root@nagios nagios]# tar zcvf etc.tar.gz ./etc/
./etc/
./etc/nagios.cfg
./etc/cgi.cfg
./etc/nrpe.cfg
./etc/htpasswd.users
./etc/objects/
./etc/objects/printer.cfg
./etc/objects/localhost.cfg
./etc/objects/contacts.cfg
./etc/objects/windows.cfg
./etc/objects/timeperiods.cfg
./etc/objects/switch.cfg
./etc/objects/commands.cfg
./etc/objects/templates.cfg
./etc/resource.cfg
[root@nagios nagios]# cd etc
[root@nagios etc]# vi nagios.cfg +34
#添加3行,注释1行
# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
#添加这2行
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
#注释1行,这是本机监控
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
# directive as shown below:
#添加1行(主动监控使用)
cfg_dir=/usr/local/nagios/etc/services #添加services(服务)目录包含
#cfg_dir=/usr/local/nagios/etc/servers #服务器
#cfg_dir=/usr/local/nagios/etc/printers #打印机
#cfg_dir=/usr/local/nagios/etc/switches #交换机
#cfg_dir=/usr/local/nagios/etc/routers #路由器
#创建services目录 并授权
[root@nagios etc]#cd /usr/local/nagios/etc
[root@nagios etc]# mkdir services
[root@nagios etc]# chown -R nagios.nagios services/
[root@nagios etc]# ll
total 80
-rw-rw-r-- 1 nagios nagios 11669 Jul 14 23:21 cgi.cfg
-rw-r--r-- 1 root root 21 Jul 14 23:22 htpasswd.users
-rw-rw-r-- 1 nagios nagios 44852 Jul 16 11:55 nagios.cfg
-rw-r--r-- 1 nagios nagios 7207 Jul 14 23:25 nrpe.cfg
drwxrwxr-x 2 nagios nagios 4096 Jul 16 12:03 objects
-rw-rw---- 1 nagios nagios 1340 Jul 14 23:21 resource.cfg
drwxr-xr-x 2 nagios nagios 4096 Jul 16 11:56 services #新增,存放主动监控项目
--------------------------------------------------------------------------------------
本文出自 “知识改变命运” 博客,请务必保留此出处http://ahtornado.blog.51cto.com/4826737/1885138
标签:nagios
原文地址:http://ahtornado.blog.51cto.com/4826737/1885138