系统环境:CentOS release 5.8 x86_64
一:监控端安装
1,安装perl模块:
1)、先安装FCGI模块
- wget http://search.cpan.org/CPAN/authors/id/F/FL/FLORA/FCGI-0.73.tar.gz
- tar xvzf FCGI-0.73.tar.gz
- cd FCGI-0.73
- perl Makefile.PL
- make
- make install
2)、安装FCGI-ProcManager模块
- wget http://mirrors.ustc.edu.cn/CPAN/authors/id/B/BO/BOBTFISH/FCGI-ProcManager-0.24.tar.gz
- tar xvzf FCGI-ProcManager-0.19.tar.gz
- cd FCGI-ProcManager-0.19
- perl Makefile.PL
- make
- make install
3)、安装IO和IO::ALL模块
- wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/IO-1.25.tar.gz
- tar zxvf IO-1.25.tar.gz
- cd IO-1.25
- perl Makefile.PL
- make
- make install
- wget http://mirrors.xmu.edu.cn/CPAN/authors/id/I/IN/INGY/IO-All-0.44.tar.gz
- tar zxvf IO-All-0.41.tar.gz
- cd IO-All-0.41
- perl Makefile.PL
- make
- make install
4)、下载Perl脚本
这个脚本的目的就是产生一个PERL的FastCGI接口,让Nginx可以以CGI方式处理Perl。注:建议把这个脚本放在Nginx安装目录,修改脚本权限为777
- http://www.chlinux.net/perl-fcgi.zip
- unzip perl-fcgi.zip
- cp perl-fcgi.pl /usr/local/nginx/
- chmod 755 /usr/local/nginx/perl-fcgi.pl
5)、建立一个CGI启动/停止脚本
这个SHELL脚本只是为了方便管理上面的Perl脚本。脚本中的nobody为nginx的运行用户,请据自己的实际情况调整。
注意事项:不能用root用户执行(会提示). 要用与Nginx相同身份的用户执行。否则可能会在Nginx Log中提示 Permision Denied。
- vi /usr/local/nginx/start_perl_cgi.sh
- #!/bin/bash
- #set -x
- dir=/usr/local/ nginx/
- stop ()
- {
- #pkill -f $dir/perl-fcgi.pl
- kill $(cat $dir/logs/perl-fcgi.pid)
- rm $dir/logs/perl-fcgi.pid 2>/dev/null
- rm $dir/logs/perl-fcgi.sock 2>/dev/null
- echo "stop perl-fcgi done"
- }
- start ()
- {
- rm $dir/now_start_perl_fcgi.sh 2>/dev/null
- chown nobody.nobody $dir/logs
- echo "$dir/perl-fcgi.pl -l $dir/logs/perl-fcgi.log -pid $dir/logs/perl-fcgi.pid -S $dir/logs/perl-fcgi.sock" >>$dir/now_start_perl_fcgi.sh
- chown nobody.nobody $dir/now_start_perl_fcgi.sh
- chmod u+x $dir/now_start_perl_fcgi.sh
- sudo -u nobody $dir/now_start_perl_fcgi.sh
- echo "start perl-fcgi done"
- }
- case $1 in
- stop)
- stop
- ;;
- start)
- start
- ;;
- restart)
- stop
- start
- ;;
- esac
修改SHELL脚本权限
chmod 755 /usr/local/nginx/start_perl_cgi.sh
启动脚本
/usr/local/nginx/start_perl_cgi.sh start
正常情况下在/usr/local/nginx/logs下生成perl-fcgi.sock这个文件,如果没有生成,请检查下上面的步聚。
2、安装Nagios和相关插件
1)、安装前准备
安装的机器上必须有一个WEB服务,本文是在Nginx环境上安装的。下载nagios主程序和相关插件程序包
- wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
- wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
- wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
安装GD库(Nagios中的statusmap和trends模块必须)
yum -y install libgd2-noxpm libgd2-noxpm-devel
2)、Nagios监控端安装
1、创建Nagios用户及组
建立Nagios账号
/usr/sbin/useradd -m -s /sbin/nologin nagios
2、创建一个名为nagcmd的用户组,用于从web接口执行外部命令。将Nagios用户和Nginx用户加入组中。
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www
注:上面的www是Nginx用户所属的组,如有不同请自行调整。
3、编译安装Nagios
- tar zxvf nagios-3.2.3.tar.gz
- cd nagios-3.2.3
- ./configure --with-command-group=nagcmd
- make
- make all
- make install
- make install-init
- make install-config
- make install-commandmode
- #这里是在Nginx下运行Nagios,这一步就不用做了
- make install-webconf
- cd ..
- 注:
- make install 用于安装主要的程序、CGI及HTML文件
- make install-init 用于生成init启动脚本
- make install-config 用于安装示例配置文件
- make install-commandmode&n

