在構建
Nagios監控平台是,Nagios依賴PHP環境和perl環境。由於Nginx不支持Perl的CGI,如何使nginx支持perl cgi?
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
cd ..
2. 安裝FCGI-ProcManager模塊
wget http://search.cpan.org/CPAN/authors/id/G/GB/GBJK/FCGI-ProcManager-0.19.tar.gz
tar xvzf FCGI-ProcManager-0.19.tar.gz
cd FCGI-ProcManager-0.19
perl Makefile.PL
make && make install
cd ..
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
cd ..
wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.41.tar.gz
tar zxvf IO-All-0.41.tar.gz
cd IO-All-0.41
perl Makefile.PL
make
make install
cd ..
4. 下載perl腳本
wget http://www.linuxeye.com/uploads/allimg/120806/perl-fcgi.pl
cp perl-fcgi.pl /usr/local/nginx/
chmod 755 /usr/local/nginx/perl-fcgi.pl
5. cgi啟動/停止腳本 (www為nginx的運行用戶)
cat /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 www.www $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 www.www $dir/now_start_perl_fcgi.sh
chmod u+x $dir/now_start_perl_fcgi.sh
sudo -u www $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 這個文件,如果沒有生成,那就要檢查下上面的步聚了.
5. 配置nginx
server {
listen 80;
server_name _;
location / {
root /usr/local/nginx/html;
index index.html index.htm index.cgi;
}
location ~ .*\.(pl|cgi)?$
{
gzip off;
fastcgi_pass unix:/usr/local/nginx/logs/perl-fcgi.sock;
fastcgi_index index.cgi;
fastcgi_pass unix:/usr/local/nginx/logs/perl-fcgi.sock;
fastcgi_index index.cgi;
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;
fastcgi_read_timeout 60;
}
}
6.Perl探針測試
cd /usr/local/nginx/html
wget http://www.linuxeye.com/uploads/allimg/120806/perlinfo.cgi