Chinaunix首页 | 论坛 | 博客
  • 博客访问: 53438
  • 博文数量: 14
  • 博客积分: 1445
  • 博客等级: 上尉
  • 技术积分: 175
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-14 22:30
文章分类

全部博文(14)

文章存档

2017年(5)

2011年(1)

2010年(8)

我的朋友

分类: LINUX

2010-09-18 16:12:39

Nagios安装配置:
系统:CentOS 5.2          Nagios:3.0.6
 

安装Nagios

[root@localhost ~]#useradd nagios

[root@localhost ~]#tar xvf nagios-0.3.6.tar.gz

[root@localhost ~]#cd nagios 3.0.6

[root@localhost ~]#chmod 777 *

[root@localhost ~]#./configure

[root@localhost ~]#make all

[root@localhost ~]#make install

[root@localhost ~]#make install-init

[root@localhost ~]#make install-commandmode

[root@localhost ~]#make install-config

[root@localhost ~]#make install-webconf

 

安装nagios-plushins:

[root@localhost ~]#tar zvf nagios-plugins-1.4.13.tar.gz

[root@localhost ~]#cd nagios-plugins-1.4.13

[root@localhost ~]#chmod 777 *

[root@localhost ~]#./configure

[root@localhost ~]#make

[root@localhost ~]#make install


安装NREP:

[root@localhost ~]#yum install openssl-devel

[root@localhost ~]#cd nagios-nrpe_2.12

[root@localhost ~]#./configure

[root@localhost ~]#make all

[root@localhost ~]#make install-plugin

 

配置Apache

[root@localhost ~]#vim /etc/httpd/conf.d/nagios

#   ServerAdmin webmaster@dummy-host.example.com

    DocumentRoot "/usr/local/nagios/share"

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

#  SSLRequireSSL

   Options ExecCGI

   AllowOverride None

   Order allow,deny

   Allow from all

#  Order deny,allow

#  Deny from all

#  Allow from 127.0.0.1

   AuthName "Nagios Access"

   AuthType Basic

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

   Require valid-user

Alias /nagios "/usr/local/nagios/share"

#  SSLRequireSSL

   Options None

   AllowOverride None

   Order allow,deny

   Allow from all

#  Order deny,allow

#  Deny from all

#  Allow from 127.0.0.1

   AuthName "Nagios Access"

   AuthType Basic

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

   Require valid-user

#   ErrorLog logs/dummy-host.example.com-error_log

#   CustomLog logs/dummy-host.example.com-access_log common

[root@localhost ~]#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

 

安装飞信

[root@localhost ~]#cd fetion_linux_20080402

[root@localhost ~]#cp sms /usr/bin/sms

[root@localhost ~]#chmod 777 /usr/bin/sms

[root@localhost ~]#cp library32/* /usr/lib/

  

修改contacts.cfg,定义联系人

[root@localhost ~]#vim /usr/local/nagios/etc/objects/contacts.cfg

define contact{

        contact_name                   nagiosadmin           

        use                                        generic-contact              

       alias                                       Nagios Admin       

        pager                                   159********

        email                                     

        }

define contact{

       contact_name                    cm

       use                                         generic-contact

       alias                                       cm

       email                                    

       pager                                    135********

}

define contactgroup{

        contactgroup_name     admins

        alias                                    Nagios Administrators

        members                         nagiosadmin,cm

        }

 

修改templates.cfg定义模板(定义报警方式,时间等):

[root@localhost ~]#vim /usr/local/nagios/etc/objects/templates.cfg

       define contact{

        name                         generic-contact             
       
service_notification_period       24×7                  

        host_notification_period            24×7                  

        service_notification_options      w,u,c,r,f,s            

        host_notification_options            d,u,r,f,s             

        service_notification_commands   notify-service-by-sms, notify-service-by-email

        host_notification_commands      notify-host-by-sms,notify-host-by-email

        register                        0                  

        }

 

修改commands.cfg

[root@localhost ~]#vim /usr/local/nagios/etc/objects/commands.cfg

define command{

command_name notify-host-by-sms
command_line /usr/bin/fetion --mobile=159xxxxxxxx --pwd=4****** --to=$CONTACTPAGER$ --msg-utf8="Host $HOSTSTATE$ alert for $HOSTNAME$! $HOSTOUTPUT$ $DATE$ $TIME$" $CONTACTPAGER$

     }

 

define command{

command_name notify-service-by-sms

command_line /usr/bin/fetion --mobile=159xxxxxxxx --pwd=****** --to=$CONTACTPAGER$ --msg-utf8="$HOSTADDRESS$ $HOSTALIAS$ $SERVICEDESC$ is $SERVICESTATE$ $SERVICEOUTPUT$ $DATE$ $TIME$" $CONTACTPAGER$    
}
  

(要使用邮件通知需保证本地sendmail能正常使用,或安装个邮件客户端)

 

被监控端

安装NREP:

[root@localhost ~]#useradd nagios

[root@localhost ~]#Yum install openssl-devel

[root@localhost ~]#cd nagios-nrpe_2.12

[root@localhost ~]#./configure

[root@localhost ~]#make all

[root@localhost ~]#make install-plugin

[root@localhost ~]#make install-daemon

[root@localhost ~]#make install-daemon-config

 

安装nagios-plugin

[root@localhost ~]#cd nagios-plugins-1.4.13

[root@localhost ~]#chmod 777 *

[root@localhost ~]#./configure

[root@localhost ~]#make

[root@localhost ~]#make install

 

监控Linux

修改服务器端配置文件:

[root@localhost ~]#vi /usr/local/nagios/etc/nagios.cfg

增加:

cfg_file=/usr/local/nagios/etc/objects/linuxser.cfg

 

建立被监控端配置文件:

 [root@localhost ~]#cd /usr/local/nagios/etc/objects

 [root@localhost ~]#cp localhost.cfg linuxser.cfg    (以localhost为模板,再根据实际情况修改)

 [root@localhost ~]#service nagios restart

 

客户端:

修改nrpe配置文件:[

~]#vi /usr/local/nagios/etc/nrpe.cfg

allowed_hosts=192.168.1.237,127.0.0.1  (要加上nagios server的ip)

command[check_/home]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /home

command[check_swap]=/usr/local/nagios/libexec/check_swap -w 30% -c 20%

command[check_sda_iostat]=/usr/local/nagios/libexec/check_iostat -d sda -w 100 -c 200

默认无法监控Linux主机swap,需更改nrep.cfg如上,要监控其他的再增加即可

 

启动nrpe

[root@localhost ~]#/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d


nrpe用5666端口,记得iptables要开发此端口。

 

监控Windows客户端:

服务器端配置跟监控Linux一样,就不重复了

客户端:

安装NSClient++-0.3.6-Win32.msi

1.去掉在[modules]段里的列出模块程序的注释,除了CheckWMI.dllRemoteConfiguration.dll

2.修改下在[Settings]段里的'password'选项;

3.去掉在[Settings]段里的'allowed_hosts'选项注释,把Nagios服务所在主机的IP加到这一行里,或是置为空,让全部主机都可以联入;

4.确认一下在[NSClient]段里的'port'选项里已经去掉注释并设置成'12489'(默认端口)

 

再加些监控非默认端口,虚拟主机....的配置:

监控非默认端口

[root@localhost ~]#vim /usr/local/nagios/etc/objects/web.cfg

define service{

        use                                                   local-service       

        host_name                                   localhost

        service_description                  HTTP

        check_command                       check_http! -p 8080!172.16.88.50

        notifications_enabled              1

        }

 

监控虚拟主机

[root@localhost ~]#vim /usr/local/nagios/etc/objects/command.cfg

增加

define command{

        command_name    check_http_vhost

        command_line    $USER1$/check_http $ARG1$

        }

 

[root@localhost ~]#vim /usr/local/nagios/etc/objects/web.cfg

       define service{

        use                       generic-service

        host_name                 Web_Proxy

        service_description          HTTP-test.com

        check_command            check_http_vhost!-H 8080

}

 

监控网页

[root@localhost ~]#vim /usr/local/nagios/etc/objects/wb.cfg

define service{

        use                                           generic-service       

        host_name                          WEB_DELL_228

        service_description        .com

        check_command              check_http_vhost!-H -u /default.aspx

        notifications_enabled       1

        }

 

常用排错命令

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

/usr/local/nagios/libexec/check_nrpe –H x.x.x.x

 

注:

unix里面负载的均值通常表示是1分钟,5分钟,15分钟内平均有多少进程处于等待状态.例如check_load -w 15,10,5 -c 30,25,20这个命令的意义如下

1分钟多于15个进程等待,5分钟多于10,15分钟多于5个则为warning状态

1分钟多于30个进程等待,5分钟多于25,15分钟多于20个则为critical状态

监控I/O需在被监控端安装sysstat,check_iostat权限需设为777或将属主和属组设为nagios

 

基本安装配置大概就是这样了,当然要深入了解nagios的话还有很多其他学习。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

阅读(1991) | 评论(0) | 转发(1) |
0

上一篇:Awstats分析日志

下一篇:LVM常用命令

给主人留下些什么吧!~~