nagios的安装这里已不在累述,参考前文
实现飞信报警,如下设置(下面配置要用到)
飞信报警
1.修改模板文件notify-service-by-fetion
修改contacts.cfg
2.
cp *.so /usr/lib/
mv li* /usr/lib/
修改/usr/local/nagios/etc/objects/commands.cfg
define command {
command_name notify-service-by-fetion
command_line /usr/local/fx/fetion --mobile=15********* --pwd=********** --to=15********** --msg-utf8="$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $LONGDATETIME$" --hide
}
这里说明一下fetion的格式:
--mobile=飞信机器人号码
--pwd=密码
--to=目标手机号码 //该号码必须是飞信机器人的飞信好友
--msg-utf8="信息内容"
--[hide|debug]隐藏/显示发送信息的过程
验证码/root/feixin
1>nagios监控linux主机基本服务
在被监控机上nrpe.cfg确保有如下内容(根据自己主机情况来设定)
allowed_hosts=192.168.20.9
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
在监控机上,创建mylinux.cfg的配置文件
# vim /usr/local/nagios/etc/objects/mylinux.cfg 如下内容
define host{
use linux-server
host_name mylinux
alias mylinux
address 192.168.20.13 //被监控机的IP地址
}
define service{
use generic-service
host_name mylinux
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name mylinux
service_description check-load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name mylinux
service_description check-disk1
check_command check_nrpe!check_sda1
}
define service{
use generic-service
host_name mylinux
service_description check-disk2
check_command check_nrpe!check_sda2
}
define service{
use generic-service
host_name mylinux
service_description check-users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name mylinux
service_description total_procs
check_command check_nrpe!check_total_procs
}
在nagios.cfg中添加一行
# vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg
查看是否有错误:# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
没有错误的话,重启nagios服务:service nagios restart
接下来利用Nagios监控linux服务器的21、80、3306端口状态
然后定义监控时间:配置文件是timeperiods.cfg
1># vim /usr/local/nagios/etc/objects/timeperiods.cfg
可根据自己的需要配置,也可以用nagios安装之后的默认timeperiods.cfg配置文件(这里默认)
define timeperiod{
timeperiod_name 24x7
alias 24 Hours A Day, 7 Days A Week
sunday 00:00-24:00
monday 00:00-24:00
tuesday 00:00-24:00
wednesday 00:00-24:00
thursday 00:00-24:00
friday 00:00-24:00
saturday 00:00-24:00
}
2>编辑contacts.cfg
# vim /usr/local/nagios/etc/objects/contacts.cfg
define contact {
contact_name mylinux-server ; Short name of user
alias admin ; Full name of user
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-fetion
host_notification_commands notify-service-by-fetion
}
3>手动创建的配置文件contactgroups.cfg,创建一个分组,其格式如下:
# vim /usr/local/nagios/etc/objects/contactgroups.cfg
define contactgroup {
contactgroup_name group
alias system administrator group
members mylinux-server
}
4>创建监控服务器各项服务的配置文件,这里用来监控服务端口的状态
# vim /usr/local/nagios/etc/objects/mylinux-server.cfg
define host{
use linux-server
host_name mylinux-server
alias mylinux-server
address 192.168.20.13 //被监控主机的IP
contact_groups group
check_command check-host-alive //宕机就发报警通知
max_check_attempts 5
notification_interval 10
notification_period 24x7
notification_options d,u,r
}
define service {
host_name mylinux-server
service_description check_tcp 80
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups group
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_tcp!80
}
define service {
host_name mylinux-server
service_description check_tcp 21
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups group
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_tcp!21
}
define service {
host_name mylinux-server
service_description check_tcp 3306
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups group
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_tcp!3306
}
define service {
host_name mylinux-server
service_description check-host-alive
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups group
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check-host-alive
}
同样在nagios.cfg中添加一行
# vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/mylinux-server.cfg
cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg
这里我监控了192.168.20.13主机的80、21、3306端口以及主机状态
检查一下配置文件,是否报错:# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
重启nagios服务:service nagios restart
以待后续......
阅读(1534) | 评论(0) | 转发(0) |