本系統採用爲每個項目單獨建一版本庫的策略。配置文件,密碼文件,訪問控制文件等都放在版本庫的conf目錄下。所以每次開始一個新項目都必須新建一個版本庫,並重新配置各配置文件。還有很重要的一條,要求各組員重新配置客戶端,包括服務器版本庫路徑,本地路徑等信息。
◆建立版本庫目錄(可建立多個,新建庫後以下各項都需重新配置。注意區別安裝目錄與版本庫目錄,以下講的都是版本庫目錄)
mkdir –p /opt/svndata/repos
◆建立svn版本庫(與上面目錄對應)
svnadmin create /opt/svndata/repos
執行此命令後svn自動在repos目錄下添加必須的配置文件.
注意:版本庫不同於一般的文件夾, 直接在操作系統上新建文件無法被SVN識別, 必須使用import等命令將文件導入版本庫.
此爲svn內部指令,create用於新建版本庫。請使用svn help查看詳細說明。
◆修改版本庫配置文件
vi /opt/svndata/repos/conf/svnserve.conf
各參數功能在配置文件的註釋中有說明, 此處配置如下:
[general]
anon-access = none # 使非授權用戶無法訪問
auth-access = write # 使授權用戶有寫權限
password-db = passwd # 指明密碼文件路徑
authz-db = authz # 訪問控制文件
realm = /opt/svndata/repos # 認證命名空間,subversion會在認證提示裏顯示,並且作爲憑證緩存的關鍵字。
其它採用默認配置. 各語句都必須頂格寫, 左側不能留空格, 否則會出錯.
其中pwd.conf 與 authz.conf 在新建版本庫時系統不會自動創建,需要自己創建。
指令簡介:這是svn配置文件的格式,請按照以上格式書寫。
◆配置用戶
vi /opt/svndata/repos/conf/passwd
修改完之後的內容如下:
### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.
### 在下面添加用戶和密碼,每行一組username = password
[users]
# harry = harryssecret
# sally = sallyssecret
###===========下面是我添加的用戶信息========#######
iitshare = password1
itblood = password2
可以添加多個,此爲用戶名密碼對。
◆配置權限
vi /opt/svndata/repos/conf/authz
修改完的內容如下
### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization line can refer to:
### - a single user,
### - a group of users defined in a special [groups] section,
### - an alias defined in a special [aliases] section,
### - all authenticated users, using the '$authenticated' token,
### - only anonymous users, using the '$anonymous' token,
### - anyone, using the '*' wildcard.
###
### A match can be inverted by prefixing the rule with '~'. Rules can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').
[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil,
Ltd./OU=Research Institute/CN=Joe Average
# [groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
# [/foo/bar]
# harry = rw
# &joe = r
# * =
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
###--------------------下面我新加的------------------------###
###屏蔽掉上面的[groups] 因爲在下面添加了
[groups]
devteam = iitshare, itblood #devteam 項目組包括兩個用戶iitshare,itblood
[/]
iitshare = rw
itblood =
[tshop:/tb2c]
@devteam = rw
itblood =
[repos:/]
@devteam = rw
itblood = r
其中,1個用戶組可以包含1個或多個用戶,用戶間以逗號分隔。
說明:
devteam = iitshare, itblood #devteam 項目組包括兩個用戶iitshare,itblood
[/]
iitshare = rw #iitshare 對根目錄有讀寫權限
itblood = #itblood 對根目錄沒有任何權限
####如果需要配置tb2c、tb2b2c項目的權限,前提條件是tshop倉庫下面需要有這兩個項目
####如果沒有的話,tshop都將不能訪問
[repos:/] #對repos倉庫的所有項目進行權限控制
@devteam = rw #控制 devteam 組對tb2c項目有讀寫權限
◆啓動服務
執行svnserve –d –r /opt/svndata/repos/ 啓動服務, 以deamon方式運行。
本系統採用svnserve方式, 這是小團隊項目的推薦方法. 這種方法維護最少, 配置最簡單.
指令簡介:此指令用於啓動svn服務,-d指明以守護模式運行,svn自動在3690端口監聽。3690是默認端口,可以使用“–listen-port=”或者“–listen-host=”來指定其它端口。-r選項用來指定svn服務的根目錄,這樣用戶就可以使用相對路徑訪問,而不用提供完整路徑。
◆檢查是否啓動
netstat -tunlp | grep svn
如果顯示以下信息說明啓動成功
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 10973/svnserve
◆將svn加入到開機啓動
編輯rc.local文件:vi /etc/rc.d/rc.local
加入如下啓動命令:
/usr/local/svn/bin/svnserve –d –r /opt/svndata/repos/
◆如果想停止svn,則使用如下命令:
killall svnserve
◆如果想將svn作爲服務:
在/etc/rc.d/init.d/目錄下新建名爲svn的文件
並設置權限爲755:chmod 755 /etc/rc.d/init.d/svn
編輯svn文件:vi /etc/rc.d/init.d/svn, 在裏面添加如下代碼:
#!/bin/bash
# build this file in /etc/rc.d/init.d/svn
# chmod 755 /etc/rc.d/init.d/svn
# centos下可以用如下命令管理svn: service svn start(restart/stop)
SVN_HOME=/opt/svn
if [ ! -f "/usr/local/svn/bin/svnserve" ]
then
echo "svnserver startup: cannot start"
exit
fi
case "$1" in
start)
echo "Starting svnserve..."
/usr/local/svn/bin/svnserve -d -r $SVN_HOME
echo "Finished!"
;;
stop)
echo "Stoping svnserve..."
killall svnserve
echo "Finished!"
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: svn { start | stop | restart } "
exit 1
esac
之後便可以以service svn start(restart/stop)方式啓動SVN。
通過web方式訪問svn有很多方法,請參閱配置websvn或配置bsSvnBrowser的方法
◆客戶端訪問
1、下載安裝文件
window 64位的話下載:TortoiseSVN-1.7.6.22632-x64-svn-1.7.4.msi
window 32位的話下載:TortoiseSVN-1.6.5.16974-win32-svn-1.6.5.msi
具體的下載文件可以在網上下載下,一找一大堆
2、通過客戶端進行訪問
地址如下:
svn://{your-server-ip}:9999/repos/ 或者 svn://{your-server-ip}:3690/repos/
注意:
不要在瀏覽器中通過http的方式進行訪問,如下地址:
http://{your-server-ip}:3690/tshop/
那樣肯定是不行的,因爲你沒有配置http的服務,上面是安裝獨立的SVN服務器