linux下安装配置nagios监控

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列出服务端或监控主机列表;

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

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

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%;

5.   配置告警

vim /etc/nagios/objects/contacts.cfg //增加:

define contact{
        contact_name               123
        use                             generic-contact
        alias                           aaa
        email              [email protected]
        }
define contact{
        contact_name               456
        use                             generic-contact
        alias                            bbb
        email              [email protected]
        }
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   24x7
#   ;发送提醒的时间段。非常重要的主机(服务)我定义为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
# 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邮箱——设置——反垃圾\黑白名单——白名单 添加[email protected]  自己定义的后缀域名;

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

[[email protected] ~]# hostname
rfyy.net
Jun 16 17:16:43 rfyy sendmail[1225]: t5G9GdAd001223: to=<[email protected]>, ctladdr=<
[email protected]
> (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)

时间: 2024-08-29 13:49:36

linux下安装配置nagios监控的相关文章

linux下安装配置zabbix监控

zabbix安装配置 环境搭建: 服务端    192.168.11.11 客户端    192.168.11.100 1.安装zabbix yum install -y epel-release 安装rpm包的lamp环境 yum install -y  httpd mysql mysql-libs php php-mysql mysql-server php-bcmath php-gd php-mbstring 安装zabbix服务端(最新版本为2.4,这里安装的2.2版本): yum in

linux下安装配置cacti监控

Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具. 环境搭建: cacti服务端:192.168.20.20 cacti客户机:192.168.20.30 cacti安装配置的步骤如下: 1.首先要安装epel扩展源 yum install  epel-release 2.(安装lamp环境)安装httpd.php.mysql yum install -y  httpd php php-mysql mysql mysql-server mysql-d

Linux下安装配置Apache服务器

Linux下安装配置Apache服务器 1. 安装Apache [[email protected] ~]# yum –y install httpd 2. 启动Apache [[email protected] ~]# systemctl start httpd 3. 查看进程 [[email protected] ~]# systemctl status httpd httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib

linux下安装配置tomcat以及tomcat开机自启配置

Linux下Tomcat安装配置以及Windows不能连接服务器Tomcat解决方案 一.从官方网站上下载tomcat软件包. 官网地址: http://tomcat.apache.org/ 点击左侧的 download的一个版本,我选择的是 tomcat7.0,选择一个后缀名为.tar.gz文件直接下载到本地. 二.通过工具SSH Secure 上传至linux服务器中,进行解压 解压tomcat压缩文件: #tar zxvf apache-tomcat-7.0.53.tar.gz 将解压后的

Linux下安装配置Nexus

一.安装和运行nexus 1.下载nexus:http://www.sonatype.org/nexus/go 可选择tgz和zip格式,以及war,选择tgz或zip时不同版本可能在启动时存在一定问题,可能是因为jdk版本问题,若无法启动请选择2.5或更早的版本 注:nexus 2.6版本之后不再支持jdk1.6 2.安装nexus 若下载war,则将其放置tomcat下的webapp目录中,改名为nexus,运行tomcat服务,即可访问http://localhost:8081/nexus

在linux下安装配置Initiator

在linux下安装和配置Initiator 环境 : 开启虚拟机,安装有linux操作系统. 首先打开linux操作系统,进入后使用命令ifconfig –a查看ip地址 在windows下安装安装有SecureCRT 7.1软件或者putty来进行远程控制     在linux下安装Initiator [[email protected] ~]# mkdir -p /mnt/cdron 创建目录并将光盘挂载到/mnt/cdrom目录下 [[email protected] ~]# mount

(转载)Linux下安装配置MySQL+Apache+PHP+WordPress的详细笔记

Linux下安装配置MySQL+Apache+PHP+WordPress的详细笔记 Linux下配LMAP环境,花了我好几天的时间.之前没有配置过,网上的安装资料比较混乱,加上我用的版本问题,安装过程中出现了一些错误,经过好几次安装,翻了好多资料,最后找出问题的所在,才把环境搭建好,对于高手来说,这或许不算什么,但对于一个刚入门的新人,却是不一样了,这篇文章记录着我的一些笔记,希望对于那些刚刚入门的人们有所帮助,仅作为参考. 安装首先我们得获得MySQL,Apache,PHP,WordPress

linux 下安装配置jboss as7以及部署应用

linux 下安装配置jboss as7以及部署应用 1.测试平台及软件 centos 5.4 jdk-7u5-linux-i586.rpm jboss-as-7.1.1.Final.zip jboss-as-quickstarts-7.1.1.CR2-dist.zip apache-maven-3.0.4-bin.tar.gz 2.安装相关软件 a.安装jdk [[email protected] ~]# chmod +x jdk-7u5-linux-i586.rpm [[email prot

linux下安装配置DHCP服务器

前提是已经安装了 core 及 base 两个组 # cat /etc/redhat-release   Red Hat Enterprise Linux Server release 6.4 (Santiago)   # uname -a  Linux localhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29  11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux 修改本机IP为静态获