-
服务器系统版本:Centos 5.3 x64
-
-
nginx版本:nginx-0.8.54
-
-
nagios版本:nagios-3.2.3
-
#所有安装所需的源码包:本站点集成下载:(以下包地址已经失效,请去官方网站下载相应的包)
-
http://blog.mgcrazy.com/download/nginx-0.8.54.tar.gz
-
http://blog.mgcrazy.com/download/pcre-8.01.tar.gz
-
http://blog.mgcrazy.com/download/nagios/FCGI-0.67.tar.gz
-
http://blog.mgcrazy.com/download/nagios/FCGI-ProcManager-0.18.tar.gz
-
http://blog.mgcrazy.com/download/nagios/nagios-3.2.3.tar.gz
-
http://blog.mgcrazy.com/download/nagios/nagios-plugins-1.4.13.tar.gz
-
http://blog.mgcrazy.com/download/nagios/nrpe-2.8.1.tar.gz
-
#Nginx 安装请参考:http://blog.mgcrazy.com/?p=792 【nginx安装】
-
nginx安装完毕后。
-
#创建nagios用户和组,并把www加入nagios管理组:
-
useradd nagios &&groupadd nagcmd && usermod -g nagcmd nagios && usermod -g nagcmd www
-
cd /usr/scr && tar xzf nagios-3.2.3.tar.gz && cd nagios-3.2.3
-
./configure --with-command-group=nagcmd --prefix=/usr/local/nagios && make all
-
make install &&make install-init && make install-config && make install-commandmode
-
#nagios安装完毕!
-
cd /usr/src &&tar zxvf nagios-plugins-1.4.13.tar.gz &&cd nagios-plugins-1.4.13
-
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
-
make && make install
-
#插件安装完毕!
-
#ls /usr/local/nagios/libexec 会显示安装的插件文件,即所有的插件都安装在libexec这个目录下。
-
#用于Nagios的WEB接口登录。
-
#记下你所设置的登录口令,一会儿你会用到它
-
这里要借助于apche的htpasswd,在有apache机器上执行下列命令
-
/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin
-
输入两次一样的密码即可。
-
chkconfig –add nagios
-
#添加到service 中,chkconfig nagios –level 35 on 设置成开机启动。
-
#把selinux、iptables关闭,或者更改iptables策略需要访问nagios
-
#然后启动nagios
-
/etc/init.d/nagios start
-
#安装php可参考 http://chinaapp.sinaapp.com/thread-627-1-1.html
-
#安装FCGI
-
cd /usr/src && tar -zxvf FCGI-0.67.tar.gz &&cd FCGI-0.67 && perl Makefile.PL
-
make && make install
-
#安装FCGI-ProcManager:
-
cd ../ && tar -xzxf FCGI-ProcManager-0.18.tar.gz &&cd FCGI-ProcManager-0.18
-
perl Makefile.PL &&make && make install
-
#安装完毕即可。
-
mkdir -p /usr/local/nagios/share/nagios
-
ln -s /usr/local/nagios/share/images /usr/local/nagios/share/nagios/images
-
ln -s /usr/local/nagios/share/stylesheets /usr/local/nagios/share/nagios/stylesheets
-
#避免无法显示图片。
-
#!/usr/bin/perl
-
use FCGI;
-
#perl -MCPAN -e ‘install FCGI’
-
use Socket;
-
#this keeps the program alive or something after exec’ing perl scripts
-
END()
-
{
-
}
-
BEGIN()
-
{
-
}
-
*CORE::GLOBAL::exit
-
=
-
sub
-
{
-
die
-
“fakeexit\nrc=”.shift().”\n”;
-
};
-
eval
-
q{exit};
-
if
-
($@)
-
{
-
exit
-
unless
-
$@
-
=~
-
/^fakeexit/;
-
}
-
;
-
&main;
-
sub main {
-
#$socket = FCGI::OpenSocket( “:3461″, 10 ); #use IP sockets
-
$socket
-
= FCGI::OpenSocket(
-
“/var/run/nagios.sock”,
-
10
-
);
-
#use UNIX sockets – user running this script must have w access to the ‘nginx’ folder!!
-
$request
-
= FCGI::Request(
-
\*STDIN,
-
\*STDOUT,
-
\*STDERR,
-
\%ENV,
-
$socket
-
);
-
if
-
($request)
-
{request_loop()};
-
FCGI::CloseSocket(
-
$socket
-
);
-
}
-
sub request_loop {
-
while(
-
$request->Accept()
-
>=
-
0
-
)
-
{
-
#processing any STDIN input from WebServer (for CGI-GET actions)
-
$env
-
=
-
$request->GetEnvironment();
-
$stdin_passthrough
-
=”;
-
$req_len
-
=
-
0
-
+
-
$ENV{CONTENT_LENGTH};
-
if
-
($ENV{REQUEST_METHOD}
-
eq
-
‘GET’){
-
$stdin_passthrough
-
.=
-
$ENV{‘QUERY_STRING’};
-
}
-
#running the cgi app
-
if
-
(
-
(-x $ENV{SCRIPT_FILENAME})
-
&&
-
#can I execute this?
-
(-s
-
$ENV{SCRIPT_FILENAME})
-
&&
-
#Is this file empty?
-
(-r $ENV{SCRIPT_FILENAME})
-
#can I read this file?
-
){
-
#http://perldoc.perl.org/perlipc.html#Safe-Pipe-Opens
-
open
-
$cgi_app,
-
‘-|’,
-
$ENV{SCRIPT_FILENAME},
-
$stdin_passthrough
-
or
-
print(“Content-type: text/plain\r\n\r\n”);
-
print
-
“Error: CGI app returned no output – Executing $ENV{SCRIPT_FILENAME} failed !\n”;
-
if
-
($cgi_app)
-
{print
-
<$cgi_app>;
-
close
-
$cgi_app;}
-
}
-
else
-
{
-
print(“Content-type: text/plain\r\n\r\n”);
-
print
-
“Error: No such CGI app – $req_len – $ENV{CONTENT_LENGTH} – $ENV{REQUEST_METHOD} – $ENV{SCRIPT_FILENAME} may not exist or is not executable by this process.\n”;
-
}
-
}
-
}
-
#设置权限chmod +x perl-cgi.pl 即可!
-
server
-
{
-
listen 80;
-
server_name 192.168.2.79;
-
root /usr/local/nagios/share;
-
index index.php;
-
auth_basic “You Name”;
-
-
auth_basic_user_file /usr/local/nagios/etc/htpasswd;
-
log_format nagios ‘$remote_addr – $remote_user [$time_local] “$request” ‘
-
‘$status $body_bytes_sent “$http_referer” ‘
-
‘”$http_user_agent” $http_x_forwarded_for’;
-
access_log /usr/local/nginx/nagios.log nagios;
-
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_index index.cgi;
-
fastcgi_pass unix:/var/run/nagios.sock;
-
-
fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name;
-
fastcgi_param QUERY_STRING $query_string;
-
-
fastcgi_param REMOTE_ADDR $remote_addr;
-
fastcgi_param REMOTE_PORT $remote_port;
-
fastcgi_param REQUEST_METHOD $request_method;
-
fastcgi_param REQUEST_URI $request_uri;
-
fastcgi_param REMOTE_USER $remote_user;
-
#默认没有红色这一句,如果没有,后面nagios页面会报错,具体错误后面给出。
-
#fastcgi_param SCRIPT_NAME $fastcgi_script_name;
-
fastcgi_param SERVER_ADDR $server_addr;
-
fastcgi_param SERVER_NAME $server_name;
-
fastcgi_param SERVER_PORT $server_port;
-
fastcgi_param SERVER_PROTOCOL $server_protocol;
-
fastcgi_param SERVER_SOFTWARE nginx;
-
fastcgi_param CONTENT_LENGTH $content_length;
-
fastcgi_param CONTENT_TYPE $content_type;
-
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
-
fastcgi_param HTTP_ACCEPT_ENCODING gzip,deflate;
-
fastcgi_param HTTP_ACCEPT_LANGUAGE zh-cn;
-
}
-
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
-
fastcgi_param SERVER_SOFTWARE nginx;
-
-
fastcgi_param QUERY_STRING $query_string;
-
fastcgi_param REQUEST_METHOD $request_method;
-
fastcgi_param CONTENT_TYPE $content_type;
-
fastcgi_param CONTENT_LENGTH $content_length;
-
-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
-
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
-
fastcgi_param REQUEST_URI $request_uri;
-
fastcgi_param DOCUMENT_URI $document_uri;
-
fastcgi_param DOCUMENT_ROOT $document_root;
-
fastcgi_param SERVER_PROTOCOL $server_protocol;
-
-
fastcgi_param REMOTE_ADDR $remote_addr;
-
fastcgi_param REMOTE_PORT $remote_port;
-
fastcgi_param SERVER_ADDR $server_addr;
-
fastcgi_param SERVER_PORT $server_port;
-
fastcgi_param SERVER_NAME $server_name;
-
-
# PHP only, required if PHP was built with –enable-force-cgi-redirect
-
fastcgi_param REDIRECT_STATUS 200;
-
启动nginx,确定有fastcGI 9000端口。 后台启动screen ./perl-cgi.pl >/dev/null
-
ctrl +a +d 退出screen
-
然后chmod 777 /var/run/nagios.sock ;并且重启service nagios restart
-
#It seems that you have chosen to not use the authentication functionality of the CGIs.
-
-
I don't want to be personally responsible for what may happen as a result of allowing
-
-
unauthorized users to issue commands to Nagios,so you'll have to disable this safeguard if you
-
-
are really stubborn and want to invite trouble.
-
-
#It appears as though you do not have permission to view information for any of the hosts you requested...
-
-
If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
-
and check the authorization options in your CGI configuration file
-
-
可参照修改:http://hi.baidu.com/shengit/blog/item/b21b770965c6e8de62d986c0.html
-
http://bbs.linuxtone.org/thread-4441-1-1.html
-
-
http://bbs.linuxtone.org/thread-7404-1-1.html
-
-
http://www.comeonsa.com/