Nginx环境下配置Nagios笔记

系统监控中,网上评论Cacti+Nagioslge两个组合,黄金搭档。
Nginx+PHP+MySQL环境已配置好,cacti环境已配置好,见《Cacti安装配置文档》[  ],下面看下Nagios的安装。

1、创建nagios用户及组
创建用户组名为nagios用于从web接口执行外部命令。将nagios用户和nginx用户加入组中。
/usr/sbin/useradd nagios
passwd nagios
/usr/sbin/groupadd nagios
/usr/sbin/usermod -g nagios nagios
/usr/sbin/usermod -g nagios addcn

2、安装nagios及插件
wget
tar zxvf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --with-command-group=nagios --with-user=nagios --prefix=/usr/local/nagios
make all
make install
make install-init
make install-config
make install-commandmode

注:
(1)make install 安装主要的程序、CGI及HTML文件
(2)make install-commandmode 给外部命令访问nagios配置文件权限
(3)make install-config 把配置文件的例子复制到nagios的安装目录

修改管理员邮件地址
vi /usr/local/nagios/etc/objects/contacts.cfg
搜索email,然后修改为你的contact email。

3、安装nagios-plugins
wget
tar -zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

4、启动nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #检验配置
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg #启动
/usr/local/nagios/bin/nagiostats #运行状态

5、搭建Perl环境
nagios依赖PHP环境和perl环境。PHP环境的配置请参考网上资料,下面来搭建Perl环境。
(1)安装perl fcgi模块
wget
tar -zxvf FCGI-0.67.tar.gz
cd FCGI-0.67
perl Makefile.PL
make && make install
(2)安装FCGI-ProcManager
wget
tar -xzxf FCGI-ProcManager-0.18.tar.gz
cd FCGI-ProcManager-0.18
perl Makefile.PL
make && make install
(3)安装perl-IO-ALL
wget
tar zxf IO-All-0.39.tar.gz
cd IO-All-0.39
perl Makefile.PL
make && make install

注:perl模块可在shell下執行"perl -MCPAN -e 'install FCGI'"进行安装。

(4)监听请求
nagios中web界面为cgi程序,我们使用unix socket来监听perl CGI请求并解析。
cd /usr/local/nginx/sbin/
wget
vi /usr/local/nginx/sbin/nginx-fcgi.pl
chmod +x /usr/local/nginx/sbin/nginx-fcgi.pl
启动nginx-fcgi.pl
/usr/local/nginx/sbin/nginx-fcgi.pl -l /usr/local/nginx/logs/nginx-fcgi.log -pid /usr/local/nginx/logs/nginx-fcgi.pid -S /usr/local/nginx/logs/nginx-fcgi.sock
添加nginx帐户权限
chown addcn:addcn /usr/local/nginx/logs/nginx-fcgi.sock
chmod 777 /usr/local/nginx/logs/nginx-fcgi.sock

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/pfpyf.html