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%!/

}

 

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

 

3)获得图库文件:

]http://dl.sf.net/nagios/imagepak-base.tar.gz[/url]

 

4)NRPE,版本2.5.2

]http://ufpr.dl.sourceforge.net/sourceforge/nagios/nrpe-2.5.2.tar.gz[/url]

 

5)NSCA,版本2.6

]http://kent.dl.sourceforge.net/sourceforge/nagios/nsca-2.6.tar.gz[/url]

 

3:切换到root用户:

sudo su

 

4:解压缩

tar zxvf nagios-2.5.tar.gz

 

5:建立运行nagios的用户:

adduser nagios

 

6:建立安装nagios的文件夹,并使这个文件夹的所有者为nagios:nagios

mkdir /usr/local/nagios

chown nagios.nagios /usr/local/nagios

 

7:确认web服务器的用户

可能会通过web接口执行一些命令,必须确定web服务器以哪个用户运行的,通常为:apache:

grep “^User” /usr/local/apache2/conf/httpd.conf

 

8:建立命令文件组

这个新的组会包括apache的用户和nagios的用户

pw groupadd nagcmd

pw usermod apache -G nagcmd

pw usermod nagios -G nagcmd

———————————-

cat /etc/group

nagcmd:*:9007:apache,nagios

———————————-

 

8:运行配置脚本并安装nagios

cd nagios-2.5

./configure –prefix=/usr/local/nagios –with-gd-lib=/usr/local/lib –with-gd-inc=/usr/local/include

———————————

*** Configuration summary for nagios 2.5 07-13-2006 ***:

 

General Options:

————————-

Nagios executable: nagios

Nagios user/group: nagios,nagios

Command user/group: nagios,nagios

Embedded Perl: no

Event Broker: yes

Install ${prefix}: /usr/local/nagios

Lock file: ${prefix}/var/nagios.lock

Init directory: /usr/local/etc/rc.d

Host OS: freebsd6.0

 

Web Interface Options:

————————

HTML URL: ]http://localhost/nagios/[/url]

CGI URL: ]http://localhost/nagios/cgi-bin/[/url]

Traceroute (used by WAP): /usr/sbin/traceroute

 

 

Review the options above for accuracy. If they look okay,

type ‘make all’ to compile the main program and CGIs.

———————————

make all

make install

make install-init

make install-commandmode

make install-config

 

9:安装nagios-plugins

tar zxvf nagios-plugins-1.4.3.tar.gz

cd nagios-plugins-1.4.3

./configure –prefix=/usr/local/nagios-plugins

make all

make install

安装完成以后在/usr/local/nagios-plugins-plugins会产生一个libexec的目录,将该目录全部移动到/usr/local/nagios目录下即可。

mv /usr/local/nagios-plugins-plugins/libexec/ /usr/local/nagios/

 

10:imagepak-base.tar.gz的安装

tar –xvzf imagepak-base.tar.gz

解压以后是base目录

mv base/ /usr/local/nagios/share/images/logos/

 

———————————————————————-