热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

centos下nginx配置perl运行bugzilla

配置bugzilla前需要先安装epel库和rpmforge库。nginx本身不带perl解析的功能,需要用到fcgi-perl,安装:yuminstallfcgi-perl写一个脚本fastcgi服务的脚本:vim/usr/local/fcgi-perl/fastcgi-wrapper.pl#!/usr/bin/pe
配置bugzilla前需要先安装epel库和rpmforge库。
nginx本身不带perl解析的功能,需要用到fcgi-perl,安装:
yum install fcgi-perl
写一个脚本fastcgi服务的脚本:
vim /usr/local/fcgi-perl/fastcgi-wrapper.pl
#!/usr/bin/perl
use FCGI;
use Socket;
use POSIX qw(setsid);
require 'syscall.ph';
&daemonize;
#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 daemonize() {
    chdir '/'                 or die "Can't chdir to /: $!";
    defined(my $pid = fork)   or die "Can't fork: $!";
    exit if $pid;
setsid                    or die "Can't start a new session: $!";
    umask 0;
}
sub main {
        $socket = FCGI::OpenSocket( "127.0.0.1:8999", 10 ); #use IP sockets
        $request = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%req_params, $socket );
        if ($request) { request_loop()};
FCGI::CloseSocket( $socket );
}
sub request_loop {
        while( $request->Accept() >= 0 ) {
           #processing any STDIN input from WebServer (for CGI-POST actions)
$stdin_passthrough ='';
$req_len = 0 + $req_params{'CONTENT_LENGTH'};
           if (($req_params{'REQUEST_METHOD'} eq 'POST') && ($req_len != 0) ){
my $bytes_read = 0;
while ($bytes_read <$req_len) {
my $data = '';
my $bytes = read(STDIN, $data, ($req_len - $bytes_read));
last if ($bytes == 0 || !defined($bytes));
$stdin_passthrough .= $data;
$bytes_read += $bytes;
}
}
#running the cgi app
if ( (-x $req_params{SCRIPT_FILENAME}) &&  #can I execute this?
(-s $req_params{SCRIPT_FILENAME}) &&  #Is this file empty?
(-r $req_params{SCRIPT_FILENAME})     #can I read this file?
){
        pipe(CHILD_RD, PARENT_WR);
        my $pid = open(KID_TO_READ, "-|");
        unless(defined($pid)) {
print("Content-type: text/plain\r\n\r\n");
print "Error: CGI app returned no output - ";
print "Executing $req_params{SCRIPT_FILENAME} failed !\n";
next;
        }
        if ($pid > 0) {
close(CHILD_RD);
print PARENT_WR $stdin_passthrough;
close(PARENT_WR);
while(my $s = ) { print $s; }
close KID_TO_READ;
waitpid($pid, 0);
        } else {
foreach $key ( keys %req_params){
$ENV{$key} = $req_params{$key};
}
# cd to the script's local directory
if ($req_params{SCRIPT_FILENAME} =~ /^(.*)\/[^\/]+$/) {
chdir $1;
}
close(PARENT_WR);
close(STDIN);
#fcntl(CHILD_RD, F_DUPFD, 0);
syscall(&SYS_dup2, fileno(CHILD_RD), 0);
#open(STDIN, "<&CHILD_RD");
exec($req_params{SCRIPT_FILENAME});
die("exec failed");
        }
}
else {
print("Content-type: text/plain\r\n\r\n");
print "Error: No such CGI app - $req_params{SCRIPT_FILENAME} may not ";
print "exist or is not executable by this process.\n";
}
        }
}
做成服务运行:
vim /etc/init.d/perl-fastcgi
#!/bin/sh
#
# nginx ? this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /opt/nginx/conf/nginx.conf
# pidfile: /opt/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
perlfastcgi="/usr/local/fcgi-perl/fastcgi-wrapper.pl"
prog=$(basename perl)
lockfile=/var/lock/subsys/perl-fastcgi
start() {
    [ -x $perlfastcgi ] || exit 5
    echo -n $"Starting $prog: "
    daemon $perlfastcgi
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
restart() {
    stop
    start
}
force_reload() {
    restart
}
rh_status() {
    status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|force-reload}"
        exit 2
    esac
改权限,并启动:
chmod 755 /etc/init.d/perl-fastcgi
chmod 755 /usr/local/fcgi-perl/fastcgi-wrapper.pl
chkconfig --add perl-fastcgi
chkconfig --level 345 perl-fastcgi on
service perl-fastcgi start
启动后可以用ps 或netstat看下进程和端口有没有起来。
nginx的安装就不讲了,在nginx内配置一个bugzilla使用的主机:
   server {
listen       80;
        server_name  bugzilla.domainname.com;
        root   /usr/local/nginx/html/bugzilla;
        index  index.cgi index.pl index.html index.htm;
        access_log /usr/local/nginx/html/bugzilla/logs/access.log  combined;
        error_log  /usr/local/nginx/html/bugzilla/logs/error.log notice;
#       location / {
#               root   /usr/local/nginx/html/bugzilla;
#               index  index.html index.htm;
#       }
        location ~ .*\.(pl|cgi)$ {
        root /usr/local/nginx/html/bugzilla;
gzip off;
include fastcgi_params;
fastcgi_pass  127.0.0.1:8999;
fastcgi_index index.cgi;
fastcgi_param  SCRIPT_FILENAME  /$document_root/$fastcgi_script_name;
        }
   }
应用配置:
service nginx reload
先写一个测试脚本跑跑看是否正常:
vim /usr/local/nginx/html/bugzilla/test.pl
#!/usr/bin/perl print "Content-type:text/html\n\n";
print <

Perl Environment Variables
EndOfHTML
foreach $key (sort(keys %ENV)) {
    print "$key = $ENV{$key}
\n";
}
print "";
保存后还要改一下权限:
chmod 755 /usr/local/nginx/html/bugzilla/test.pl
再用浏览器访问一下这个页面是否正常运行了。
没问题后fcgi-perl环境就算配置好了,下面安装bugzilla:
cd /usr/local/nginx/html/bugzilla
wget http://ftp.mozilla.org/pub/mozilla.org/webtools/bugzilla-4.4.tar.gz
tar -xvzf bugzilla-4.4.tar.gz
mv bugzilla-4.4/* /usr/local/nginx/html/bugzilla/
cd web
安装前要检查bugzilla所需的模块是否都安装了:
./checksetup.pl --check-modules
如果没有安装,用下面的方式安装:   
yum  --disablerepo=epel install perl-DateTime perl-DateTime-TimeZone  perl-DBI perl-Template-Toolkit perl-Template-Toolkit perl-Email-Send perl-Email-MIME perl-URI perl-List-MoreUtils perl-DBD-Pg  perl-DBD-Oracle  perl-GD  perl-Chart perl-Template-GD perl-GDTextUtil perl-GDGraph perl-MIME-tools perl-libwww-perl perl-XML-Twig perl-PatchReader perl-LDAP perl-Authen-SASL perl-RadiusPerl perl-SOAP-Lite JSON-RPC perl-JSON-XS  perl-Test-Taint perl-HTML-Parser perl-HTML-Scrubber perl-Email-MIME-Attachment-Stripper  perl-Email-Reply perl-TheSchwartz perl-Daemon-Generic Math-Random-Secure
再次用./checksetup.pl --check-modules检查,发现还有几个包没安装,提示用下面命令安装,但我执行后一直安装不上:
/usr/bin/perl install-module.pl JSON::RPC
/usr/bin/perl install-module.pl Apache2::SizeLimit
/usr/bin/perl install-module.pl Math::Random::Secure
/usr/bin/perl install-module.pl Email::MIME
那就不用bugzilla安装模块了,自己安装:
perl -MCPAN -e "install Email::MIME"
perl -MCPAN -e shell
cpan>force install JSON::RPC
cpan>force install Math::Random::Secure
最后再检查下,应该没问题了。
编辑配置文件,把目录,数据库ip,库名,用户和密码之类的填好。
vim localconfig
然后就可以正式安装了:
./checksetup.pl
会提示输入一个邮箱和密码,这个是默认的管理员用户和密码。
安装好后就浏览器打开看看是否正常就行了。
另外数据库还需要优化一下,加入下面两行:
[mysqld]
max_allowed_packet=4M
ft_min_word_len=2
更改后要重启数据库。
安装繁体中文包:
http://code.google.com/p/bugzilla-tw/
wget http://code.google.com/p/bugzilla-tw/downloads/detail?name=bugzilla.zh-TW.4.4r.20130609.tar.gz
tar -xvzf bugzilla.zh-TW.4.4r.20130609.tar.gz
cp -rf bugzilla-tw/template/zh-TW  /usr/local/nginx/html/bugzilla/template
再打开浏览器时就会显示繁体中文了。
最后加上几个cron,bugzilla用的:
crontab -e 
5  0 * * * cd /home/httpd/bugzilla.domainname.com/web && ./collectstats.pl
55 0 * * * cd /home/httpd/bugzilla.domainname.com/web && ./whineatnews.pl
*/15 * * * * cd /home/httpd/bugzilla.domainname.com/web && ./whine.pl 

推荐阅读
  • ZABBIX 3.0 配置监控NGINX性能【OK】
    1.在agent端查看配置:nginx-V查看编辑时是否加入状态监控模块:--with-http_stub_status_module--with-http_gzip_stat ... [详细]
  • 本文介绍了在mac环境下使用nginx配置nodejs代理服务器的步骤,包括安装nginx、创建目录和文件、配置代理的域名和日志记录等。 ... [详细]
  • 本文主要介绍关于linux文件描述符设置,centos7设置文件句柄数,centos7查看进程数的知识点,对【Linux之进程数和句柄数】和【linux句柄数含义】有兴趣的朋友可以看下由【东城绝神】投 ... [详细]
  • MySQL5.6.40在CentOS764下安装过程 ... [详细]
  • 环境配置tips
    一、MySQL在Linux下数据库名、表名、列名、别名大小写规则是这样的:  1、数据库名与表名是严格区分大小写的;  2、表的别名是严格区分大小写的& ... [详细]
  • 图解redis的持久化存储机制RDB和AOF的原理和优缺点
    本文通过图解的方式介绍了redis的持久化存储机制RDB和AOF的原理和优缺点。RDB是将redis内存中的数据保存为快照文件,恢复速度较快但不支持拉链式快照。AOF是将操作日志保存到磁盘,实时存储数据但恢复速度较慢。文章详细分析了两种机制的优缺点,帮助读者更好地理解redis的持久化存储策略。 ... [详细]
  • 本文介绍了在Mac上配置环境变量,实现Python3的命令行调用的步骤。首先通过官网下载或使用brew安装Python3,并找到安装路径。然后将该路径添加到环境变量中,可以通过编辑.bash_profile文件或执行source命令来实现。配置完成后,即可在命令行中直接调用Python3。 ... [详细]
  • 图片复制到服务器 方向变了_双服务器热备更新配置文件步骤问题及解决方法
    本文介绍了在将图片复制到服务器并进行方向变换的过程中,双服务器热备更新配置文件所出现的问题及解决方法。通过停止所有服务、更新配置、重启服务等操作,可以避免数据中断和操作不规范导致的问题。同时还提到了注意事项,如Avimet版本的差异以及配置文件和批处理文件的存放路径等。通过严格执行切换步骤,可以成功进行更新操作。 ... [详细]
  • 本文详细介绍了Vim编辑器中的三种模式(命令模式、末行模式和编辑模式)以及它们之间的操作区别和切换方法。Vim编辑器凭借其多种命令快捷键和高效率的操作方式,得到了广大厂商和用户的认可。对于想要高效操作文本的用户来说,了解这些模式的使用方法是必不可少的。 ... [详细]
  • mac php错误日志配置方法及错误级别修改
    本文介绍了在mac环境下配置php错误日志的方法,包括修改php.ini文件和httpd.conf文件的操作步骤。同时还介绍了如何修改错误级别,以及相应的错误级别参考链接。 ... [详细]
  • Silverlight杂记控件相关
    Button控件1用于可视的表现的属性2索引和状态3模板4button的内容之所以可以放任意的控件是因为调用使用一个ContentPresenter控件来呈现。5button控件的 ... [详细]
  • Ihavethisfollowinginputfile:我有以下输入文件:test.csvdone_cfg,,,,port<0>,clk_in,subcktA,ins ... [详细]
  • 前言对于从事技术的人员来说ajax是这好东西,都会使用,而且乐于使用。但对于新手,开发一个ajax实例,还有是难度的,必竟对于他们这是新东西。leo开发一个简单的ajax实例,用的是 ... [详细]
  • PHP编程能开发哪些应用?
    导读:很多朋友问到关于PHP编程能开发哪些应用的相关问题,本文编程笔记就来为大家做个详细解答,供大家参考,希望对大家有所帮助!一起来看看吧!本文目录一览: ... [详细]
  • 装kaldi时在make那一步总报libtoolisnotinstalled.然后我无论怎么安装libtool都不行,求大神们指点一下啊!gaoxun@ubuntu:~kaldi-t ... [详细]
author-avatar
允思顾我在
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有