六、服务端口修改后的设置
1
、被监控机的远程连接ssh服务默认端口由22改为65422后,怎么修改nagios的配置?
(1)查看check_ssh参数的用法:
[root@localhost ]# cd /usr/local/nagios/libexec
[root@localhost ]# ./check_ssh (
直接执行命令会得到参数使用方法)
check_ssh: Could not parse arguments
Usage:
check_ssh [-46] [-t <timeout>] [-r <remote version>] [-p <port>] <host>
(注意这边端口号-p是放在主机地址host前面的,顺序不能反过来)
(2)查看command.cfg命令参数调用的情况:
[root@localhost ]# cat /usr/local/nagios/etc/objects/command.cfg
define command{
command_name check_ssh
command_line $USER1$/check_ssh $ARG1$ $HOSTADDRESS$
(
这边主机地址前面已经有带一个输入值
)
}
(说明:这边主机地址前面已经有带一个输入值“$ARG1$” ,所以文件不用做修改。)
(3)修改主调用程序linux.cfg中的参数设置
[root@localhost ]# vim /usr/local/nagios/etc/objects/linux.cfg
define service{
use local-service
host_name nfs-server
service_description SSH
check_command check_ssh!-p 65422
(这里设置被控机上面修改后的ssh端口号)
-p 后面加的是$ARG1$的输入值 65422
notifications_enabled 0
notification_interval 10 (
告警发送邮件的时间间隔10分钟,默认单位是分钟)
}
(4)验证参数据修改是否正确
[root@localhost ]#
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@localhost ]# service nagios reload
2
、被监控机的web发布http服务默认端口由80改为88后,怎么修改nagios的配置?
(1)查看check_http参数的用法:
[root@localhost ]# cd /usr/local/nagios/libexec
[root@localhost ]# ./check_http (
直接执行命令会得到参数使用方法)
check_http: Could not parse arguments
Usage:
check_http -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]
[-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth]
[-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]
[-e <expect>] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]
[-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]
[-A string] [-k string] [-S] [--sni] [-C <age>] [-T <content-type>]
[-j method]
(注意这边端口号-p是放在主机地址host后面的,顺序不能反过来)
(2)方法一
:(这种方法比较好)
A
、修改command.cfg命令参数调用的情况:
[root@localhost ]# vim /usr/local/nagios/etc/objects/command.cfg
define command{
command_name check_http
command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
}
define command{
command_name check_http88
(
这里增加http88端口的命令)
command_line $USER1$/check_http -I $HOSTADDRESS$ -p 88 $ARG1$
}
define command{
command_name check_http_url
(
这里增加检测网站地址通不通的命令)
command_line $USER1$/check_http $ARG1$
}
B
、修改主调用程序linux.cfg中的参数设置
[root@localhost ]# vim /usr/local/nagios/etc/objects/linux.cfg
define service{
use local-service
host_name nfs-server
service_description HTTP:88
check_command check_http88
(
这里设置被控机上面修改后的调用命令http88
)
notifications_enabled 1
(
是否报警的设置)
}
define service{
use generic-service
host_name 192.168.0.50
service_description sjgg www.baidu.com
servicegroups web_server
check_command check_http_url!-H www.baidu.com -p 80
(
检测这个网站的80端口通不通)
}
(3)方法二
:
A
、查看command.cfg命令参数调用的情况:
[root@localhost ]# vim /usr/local/nagios/etc/objects/command.cfg
define command{
command_name check_http
command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
}
(说明:这边主机地址前面已经有带一个输入值“$ARG1$” ,所以文件不用做修改。)
B
、修改主调用程序linux.cfg中的参数设置
[root@localhost ]# vim /usr/local/nagios/etc/objects/linux.cfg
define service{
use local-service
host_name nfs-server
service_description HTTP
check_command check_http!-p 88
(
这里设置被控机上面修改后的http端口号88
)
notifications_enabled 1
}
(3)验证参数据修改是否正确
[root@localhost ]#
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@localhost ]# service nagios reload