windwos下svn配置和基於Apache配置

1,軟件下載

系統要求Windows XP(32-bit and 64-bit)、Windows Server 2003 (32-bit and 64-bit)、Windows Server 2008 (64-bit)、Windows Vista(32-bit and 64-bit)、Windows 7 (32-bit and 64-bit)。

下載WANdiscoSubversion,它包括Subversion、Apache、TortoiseSVN軟件包。

2,軟件安裝

根據提示安裝即可。

注意以下幾點:

1. 建立一個svn server。在第2步選擇組件中,選擇了subversion 1.6.12 server選項。如果你僅僅只需要svn client,就可以去掉這個選項。

2. 在第4步,Apache Httpd configuration如下圖所示:
[img]http://dl.iteye.com/upload/attachment/317067/dba427bd-2004-31f8-a637-101263d3a72d.png[/img]

Repository Directory,意思是版本庫目錄。默認爲:C:\repositories。
Repository Location Prefix,意思是URL訪問版本庫的根目錄。默認爲/svn,例如:
http://192.168.1.2/svn/repository/
Repository Directory對應的內容改爲,你存放版本庫的目錄。例如:d:\svn。
直接按Install安裝也可以,可以通過修改配置文件Apache2/conf/subversion.conf的方式修改。

3,建立版本庫(Repository)

運行Subversion服務器需要首先要建立一個版本庫(Repository),可以看作服務器上存放數據的數據庫。Svn把與當前版本庫對應項目的所有修改信息,保存到版本庫中。

1) 在安裝了Subversion服務器之後,可以直接運行,如:

cmd命令界面輸入:

3. svnadmin create d:\svn\repository

就會在目錄d:\svn\repository下創建一個版本庫,版本庫模式爲BDB。

2) 我們也可以使用TortoiseSVN圖形化的完成這一步:

在目錄d:\svn\repository下"右鍵->TortoiseSVN->Create Repository here...“然後就創建了一系列目錄和文件

4,配置用戶和權限

1) 來到d:\svn\repository\conf目錄,修改svnserve.conf:

改爲:

[general]

# anon-access = read

auth-access = write

password-db = passwd

authz-db = authz

realm = testproject

注意以上所有命令,必須置頂,即去除#號的同時也要去掉空格號。

下面來解釋下上面命令的意思。

"anon-access = read"意思是,匿名訪問用戶權限爲:讀。

"auth-access = write"意思是,驗證用戶權限爲:讀寫。

"password-db = passwd"意思是,用戶密碼文件(配置允許訪問的svn用戶及密碼)指向: 同目錄的passwd。當然你也可以用絕對路徑的方式指定。

"authz-db = authz"意思是,權限配置文件指向:同目錄的authz。權限配置文件會更改用戶密碼文件中定義的默認權限。

"realm = testproject"意思是,版本庫標識符,在權限配置文件中會用到。

2) 然後修改同目錄的passwd文件,去掉下面三行的註釋:

[users]

# harry = harryssecret

# sally = sallyssecret

最後變成:

[users]

harry = harryssecret

sally = sallyssecret

在passwd文件中,“=”前的字符就是用戶名,後面的就是密碼。還要注意“[users]”前面的註釋“#”一定要刪除掉。

3) 在是修改同目錄下的authz文件。

* 權限配置文件中出現的用戶名必須已在用戶配置文件中定義。

* 對權限配置文件的修改立即生效,不必重啓svn。

用戶組格式:

[groups]

<用戶組名> = <用戶1>,<用戶2>

其中,1個用戶組可以包含1個或多個用戶,用戶間以逗號分隔。

版本庫目錄格式:

[<版本庫>:/項目/目錄]

@<用戶組名> = <權限>

<用戶名> = <權限>

其中,方框號內部分可以有多種寫法:

/ 表示根目錄及以下。根目錄是svnserve啓動時指定的,我們指定爲E:\svn。這樣,/就是表示對全部版本庫設置權限。

結合以上所述,創建的版本庫repository,及其svnserve.conf配置文件中"realm = testproject"

testproject:/ 表示對版本庫repository設置權限

testproject:/abc 表示對版本庫repository中的abc項目設置權限

testproject:/abc/aaa 表示對版本庫repository中的abc項目的aaa目錄設置權限

版本庫標識符(repository's uuid)的作用,當兩個版本庫使用同一個權限配置文件時候,用於區分不同的版本庫。

權限主體可以是用戶組、用戶或*,用戶組在前面加@,*表示全部用戶。權限可以是w、r、wr和空,空表示沒有任何權限。

示例:

[groups]
admin = harry,sally

[/]
@admin = rw

[testproject:/abc/aaa]
king = rw


[testproject:/]
@admin = rw

注意:在基於apache配置的SVN 中
"realm = <版本庫的文件夾名稱>"(例如:版本庫文件夾名稱爲repository
[repository:/]
@admin = rw)

5-1,運行獨立服務器

cmd命令界面中運行
svnserve -d -r E:\svn

我們的服務器程序就已經啓動了。注意不要關閉命令行窗口,關閉窗口也會把svnserve停止。這時,我們可以用"svn://localhost"了

5-2,初始化導入

來到我們想要導入的項目,例如:E:\flexworkspace\flex

右鍵->TortoiseSVN->Import...

在URL of repository輸入"file:///e:/svn/repository/flex"

在URL of repository輸入“svn://192.168.1.2/repository/flex”

在URL of repository輸入“http://localhost/svn/repository/flex”(需要配置apache)

在Import Message中輸入你的日誌信息

完成之後目錄沒有任何變化,如果沒有報錯,數據就已經全部導入到了我們剛纔定義的版本庫中。

需要注意的是,這一步操作可以完全在另一臺安裝 了TortoiseSVN的主機上進行。例如運行svnserve的主機IP是133.96.121.22,則URL部分輸入的內容就是 “svn://133.96.121.22/repository”。這裏注意,svn://在svn獨立服務器啓動,即第5-1步執行的情況下,才被支持的一種通信協議。

"svn://localhost"指向的是,命令"svnserve -d -r E:\svn" -r後面指向的目錄E:\svn。

7,基本客戶端操作

取出版本庫到一個工作拷貝:

來到任意空目錄下,例如:E:\project,運行右鍵->Checkout,在URL of repository中輸入svn://localhost/repository/flex,這樣我們就得到了一份工作拷貝。

在工作拷貝中作出修改並提交:

打開任意文件例如:readme.txt,作出修改,然後右鍵->Commit...,這樣我們就把修改提交到了版本庫,我們可以運行。

察看所作的修改:

readme.txt上右鍵 ->TortoiseSVN->Show Log,這樣我們就可以看到我們對這個文件所有的提交。在版本1上右鍵->Compare with working copy,我們可以比較工作拷貝的文件和版本1的區別。

8,配置基於Apache的SVN服務器

8.1.安裝

如果安裝的是WANdiscoSubversion,同時配置了以上設置。就可以通過瀏覽器訪問你的版本庫了。

在瀏覽器中輸入:http://localhost/svn/repository

8.2.設置

當然,我們要知其然,更要求其所以然。有兩個Apache配置文件與svn有關,分別是httd.conf和subversion.conf。

使用如記事本之類的文本編輯器編輯Apache的配置文件(例如D:\WANdisco\Subversion\Apache2\conf),修改以下內容:

subversion.conf的設置,從httpd.conf最後行“Include conf/subversion.conf”可以看出,subversion.conf只是httpd.conf的擴展文件而已。

首先,看subversion.conf文件內容,去除不需要的註釋:
#
# WANdisco Subversion Configuration
# http://www.wandisco.com
#
# For more information on HTTPD configuration options for Subversion please see:
# http://svnbook.red-bean.com/nightly/en/svn.serverconfig.httpd.html
# Please remember that when using webdav HTTPD needs read and write access your repositories.

# You can generate your username/password file data from here:
# http://www.htaccesstools.com/htpasswd-generator/

Timeout 3000000
MaxKeepAliveRequests 0
KeepAlive On
KeepAliveTimeout 300000
ThreadsPerChild 300
MaxRequestsPerChild 0

<VirtualHost *:80>
KeepAlive On
<Location /svn>
DAV svn
#SVNPath "D:\SVN\ls"
SVNParentPath "D:\SVN"
# SVNParentPath and authz fix http://subversion.tigris.org/issues/show_bug.cgi?id=2753
RedirectMatch ^(/svn)$ $1/
AuthType Basic
AuthName "Subversion repositories!Login needed!"
# If you didn't specify a password file during installation the
# next line needs to be configured for user authentication.
AuthUserFile "D:\WANdisco\conf\passwd"
AuthzSVNAccessFile "D:\SVN\Repository\conf\authz"
# Satisfy Any
Require valid-user
# Order allow,deny
# Allow from all
SVNAutoversioning on
</Location>
# Enable Subversion logging
CustomLog logs/svn_logfile "%t %u %{SVN-ACTION}e" env=SVN-ACTION
</VirtualHost>



主要來解釋下,<Location /svn></VirtualHost>之間內容的意思。

DAV svn
告訴Apache哪個模塊使用svn作爲根目錄。

SVNPath
其語法是:
   <Location /svn/repos_name>
DAV svn
SVNPath /absolute/path/to/repository
</Location>
其中 "/svn/repos_name" 就是客戶端存取特定檔案庫的 URI(Uniform Resource Indentifier),SVNPath 後面指定的路徑則是檔案庫的絕對路徑,假設我們的檔案庫實際存放的路徑是 d:/svn/repository,並且希望客戶端使用 "http://myserver/svn/repos_name" 的 URL 來存取檔案庫,例如:
<Location /svn>
DAV svn
SVNPath d:/svn/repository
</Location>

SVNParentPath
如果你的檔案庫都集中放在某個目錄之下,例如:d:/svn,那你就可以使用 SVNParentPath 的方式指定檔案庫的根路徑,例如:
<Location /svn>
DAV svn
SVNParentPath "d:/svn"
</Location>
這表示可以讓任何人都可以透過 http://myserver/svn/<檔案庫名稱> 的方式,存取位於 d:/svn 這個目錄以下的所有檔案庫。也就是說,這個設定動作只需要一次,如果使用 SVNPath,你必須爲各個檔案庫分別指定對應的路徑。
以上兩種設定方式都可以,方便起見,這裏我用 SVNParentPath 來統一指定所有檔案庫的父層 URL 路徑。
注意:當設定方式爲SVNParentPath 時,訪問URL必須爲 http://myserver/svn/<檔案庫名稱>(例如:http://192.168.1.2/svn/repository),如果使用 http://myserver/svn將出現如下錯誤:
Forbidden You don't have permission to access /svn/ on this server。

AuthType Basic。
啓用基本的驗證,比如用戶名/密碼對

AuthName "Subversion repositories"
當一個驗證對話框彈出時,告訴用戶這個驗證是用來做什麼的

AuthUserFile "D:\WANdisco\conf\passwd"
指定D:\WANdisco\Subversion\passwd用爲密碼文件用來驗證用戶的用戶名及密碼

AuthzSVNAccessFile "D:\WANdisco\conf\authz"
指定D:\WANdisco\Subversion\authz來限定各個用戶或組在版本庫中目錄的訪問權限

Require valid-user
限定用戶只有輸入正確的用戶名及密碼後才能訪問這個路徑

其中,passwd文件需要用Apache2\bin下的htpasswd.exe來生成。

在命令行下,進入bin目錄下,運行htpasswd -c passwd <username>。將會提示你輸入密碼。成功輸入密碼後,將在bin目錄下生成passwd文件。把它放到D:\WANdisco\Subversion\下即可


注意:在使用Apache的時候,檔案庫文件夾->conf文件夾下(svnserver.conf,passwd,authz)文件是沒有用的,不需要啓動獨立服務器(svnserve -d -r d:svn)

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]
admin = admin
# 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

[repository:/flex]
@admin = rw


passwd

admin:$apr1$hZ9bl.Lv$25M8fEtNuPymBhPw8cWBA0

或者
admin:admin
xes:2860086
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章