阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下安装配置Nagios监控

135次阅读
没有评论

共计 8047 个字符,预计需要花费 21 分钟才能阅读完成。

nagios 安装配置:
Nagios 官网 http://www.nagios.org
环境搭建:
CentOS6.6 192.168.11.30    做服务端
centos6.6 192.168.11.100  做客户端

1. Nagios 安装 – 服务端(192.168.11.30)
Centos6 默认的 yum 源里没有 nagios 相关的 rpm 包,但是我们可以安装一个 epel 的扩展源:
yum install -y epel-release

安装 nagios 相关的包
yum install -y httpd nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

设置登录 nagios 后台的用户和密码:
htpasswd -c /etc/nagios/passwd nagiosadmin

nagios -v /etc/nagios/nagios.cfg 检测配置文件是否有错误
启动服务:
service httpd start
service nagios start

浏览器访问:http://192.168.11.30/nagios/
弹出认证对话框,需要输入 nagiosadmin 及密码,登录 nagios 界面;
左侧 hosts 列出服务端或监控主机列表;

Linux 下安装配置 Nagios 监控

services 列出监控的 8 个服务项目(系统负载、用户、HTTP、ping、磁盘分区、SSH、swap 交换分区、系统进程)

Linux 下安装配置 Nagios 监控

————————————– 分割线 ————————————–

在 Ubuntu 下配置 Mrtg 监控 Nginx 和服务器系统资源 http://www.linuxidc.com/Linux/2013-08/88417.htm

使用 snmp+Mrtg 监控 Linux 系统 http://www.linuxidc.com/Linux/2012-11/73561.htm

Mrtg 服务器搭建(监控网络流量)http://www.linuxidc.com/Linux/2012-07/64315.htm

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在 RHEL5.3 上配置基本的 Nagios 系统(使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

————————————– 分割线 ————————————–

2. Nagios 安装 – 客户端(192.168.11.100)
在客户端机器上
yum install -y epel-release
yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

编辑配置文件:
vim /etc/nagios/nrpe.cfg 
找到“allowed_hosts=127.0.0.1”改为“allowed_hosts=127.0.0.1,192.168.11.30”后面的 ip 为服务端 ip
找到”dont_blame_nrpe=0”改为“dont_blame_nrpe=1”
启动客户端
/etc/init.d/nrpe start

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2015-07/120408p2.htm

3. 监控中心服务端(192.168.11.30)添加被监控主机(192.168.11.100)
服务端进行下面的操作:
cd /etc/nagios/conf.d/
vim 192.168.11.100.cfg                  // 加入:
define host{
        use                    linux-server           
        host_name          192.168.11.100
        alias                  11.100
        address                192.168.11.100
        }
define service{
        use                    generic-service
        host_name              192.168.11.100
        service_description    check_ping
        check_command          check_ping!100.0,20%!200.0,50%
        max_check_attempts 5
        normal_check_interval 1
}
define service{
        use                    generic-service
        host_name              192.168.11.100
        service_description    check_ssh
        check_command          check_ssh
        max_check_attempts      5
#;当 nagios 检测到问题时,一共尝试检测 5 次都有问题才会告警,如果该数值为 1,那么检测到问题立即告警
        normal_check_interval 1
#;重新检测的时间间隔,单位是分钟,默认是 3 分钟
        notification_interval          60
#;在服务出现异常后,故障一直没有解决,nagios 再次对使用者发出通知的时间。单位是分钟。如果你认为,所有的事件只需要一次通知就够了,可以把这里的选项设为 0。
}
define service{
        use                    generic-service
        host_name              192.168.11.100
        service_description    check_http
        check_command          check_http
        max_check_attempts      5
        normal_check_interval 1
}

以上服务不依赖于客户端 nrpe 服务,我们可以想象,我们在自己电脑上可以使用 ping 或者 telnet 探测远程任何一台机器是否存活、是否开启某个端口或服务。而当我们想要检测客户端上的某个具体服务的情况时,就需要借助于 nrpe 了,比如想知道客户端机器的负责或磁盘使用情况。

4.  继续添加服务
服务端:vim /etc/nagios/objects/commands.cfg
增加:
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

继续编辑 vim /etc/nagios/conf.d/192.168.11.100.cfg
增加如下内容:
define service{
        use    generic-service
        host_name      192.168.11.100
        service_description    check_load
        check_command          check_nrpe!check_load
        max_check_attempts 5
        normal_check_interval 1
}
define service{
        use    generic-service
        host_name      192.168.11.100
        service_description    check_disk_hda1
        check_command          check_nrpe!check_hda1
        max_check_attempts 5
        normal_check_interval 1
}
define service{
        use    generic-service
        host_name      192.168.11.100
        service_description    check_disk_hda2
        check_command          check_nrpe!check_hda2
        max_check_attempts 5
        normal_check_interval 1
}

说明:check_nrpe!check_load:这里的 check_nrpe 就是在 commands.cfg 刚刚定义的,check_load 是远程主机上的一个检测脚本;

在监控客户机机上 vim /etc/nagios/nrpe.cfg 搜索 check_load,这行就是在服务端上要执行的脚本了,我们可以手动执行这个脚本
把 check_hda1 更改一下:/dev/hda1 改为 /dev/sda1
再加一行 command[check_hda2]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda2
客户端上重启一下 nrpe 服务: service nrpe restart
服务端也重启一下 nagios 服务: service nagios restart

重启之后在 web 界面会出现 192.168.11.100 的监控信息:
service 是脚本定义的服务名;DISK(87% inode=99%)表示磁盘剩余空间比例 87%,inode 剩余 99%;

Linux 下安装配置 Nagios 监控

5.  配置告警
vim /etc/nagios/objects/contacts.cfg // 增加:
define contact{
        contact_name              123
        use                            generic-contact
        alias                          aaa
        email              aaa@163.com
        }
define contact{
        contact_name              456
        use                            generic-contact
        alias                            bbb
        email              bbb@163.com
        }
define contactgroup{
        contactgroup_name          common
        alias                                  common
        members                          123,456
        }

然后在要需要告警的服务里面加上 contactgroup
vi /etc/nagios/conf.d/192.168.11.100.cfg    增加下面的内容:

define service{
        use    generic-service,srv-pnp
        host_name      192.168.11.100
        service_description    check_load
        check_command          check_nrpe!check_load
        max_check_attempts 5
        normal_check_interval 1
        contact_groups        common
        notifications_enabled  1
#;是否开启提醒功能。1 为开启,0 为禁用。一般,这个选项会在主配置文件(nagios.cfg)中定义,效果相同。
        notification_period  24×7
#;发送提醒的时间段。非常重要的主机(服务)我定义为 7×24,一般的主机(服务)就定义为上班时间。如果不在定义的时间段内,无论什么问题发生,都不会发送提醒。
        notification_optionsc
#;这个是 service 的状态。w 为 waning,u 为 unknown, c 为 critical, r 为 recover(恢复了), 可以写多个状态,使用逗号隔开,类似的还有一个  host 对应的状态:d,u,r  d = 状态为 DOWN, u = 状态为 UNREACHABLE , r = 状态恢复为 OK,需要加入到 host 的定义配置里。
}

配置告警邮件:
要想收到邮件,需要安装 sendmail 包 yum install -y sendmail;
安装后启动 sendmail 服务;/etc/init.d/sendmail start
并且关闭 postfix    # /etc/init.d/postfix stop
netstat -nlp 查看 sendmail 服务是否被监听

告警邮箱地址不能写 QQ 邮箱,因为会拦截 sendmail 发出的邮件,显示 550 错误;可以填写 163 的邮箱;

/var/log/maillog    查看 mail 日志

并且保持 hostname 一致;可以自定义一个域名;

/etc/sysconfig/network
HOSTNAME=localhost.localdomain

12345 # cat /etc/hosts
127.0.0.1  localhost localhost.localdomain
::1        localhost localhost.localdomain
192.168.11.30 rfyy.net rfyy
127.0.0.1 rfyy.net rfyy

登录 163 邮箱——设置——反垃圾 \ 黑白名单——白名单 添加 nagios@rfyy.net  自己定义的后缀域名;

重启机器,启动各项服务,发现 hostname 变为 rfyy.net,查看日志发送邮件名也变为自定义的;163 也收到告警邮件了;
[root@rfyy ~]# hostname
rfyy.net

Jun 16 17:16:43 rfyy sendmail[1225]: t5G9GdAd001223: to=<xxx@163.com>, ctladdr=<
nagios@rfyy.net
> (497/498), delay=00:00:03, xdelay=00:00:03, mailer=esmtp, pri=120678, relay=163mx01.mxmail.netease.com. [220.181.14.136], dsn=2.0.0, stat=Sent (Mail OK queued as mx12,PsCowEBZ4UJBeX9VOdmmBw–.5481S3 1434417474)

Linux 下安装配置 Nagios 监控

Nagios 的详细介绍:请点这里
Nagios 的下载地址:请点这里

本文永久更��链接地址:http://www.linuxidc.com/Linux/2015-07/120408.htm

nagios 安装配置:
Nagios 官网 http://www.nagios.org
环境搭建:
CentOS6.6 192.168.11.30    做服务端
centos6.6 192.168.11.100  做客户端

1. Nagios 安装 – 服务端(192.168.11.30)
Centos6 默认的 yum 源里没有 nagios 相关的 rpm 包,但是我们可以安装一个 epel 的扩展源:
yum install -y epel-release

安装 nagios 相关的包
yum install -y httpd nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

设置登录 nagios 后台的用户和密码:
htpasswd -c /etc/nagios/passwd nagiosadmin

nagios -v /etc/nagios/nagios.cfg 检测配置文件是否有错误
启动服务:
service httpd start
service nagios start

浏览器访问:http://192.168.11.30/nagios/
弹出认证对话框,需要输入 nagiosadmin 及密码,登录 nagios 界面;
左侧 hosts 列出服务端或监控主机列表;

Linux 下安装配置 Nagios 监控

services 列出监控的 8 个服务项目(系统负载、用户、HTTP、ping、磁盘分区、SSH、swap 交换分区、系统进程)

Linux 下安装配置 Nagios 监控

————————————– 分割线 ————————————–

在 Ubuntu 下配置 Mrtg 监控 Nginx 和服务器系统资源 http://www.linuxidc.com/Linux/2013-08/88417.htm

使用 snmp+Mrtg 监控 Linux 系统 http://www.linuxidc.com/Linux/2012-11/73561.htm

Mrtg 服务器搭建(监控网络流量)http://www.linuxidc.com/Linux/2012-07/64315.htm

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在 RHEL5.3 上配置基本的 Nagios 系统(使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

————————————– 分割线 ————————————–

2. Nagios 安装 – 客户端(192.168.11.100)
在客户端机器上
yum install -y epel-release
yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe

编辑配置文件:
vim /etc/nagios/nrpe.cfg 
找到“allowed_hosts=127.0.0.1”改为“allowed_hosts=127.0.0.1,192.168.11.30”后面的 ip 为服务端 ip
找到”dont_blame_nrpe=0”改为“dont_blame_nrpe=1”
启动客户端
/etc/init.d/nrpe start

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2015-07/120408p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计8047字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中