以下內容從http://ihacklog.com/server/ubuntu-server/ubuntu-svn-setup.html來
1.SubVersion服務安裝
1
2 |
sudo apt-get install subversion
sudo apt-get install libapache2-svn |
2.服務器配置
2.1相關用戶、組的設定
將自己和“www-data”(Apache 用戶)加入組subversion中
1
2 |
sudo addgroup subversion
sudo usermod -G subversion -a www-data |
看下結果:
1
|
cat /etc/group|grep subversion
|
這裏注意,需要註銷然後再登錄以便您能夠成爲 subversion 組的一員,然後就可以執行簽入文件(Check in,也稱提交文件)的操作了
倉庫位置我們就放在/home/svn下吧:
1
|
sudo mkdir /home/svn
|
2.2配置subversion
編輯/etc/subversion/config 文件,修改相關設置
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
### 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 :
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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配置文件的位置 AuthzSVNAccessFile /etc/subversion/dav_svn.authz # 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 服務器
1
|
sudo /etc/init.d/apache2 restart
|
4.創建 SVN 文件倉庫
1
2 3 4 5 6 7 |
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的創建
1
|
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組的讀寫權限
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[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服務器:
1
|
killall svnserve; svnserve -d -r /home/svn/
|
您可以通過下面的命令來訪問文件倉庫:
1
|
svn co http://hostname/svn/myproject myproject --username user_name --password passwd
|
創建目錄試試:
1
|
svn mkdir "http://localhost/svn/vod/branches" "http://localhost/svn/vod/tags" "http://localhost/svn/vod/trunk" -m "create a new project vod" --username vod --password passwd
|
如果在Check in的時候遇到如下錯誤:
Can’t open ‘/home/svn/myproject/db/txn-current-lock’: Permission denied
查看txn-current-lock文件的權限和用戶以及組信息,應該類似於:
1
|
ls -l /home/svn/myproject/db/txn-current-lock
|
-rw-rwSr– 1 root subversion 0 2009-06-18 15:33 txn-current-lock
除了權限以外,用戶及其組如果不對,則仍然會遇到上述問題,可以再次運行命令:
1
|
sudo chown -R root:subversion myproject
|
參考文章:
http://www.blogjava.net/rain1102/archive/2009/02/23/256338.html
http://bbs.iusesvn.com/thread-6-1-1.html
http://snowolf.javaeye.com/blog/740347
http://wiki.ubuntu.org.cn/index.php?title=SubVersion&variant=zh-cn#.E9.80.9A.E8.BF.87_WebDAV_.E5.8D.8F.E8.AE.AE.E8.AE.BF.E9.97.AE.28http:.2F.2F.29