实战:监控外部服务器NFS服务
1、安装配置NFS服务器
[root@yu61 objects]# service rpcbind status
rpcbind (pid 1614) 正在运行...
[root@yu61 ~]# vim /etc/exports
/tmp *(rw)
[root@yu61 ~]# /etc/init.d/nfs restart
[root@yu61 ~]# showmount -e 192.168.1.61
Export list for 192.168.1.61:
/tmp *
2、编辑check_nfs命令脚本
[root@yu61 libexec]# pwd
/usr/local/nagios/libexec
[root@yu61 libexec]# cat check_nfs
check_nfs
#!/bin/bash
. /data1/server/nagios/libexec/utils.sh
CHECKNAME="Mount NFS"
RESULT=""
EXIT_STATUS=$STATE_OK
NFSFSTAB=`LC_ALL=C awk '!/^#/ && $3 ~ /^nfs/ && $3 != "nfsd" && $4 !~ /noauto/ { print $1 }' /etc/fstab`
NFSMTAB=`LC_ALL=C awk '$3 ~ /^nfs/ && $3 != "nfsd" && $2 != "/" { print $1 }' /proc/mounts`
theend() {
echo $RESULT
exit $EXIT_STATUS
}
CHECK_MOUNT(){
LIST=""
for list in $NFSFSTAB
do
NFS_MOUNT=$(LC_ALL=C cat /proc/mounts |cut -d " " -f 1|grep "${list}$")
if [ -z "${NFS_MOUNT}" ];then
LIST="$LIST$list "
fi
done
}
if [ -n "${NFSMTAB}" ];then
CHECK_MOUNT
if [ -z "${LIST}" ];then
RESULT="$CHECKNAME OK - NFS BE MOUNTED PROPERLY"
EXIT_STATUS=$STATE_OK
else
RESULT="$CHECKNAME WARNING - ${LIST} NOT BE MOUNTED"
EXIT_STATUS=$STATE_WARNING
fi
else
RESULT="$CHECKNAME CRITICAL - ALL NFS NOT BE MOUNTED"
EXIT_STATUS=$STATE_CRITICAL
fi
Theend
注释:为了安全起见修改权限,不修改默认为644 root
[root@yu61 libexec]# chmod 755 check_nfs
[root@yu61 libexec]# chown nagios:nagcmd check_nfs
[root@yu61 libexec]# ll check_nfs
-rwxr-xr-x 1 nagios nagcmd 973 5月 22 13:27 check_nfs
3、修改配置文件
[root@yu61 objects]# cat hosts.cfg ##末尾添加
####################chreck_host###########################
define host{
use linux-server
host_name yu61
alias nfs服务
address 192.168.1.61
icon_image switch.gif
statusmap_image switch.gd2
2d_coords 100,200
3d_coords 100,200,100
}
[root@yu61 objects]# cat service.cfg ##末尾添加
###################check_server_mysql#############################
define service{
use local-service
host_name yu61
service_groups nfs服务组
service_description nfs服务
check_command check_nrpe!check_nfs
}
##########################check_server_mysql_groups######################
define servicegroup{
servicegroup_name nfs服务组
alias nfs服务器
members yu61,nfs服务
}
[root@yu61 objects]# vim commands.cfg ##末尾添加
#'check_nrpe' command definition
definecommand{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c$ARG1$
}
define command{
command_name check_nfs
command_line $USER1$/check_nfs
}
4、检测服务配置及启动服务
[root@yu61 objects]# /etc/init.d/nagios checkconfig
Total Warnings: 0
Total Errors: 0
[root@yu61 objects]# /etc/init.d/nagios reload
5、测试查看主机和服务
http://192.168.1.63/nagios/
实战:监控外部服务器httpd服务
1、修改配置文件
[root@yu61 objects]# cat hosts.cfg ##最后编辑
define host{
use linux-server
host_name yu63
alias http服务
address 192.168.1.63
icon_image switch.gif
statusmap_image switch.gd2
2d_coords 100,200
3d_coords 100,200,100
}
[root@yu61 objects]# cat service.cfg ##最后添加
###################check_server_httpd-63#############################
define service{
use local-service
host_name yu63
service_groups http服务组
service_description http服务
check_command check_http
}
##########################check_server_http-63_groups######################
define servicegroup{
servicegroup_name http服务组
alias http服务器
members yu63,http服务
}
#Check_http的命令默认就有的
2、检测配置文件和重启服务
[root@yu61 objects]# /etc/init.d/nagios checkconfig
Total Warnings: 0
Total Errors: 0
[root@yu63 nrpe-2.12]# service iptables stop
[root@yu63 nrpe-2.12]# setenforce 1
setenforce: SELinux is disabled
[root@yu63 nrpe-2.12]# service httpd restart
3、测试查看主机和服务

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-06/145029.htm

