天天看點

Linux 下 Trac SVN apache SSL 配置安裝以及整合

trac + SVN + apache(SSL) 安裝

1. 簡介:

   由于項目需求,是以要部署一台Trac并且和現有的SVN整合. 至于什麼是Trac和SVN,就不多介紹了.

2. 安裝步驟:

   (1) 安裝apache(此步驟略)

   (2) 安裝SVN

   shell > tar zxvf subversion-1.5.6.tar.gz

   shell > cd subversion

   shell > ./configure –with-apxs=/usr/local/apache/bin/apxs –prefix=/usr/local/svn –with-apr=/usr/local/apache –with-apr-util=/usr/local/apache –with-

ssl  –enable-maintainer-mode –without-berkeley-db PYTHON=/usr/bin/python –with-swig=/usr/bin/swig –enable-shared –enable-static –enable-swig-

binding=python

   shell > make && make install

   (3) 配置apache:

       建立證書:

       shell > maker /usr/local/apache/conf/key

       shell > cd /usr/local/apache/conf/key

       shell > openssl genrsa -out xuan-lu.key 1024

       shell > chmod 600 /usr/local/apache/key/xuan-lu.key

       shell > openssl req -new -key xuan-lu.key -out xuan-lu.csr

               You are about to be asked to enter information that will be incorporated

               into your certificate request.

               What you are about to enter is what is called a Distinguished Name or a DN.

               There are quite a few fields but you can leave some blank

               For some fields there will be a default value,

               If you enter ‘.’, the field will be left blank.

               —–

               Country Name (2 letter code) [GB]:CN

               State or Province Name (full name) [Berkshire]:China

               Locality Name (eg, city) [Newbury]:Shang Hai

               Organization Name (eg, company) [My Company Ltd]:99 Roses

               Organizational Unit Name (eg, section) []:99 Roses

               Common Name (eg, your name or your server’s hostname) []:xuan-lu

               Email Address []:[email protected]

               Please enter the following ‘extra’ attributes

               to be sent with your certificate request

               A challenge password []:xuan-lu

               An optional company name []:xuan-lu

       shell > openssl x509 -req -days 365 -in xuan-lu.csr -signkey xuan-lu.key -out xuan-lu.crt

       shell > ls

               xuan-lu.crt  xuan-lu.csr  xuan-lu.key

       配置apache:

       shell > /usr/local/apache/bin/htpasswd -c /home/svn/user/svn_user.conf martin

               New password:

               Re-type new password:

               Adding password for user martin

       shell > vi /usr/local/apache/conf/httpd.conf

                 取消對下的ssl的注釋:

               # Secure (SSL/TLS) connections

                 Include conf/extra/httpd-ssl.conf

       shell > vi /usr/local/apache/conf/extra/httpd-ssl.conf

               添加如下:

               <VirtualHost *:443>

                    ServerName svn.xuan-lu.net

                    SSLEngine on

                    SSLCertificateFile "/usr/local/apache/key/xuan-lu.crt"

                    SSLCertificateKeyFile "/usr/local/apache/key/xuan-lu.key"

                 <Location />

                    DAV svn

                    SVNPath /home/svn/xuan-lu/

                    AuthType Basic

                    AuthName "xuan-lu!!! SVN"

                    AuthUserFile /home/svn/user/svn_user.conf

                    AuthzSVNAccessFile /home/svn/xuan-lu/conf/authz

                    Require valid-user

                 </Location>

               </VirtualHost>

       shell > service httpd restart

       注:  解釋下SVN 的權限配置檔案的使用

            [groups]

            admin = martin

            user_r = user_1

            user_rw = user_2

            [/]

            * =

            @admin = rw

            [/xuan-lu]

            @user_r = r

            @user_rw = rw

       使用者分别分為admin,user_r和user_rw三個組,其中隻有admin組使用者對/(根)目錄有讀寫權限,組user_r對/99rose目錄僅僅有讀的權限,而組user_rw對/xuan-lu目錄具備讀寫

的權限.根據不同的需求可以定制不同的權限,這裡不多做介紹.

   (2) 安裝trac

       shell > cd /home/tools/subversion      (個人習慣在/home/目錄下建立一個tools目錄用來放置源碼包)

       shell > make swig-py

       shell > make install-swig-py

       shell > echo /usr/local/svn/lib/svn-python > /usr/lib/python2.4/site-packages/subversion.pth

       驗證svn-python (沒報錯即可)

       shell > python

             >>>import svn.repos

             >>>

       shell > cd /home/tools/

       shell > tar zxvf Trac-0.11.5.tar.gz

       shell > cd Trac-0.11.5

       shell > sh setuptools-0.6c9-py2.4.egg

       shell > python ./setup.py install

       生成 trac

       shell > trac-admin /home/svn/trac_xuan-lu initenv

Creating a new Trac environment at /home/svn/trac_xuan-lu

Trac will first ask a few questions about your environment

in order to initialize and prepare the project database.

Please enter the name of your project.

This name will be used in page titles and descriptions.

Project Name [My Project]> 99 Roses !!!

Please specify the connection string for the database to use.

By default, a local SQLite database is created in the environment

directory. It is also possible to use an already existing

PostgreSQL database (check the Trac documentation for the exact

connection string syntax).

Database connection string [sqlite:db/trac.db]>

Please specify the type of version control system,

By default, it will be svn.

If you don’t want to use Trac with version control integration,

choose the default here and don’t specify a repository directory.

in the next question.

Repository type [svn]>

Please specify the absolute path to the version control

repository, or leave it blank to use Trac without a repository.

You can also set the repository location later.

Path to repository [/path/to/repos]> /home/svn/xuan-lu

… …

      配置Apache( 安裝mod_python 以及配置 trac)

       shell > ./configure –with-apxs=/usr/local/apache/bin/apxs

       shell > vi vi src/connobject.c

        … …

    141     while ((bytes_read < len || len == 0) &&

    142            !(b == APR_BRIGADE_SENTINEL(bb) ||

    143              APR_BUCKET_IS_EOS(b) || APR_BUCKET_IS_FLUSH(b))) {

       修改142行為上所示(原為  !(b == APR_BRIGADE_SENTINEL(b) ||    )

       否則會報如下錯誤:

       … …

       connobject.c:142: error: request for member ……in something not a structure or union

       apxs:Error: Command failed with rc=65536

       .

       make[1]: *** [mod_python.so] Error 1

       make[1]: Leaving directory `/home/tools/mod_python-3.3.1/src’

       make: *** [do_dso] Error 2

       shell > make && make install

       LoadModule python_module      modules/mod_python.so

       配置虛拟主機:

       shell > vi /usr/local/apache/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

    DocumentRoot /home/svn/trac_xuan-lu

    ServerName trac.xuan-lu.net

  <Location "/">

        SetHandler mod_python

        PythonInterpreter main_interpreter

        PythonHandler trac.web.modpython_frontend

        PythonOption TracEnv /home/svn/trac_xuan-lu

        PythonOption TracUriRoot /

        AuthType Basic

        AuthName "xuan-luTrac Server"

        AuthUserFile /home/svn/user/svn_user.conf

        Require valid-user

  </Location>

  <Directory "/home/svn/trac_xuan-lu">

   AllowOverride All

   Order Deny,Allow

  </Directory>

</VirtualHost>

       到此為止 trac 和 apache 以及 SVN 的整合 已經結束 下面将介紹一些簡單的修改.

  1. 開啟trac 的webadmin功能:

     shell > vi /home/svn/trac_xuan-lu/conf/trac.ini

     在配置檔案結尾加上

     [components]

     webadmin.* = enabled

     給予martin 使用者 webadmin 權限:

     shell > trac-admin /home/svn/trac_xuan-lu/

             Welcome to trac-admin 0.11.5

             Interactive Trac administration console.

             Copyright (c) 2003-2009 Edgewall Software

             Type:  ‘?’ or ‘help’ for help on commands.

             Trac [/home/svn/trac_xuan-lu]> permission add martin TRAC_ADMIN

             Trac [/home/svn/trac_xuan-lu]>

     重新整理頁面用martin使用者登入,就會發現,多了admin選項

  2. 更改trac左上方的logo

     … …

     [header_logo]

     alt = (please configure the [header_logo] section in trac.ini)

     height = -1

     link = /

     width = -1

  3. Trac整合SVN使用者權限:

     [trac]

     authz_file = /home/svn/xuan-lu/conf/authz

     authz_module_name = xuan-lu

  4. 解決trac中SVN源檔案亂碼問題:

     shell >

     default_charset = utf-8   (原來為:iso-8859-15)

  6. 使用者權限配置:

     (1) 使用martin登入

     (2) 選擇admin

     (3) 選擇左側:Permissions選項

     (4) 可以看到配置使用者的權限選項了(界面的右側)

     權限根據自己實際需求去進行操作:

     BROWSER_VIEW                  #  檢視版本庫

     CHANGESET_VIEW              #  檢視修改記錄

     FILE_VIEW                          #  檢視檔案内容

     LOG_VIEW                          #  檢視日志

     MILESTONE_VIEW              #  檢視裡程杯

     REPORT_SQL_VIEW           #  檢視報告查詢語句

     REPORT_VIEW                   #  檢視報告

     ROADMAP_VIEW                #  檢視路标

     SEARCH_VIEW                  #  顯示查找

     TICKET_CREATE                #  建立任務單

     TICKET_MODIFY                #  修改任務單

     TICKET_VIEW                   #  顯示任務單

     TIMELINE_VIEW               #  檢視時間

     WIKI_CREATE                   #  建立wiki

     WIKI_MODIFY                   #  修改wiki

     WIKI_VIEW                     #  檢視wiki