RedHat EL5 部署Trac 编译Apache mod_python mod_ldap

需要部署一套Trac做为WIKI来使用,同时为了结合LDAP认证,决定采用以下组件:
1. Apache
2. Python
3. mod_python
4. mod_ldap
5. apr
6. apr-util
7. Trac 0.12

编译安装步骤如下

1. apr

tar xzvfapr-1.4.2.tar.gz

cd apr-1.4.2

./configure --prefix=/usr/local/apr && make && make install

2. apr-util

wget http://labs.renren.com/apache-mirror/apr/apr-util-1.3.10.tar.gz

tar xzvfapr-util-1.3.10.tar.gz

cd apr-util-1.3.10

./configure --with-apr=/usr/local/apr/bin/ --with-ldap && make && make install


3. Apache

wget http://labs.renren.com/apache-mirror//httpd/httpd-2.2.17.tar.gz

tar xzvfhttpd-2.2.17.tar.gz

cdhttpd-2.2.17

./configure --prefix=/usr/local/apache --enable-track-vars --enable-cgi --enable-modules=all --enable-mods-shared=all --enable-file-cache --enable-disk-cache --enable-cache --enable-mem-cache --enable-dumpio --enable-logio --enable-mime-magic --enable-headers --enable-usertrack --enable-version --enable-ssl --enable-http --enable-rewrite --enable-proxy --enable-proxy-connect --enable-proxy-http --enable-proxy-ftp --enable-proxy-ajp --enable-proxy-balancer --enable-so --enable-authnz-ldap --enable-ldap --with-par=/usr/local/apr --with-apr-util=/usr/local/apr-util/ && make && make install

上面有很多是不需要的,可酌情删减


4. python

tar xjvfPython-2.7.tar.bz2

cd Python-2.7

./configure --enable-shared && make && make install

--enable-shared一定要有,要不然后面编译mod_python会出问题。

下面三部替换系统默认Python为Python2.7,谨慎!可能引起某些软件不能运行,如yum

rm -f /usr/local/bin/python

rm -f /usr/bin/python

ln -s /usr/local/bin/python2.7 /usr/local/bin/python

针对yum不能运行:

vim /usr/bin/yum

替换第一行为: #!/usr/bin/python2.4

即制定以python2.4运行yum


5. mod_python

wget http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.1.tgz

tar xzvfmod_python-3.3.1.tgz

cd mod_python-3.3.1

./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/bin/python && make && make install

编译过程钟可能出现下面错误

错误1:

connobject.c: 在函数‘_conn_read’中:
connobject.c:142: 错误: 在非结构或联合中请求成员‘next’
apxs:Error: Command failed with rc=65536


解决方案:

修改src/connobject.c第142行
把!(b == APR_BRIGADE_SENTINEL(b) || 改为!(b == APR_BRIGADE_SENTINEL(bb) ||


错误2:

/usr/local/lib/python2.5/config/libpython2.5.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
apxs:Error: Command failed with rc=65536


解决方案:

首先,确认编译Python的时候有没有加上--enable-shared,如果没有,加上重新编译

此时行Python可能出现以错误


错误2.1

python: error while loading shared libraries: libpython2.7.so.1.0:

cannot open shared object file: No such file or


错误2.1解决方案:

新建下面文件

vim /etc/ld.so.conf.d/python2.7.conf

加入内容:

/usr/local/lib

保存退出后运行:

ldconfig


每次编译mod_python都是一次痛苦的经历,上面解决方案参考:

http://agiletesting.blogspot.com/2007/10/compiling-modpython-on-rhel-64-bit.html


6. Trac

安装:

如果装了easy_install,很简单

easy_install Trac=0.12.1

否则

wget http://ftp.edgewall.com/pub/trac/Trac-0.12.1.tar.gz

tar xzvfTrac-0.12.1.tar.gz

cdTrac-0.12.1

python setup.py install


配置运行:

创建项目目录

mkdir -p /opt/trac/myproject

创建项目

trac-admin /opt/trac/myproject

根据提示:

1. 填入项目名称

2. 填入数据库连接

如果用sqlite默认的就行了

如果是mysql


首先在mysql里面创建数据

create database myproject

赋权限

grant all privileges on myproject.* to 'myuser'@'localhost' identified by 'mypassword';

数据库连接填

mysql://mypassword:myuser@localhost/myproject


测试运行:

tracd --port 8000 /opt/trac/myproject

打开浏览器访问: http://[HOST_IP]:8000 即可, [HOST_IP]是服务器的IP


可选,给用Trac户加管理员权限

trac-admin /opt/trac/myproject permission add username TRAC_ADMIN


配置在Apache运行:

vim /usr/local/apace/conf/httpd

加上以下内容


LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule python_module modules/mod_python.so

<VirtualHost *:80>
    DocumentRoot /opt/trac/myprj

    <Location />
        SetHandler mod_python
        PythonInterpreter main_interpreter
        PythonHandler trac.web.modpython_frontend
        PythonOption TracEnv /opt/trac/myprj
        PythonOption TracUriRoot /
        AuthType Basic
        AuthName "Trac"
        AuthBasicProvider "ldap"
        authzldapauthoritative Off
        AuthLDAPBindDN "[email protected]"
        AuthLDAPBindPassword"passwd"
        AuthLDAPURL"ldap://ldap.example.com:389/DC=example,DC=com?sAMAccountName?sub?(objectClass=*)"
        Require valid-user
        Require group "cn=group1, ou=groups, dc=example, dc=com"
    </Location>
</VirtualHost>

红色部分根据具体情况配置

重启Apache

/usr/local/apace/bin/apachectl restart


大功告成

相关推荐