www.itaoo.com 项目即将上线,前段时间一直在折腾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
http://httpd.apache.org/download.cgi#apache22
安装apache:
[root@tes102 nagios]# tar -xvf httpd-2.2.19.tar.gz
在安装apache 之前 先安装以下包:
A. Apache portable Run-time libraries,Apache可移植运行库,可以加速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) 下载 服务器端 包
http://www.nagios.org/download/core
(2) 下载插件包
http://www.nagios.org/download/plugins
http://nchc.dl.sourceforge.net/sourceforge/nagios/nrpe-2.8.1.tar.gz
(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
B.nagios 与 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/<, referer: http://192.168.18.102/nagios/side.php
[Thu Aug 25 09:49:04 2011] [error] [client 192.168.14.101] File does not exist: /usr/local/nagios/share/<, referer: http://192.168.18.102/nagios/side.php
下载php 源码
http://cn.php.net/get/php-5.3.8.tar.gz/from/a/mirror
安装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/,如需转载,请注明出处,否则将追究法律责任。