2、部署Nagios监控平台
安装前的准备工作:
1)、添加防火墙规则
vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp--dport 80 -j ACCEPT #web访问查看监控
-A INPUT -m state --state NEW -m tcp -p tcp--dport 5666 -j ACCEPT #nrpe通信端口
保存退出,最后重启防火墙使配置生效
/etc/init.d/iptables restart
2)、关闭SELinux
vim /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
2)、配置Windows客户端
Windows客户端需要安装NSClient++,下载地址是:http://www.nsclient.org/,下载软件后,直接点击运行安装即可。
在选择安装类型的时候,可以感觉自己的需要选择安装,我这里选择的是“典型”安装,在安装的过程中会有一个配置,主要有以下几点:
Allowed hosts:这是运行那些主机,在后面添加监控主机的ip(192.168.17.10),这个也可以安装完之后修改配置文件。
password:用于通信的密码
Modules to load:这里是选择要加载的模块,根据实际选择,需要就勾选。
安装完成后,NSClient++会以服务的形式运行,可以使用命令:services.msc 打开服务查看NSClient++是否运行,它监听的端口是TCP 12489 4、在监控服务器上配置监控的客户机
1)、设置linux 客户端
(1)、在监控服务器上配置Linux主机(192.168.17.20)的监控,我们可以直接使用现在系统上有的模版修改,把配置文件存放到/etc/nagios/conf.d/目录,配置文件的名字可以使用主机类型+IP地址命名,比如linux192.168.17.20.cfg
修改如下:
vim/etc/nagios/conf.d/linux192.168.17.10.cfg
# Define a host for the 192.168.17.20machine
define host{
use linux-server
host_name 192.168.17.20
alias 17.20
address 192.168.17.20
}
# Define a service to "ping" thelocal machine
define service{
use local-service
host_name 192.168.17.20
service_description PING
check_command check_ping!100.0,20%!500.0,60%
max_check_attempts 5 #检查5次才报警
normal_check_interval 1 #重新检查时间,默认3分钟
}
# Define a service to check the disk spaceof the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition.
define service{
use local-service
host_name 192.168.17.20
service_description Root Partition
check_command check_local_disk!20%!10%!/
max_check_attempts 5
normal_check_interval 1
}
# Define a service to check the number ofcurrently logged in
# users on the local machine. Warning if > 20 users, critical
# if > 50 users.
define service{
use local-service
host_name 192.168.17.20
service_description Current Users
check_command check_local_users!20!50
max_check_attempts 5
normal_check_interval 1
}
# Define a service to check the number ofcurrently running procs
# on the local machine. Warning if > 250 processes, critical if
# > 400 users.
define service{
use local-service
host_name 192.168.17.20
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
max_check_attempts 5
normal_check_interval 1
}
# Define a service to check the load on thelocal machine.
define service{
use local-service
host_name 192.168.17.20
service_description Current Load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
max_check_attempts 5
normal_check_interval 1
}
# Define a service to check the swap usagethe local machine.
# Critical if less than 10% of swap isfree, warning if less than 20% is free
define service{
use local-service
host_name 192.168.17.20
service_description Swap Usage
check_command check_local_swap!20!10
max_check_attempts 5
normal_check_interval 1
}
# Define a service to check SSH on thelocal machine.
# Disable notifications for this service bydefault, as not all users may have SSH enabled.
define service{
use local-service
host_name 192.168.17.20
service_description SSH
check_command check_ssh
notifications_enabled 0
max_check_attempts 5
normal_check_interval 1
}
# Define a service to check HTTP on thelocal machine.
# Disable notifications for this service bydefault, as not all users may have HTTP enabled.
define service{
use local-service
host_name 192.168.17.20
service_description HTTP
check_command check_http
notifications_enabled 0
max_check_attempts 5
normal_check_interval 1
} 在这定义的服务中,需要使用到nrpe检测客户机的状态的有检测磁盘(check_local_disk)、负载(check_local_load)等,需要在客户机上的配置文件(/etc/nagios/nrpe.cfg)上有定义这样的命令,如果没有,则需要自行编写。
(2)、自定义监控项目
在nagios中默认的模版是没有监控内存的,需要自行定义,以下就使用自定的方式通过NRPE来监控远程服务器上的内存使用率。
a、监控的客户机下操作
下载监控内存的脚本
cd /usr/lib64/nagios/plugins/ #请根据系统的版本进入响应的目录
wget #下载脚本
mv check_mem.pl check_mem
chmod +x check_mem 可以使用如下命令测试脚本是否可用
./check_mem -f -w 30 -c 20 #可用内存为30%就警告,20%就严重警告