系统监控中,网上评论cacti+nagioslge两个组合,黄金搭档。
nginx+php+mysql环境已配置好,cacti环境已配置好,见《cacti安装配置文档》[http://addcn.blogbus.com/logs/88849862.html],下面看下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 http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
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 http://nchc.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz
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 http://www.cpan.org/modules/by-module/FCGI/FCGI-0.67.tar.gz
tar -zxvf FCGI-0.67.tar.gz
cd FCGI-0.67
perl Makefile.PL
make && make install
(2)安装FCGI-ProcManager
wget http://search.cpan.org/CPAN/authors/id/G/GB/GBJK/FCGI-ProcManager-0.18.tar.gz
tar -xzxf FCGI-ProcManager-0.18.tar.gz
cd FCGI-ProcManager-0.18
perl Makefile.PL
make && make install
(3)安装perl-IO-ALL
wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.39.tar.gz
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 http://addcn.googlecode.com/svn/trunk/conf/nagios/nginx-fcgi.pl
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
6、配置nginx
nagios下share文件链接到网站根目录,并改名为nagios。
ln -s /usr/local/nagios/share /home/htdocs/nagios
vi /usr/local/nginx/conf/nginx.conf
server
{
# nginx-fcgi.pl
location ~ .cgi$
{
root /usr/local/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*).cgi /$1.cgi break;
fastcgi_index index.cgi;
fastcgi_pass unix:/usr/local/nginx/logs/nginx-fcgi.sock;
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name;
fastcgi_param HTTP_ACCEPT_LANGUAGE zh-cn;
include /usr/local/nginx/conf/fastcgi.conf;
}
# nagios
#location /nagios {
# gzip off;
# alias /usr/local/nagios/share/;
#}
}
重启nginx
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
查看访问
http://192.168.1.36/nagios/