6-16 663 views
一、概述
Nagios监控相对简单,对监控对象不是很复杂的的情况,使用这个比较方便。网上相关资料很多,这里只是记录下我的安装记录,网上一般是编译安装的。我这记录的是yum安装~ 环境是centos6.5
二、部署监控机器
1、安装epel,这个可以rpm安装,也可以添加Yum源安装,推荐加个Yum源安装吧。注意安装与你版本相对应的Yum源。
2、安装nagios、nagios-plugin与nrpe
# yum install nagios nagios-plugins nagios-plugins-all nagios-plugins-nrpe nrpe
# htpasswd -c /etc/nagios/htpasswd.user nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
[/etc/nagios/passwd如果已经存在的话, 用户名/密码是: nagiosadmin/nagiosadmin]
3、修改/etc/httpd/conf.d/nagios.conf
修改保存用户密码文件
AuthUserFile /etc/nagios/passwd 修改成–> AuthUserFile /etc/nagios/htpasswd.users
保存退出
4、启动apache与nagios
# /etc/init.d/httpd restart
# /etc/init.d/nagios start
5、登陆http://localhost/nagios/,输入用户密码后查看是否正常运行
6、配置文件修改
添加自定义监控项
#cd /etc/nagios/objects/
#vim android.cfg
define host{
use linux-server
host_name server_4001
address 10.98.1.14
check_interval 10
}
#vim android_server.cfg
define service{
use generic-service
host_name server_4001
service_description tcp7001
check_command check_tcp!7001
}
define service{
use generic-service
host_name server_4001
service_description tcp8001
check_command check_outIP!192.144.170.153!8001
}
define service{
use generic-service
host_name server_4001
service_description check_http
check_command check_http! -w 5 -c 10 -p 7001 -u “http://10.98.1.14/mbean/query/online_num.do”
}
添加定义
vim /etc/nagios/objects/commands.cfg
#check tcp端口
define command{
command_name check_outIP
command_line $USER1$/check_tcp -H $ARG1$ -p $ARG2$
}
#check mysql链接
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $ARG1$ -u admin -p Playmore123! -d $ARG2$
}
# For weixin
define command{
command_name notify-host-by-weixin
command_line /usr/local/nagios/libexec/set_to_weixin.sh “version:VNHD_JH\nhost\n-@@-$NOTIFICATIONTYPE$-@@-$HOSTNAME$-@@-$HOSTSTATE$-@@-$HOSTADDRESS$-@@-$HOSTOUTPUT$-@@-$CONTACTALIAS$
”
}
define command{
command_name notify-service-by-weixin
command_line /usr/local/nagios/libexec/set_to_weixin.sh “version:VNHD_JH\nservice\n-@@-$NOTIFICATIONTYPE$-@@-$SERVICEDESC$-@@-$HOSTALIAS$-@@-$HOSTADDRESS$-@@-$SERVICESTATE$-@@-$SERVI
CEOUTPUT$-@@-$CONTACTALIAS$”
}
# NRPE Command
define command{
command_name nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
将cfg添加到nagios主配置项
# echo “cfg_file=/etc/nagios/objects/android.cfg” >> /etc/nagios/nagios.cfg
# echo “cfg_file=/etc/nagios/objects/android_server.cfg” >> /etc/nagios/nagios.cfg
/etc/init.d/nagios restart 重启
三、被控机器部署
1、安装需要软件
# yum install nagios-plugins nagios-plugins-nrpe nrpe nagios-plugins-load nagios-plugins-disk nagios-plugins-swap
yum提示找不到nagios包的话可以先: 安装epel
2、配置nrpe
# vi /etc/nagios/nrpe.cfg 修改监控机的地址或域名
allowed_hosts=127.0.0.1,10.98.1.8
3、修改/etc/hosts.allow增加主监控机ip
# echo ‘nrpe:10.98.1.8’>> /etc/hosts.allow
4、启动 NRPE 守护进程:
# /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d
可以将此命令加入 /etc/rc.local ,以便开机自动启动。
# echo “/usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d” >> /etc/rc.local
5、从主监控机上检查 NRPE 是否正常:
# /usr/lib/nagios/plugins/check_nrpe -H 10.98.1.14
NRPE v2.12
6、若有防火墙记得将ping放开和5666端口,否则会导致监控机检测不到被监控机状态
iptables -A INPUT -p icmp -j ACCEPT
测试:做好微信报警功能~
版权属于: 抓不住的疯
原文地址: https://www.ycy114.com/index.php/2018/06/16/nagios%e7%9b%91%e6%8e%a7/
转载时必须以链接形式注明原始出处及本声明。