天天看點

在Linux系統下Apache完美內建SVN(Yum安裝版)

svn(subversion)是目前最流行的開源版本控制工具。使用apache內建svn比svn服務獨立運作好處多多,最大的優點是使svn使用http80端口檢出,防火牆可以少開放一個端口,減少伺服器安全風險和降低維護成本。下面在CentOS6.0系統下通過yum安裝的方式,介紹在linux下apache完美內建svn。

一、規劃目錄:
網站位址 http://www.aiezu.com
網站根目錄 /storage/web/aiezu
SVN位址 http://www.aiezu.com/svn/aiezu
SVN資料倉庫目錄 /storage/svn/aiezu
二、安裝apache:

安裝apache包:

yum -y install httpd #必須
yum -y install mysql mysql-server php php-mbstring php-gd #可選安裝      

建立站點根目錄:

mkdir -p /storage/web/aiezu      

建立基于域名的虛拟主機,vim /etc/httpd/conf.d/www.aiezu.com.conf添加以下内容:

NameVirtualHost *:80
<Directory “/storage/web/aiezu”>
Options -Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /storage/web/aiezu
ServerName www.aiezu.com
ErrorLog logs/www.aiezu.com-error_log
CustomLog logs/www.aiezu.com-access_log common
</VirtualHost>      

啟動apache和mysql服務:

service mysqld start
service httpd start      
三、安裝和配置apache SVN子產品:

安裝apache服務SVN子產品mod_dav_svn:

yum -y install mod_dav_svn
#會自動安裝mod_dav_svn及其依賴包:mod_dav_svn-1.6.11-9,neon-0.29.3-2,pakchois-0.4-3.2,subversion-1.6.11-9      

建立svn資料倉庫:

mkdir -p /storage/svn/aiezu
svnadmin create /storage/svn/aiezu      

建立svn帳号并設定密碼:

htpasswd -c /storage/svn/aiezu/conf/passwd svnuser      

配置設定svn帳号權限:

[aiezu:/]
svnuser = rw #設定aiezu資料倉庫svnuser使用者有讀寫權限      

配置svn資料倉庫檔案系統權限:

chown -R apache.apache /storage/svn/aiezu
chcon -R -t httpd_sys_content_t /storage/svn/aiezu #selinux權限      

配置svn資料倉庫checkout位址:

vim /etc/httpd/conf.d/subversion.conf,添加如下内容:

LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
<Location /svn>
DAV svn
SVNListParentPath on
SVNParentPath /storage/svn
AuthType Basic
AuthName “Authorization”
AuthUserFile /storage/svn/aiezu/conf/passwd
AuthzSVNAccessFile /storage/svn/aiezu/conf/authz
Require valid-user
</Location>      

重新加載apache配置:

service httpd reload      
四、配置svn post-commit鈎子:

當我們希望在像svn資料倉庫送出新版本時,自動将更新同步到我們的網站,這時我們可以使用svn鈎子,svn鈎子必須放在svn資料倉庫的hooks目錄下,這裡我們要添加是svn commit(svn送出)鈎子post-commit:

vim /storage/svn/aiezu/hooks/post-commit,添加如下内容:

#!/bin/bash
export LANG=”zh_CN.UTF-8″
export LANG=”zh_CN.UTF-8″
export LC_CTYPE=”zh_CN.UTF-8″
svn update /storage/web/aiezu/ –username=svnuser –password=svnpass –non-interactive      

授予可執行權限:

chmod a+x /storage/svn/aiezu/hooks/post-commit      

檢出版本庫:

svn checkout http://www.aiezu.com/svn/aiezu /storage/web/aiezu/      
五、常見錯誤及其解答:

1、svn checkout(svn檢出)時錯誤一:

The URI does not contain the name of a repository. [403, #190001]      

解答:這是由于subversion.conf檔案中SVNParentPath路徑設定不正确引起的,SVNParentPath路徑必須為svnadmin create生成資料倉庫路勁的父目錄,如上面建立資料倉庫的指令為svnadmin create /storage/svn/aiezu,則SVNParentPath為/storage/svn。

2、svn checkout時錯誤二:

Unable to connect to a repository at URL ‘http://www.aiezu.com/svn’
Access to ‘http://www.aiezu.com/svn’ forbidden      

解答:svn資料倉庫的SVN URL位址不正确,當subversion.conf中設定SVNListParentPath on時,SVN URL位址為SVNParentPath下的具體資料倉庫,而不是SVNParentPath指定的目錄。

3、svn checkout時錯誤三:

Unable to connect to a repository at URL http://www.aiezu.com/svn/test’
Could not open the requested SVN filesystem      
post-commit hook failed (exit code 1) with output:
svn: Can’t open file ‘/storage/web/aiezu/.svn/lock’: Permission denied      

繼續閱讀