用nagios来监控网络服务器和网络服务.docx

上传人:b****1 文档编号:18141525 上传时间:2023-04-24 格式:DOCX 页数:28 大小:24.36KB
下载 相关 举报
用nagios来监控网络服务器和网络服务.docx_第1页
第1页 / 共28页
用nagios来监控网络服务器和网络服务.docx_第2页
第2页 / 共28页
用nagios来监控网络服务器和网络服务.docx_第3页
第3页 / 共28页
用nagios来监控网络服务器和网络服务.docx_第4页
第4页 / 共28页
用nagios来监控网络服务器和网络服务.docx_第5页
第5页 / 共28页
点击查看更多>>
下载资源
资源描述

用nagios来监控网络服务器和网络服务.docx

《用nagios来监控网络服务器和网络服务.docx》由会员分享,可在线阅读,更多相关《用nagios来监控网络服务器和网络服务.docx(28页珍藏版)》请在冰豆网上搜索。

用nagios来监控网络服务器和网络服务.docx

用nagios来监控网络服务器和网络服务

Nagios

nagios可以对服务器进行全面的监控,包括服务(apache、mysql、ntp、dns、disk、qmail和sshd等等)的状态,服务器的状态(up、down等等)。

它是一个完全GPL协议的开源软件包,包含有nagios主程序和它的各个插件,配置非常灵活,可以监视的项目很多,可以自定义shell脚本进行监控服务,非常适合大型网络。

nagios的包含主动监控和被动监控。

主动检查是通过监控中心的主机发出请求,让运行在远程主机上的nrpe守护进程收集信息,然后报告它,它通过web接口把数据显示在页面上。

它的工作原理如下:

被动监控是当远程被监控主机处于防火墙之内的时候,只有远程主机可以访问到监控中心,防火墙之内可以设置另外一个监控中心,远程监控中心的nagios收集服务器信息以后,和nsca报告,由naca客户端报告naca的服务器端,然后报告监控中心的nagios,通过web接口显示监控结果。

nagios的功能非常强大,http:

//www.nagios.org/是它的窝,只有e文、法文和日文,没有中文,可惜啊。

我现在引用它的一段文字进行总结一下到底什么是nagios:

What Is This?

什么是nagios?

 

Nagios® is a system and network monitoring application. It watches hosts and services that you specify, alerting you when things go bad and when they get better. 

Nagios was originally designed to run under Linux, although it should work under most other unices as well. 

Some of the many features of Nagios® include:

 

Monitoring of network services (SMTP, POP3, HTTP, NNTP, PING, etc.) 

Monitoring of host resources (processor load, disk usage, etc.) 

Simple plugin design that allows users to easily develop their own service checks 

Parallelized service checks 

Ability to define network host hierarchy using "parent" hosts, allowing detection of and distinction between hosts that are down and those that are unreachable 

Contact notifications when service or host problems occur and get resolved (via email, pager, or user-defined method) 

Ability to define event handlers to be run during service or host events for proactive problem resolution 

Automatic log file rotation 

Support for implementing redundant monitoring hosts 

Optional web interface for viewing current network status, notification and problem history, log file, etc.

Nagios是一个监视系统和网络的应用程序。

它监视你所指定主机和服务,当监视的内容变好或者变坏时发出警告。

Nagios最初是被设计在Linux平台上运行的,然而现在在其他平台上也运行良好。

Nagios的特性包括:

监视网络服务(SMTP, POP3, HTTP, NNTP, PING, 等等)

监视主机资源(处理器负载、磁盘空间等)

容许用户开发自己的插件去检查自定义的项目;

通过使用“父主机”,定义网络主机的分层,容许探测主机down掉或者不可到达。

可以定义在主机或服务运行期间,事件发生以后如何处理和解决方式;

自动记录错误日志;

支持冗余监视;

可选web接口,通过web页面查看当前网络状态,提示和报告故障历史,日志文件等;

Nagios的系统要求:

Linux、Unix等

apache

GD库(1.63以上)

zlib

pnglib

jpeglib

basic icons

等,其中apache的安装在blog中已经有相关的文章,搜索一下就行;gd、zlib、pnglib和jpeglib安装比较简单,步骤:

下载tarball

tar zxvf xxx.tar.gz

cd xxx

./configure

make && make install

----------------------------------------------------------------------

Nagios的安装过程(FreeBSD)

----------------------------------------------------------------------

nagios的安装比较简单,复杂的是设置和配置参数的设定。

不过你要放松一点,毕竟我们要搞定它,不是吗?

那就开始吧:

1:

获得最新的安装包,http:

//www.nagios.org/download

2:

以root身份登录服务器,目前最新的版本是2.5:

1)nagios,版本2.5:

fetch http:

//superb- 

or

wget http:

//superb-

2)获得nagios插件,版本1.4.3:

3)获得图库文件:

4)NRPE,版本2.5.2

5)NSCA,版本2.6

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/

            CGI URL:

 http:

//localhost/nagios/cgi-bin/

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/

----------------------------------------------------------------------

现在开始配置:

----------------------------------------------------------------------

1:

配置web接口

假设你已经运行了apache,如果没有,请参考:

http:

//localhost/upload/blog.php?

do-showone-tid-18.html

vi /usr/local/apache2/conf/httpd.conf

添加如下内容:

ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

  Options ExecCGI

  AllowOverride None

  Order allow,deny

  Allow from all

  AuthName "Nagios Access"

  AuthType Basic

  AuthUserFile /usr/local/nagios/etc/htpasswd.users

  Require valid-user

Alias /nagios /usr/local/nagios/share

  Options None

  AllowOverride None

  Order allow,deny

  Allow from all

  AuthName "Nagios Access"

  AuthType Basic

  AuthUserFile /usr/local/nagios/etc/htpasswd.users

  Require valid-user

修改完毕,保存文件,并重启apache:

/usr/local/apahce2/bin/apachectl restart

2:

配置apache的BASIC认证:

生成认证密码:

/usr/local/apache2/bin/htpasswd –c /usr/local/nagios/etc/htpasswd.users nagios nagios 

apache接口配置完成。

开始配置nagios:

cd /usr/local/nagios/etc/

在/usr/local/nagios/etc下是nagios的配置模板文件-sample,把.cfg-sample文件全部拷贝成.cfg 

例如:

cp nagios.cfg-sample nagios.cfg 

全部拷贝完成即可.

vi minimal.cfg

注释所有command:

注释的方法是在每一个定义语句前面添加”#“

修改cgi.cfg

修改use_authentication=1为use_authentication=0,即不用验证.不然有一些页面不会显示。

现在检查配置文件是否有语法错误:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

如果正确,会显示以下结果:

Total Warnings:

 0

Total Errors:

   0

否则,需要根据提示进行修改配置文件。

配置文件等会再弄。

现在启动nagios

/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

为了使nagios异常中断,我们使用daemontools启动:

安装daemontool:

mkdir -p /package

chmod 1755 /package

cd /package

fetch http:

//cr.yp.to/daemontools/daemontools-0.76.tar.gz

cd admin/daemontools-0.76/

package/install

检查svscan进程是否启动:

ps aux | grep svscan

root       376 0.0 0.0 1636   0 con- IW   -       0:

00.00 /bin/sh /command/svscanboot

root       411 0.0 0.0 1224   208 con- S   8Jul06   0:

42.50 svscan /service

ok,启动正常了。

cd /service

mkdir nagios

chmod 1755 nagios

touch ./run

chmod 755 ./run

vi run

PATH=/usr/local/bin:

/usr/bin:

/bin

export PATH

exec env - PATH=$PATH \

/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg

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               l

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1