nagios的web页面从apache到nginx的迁移步骤
发表时间:2018-10-16 17:31 | 分类:Nagios | 浏览:1,236 次
Nginx和Nagios的安装过程略。由于Nginx不支持Perl的CGI,所以先需要来搭建Perl环境。让Nginx支持Perl的CGI方法有好几种,基本原理都是通过Perl的FCGI模块实现。
- yum -y install perl-devel
安装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 ../
安装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 ../
安装IO perl-IO-String IO::ALL模块
- #安装IO
- 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 ../
- #安装 perl-IO-String
- yum install perl-IO-String
- #安装IO::ALL模块
- wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.87.tar.gz
- tar zxvf IO-All-0.87.tar.gz
- cd IO-All-0.87
- perl Makefile.PL
- make && make install
- cd ../
下载Perl脚本
- wget http://download.chekiang.info/blog/perl-fcgi.zip
- unzip perl-fcgi.zip
- cp perl-fcgi.pl /usr/local/nginx/
- #修改脚本权限
- chmod 755 /usr/local/nginx/perl-fcgi.pl
建立一个CGI启动/停止脚本
这个SHELL脚本只是为了方便管理上面的Perl脚本。脚本中的www为nginx的运行用户,请据自己的实际情况调整。
注意事项:不能用root用户执行(会提示). 要用与Nginx相同身份的用户执行。否则可能会在Nginx Log中提示 Permision Denied。
- vim /usr/local/nginx/start_perl_cgi.sh
- #!/bin/bash
- 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
- #修改脚本权限
- chmod 755 /usr/local/nginx/start_perl_cgi.sh
- #启动脚本
- /usr/local/nginx/start_perl_cgi.sh start
- 正常情况下在/usr/local/webserver/nginx/logs下生成perl-fcgi.sock这个文件,如果没有生成,请检查下上面的步聚
- #启动
- /usr/local/nginx/start_perl_cgi.sh start
配置NGINX
Nagios Web界面登陆帐号及密码
- htpasswd -c /usr/local/nagios/etc/nagiospasswd mike
如果你没有htpasswd(这个工具由Apache安装包所提供),可在线生成,地址:http://www.4webhelp.net/us/password.php。
修改Nagios配置文件,给新增的用户增加访问权限
- vi /usr/local/nagios/etc/cgi.cfg
- #以下几项中分别加入新增的用户,多用户用逗号分隔。
- authorized_for_system_information=nagiosadmin,mike
- authorized_for_configuration_information=nagiosadmin,mike
- authorized_for_system_commands=nagiosadmin,mike
- authorized_for_all_services=nagiosadmin,mike
- authorized_for_all_hosts=nagiosadmin,mike
- authorized_for_all_service_commands=nagiosadmin,mike
- authorized_for_all_host_commands=nagiosadmin,mike
nginx配置如下
- #nagios
- location ~ .*\.(cgi|pl)?$ {
- gzip off;
- root /usr/local/nagios/sbin;
- rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
- fastcgi_pass unix:/usr/local/nginx/logs/perl-fcgi.sock;
- fastcgi_param SCRIPT_FILENAME /usr/local/nagios/sbin$fastcgi_script_name;
- fastcgi_index index.cgi;
- fastcgi_read_timeout 60;
- fastcgi_param REMOTE_USER $remote_user;
- include fastcgi.conf;
- auth_basic "Nagios Access";
- auth_basic_user_file /usr/local/nagios/etc/htpasswd.users;
- }
- location ~ ^(/nagios.*\.php)(.*)$ {
- root /home/wwwroot/monitor.nbhao.org;
- # comment try_files $uri =404; to enable pathinfo
- try_files $uri =404;
- fastcgi_pass unix:/tmp/php56-cgi.sock;
- fastcgi_index index.php;
- include fastcgi.conf;
- #include pathinfo.conf;
- }
pnp4nagios配置如下
- #PNP4Nagios
- location ~ ^(/pnp4nagios.*\.php)(.*)$ {
- root /home/wwwroot/monitor.nbhao.org;
- if ( $uri !~ /pnp4nagios/index.php(.*)) {
- rewrite ^/pnp4nagios/(.*)$ /$1;
- break;
- }
- fastcgi_pass unix:/tmp/php53-cgi.sock;
- fastcgi_index index.php;
- include fastcgi.conf;
- # this splits out the trailing path
- # eg index.php?host -> $fastcgi_path_info == 'host'
- fastcgi_split_path_info ^(.+\.php)(.*)$;
- fastcgi_param PATH_INFO $fastcgi_path_info;
- fastcgi_param SCRIPT_FILENAME /usr/local/pnp4nagios/share/index.php;
- auth_basic "Nagios Access";
- auth_basic_user_file /usr/local/nagios/etc/htpasswd.users;
- }
特别注意pnp4nagios安装的时候需要确保php.ini中的disable_functions没有proc_open,否则会报Undefined variable的错误。找了好久才发现是这个问题。。。