nagios 搭建

wangxiangtao發表於2011-09-20

專案即將上線,前段時間一直在折騰dell MD3200i儲存, mysql資料庫,由於服務已經進入了廣州IDC 機房,為了更好了解所有伺服器的健康與負載,以及相關服務的狀態,需要安裝監控軟體, 推薦使用nagios cacti 以下為nagios 監控的搭建過程:

系統平臺如下:

[root@tes102 ~]# rpm  -q redhat-release

redhat-release-5Server-5.5.0.2

[root@tes102 ~]# uname -a

Linux tes102.gz.cn 2.6.18-194.el5xen #1 SMP Tue Mar 16 22:01:26 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

 

Apache 的部署:

(1)     從官檔上下載httpd-2.2.19.tar

    

安裝apache

[root@tes102 nagios]# tar -xvf httpd-2.2.19.tar.gz

在安裝apache 之前 先安裝以下包:

A.    Apache portable Run-time librariesApache可移植執行庫可以加速IO的訪問和使用Openssl

[root@tes102 nagios]# tar -xvf apr-1.3.8.tar.gz

[root@tes102 apr-1.3.8]# ./configure --enable-debug --enable-threads  --disable-ipv6 --with-devrandom=/dev/random

Make & makeinstall

B.    實現Unicode和其他的傳統編碼之間轉換的需求

[root@tes102 nagios]# tar -xvf libiconv-1.13.tar.gz

[root@tes102 libiconv-1.13]# ./configure  --enable-static=yes

Make & make install

C.    Apr 字型轉換函式:

[root@tes102 nagios]# tar -xvf apr-iconv-1.2.1.tar.gz

[root@tes102 apr-iconv-1.2.1]# ./configure --with-apr=/usr/local/apr/bin/apr-1-config

Make & make install

D.    Apr 輔助工具:

[root@tes102 nagios]# tar -xvf  apr-util-1.3.9.tar.gz

[root@tes102 apr-util-1.3.9]# ./configure --with-apr=/usr/local/apr/bin/apr-1-config  --with-apr-iconv --with-mysql  --with-iconv

Make &  make install

E.    Perl庫,用於perl相容的正規表示式

[root@tes102 nagios]# tar -xvf pcre-7.9.tar.gz

[root@tes102 pcre-7.9]# ./configure --enable-rebuild-chartables --enable-utf8 --enable-newline-is-any --enable-pcregrep-libz --enable-pcregrep-libbz2

Make &  make install

(2)   安裝apache

[root@tes102 httpd-2.2.19]# ./configure --enable-modules=all --enable-mods-shared=all --enable-file-cache --enable-cache --enable-disk-cache --enable-mem-cache --enable-echo  --enable-example --enable-case-filter --enable-ext-filter --enable-charset-lite --enable-logio --enable-mime-magic --enable-expires --enable-headers --enable-usertrack --enable-unique-id --enable-version --enable-proxy --enable-proxy-connect --enable-proxy-http --enable-proxy-ftp --enable-proxy-ajp --enable-proxy-balancer  --enable-ssl  --enable-static-htpasswd  --enable-static-ab --enable-http --enable-dav --enable-info --enable-cgi --enable-vhost-alias --enable-rewrite --enable-so --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config --with-mpm=prefork

Make &  make install

[root@tes102 httpd-2.2.19]#  /usr/local/apache2/bin/apachectl  -t

/usr/local/apache2/bin/httpd: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory

處理方法:

[root@tes102 httpd-2.2.19]# vim /etc/ld.so.conf

新增一行 /usr/local/lib

[root@tes102 httpd-2.2.19]# /sbin/ldconfig

 

[root@tes102 httpd-2.2.19]#  /usr/local/apache2/bin/apachectl  -t

Syntax OK

[root@tes102 httpd-2.2.19]# apachectl start

[root@tes102 httpd-2.2.19]# apachectl stop

---無報錯 證明 apache 搭建成功

(3)  配置 httpd.conf 檔案

 

Nagios 的配置

 

(1)     下載 伺服器端

 

(2)     下載外掛包

 

(3)     新增nagios 帳號

   [root@tes102 conf]# useradd   nagios  -s /sbin/nologin

(4)     安裝 nagios 服務端

 

[root@tes102 nagios]# tar -xvf  nagios-3.2.1.tar.gz

[root@tes102 nagios-3.2.1]#./configure –prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios

[root@tes102 nagios-3.2.1]# make all

  make install

     - This installs the main program, CGIs, and HTML files

 

  make install-init

     - This installs the init script. in /etc/rc.d/init.d

 

  make install-commandmode

     - This installs and configures permissions on the

       directory for holding the external command file

 

  make install-config

     - This installs *SAMPLE* config files in /usr/local/nagios/etc

       You'll have to modify these sample files before you can

       use Nagios.  Read the HTML documentation for more info

       on doing this.  Pay particular attention to the docs on

       object configuration files, as they determine what/how

       things get monitored!

 

  make install-webconf

     - This installs the Apache config file for the Nagios

       web interface  ---此步不用執行,可以手動配置httpd.cnf

(5)     安裝nagios 外掛

[root@tes102 nagios]# tar -xvf  nagios-plugins-1.4.15.tar.gz

[root@tes102 nagios-plugins-1.4.15]# ./configure -prefix=/usr/local/nagios

Make & Make install

(6)     配置nagios

A.      為了方便維護, 註釋掉localhost.cfg , 新增 hosts.cfg  hostgroups.cfg

Contactgroups.cfg

[root@tes102 etc]# vim   nagios.cfg

 

# Definitions for monitoring the local (Linux) host

## modified by  gabriel  start with  2011-08-24

## In  order to  add host group   contact group

#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

 

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

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

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

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

## modified  by gabriel  end  with  2011-08-24

B.      建立相關檔案  chown nagios.nagios    chmod 664

C.       

(7)     安裝並配置 nrpe

A 安裝

[root@tes102 nagios]# tar -xvf nrpe-2.8.1.tar.gz

[root@tes102 nrpe-2.8.1]# ./configure -prefix=/usr/local/nrpe

*** Configuration summary for nrpe 2.8.1 05-10-2007 ***:

 

 General Options:

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

 NRPE port:    5666

 NRPE user:    nagios

 NRPE group:   nagios

 Nagios user:  nagios

     Nagios group: nagios

Make  &  make install

 

Bnagios nrpe 相互複製check檔案保證通訊

[root@tes102nrpe-2.8.1]#cp /usr/local/nrpe/libexec/check_nrpe  /usr/local/nagios/libexec/

[root@tes102 libexec]# cp /usr/local/nagios/libexec/* /usr/local/nrpe/libexec/

C.配置nrpe

[root@tes102 libexec]# cp /soft/nagios/nrpe-2.8.1/sample-config/nrpe.cfg  /usr/local/nrpe/etc/

 

[root@tes102 libexec]# chown  nagios.nagios /usr/local/nrpe/etc -R

[root@tes102 libexec]# chmod 755   /usr/local/nrpe/etc -R

    [root@tes102 libexec]# cat ../etc/nrpe.cfg | grep -v ^$ | grep -v ^#

pid_file=/var/run/nrpe.pid

server_port=5666

server_address=192.168.18.102

nrpe_user=nagios

nrpe_group=nagios

allowed_hosts=127.0.0.1,192.168.18.102

 

dont_blame_nrpe=0

debug=0

command_timeout=60

connection_timeout=300

command[check_users]=/usr/local/nrpe/libexec/check_users -w 5 -c 10

command[check_load]=/usr/local/nrpe/libexec/check_load -w 15,10,5 -c 30,25,20

command[check_df]=/usr/local/nrpe/libexec/check_disk -x /dev -w 20 -c 10

command[check_zombie_procs]=/usr/local/nrpe/libexec/check_procs -w 5 -c 10 -s Z

command[check_total_procs]=/usr/local/nrpe/libexec/check_procs -w 150 -c 200

command[check_ips]=/usr/local/nrpe/libexec/ip_conn.sh 8000 10000

 

[root@tes102 libexec]# e

 

C.檢查程式以及 外掛情況

檢視程式埠號

[root@tes102 libexec]# netstat -an

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address               Foreign Address             State

tcp        0      0 192.168.18.102:5666         0.0.0.0:*                   LISTEN

檢視程式

[root@tes102 libexec]# ps -ef |  grep -v grep | grep  nrpe

nagios   20428     1  0 16:23 ?        00:00:00 nrpe -c /usr/local/nrpe/etc/nrpe.cfg –d

 

 

檢查外掛使用情況

 

[root@tes102 libexec]# ./check_nrpe  -H 192.168.18.102 -c check_df

DISK OK - free space: / 103556 MB (84% inode=99%); /boot 167 MB (92% inode=99%); /dev/shm 1799 MB (100% inode=99%);| /=18531MB;128712;128722;0;128732 /boot=13MB;169;179;0;189 /dev/shm=0MB;1779;1789;0;1799

 

錯誤處理  需要安裝php

[Wed Aug 24 22:33:01 2011] [notice] Apache/2.2.19 (Unix) mod_ssl/2.2.19 OpenSSL/0.9.8e-fips-rhel5 DAV/2 configured -- resuming normal operations

[Thu Aug 25 09:43:02 2011] [error] [client 192.168.14.101] File does not exist: /usr/local/nagios/share/

[Thu Aug 25 09:49:04 2011] [error] [client 192.168.14.101] File does not exist: /usr/local/nagios/share/http://192.168.18.102/nagios/side.php

下載php 原始碼

安裝php

 

Make & make install

在安裝過程中

…………

/root/php-5.3.8/ext/xmlrpc/libxmlrpc/encodings.c:73: undefined reference to `libiconv_open'

/root/php-5.3.8/ext/xmlrpc/libxmlrpc/encodings.c:81: undefined reference to `libiconv'

/root/php-5.3.8/ext/xmlrpc/libxmlrpc/encodings.c:101: undefined reference to `libiconv_close'

collect2: ld returned 1 exit status

make: *** [sapi/cli/php] ?.. 1

 

處理方法:  ./configure   vim Makefile 

EXTRA_LIBS=…. 列中新增引數 –liconv

然後make  && make install

 

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8117479/viewspace-707949/,如需轉載,請註明出處,否則將追究法律責任。

相關文章