1.SubVersion服務安裝
sudo apt-get install subversion sudo apt-get install libapache2-svn
2.服務器配置
2.1相關用戶、組的設定
將自己和“www-data”(Apache 用戶)加入組subversion中
sudo addgroup subversion
sudo usermod -G subversion -a www-data
看下結果:
cat /etc/group|grep subversion
這里注意,需要注銷然后再登錄以便您能夠成為 subversion 組的一員,然后就可以執行簽入文件(Check in,也稱提交文件)的操作了
倉庫位置我們就放在/home/svn下吧(注意,在阿里雲里數據最好放在數據盤里,不要放在系統盤,系統盤太小):
sudo mkdir /home/svn
2.2配置subversion
編輯/etc/subversion/config 文件,修改相關設置(筆者基本上是默認設置,沒做任何修改)
### Section for configuring miscelleneous Subversion options. [miscellany] global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo *.rej *~ #*# .#* .*.swp .DS_Store ### Set mime-types-file to a MIME type registry file, used to ### provide hints to Subversion's MIME type auto-detection ### algorithm. # mime-types-file = /path/to/mime.types ### Set enable-auto-props to 'yes' to enable automatic properties ### for 'svn add' and 'svn import', it defaults to 'no'. ### Automatic properties are defined in the section 'auto-props'. enable-auto-props = yes ### Section for configuring automatic properties. [auto-props] ### The format of the entries is: ### file-name-pattern = propname[=value][;propname[=value]...] ### The file-name-pattern can contain wildcards (such as '*' and ### '?'). All entries which match (case-insensitively) will be ### applied to the file. Note that auto-props functionality ### must be enabled, which is typically done by setting the ### 'enable-auto-props' option. *.c = svn:eol-style=native *.cpp = svn:eol-style=native *.h = svn:eol-style=native *.dsp = svn:eol-style=CRLF *.dsw = svn:eol-style=CRLF *.sh = svn:eol-style=native;svn:executable *.txt = svn:eol-style=native *.png = svn:mime-type=image/png *.jpg = svn:mime-type=image/jpeg Makefile = svn:eol-style=native *.php = svn:keywords=Id Rev Date URL Revision Author
global-ignores是提交時忽略的文件類型,啟用auto-props后,讓subversion自動添加Id,Revision等keywords
這樣就可以使用svn的keywords了。特別是eclipse里就方便多了。設置一下就可以使用
$$Id$$、$$Reversion $$、$$Date $$、$$Author$$ 、$$URL$$作為注釋模板的內容,方便極了。
如果在客戶端訪問subversion版本庫時出現這個錯誤:
svnserve.conf:102: Option expected
為什么會出現這個錯誤呢,就是因為subversion讀取配置文件svnserve.conf時,無法識別有前置空格的配置文件。
要避免出現這個錯誤,應該在去掉這些行前的#時,也要順手去掉前面的空格。
3.apache mod_dav_svn 配置
通過 WebDAV 協議訪問(http://)
關於WebDAV :
WebDAV (Web-based Distributed Authoring and Versioning) 一種基於 HTTP 1.1協議的通信協議.它擴展了HTTP 1.1,在GET、POST、HEAD等幾個HTTP標准方法以外添加了一些新的方法,使應用程序可直接對Web Server直接讀寫,並支持寫文件鎖定(Locking)及解鎖(Unlock),還可以支持文件的版本控制。
編輯 /etc/apache2/mods-available/dav_svn.conf :
root@hywd:/etc/apache2/mods-available# cat dav_svn.conf
# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
#
# NOTE: for a setup with multiple vhosts, you will want to do this
# configuration in /etc/apache2/sites-available/*, not here.
# <Location URL> ... </Location>
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/
# Note, a literal /svn should NOT exist in your document root.
<Location /svn>
#enable the repository
DAV svn
# Set this to the path to your repository
#SVNPath /home/svn/vod
# Alternatively, use SVNParentPath if you have multiple repositories under
# under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
# You need either SVNPath and SVNParentPath, but not both.
#用這個,以便放多個repository
SVNParentPath /home/svn
# Basic Authentication is repository-wide. It is not secure unless
# you are using https. See the 'htpasswd' command to create and
# manage the password file - and the documentation for the
# 'auth_basic' and 'authn_file' modules, which you will need for this
# (enable them with 'a2enmod').
AuthType Basic
AuthName "Subversion Repository"
#指定基本用戶驗證的密碼文件存放位置
AuthUserFile /etc/subversion/dav_svn.passwd
# To enable authorization via mod_authz_svn
#mod_authz_svn配置文件的位置, 有
<IfModule mod_authz_svn.c>
AuthzSVNAccessFile /etc/subversion/dav_svn.authz
</IfModule>
# The following three lines allow anonymous read, but make
# committers authenticate themselves. It requires the 'authz_user'
# module (enable it with 'a2enmod').
#<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
#</LimitExcept>
</Location>
重啟 Apache 2 Web 服務器
sudo /etc/init.d/apache2 restart
4.創建 SVN 文件倉庫
cd /home/svn
sudo mkdir myproject
#更改版本庫所屬用戶、組
sudo chown -R root:subversion myproject
sudo svnadmin create /home/svn/myproject
#賦予組成員對所有新加入文件倉庫的文件擁有相應的權限:
sudo chmod -R g+rws myproject
5.密碼文件dav_svn.passwd的創建
sudo htpasswd -c /etc/subversion/dav_svn.passwd user_name
它會提示你輸入密碼,當您輸入了密碼,該用戶就建立了。“-c”選項表示創建新的/etc/subversion/dav_svn.passwd 文件,所以user_name所指的用戶將是文件中唯一的用戶。如果要添加其他用戶,則去掉“-c”選項即可:
sudo htpasswd /etc/subversion/dav_svn.passwd other_user_name
6.授權配置文件dav_svn.authz (該文件如果沒有,就自己創建)
這里我指定了兩個組:管理員組和測試組,指定了兩個倉庫(vod 、 ThinkPHP 和ftpuserms)的權限 。
vod倉庫下管理員組設置為讀寫權限,測試組只有讀的權限
ThinkPHP倉庫下管理員組設置為讀寫權限,測試組只有讀的權限
定義ftpuserms儲存庫下test目錄的訪問權限:
禁止所有用戶訪問,星號代表所有用戶,權限為空代表沒有任何權限
打開test3用戶的讀權限,打開administrator組的讀寫權限
[groups] administrator=admin,yuan tester=test1,test2,test3 [vod:/] @administrator=rw tester=r [ThinkPHP:/] @administrator=rw tester=r [ftpuserms:/test] @administrator=rw *= test3=r
啟動SVN服務器:
killall svnserve;
svnserve -d -r /home/svn/
您可以通過下面的命令來訪問文件倉庫:
svn co http://hostname/svn/myproject myproject --username user_name --password passwd
如果在Check in的時候遇到如下錯誤:
Can’t open ‘/home/svn/myproject/db/txn-current-lock’: Permission denied
查看txn-current-lock文件的權限和用戶以及組信息,應該類似於:
ls -l /home/svn/myproject/db/txn-current-lock
-rw-rwSr– 1 root subversion 0 2009-06-18 15:33 txn-current-lock
除了權限以外,用戶及其組如果不對,則仍然會遇到上述問題,可以再次運行命令:
sudo chown -R root:subversion myproject
參考文章:
http://ihacklog.com/post/ubuntu-svn-setup.html