杂兵的绝望攻略:nagios plugin yum 安装方法.(未完)

来源:百度文库 编辑:偶看新闻 时间:2024/04/25 06:14:19

1.首先确保yum源头可从该站点更新相关yum安装包:http://download.fedora.redhat.com/pub/epel/5/i386/

  #rpm -ivh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

   直接安装即可.

[root@bogon etc]# rpm -ivh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
Retrieving http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
warning: /var/tmp/rpm-xfer.Qrsal7: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%]

2.nagios server版本:centos 5.5

3.进入root账号下:

切换为root用户
su -l

创建新帐户名为nagios并给它一个登录口令

/usr/sbin/useradd nagios

passwd nagios

创建一个用户组名为nagios,并把nagios帐户加入该组

/usr/sbin/groupadd nagios

/usr/sbin/usermod -G nagios nagios

创建一个用户组名为nagcmd来执行外部命令并可以通过WEB接口来执行。将nagios用户和apache用户都加到这个组中。

/usr/sbin/groupadd nagcmd

/usr/sbin/usermod -G nagcmd nagios

/usr/sbin/usermod -G nagcmd apache

4.进入系统,root下:

root#

[root@bogon etc]# yum install httpd  gcc glibc glibc-common gd gd-devel nagios nagios-plugins nrpe (后期添加:nagios-plugins-all nagios-common)
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: data.nicehosting.co.kr
* base: data.nicehosting.co.kr
* epel: mirrors.sohu.com
* extras: data.nicehosting.co.kr
* updates: centos.tt.co.kr
Setting up Install Process
Package httpd-2.2.3-45.el5.centos.1.i386 already installed and latest version
Package gcc-4.1.2-50.el5.i386 already installed and latest version
Package gd-2.0.33-9.4.el5_4.2.i386 already installed and latest version
Package nagios-2.12-10.el5.i386 already installed and latest version
Package nagios-plugins-1.4.15-2.el5.i386 already installed and latest version
Package nrpe-2.12-16.el5.i386 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package gd-devel.i386 0:2.0.33-9.4.el5_4.2 set to be updated
--> Processing Dependency: freetype-devel for package: gd-devel
--> Processing Dependency: libjpeg-devel for package: gd-devel
--> Processing Dependency: libpng-devel for package: gd-devel
--> Processing Dependency: libXpm-devel for package: gd-devel
--> Processing Dependency: libX11-devel for package: gd-devel
--> Processing Dependency: fontconfig-devel for package: gd-devel
--> Processing Dependency: glibc = 2.5-58.el5_6.3 for package: nscd
--> Processing Dependency: glibc = 2.5-58.el5_6.3 for package: glibc-devel
--> Processing Dependency: glibc = 2.5-58.el5_6.3 for package: glibc-headers
---> Package glibc.i686 0:2.5-58.el5_6.4 set to be updated
---> Package glibc-common.i386 0:2.5-58.el5_6.4 set to be updated
--> Running transaction check
---> Package fontconfig-devel.i386 0:2.4.1-7.el5 set to be updated
---> Package freetype-devel.i386 0:2.2.1-28.el5_5.1 set to be updated
--> Processing Dependency: freetype = 2.2.1-28.el5_5.1 for package: freetype-devel
---> Package glibc-devel.i386 0:2.5-58.el5_6.4 set to be updated
---> Package glibc-headers.i386 0:2.5-58.el5_6.4 set to be updated
---> Package libX11-devel.i386 0:1.0.3-11.el5 set to be updated
--> Processing Dependency: xorg-x11-proto-devel >= 7.1-2 for package: libX11-devel
--> Processing Dependency: libXau-devel for package: libX11-devel
--> Processing Dependency: libXdmcp-devel for package: libX11-devel
---> Package libXpm-devel.i386 0:3.5.5-3 set to be updated
---> Package libjpeg-devel.i386 0:6b-37 set to be updated
---> Package libpng-devel.i386 2:1.2.10-7.1.el5_5.3 set to be updated
--> Processing Dependency: libpng = 2:1.2.10-7.1.el5_5.3 for package: libpng-devel
---> Package nscd.i386 0:2.5-58.el5_6.4 set to be updated
--> Running transaction check
---> Package freetype.i386 0:2.2.1-28.el5_5.1 set to be updated
---> Package libXau-devel.i386 0:1.0.1-3.1 set to be updated
---> Package libXdmcp-devel.i386 0:1.0.1-2.1 set to be updated
---> Package libpng.i386 2:1.2.10-7.1.el5_5.3 set to be updated
---> Package xorg-x11-proto-devel.i386 0:7.1-13.el5 set to be updated
--> Processing Dependency: mesa-libGL-devel for package: xorg-x11-proto-devel
--> Running transaction check
---> Package mesa-libGL-devel.i386 0:6.5.1-7.8.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
Package                                     Arch                        Version                                        Repository                      Size
=============================================================================================================================================================
Installing:
gd-devel                                    i386                        2.0.33-9.4.el5_4.2                             base                            97 k
Updating:
glibc                                       i686                        2.5-58.el5_6.4                                 updates                        5.3 M
glibc-common                                i386                        2.5-58.el5_6.4                                 updates                         16 M
Installing for dependencies:
fontconfig-devel                            i386                        2.4.1-7.el5                                    base                           168 k
freetype-devel                              i386                        2.2.1-28.el5_5.1                               base                           148 k
libX11-devel                                i386                        1.0.3-11.el5                                   base                           661 k
libXau-devel                                i386                        1.0.1-3.1                                      base                            11 k
libXdmcp-devel                              i386                        1.0.1-2.1                                      base                           7.5 k
libXpm-devel                                i386                        3.5.5-3                                        base                            31 k
libjpeg-devel                               i386                        6b-37                                          base                           105 k
libpng-devel                                i386                        2:1.2.10-7.1.el5_5.3                           base                           181 k
mesa-libGL-devel                            i386                        6.5.1-7.8.el5                                  base                           461 k
xorg-x11-proto-devel                        i386                        7.1-13.el5                                     base                           247 k
Updating for dependencies:
freetype                                    i386                        2.2.1-28.el5_5.1                               base                           312 k
glibc-devel                                 i386                        2.5-58.el5_6.4                                 updates                        2.0 M
glibc-headers                               i386                        2.5-58.el5_6.4                                 updates                        603 k
libpng                                      i386                        2:1.2.10-7.1.el5_5.3                           base                           241 k
nscd                                        i386                        2.5-58.el5_6.4                                 updates                        167 k

Transaction Summary
=============================================================================================================================================================
Install      11 Package(s)
Upgrade       7 Package(s)

Total download size: 27 M
Is this ok [y/N]: y
Downloading Packages:
http://data.nicehosting.co.kr/os/CentOS/5.6/os/i386/CentOS/libXdmcp-devel-1.0.1-2.1.i386.rpm: [Errno 14] HTTP Error 403: Forbidden
Trying other mirror.
(1/18): libXdmcp-devel-1.0.1-2.1.i386.rpm                                                                                             | 7.5 kB     00:00    
(2/18): libXau-devel-1.0.1-3.1.i386.rpm                                                                                               |  11 kB     00:00    
(3/18): libXpm-devel-3.5.5-3.i386.rpm                                                                                                 |  31 kB     00:02    
(4/18): gd-devel-2.0.33-9.4.el5_4.2.i386.rpm                                                                                          |  97 kB     00:10    
(5/18): libjpeg-devel-6b-37.i386.rpm                                                                                                  | 105 kB     00:05    
(6/18): freetype-devel-2.2.1-28.el5_5.1.i386.rpm                                                                                      | 148 kB     00:12    
(7/18): nscd-2.5-58.el5_6.4.i386.rpm                                                                                                  | 167 kB     00:17    
(8/18): fontconfig-devel-2.4.1-7.el5.i386.rpm                                                                                         | 168 kB     00:10    
(9/18): libpng-devel-1.2.10-7.1.el5_5.3.i386.rpm                                                                                      | 181 kB     00:13    
(10/18): libpng-1.2.10-7.1.el5_5.3.i386.rpm                                                                                           | 241 kB     00:18    
(11/18): xorg-x11-proto-devel-7.1-13.el5.i386.rpm                                                                                     | 247 kB     00:18    
(12/18): freetype-2.2.1-28.el5_5.1.i386.rpm                                                                                           |  40 kB     01:33    
http://centos.tt.co.kr/5.6/os/i386/CentOS/freetype-2.2.1-28.el5_5.1.i386.rpm: [Errno 4] Socket Error: timed out
Trying other mirror.
(12/18): freetype-2.2.1-28.el5_5.1.i386.rpm                                                                                           | 312 kB     00:28    
(13/18): mesa-libGL-devel-6.5.1-7.8.el5.i386.rpm                                                                                      | 461 kB     00:47    
(14/18): glibc-headers-2.5-58.el5_6.4.i386.rpm                                                                                        | 603 kB     00:30    
(15/18): libX11-devel-1.0.3-11.el5.i386.rpm                                                                                           | 661 kB     00:44    
(16/18): glibc-devel-2.5-58.el5_6.4.i386.rpm                                                                                          | 2.0 MB     02:54    
(17/18): glibc-2.5-58.el5_6.4.i686.rpm                                                                                                | 5.3 MB     07:03    
(18/18): glibc-common-2.5-58.el5_6.4.i386.rpm                                                                                         |  16 MB     23:08    
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                         12 kB/s |  27 MB     39:35    
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : glibc-common                                                                                                                         1/25
  Installing     : libXau-devel                                                                                                                         2/25
  Installing     : libjpeg-devel                                                                                                                        3/25
  Updating       : glibc                                                                                                                                4/25
  Updating       : glibc-headers                                                                                                                        5/25
  Updating       : libpng                                                                                                                               6/25
  Updating       : freetype                                                                                                                             7/25
  Updating       : nscd                                                                                                                                 8/25
  Installing     : freetype-devel                                                                                                                       9/25
  Installing     : fontconfig-devel                                                                                                                    10/25
  Installing     : libpng-devel                                                                                                                        11/25
  Updating       : glibc-devel                                                                                                                         12/25
  Installing     : xorg-x11-proto-devel                                                                                                                13/25
  Installing     : libX11-devel                                                                                                                        14/25
  Installing     : libXdmcp-devel                                                                                                                      15/25
  Installing     : mesa-libGL-devel                                                                                                                    16/25
  Installing     : libXpm-devel                                                                                                                        17/25
  Installing     : gd-devel                                                                                                                            18/25
  Cleanup        : libpng                                                                                                                              19/25
  Cleanup        : freetype                                                                                                                            20/25
  Cleanup        : nscd                                                                                                                                21/25
  Cleanup        : glibc                                                                                                                               22/25
  Cleanup        : glibc-common                                                                                                                        23/25
  Cleanup        : glibc-devel                                                                                                                         24/25
  Cleanup        : glibc-headers                                                                                                                       25/25

Installed:
  gd-devel.i386 0:2.0.33-9.4.el5_4.2                                                                                                                        

Dependency Installed:
  fontconfig-devel.i386 0:2.4.1-7.el5    freetype-devel.i386 0:2.2.1-28.el5_5.1  libX11-devel.i386 0:1.0.3-11.el5  libXau-devel.i386 0:1.0.1-3.1         
  libXdmcp-devel.i386 0:1.0.1-2.1        libXpm-devel.i386 0:3.5.5-3             libjpeg-devel.i386 0:6b-37        libpng-devel.i386 2:1.2.10-7.1.el5_5.3
  mesa-libGL-devel.i386 0:6.5.1-7.8.el5  xorg-x11-proto-devel.i386 0:7.1-13.el5

Updated:
  glibc.i686 0:2.5-58.el5_6.4                                               glibc-common.i386 0:2.5-58.el5_6.4                                             

Dependency Updated:
  freetype.i386 0:2.2.1-28.el5_5.1      glibc-devel.i386 0:2.5-58.el5_6.4      glibc-headers.i386 0:2.5-58.el5_6.4      libpng.i386 2:1.2.10-7.1.el5_5.3    
  nscd.i386 0:2.5-58.el5_6.4          

Complete!
[root@bogon etc]#

4.这个时候由于iptable没有开启tcp80端口,apache不可访问。

开启iptable的http端口。

5.登录http://ipaddress/

6.登录http://192.168.1.23/nagios,发现无法正常访问。一般是由于访问权限不够造成。

 

7.编辑访问权限,如下:

[root@bogon conf.d]# pwd
/etc/httpd/conf.d
[root@bogon conf.d]# vi nagios.cfg

 

ScriptAlias /nagios/cgi-bin/ /usr/lib/nagios/cgi-bin/

   Options ExecCGI
   order deny,allow
   deny from all
   allow from 127.0.0.1
   AuthType Basic
   AuthUserFile /etc/nagios/passwd
   AuthName "nagios"
   require valid-user

Alias /nagios/ /usr/share/nagios/html/

   Options None
   order deny,allow
   deny from all
   allow from 127.0.0.1
   AuthType Basic
   AuthUserFile /etc/nagios/passwd
   AuthName "nagios"
   require valid-user

# For SSL-servers
#
#   Options ExecCGI
#   SSLRequireSSL
#   order deny,allow
#   deny from all
#   allow from 127.0.0.1
#   AuthType Basic
#   AuthUserFile /etc/nagios/passwd
#   AuthName "nagios"
#   require valid-user
#

#
#Alias /nagios/ /usr/share/nagios/html/
#
#   Options None
#   SSLRequireSSL
#   order deny,allow
#   deny from all
#   allow from 127.0.0.1
#   AuthType Basic
#   AuthUserFile /etc/nagios/passwd
#   AuthName "nagios"
#   require valid-user
#

 

将上面的

deny from all
改为:allow from all

 

再wq保存退出。

 

8.编辑访问密码,由上图可以看出用户密码保存在

/etc/nagios/passwd  中。

设定密码:#htpasswd –c  /etc/nagios/passwd/htpasswd.users nagiosadmin

 

9.登录web界面:http://192.168.1.23/nagios/

 

(注意:必须在nagios后面加“/”.否则登录失败)

然后弹出一个框。输入用户名:nagiosadmin和密码:nagiosadmin

若输入正确的用户名和密码依旧无法进入,则修改以下文件,确保认证密码对应正确的文件夹。

[root@bogon selinux]# cd /etc/httpd/conf.d/
[root@bogon conf.d]# ls
nagios.conf  nagios.conf.rpmsave  proxy_ajp.conf  README  squid.conf  welcome.conf
[root@bogon conf.d]# more nagios.conf
ScriptAlias /nagios/cgi-bin/ /usr/lib/nagios/cgi-bin/

   Options ExecCGI
   order deny,allow
   allow from all
   allow from 127.0.0.1
   AuthType Basic
   AuthUserFile /etc/nagios/passwd
   AuthName "nagios"
   require valid-user

Alias /nagios/ /usr/share/nagios/html/

   Options None
   order deny,allow
   allow from all
   allow from 127.0.0.1
   AuthType Basic
   AuthUserFile /etc/nagios/passwd
   AuthName "nagios"
   require valid-user

# For SSL-servers
#

AuthUserFile /etc/nagios/passwd 改为: AuthUserFile /etc/nagios/passwd/htpasswd.users

再次登录,出现以下界面,则显示成功,再点击“host detail”。会出现以下界面。

10.当出现上述界面,一般是由于“cgi.cfg中的use_authentication=1”造成,将1改成0可行。

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

摘录:http://tenhlf.blog.163.com/blog/static/5363158120100211105433/

所有的安装配置里面,都说将cgi.cfg的use_authentication=0,据说这样能够访问全部的页面。事实上,这是一个偷懒的做法,而且在以后必将会更正。

我们会在web页面对一些设置进行更改,在nagios的机制中,都会通过nagios.cmd。而use_authentication=0,会 disable external_command_file的使用,于是,所有更改都会提示authentication错误。

正确的做法,首先,将cgi.cfg的use_authentication=1,然后我们授权用户的权限。
authorized_for_system_information=*
authorized_for_configuration_information=*
authorized_for_system_commands=siemsen
authorized_for_all_services=*
authorized_for_all_hosts=*
authorized_for_all_service_commands=*
authorized_for_all_host_commands=*
*代表所有用户,也可以用逗号形式将用户逐一添入(推荐这种方法)。例如:
authorized_for_system_information=nagios,nagiosadmin,www-data,apacheuser

#======================以下没能测试,可能对源码安装方式有效

接着,要改变nagios.cmd所在目录/usr/local/nagios/var/rw的权限,命令如下。
chown nagios.nagiocmd /usr/local/nagios/var/rw
chmod u+rwx /usr/local/nagios/var/rw
chmod g+rwx /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
最后重起nagios:
/etc/init.d/nagios restart
再去更新设置,就能成功了!

#=========================================

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

登录http://192.168.1.23/nagios/ 显示:

当验证文件的正确性时,出现以下警告,不明其含义。

[root@bogon nagios]# /usr/sbin/nagios -v /etc/nagios/nagios.cfg

Nagios 2.12
Copyright (c) 1999-2007 Ethan Galstad (http://www.nagios.org)/
Last Modified: 05-19-2008
License: GPL

Reading configuration data...

Running pre-flight check on configuration data...

Warning: Size of service_message struct (8356 bytes) is > POSIX-guaranteed atomic write size (512 bytes).  Service checks results may get lost or mangled!
Checking services...
    Checked 5 services.
Checking hosts...
    Checked 1 hosts.
Checking host groups...
    Checked 1 host groups.
Checking service groups...
    Checked 0 service groups.
Checking contacts...
    Checked 1 contacts.
Checking contact groups...
    Checked 1 contact groups.
Checking service escalations...
    Checked 0 service escalations.
Checking service dependencies...
    Checked 0 service dependencies.
Checking host escalations...
    Checked 0 host escalations.
Checking host dependencies...
    Checked 0 host dependencies.
Checking commands...
    Checked 22 commands.
Checking time periods...
    Checked 4 time periods.
Checking extended host info definitions...
    Checked 0 extended host info definitions.
Checking extended service info definitions...
    Checked 0 extended service info definitions.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 1
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

11. 验证nagios与httpd均可随机启动。

[root@bogon nagios]# chkconfig --list | grep nagios
nagios             0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@bogon nagios]# chkconfig --list | grep httpd
httpd              0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@bogon nagios]#

12.安装nagios-plugins-all(所有check-*插件)

[root@bogon plugins]# yum install nagios-plugins-all

安装完毕。显示:

[root@bogon plugins]# pwd
/usr/lib/nagios/plugins
[root@bogon plugins]# dir
check_breeze   check_disk      check_fping  check_ide_smart  check_load      check_mysql_query    check_ntp_peer    check_ping     check_simap  check_swap     check_wave
check_by_ssh   check_disk_smb  check_ftp    check_imap         check_log         check_nagios    check_ntp_time    check_pop      check_smtp   check_tcp     eventhandlers
check_clamd    check_dns       check_game   check_ircd         check_mailq     check_nntp        check_nwstat    check_procs    check_snmp   check_time     negate
check_cluster  check_dummy     check_hpjd   check_jabber     check_mrtg      check_nntps    check_oracle    check_real     check_spop   check_udp     urlize
check_dhcp     check_file_age  check_http   check_ldap         check_mrtgtraf  check_nt        check_overcr    check_rpc      check_ssh    check_ups     utils.pm
check_dig      check_flexlm    check_icmp   check_ldaps      check_mysql     check_ntp        check_pgsql    check_sensors  check_ssmtp  check_users  utils.sh
[root@bogon plugins]#

登录http//192.168.1.23/nagios/ 显示正常

13.编辑/etc/nagios/nagios.cfg

在/etc/nagios/中新建文件夹:

touch cfgfiles

再将以下文件

#cfg_file=/etc/nagios/contactgroups.cfg
#cfg_file=/etc/nagios/contacts.cfg
#cfg_file=/etc/nagios/dependencies.cfg
#cfg_file=/etc/nagios/escalations.cfg
#cfg_file=/etc/nagios/hostgroups.cfg
#cfg_file=/etc/nagios/hosts.cfg
#cfg_file=/etc/nagios/services.cfg
#cfg_file=/etc/nagios/timeperiods.cfg

变更为:

#cfg_file=/etc/nagios/cfgfiles/ctgroups.cfg
#cfg_file=/etc/nagios/cfgfiles/contacts.cfg
#cfg_file=/etc/nagios/cfgfiles/dependencies.cfg
#cfg_file=/etc/nagios/cfgfiles/escalations.cfg
#cfg_file=/etc/nagios/cfgfiles/hostgroups.cfg
#cfg_file=/etc/nagios/cfgfiles/hosts.cfg
#cfg_file=/etc/nagios/cfgfiles/services.cfg
#cfg_file=/etc/nagios/cfgfiles/timeperiods.cfg