天天看點

CentOS 6.4安裝Nagios 3.5.0

Nagios是一款開源的免費網絡監視工具,能有效監控Windows、Linux和Unix的主機狀态,交換機路由器等網絡設定,列印機等。在系統或服務狀态異常時發出郵件或短信報警第一時間通知網站運維人員,在狀态恢複後發出正常的郵件或短信通知。

一.安裝環境的配置

1.關閉防火牆

為了防止因為防火牆的原因影響我們安裝的環境,我們對防火牆進行關閉,如果在實際的生産環境中,我們是不建議關閉防火牆的。

[root@Nagios ~]# service iptables stop

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Setting chains to policy ACCEPT: filter          [  OK  ]

iptables: Unloading modules:                               [  OK  ]

[root@Nagios ~]# chkconfig iptables off

2.關閉SELinux

如果未關閉SELinux,則可能在安裝完成後,會出現Internal Server Error錯誤

編輯/etc/selinux/config

[root@Nagios ~]# vim /etc/selinux/config

将SELINUX=disabled

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of these two values:

#     targeted - Targeted processes are protected,

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted

3.修改hosts檔案

已知我們這台機器的主機名為Nagios,則修改/etc/hosts

127.0.0.1  Nagios localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

添加上面紅色部分即可,否則啟動apache服務的時候可能出現

Starting httpd: httpd: apr_sockaddr_info_get() failed for Nagios

做完以上3個步驟後,我們需要重新啟動伺服器。

二.軟體的準備

1.安裝必要的軟體

[root@Nagios ~]# yum -y install wget make openssl openssl-devel httpd php gcc glibc \

> glibc-common gd gd-devel net-snmp mysql \

> mysql-server mysql-devel php-mysql perl perl-devel gnutls gnutls-devel

2.MySQL的配置(此步可省略)

雖然現在還并未使用MySQL,但是在以後的配置需要用到。

首先啟動MySQL伺服器

[root@Nagios ~]# service mysqld start

接着設定更改MySQL root賬戶的密碼

[root@Nagios ~]# mysqladmin -u root password 123456

三.軟體的安裝

1.Nagios賬戶及組的添加

[root@Nagios ~]# useradd nagios

[root@Nagios ~]# groupadd nagcmd

[root@Nagios ~]# usermod -a -G nagcmd nagios

[root@Nagios ~]# usermod -a -G nagcmd apache

2.軟體的下載下傳

Nagios軟體的下載下傳

[root@Nagios ~]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.5.0.tar.gz

[root@Nagios ~]# wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

3.Nagios軟體的解壓

[root@Nagios ~]# tar zxvf nagios-3.5.0.tar.gz

[root@Nagios ~]# tar zxvf nagios-plugins-1.4.16.tar.gz

4.Nagios的編譯與安裝

首先進入Nagios解壓後所在的目錄

[root@Nagios ~]# cd nagios

[root@Nagios nagios]# ./configure --with-command-group=nagcmd

[root@Nagios nagios]# make all

[root@Nagios nagios]# make install 

[root@Nagios nagios]# make  install-init

[root@Nagios nagios]# make  install-config

[root@Nagios nagios]# make  install-commandmode

[root@Nagios nagios]# make  install-webconf

[root@Nagios nagios]# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/

[root@Nagios nagios]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers/

測試nagios的配置檔案

[root@Nagios nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

如果最後出現

Total Warnings: 0

Total Errors:   0

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

就證明nagios配置無誤可正常啟動!

啟動Nagios服務:

[root@Nagios nagios]# service nagios start

Starting nagios: done.

啟動httpd服務:

[root@Nagios nagios]# service httpd start

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

                                                          [  OK  ]

添加通路WEB服務的賬戶及密碼

[root@Nagios nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users admin

New password:

Re-type new password:

Adding password for user admin

這個時候就已經添加好了通路web網站的使用者了

5.Nagios plugin的安裝

首先進入Nagios plugin解壓目錄

[root@Nagios nagios]# cd ../nagios-plugins-1.4.16

進行編譯:

[root@Nagios nagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-extra-opts --enable-perl-modules --enable-libtap

編譯成功後,會出現如下資訊:

          --with-apt-get-command:

             --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s

              --with-ping-command: /bin/ping -n -U -w %d -c %d %s

                      --with-ipv6: yes

                     --with-mysql: /usr/bin/mysql_config

                   --with-openssl: yes

                    --with-gnutls: no

              --enable-extra-opts: yes

                      --with-perl: /usr/bin/perl

            --enable-perl-modules: yes

                    --with-cgiurl: /nagios/cgi-bin

              --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin

                  --enable-libtap: yes

插件的安裝

[root@Nagios nagios-plugins-1.4.16]# make

[root@Nagios nagios-plugins-1.4.16]# make install

最後将nagios及httpd加入啟動項,并自動啟動

[root@Nagios nagios-plugins-1.4.16]# chkconfig --add nagios

[root@Nagios nagios-plugins-1.4.16]# chkconfig --level 35 nagios on

[root@Nagios nagios-plugins-1.4.16]# chkconfig --add httpd

[root@Nagios nagios-plugins-1.4.16]# chkconfig --level 35 httpd on

本文轉自 rong341233 51CTO部落格,原文連結:http://blog.51cto.com/fengwan/1215237