nginx平台架设nagios
nagios作用
1.
监控网络服务(SMTP、POP3、HTTP、NNTP、PING等);
2.
监控主机资源(处理器负荷、磁盘利用率等);
3.
简单地插件设计使得用户可以方便地扩展自己服务的检测方法;
4.
并行服务检查机制;
5.
具备定义网络分层结构的能力,用”parent”主机定义来表达网络主机间的关系,这种关系可被用来发现和明晰主机宕机或不可达状态;
6.
当服务或主机问题产生与解决时将告警发送给联系人(通过EMail、短信、用户定义方式);
7.
具备定义事件句柄功能,它可以在主机或服务的事件发生时获取更多问题定位;
8.
自动的日志回滚;
9.
可以支持并实现对主机的冗余监控;
10.
可选的WEB界面用于查看当前的网络状态、通知和故障历史、日志文件等;
Nagios所需要的运行条件是机器必须可以运行Linux(或是Unix变种)并且有C语言编译器。你必须正确地配置TCP/IP协议栈以使大多数的服务检测可以通过网络得以进行。
安装
建立nagios账号
/usr/sbin/useradd nagios && passwd nagios
创建一个用户组名为nagcmd用于从Web接口执行外部命令。将nagios用户和apache用户都加到这个组中。
- /usr/sbin/groupadd nagcmd
- /usr/sbin/usermod -G nagcmd nagios
- /usr/sbin/usermod -G nagcmd apache
安装nagios及插件
- tar zxvf nagios-3.2.1
- cd nagios-3.2.1
- ./configure --with-command-group=nagcmd --prefix=/usr/local/nagios
- make all
- make install
- make install-init
- make install-config
- make install-commandmode
正确安装完毕,/usr/local/nagios目录下将会有这几个文件夹
bin etc include libexec sbin share var
安装nagios‐plugins
- tar zxvf nagios-plugins-1.4.14
- cd nagios-plugins-1.4.14
- ./configure --with-nagios-user=nagios --with-nagios-group=nagios --perfix=/usr/local/nagios
- make && make install
在另一台机上编译安装apache,需要用到htpasswd这工具来生成登陆的用户名和密码
/usr/local/httpd/bin/htpasswd -c /usr/local/nagios/etc/viyin.net viyin
[root@game bin]# ./htpasswd -c /root/viyin.net viyin
New password:
Re-type new password:
Adding password for user viyin
验证配置文件
[root@vi bin]# pwd
/usr/local/nagios/bin
[root@vi bin]# ./nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 3.2.1
Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 03-09-2010
License: GPL
Website: http://www.nagios.org
Reading configuration data…
Read main config file okay…
Processing object config file ‘/usr/local/nagios/etc/objects/commands.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/contacts.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/timeperiods.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/templates.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/localhost.cfg’…
Read object config files okay…
Running pre-flight check on configuration data…
Checking services…
Checked 8 services.
Checking hosts…
Checked 1 hosts.
Checking host groups…
Checked 1 host groups.
Checking service groups…
Checked 0 service groups.
Checking contacts…
Checked 1 contacts.
Checking contact groups…
Checked 1 contact groups.
Checking service escalations…
Checked 0 service escalations.
Checking service dependencies…
Checked 0 service dependencies.
Checking host escalations…
Checked 0 host escalations.
Checking host dependencies…
Checked 0 host dependencies.
Checking commands…
Checked 24 commands.
Checking time periods…
Checked 5 time periods.
Checking for circular paths between hosts…
Checking for circular host and service dependencies…
Checking global event handlers…
Checking obsessive compulsive processor commands…
Checking misc settings…
Total Warnings: 0
Total Errors: 0
Things look okay – No serious problems were detected during the pre-flight check
[root@vi bin]#
启动nagios服务
service nagios start
将nagios服务加入开机启动
chkconfig –add nagios
chkconfig nagios on
安装nrpe
- tar zxvf nrpe-2.12
- cd nrpe-2.12
- ./configure
- make all
- make installplugin
- make install-daemon
- make install-daemon-config
同样,在被监控机上也要安装nrpe,nagios‐plugins
在监控与被监控机上启动NRPE:
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
nagios安装完成
nginx cgi的配置
下载nginx-fcgi脚本
wget http://www.nginx.eu/nginx-fcgi/nginx-fcgi.txt
注释掉nginx-fcgi.txt 中的
if ( $> == “0″ ) {
print “\n\tERROR\tRunning as a root!\n”;
print “\tSuggested not to do so !!!\n\n”;
exit 1;
}
否则会提示:ERROR Running as a root! Suggested not to do so !!!
mv nginx-fcgi.txt /usr/local/nginx/sbin/nginx-fcgi
chmod +x /usr/local/nginx/sbin/nginx-fcgi
安装perl cgi模块
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
安装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
继续安装
wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.39.tar.gz
wget http://search.cpan.org/CPAN/authors/id/J/JV/JV/Getopt-Long-2.38.tar.gz
创建fastcgi_pass 接口
su www 切换到nginx运行用户
/usr/local/nginx/sbin/nginx-fcgi -l /home/wwwroot/nginx-fcgi.log -pid /tmp/nginx-fcgi.pid -S /tmp/nginx-fcgi.sock
无报错
nginx配置文件
server
{
listen 80;
server_name www.6fine.com www.viyin.net;
index index.html index.htm index.php default.html default.htm de
fault.php;
root /usr/local/nagios/share;
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.cgi$ {
root /usr/local/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
fastcgi_pass unix:/tmp/nginx-fcgi.sock;
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_na
me;
include fcgi.conf;
auth_basic “Nagios Access”;
auth_basic_user_file /usr/local/nagios/etc/viyin.net;
}
location /nagios {
alias /usr/local/nagios/share;
}
location / {
auth_basic “Nagios Access”;
auth_basic_user_file /usr/local/nagios/etc/viyin.net;
}
}
完成
参考:http://bbs.linuxtone.org/viewthread.php?tid=4441&highlight=Nagios
没有应用过.唉~
正在配置apache下的nagios,不过应该是差不多的.
做个友链接吧,已经做好了 :)
楼主可以提供下nginx-fcgi.txt文件吗?
期待解答!