1.下载Trac安装包并解压

wget http://download.edgewall.org/trac/Trac-1.0.tar.gz
tar xvf Trac-1.0.tar.gz
cd Trac-1.0
2. 解开之后查看一下其中的INSTALL文件,其中的Requirements一节详细列出了安装Trac所必须的软件:
Python >= 2.5。(Centos 5.5不符合要求需要升级python)
Genshi >= 0.6。(在与Trac同一个网站上有下载)
可选的subversion >= 1.0(推荐>=1.1.x)和subversion的SWIG Python绑定
PySQLite,需要用于SQLite 3.x版本的PySQLite 2.x版
可运行python或CGI的Web服务器  

接下来就先解决这些前提条件
yum install -y wget curl curl-devel unzip ncurses-devel libxml2-devel openssl-devel libjpeg-devel libpng-devel freetype-de
vel autoconf automake libtool gcc gcc-c++ flex bison vim-enhanced python-devel pcre pcre-devel zlib zlib-devel libevent li
bevent-devel libtool-libs libtool-ltdl libtool-ltdl-devel bzip2 bzip2-devel gdb e2fsprogs-devel
 
安装sqlite 3
yum install -y sqlite sqlite-devel

安装subversion
yum install -y subversion subversion-devel

安装python2.7
wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
tar xvf Python-2.7.1.tgz
cd Python-2.7.1
./configure --enable-shared   //一定要加上--enable-shared参数,否则下面装mod_python会报错
make && make install
echo '/usr/local/lib' >> /etc/ld.so.conf && ldconfig
 
安装python setuptools-0.6
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar xvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py install
 
安装Genshi
wget http://ftp.edgewall.com/pub/genshi/Genshi-0.6.tar.gz
tar xvf Genshi-0.6.tar.gz
cd Genshi-0.6
python setup.py install
 
安装 PySQLite 2.x
wget  http://pysqlite.googlecode.com/files/pysqlite-2.6.3.tar.gz
tar xvf pysqlite-2.6.3.tar.gz 
cd pysqlite-2.6.3
python setup.py install
 
安装apache
wget http://archive.apache.org/dist/httpd/httpd-2.2.17.tar.gz
tar xvf httpd-2.2.17.tar.gz
cd cd httpd-2.2.17
./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-proxy --enable-ssl --with-ssl
make && make install
vi /usr/local/apache/conf/httpd.conf
修改apache以apache用户和apache用户组运行
安装mod_python-3.3.1(apache的python模块)
wget http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.1.tgz
tar xvf mod_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 --with-max-locks=32 --with-flex=/usr/bin/flex
make && make install
echo 'LoadModule python_module modules/mod_python.so'  >>/usr/local/apache/conf/httpd.conf
 
 
3.安装trac
tar xvf  Trac-1.0.tar.gz
cd Trac-1.0
python setup.py install
 
配置apache配置文件
我们将把 /data/trac 作为项目的主目录,所有新建的trac项目都放在该目录下, 访问URL为 /trac/<项目名>。
 
在/usr/local/apache/conf/httpd.conf下添加Trac的配置:
<Location /trac>
    SetHandler mod_python
    PythonInterpreter main_interpreter
    PythonHandler trac.web.modpython_frontend
    PythonOption TracEnvParentDir /data/trac
    PythonOption TracUriRoot /trac/
    PythonOption PYTHON_EGG_CACHE /tmp/egg-cache
</Location>
 
然后在/data下建立trac目录并设置权限
# cd /data
# mkdir trac
# chown apache.apache trac
 
启动apache:
/usr/local/apache/bin/httpd -k start
接下来访问http://localhost/trac,如果看到“Available Projects”字样,就说明trac配置成功!
 
4.建立trac项目
下面要建立一个Trac的演示项目。进入 /data/trac,用trac-admin命令建立:
 
# cd /data/trac
# trac-admin domob initenv        (domob为项目名称,根据需要创建,接下来的提问全部按回车即可)
# chown -R apache.apache domob
 
然后访问http://localhost/trac/domob,即可看到Trac的主界面了!
 
与svn结合:
如果想在Trac中查看subversion的代码库,首先建立用于放置代码库的目录,并建立代码库:
# cd /data
# mkdir svn
# chown apache.apache svn
# cd svn
# svnadmin create domob        (domob为代码库名称,可以任意选择)
# chown -R apache.apache domob
然后进入项目中的conf目录, 修改trac.ini中的repository_dir变量为代码库完整路径即可。这个方法要求/data/trac下的所有内容必须属于apache用户,否则Trac会出错。 
 
5.配置trac管理界面:
接下来需要配置好认证,这样才能方便地通过浏览器来修改项目设置。
首先在 /data/trac 下建立 .htpasswd 文件,用来保存用户名和密码:
# cd /data/trac
# /usr/local/apache/bin/htpasswd -c .htpasswd root   (建立用户root。如果.htpasswd文件存在,则不用加-c)
然后继续修改 /usr/local/apache/conf/httpd.conf ,在末尾添加以下内容:
<LocationMatch "/trac/[^/]+/login">
    AuthType Basic
    AuthName "Trac"
    AuthUserFile /data/trac/.htpasswd
    Require valid-user
</LocationMatch>
然后重新启动httpd:
# /etc/init.d/httpd restart
最后,进入/data/trac,给刚才建好的domob项目设置权限:
# trac-admin domob permission add root TRAC_ADMIN
这样,访问 http://localhost/trac/domob,然后点击上方菜单中的“Login”, 输入用户名root登录之后,即可在右上角看到“Admin”菜单,点击之后即可进入管理界面。
 
6.trac插件安装
所有可用插件都可以在 http://trac-hacks.org/ 网站上下载
(1).安装账号管理插件accountmanager
wget http://trac-hacks.org/changeset/latest/accountmanagerplugin/0.11?old_path=/&filename=accountmanagerplugin/0.11&format=zip
unzip accountmanagerplugin_0.11-r12573.zip
cd accountmanagerplugin/0.11
python setup.py bdist_egg
cp dist/TracAccountManager-0.4.2-py2.7.egg /data/trac/domob/plugins/
然后刷新trac管理页面就出现Accounts管理了,进入下面的configuration中进行相应修改,使密码文件指向/data/trac/.htpasswd,
然后就可以注释apache关于trac认证配置了,以后就不用手动修改认证文件了
 
(2).安装autocompleteusers插件
wget  http://trac-hacks.org/changeset/latest/autocompleteusersplugin?old_path=/&filename=autocompleteusersplugin&format=zip
unzip autocompleteusersplugin-r12573.zip
cd autocompleteusersplugin/trunk
python setup.py bdist_egg
cp dist/AutocompleteUsers-0.4.2dev-py2.7.egg /data/trac/domob/plugins
验证:
插件管理中看到有AutocompleteUsers-0.4.2dev出现
新建一new ticket测试cc中是否会自动完成用户
 
(3).安装DateFiled插件
wget http://trac-hacks.org/changeset/latest/datefieldplugin?old_path=/&filename=datefieldplugin&format=zip
unzip datefieldplugin-r12573.zip
cd datefieldplugin/1.0
python setup.py bdist_egg
cp dist/TracDateField-3.0.0dev-py2.7.egg /data/trac/domob/plugins/
 
其它插件相同安装方法不再一一介绍.
 
Trac升级方法:
1.停止Trac服务
2.更新Trac
如果现在的一些依赖包满足新版Trac要求,可以用easy_install --upgrade Trac==1.0 直接更新
如果不满足需要重新安装
3.更新项目Trac环境
cd /data/trac
cp -r domob domb-old  //更新前最好先备份一下防止发生意外导致无法回滚
trac-admin domob upgrade  //更新trac环境需要很长时间
4.更新文档
trac-admin domob wiki upgrade
4.重新编译安装用到的插件