FreeBSD 下用nagios来监控网络服务器和网络服务(4)

mkdir log

cd log

touch ./run

chmod 755 ./run

vi ./run

#!/bin/sh

exec setuidgid logadmin multilog t s1000000 n100 ./main

 

mkdir main

chmod 777 main

chown nagios.nagios main

touch status

chown nagios.nagios status

 

svc -u /service/nagios/

svstat /service/nagios/

root@## ps auxww | grep nagios

root     23276 0.0 0.1 1176   488 ?? I   5:00PM   0:01.71 supervise nagios

nagios   34251 0.0 0.3 2316 1552 ?? S   6:06PM   0:00.10 /usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg

root@##

 

ok,现在把nagios服务做成自动启动的服务。

通过svc命令可以启动或者停止服务。

———————————————————————————

svc opts services

opts is a series of getopt-style options. services consists of any number of arguments, each argument naming a directory used by supervise.

 

-u: Up. If the service is not running, start it. If the service stops, restart it.

-d: Down. If the service is running, send it a TERM signal and then a CONT signal. After it stops, do not restart it.

-o: Once. If the service is not running, start it. Do not restart it if it stops.

-p: Pause. Send the service a STOP signal.

-c: Continue. Send the service a CONT signal.

-h: Hangup. Send the service a HUP signal.

-a: Alarm. Send the service an ALRM signal.

-i: Interrupt. Send the service an INT signal.

-t: Terminate. Send the service a TERM signal.

-k: Kill. Send the service a KILL signal.

-x: Exit. supervise will exit as soon as the service is down. If you use this option on a stable system, you’re doing something wrong; supervise is designed to run forever.

———————————————————————————

比如:

停止nagios--svc -d /service/nagios/

重启nagios--svc -t /service/nagios/

启动nagios--svc -u /service/nagios/

 

当然,你也可以使用inited的方式进行:

/usr/local/etc/rc.d/nagios start/stop

 

好,反正daemontools很强大,以后慢慢熟悉,转入正题。

现在打开网页:http://localhost/nagios/

一定会让你大吃一惊,呵呵,俺的服务器和服务状态都清楚的看到。

现在俺们的nagios中只有一个,那就是它自己,localhost,呵呵,等会俺们添加别的主机和主机服务,ok,俺们认识一下nagios的庐山真面目:

 

配置nagios:

 

1)为主机添加服务

2)添加主机并添加服务

3)停止一个服务

4)删除一台主机和服务

5)查看所有主机的故障

6)查看一台特定的主机状态

7)改变报警的时间间隔

8)改变发现故障的重试次数

9)如何在nagios中使用外部命令

 

 

1)为主机添加一个服务

为localhost主机添加qmail服务的监控,方法如下:

vi minimal.cfg

define service{

use                   generic-service       ; Name of service template to use

host_name               localhost

service_description         qmail_smtp

is_volatile               0

check_period             24×7

max_check_attempts         1

normal_check_interval       1

retry_check_interval         1

contact_groups             admins

notification_options         w,u,c,r

notification_interval       960

notification_period         24×7

check_command             check_smtp!20%!10%!/

}

 

以下文章点击率最高

Loading…

发表评论