CentOS下搭建SVN服務器


一,介紹SVN

    SVN是Subversion的簡稱,是一個開放源代碼的版本控制系統,相較於RCS、CVS,它采用了分支管理系統,它的設計目標就是取代CVS。互聯網上很多版本控制服務已從CVS遷移到Subversion。說得簡單一點SVN就是用於多個人共同開發同一個項目,共用資源的目的。 ----百度百科

二,安裝SV

官網下載: http://subversion.apache.org/packages.html

SVN客戶端TortoiseSVN :https://tortoisesvn.net/downloads.html

 1,yum install subversion安裝

1
[root@localhost conf] # yum install subversion

 2,新建一個目錄用於存儲SVN目錄

1
[root@localhost] mkdir  /svn

 3,新建一個測試倉庫

1
2
3
4
5
6
7
8
9
[root@localhost svn] # svnadmin create /svn/test/
[root@localhost svn] # ll /svn/test/
total 24
drwxr-xr-x. 2 root root 4096 Jul 28 18:12 conf
drwxr-sr-x. 6 root root 4096 Jul 28 18:12 db
-r--r--r--. 1 root root    2 Jul 28 18:12  format
drwxr-xr-x. 2 root root 4096 Jul 28 18:12 hooks
drwxr-xr-x. 2 root root 4096 Jul 28 18:12 locks
-rw-r--r--. 1 root root  229 Jul 28 18:12 README.txt

以下關於目錄的說明:

hooks目錄:放置hook腳步文件的目錄

locks目錄:用來放置subversion的db鎖文件和db_logs鎖文件的目錄,用來追蹤存取文件庫的客戶端

format目錄:是一個文本文件,里邊只放了一個整數,表示當前文件庫配置的版本號

conf目錄:是這個倉庫配置文件(倉庫用戶訪問賬戶,權限)

 

 4,配置SVN服務的配置文件svnserver.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
[root@localhost conf] # vim svnserve.conf 
### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository.  (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)
### Visit http://subversion.tigris.org/ for more information.
[general]
### These options control access to the repository for unauthenticated
### and authenticated users.  Valid values are "write", "read",
### and "none".  The sample settings below are the defaults.
anon-access =  read          ##注意前邊不要有空格,要頂齊
auth-access = write          ##注意前邊不要有空格,要頂齊
### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
password-db =  passwd         ##注意前邊不要有空格,要頂齊
### The authz-db option controls the location of the authorization
### rules for path-based access control.  Unless you specify a path
### starting with a /, the file's location is relative to the the
### directory containing this file.  If you don't specify an
### authz-db, no path-based access control is done.
### Uncomment the line below to use the default authorization file.
authz-db = authz           
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository's uuid.
realm = This is My First Test Repository    ##這個是提示信息
[sasl]
### This option specifies whether you want to use the Cyrus SASL
### library for authentication. Default is false.
### This section will be ignored if svnserve is not built with Cyrus
### SASL support; to check, run 'svnserve --version' and look for a line
### reading 'Cyrus SASL authentication is available.'
# use-sasl = true
### These options specify the desired strength of the security layer
### that you want SASL to provide. 0 means no encryption, 1 means
### integrity-checking only, values larger than 1 are correlated
### to the effective key length for encryption (e.g. 128 means 128-bit
### encryption). The values below are the defaults.
# min-encryption = 0
# max-encryption = 256

 

 5,配置訪問用戶及密碼

1
2
3
4
5
6
7
8
9
10
11
[root@localhost conf] # vim 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.
[ users ]
# harry = harryssecret
# sally = sallyssecret
lqb = lqb123456
test1 = 123456
test2 = 654321

 

 6,配置新用戶的授權文件

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
[root@localhost conf] # vim 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
admin = lqb,test2
user = test1
[ /svn/test/ ]
@admin = rw 
@user = r

備注:

admin = lqb,test2   創建admin組,組成員為:lqb,test2

user = test1      創建用戶組,用戶成員:test1

[test:/]       賦予根權限,為了便於管理和權限的控制,可以把權限細化到版本庫中相應的目錄

@admin = rw       admin組有讀寫的權限

@user = r        user組只有讀的權限

*=            表示除了上面設置的權限用戶組以外,其他所有用戶都設置空權限,空權限表示禁止訪問本目錄,這很重要一定要加上。

       

備注:版本庫的目錄格式如下:

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

@<用戶組名> = 權限

<用戶名> = 權限

其中[]內容有許多寫法:

[/],表示根目錄及其一下的路徑,根目錄是svnserver啟動時指定好的,上述實例中我們指定為:/svn/svndata([/]=/svn/svndata).[/]就是表示對全部版本設置的權限

[test:/],表示對版本庫test設置權限;

[test:/svnadmin],表示對版本庫test中的svnadmin項目設置權限;

[test:/svnadmin/second],表示對版本庫test中的svnadmin項目的目錄設置權限;

 

權限的主體可以是用戶組,用戶或者*,用戶組在前面要以@開頭,*表示全部用戶

權限分為:r ,w, rw和null ,null空表示沒有任何權限。

auhtz配置文件中的每個參數,開頭不能有空格,對於組要以@開頭,用戶不需要。

 

 7,啟動svn服務

1
[root@localhost conf] #svnserve -d -r /svn/

注意:更改svnserver.conf時需要重啟SVN服務,更改authz,passwd文件時則不需要重啟服務

 

 二,通過客戶端進行連接:

<一>,Windos客戶端連接操作

 1,使用windows的客戶端來進行連接

 

 2,在Linux使用如下命令行:

1
2
3
4
[root@localhost conf] # svn co svn://192.168.200.200/test
A     test /工作文檔.txt.bak
A     test /soft
Checked out revision 2.

如果失敗的話,基本上可以斷定authz文件的配置有問題,可以修改下:

1
2
3
4
5
6
admin = lqb,test2
user = test1
[/]
@admin = rw 
@user = r 
* =       ###表示除了上面設置的權限用戶組以外,其他所有用戶都設置空權限,空權限表示禁止訪問本目錄

 

 3,check out后會在桌面創建一個文件夾,說明操作成功,接下來向該文件夾放文件,然后右鍵SVN commit,會看到文件在同步,如圖一,二,三,四,五

    圖一

圖二

圖三

圖四

 

 4,同步完成之后,我們可以在本地查看是否同步到服務器中,右擊桌面--->TortoiseSVN→Repo Browser即可查看,也可以先SVN Update更新一下,確保內容是最新的。 

 5,如果要刪除文件,直接本地刪除然后commit即可。

  如果查看歷史版本TortoiseSVN,右擊文件夾-->TortoiseSVN-->Show log.而且可以查看文檔發生了什么變化。

   如果版本庫地址發生了變化更換的步驟如下:右擊文件夾-->TortoiseSVN-->Relocate修改地址確認commit即可

 

<二>,Linux客戶端同步過程:

把linux做為SVN客戶端,所以你操作的並不一定是SVN的服務器那台,以后如果說我要定時自動發布代碼等等,這時候就要用到腳本了,所以接下來的也是很重要的首先安裝SVN,步驟同上,在此就不在贅述。

1,同步文件,check out:  svn co svn://192.168.1.202/sadoc /data/svndata/ --username=我的用戶名 --password=我的密碼

1
2
3
4
5
6
7
8
9
10
[root@localhost conf] # svn co svn://192.168.200.200/test /svn --username=lqb --password=lqb123456
A     /svn/svn .txt.bak
A     /svn/ 工作文檔.txt.bak.bak
A     /svn/svn-test .txt
A     /svn/svn .txt
A     /svn/ 工作文檔.txt.bak
A     /svn/ROOT .war
A     /svn/soft
A     /svn/soft/ROOT .war
Checked out revision 16.

注意!  你的密碼,對於認證域:   <svn://23.110.85.249:3690> 68cfb7eb-c123-4643-8825-8a067020e3f4只能明文保存在磁盤上!

  如果可能的話,請考慮配置你的系統,讓 Subversion可以保存加密后的密碼。請參閱文檔以獲得詳細信息。

  你可以通過在“ /root/ .subversion /servers ”中設置選項“store-plaintext-passwords”為“ yes ”或“no”,來避免再次出現此警告。

 

2,版本庫內容更新

1
2
3
4
5
6
[root@localhost conf] # svn update svn://192.168.200.200/test /svn --username=lqb --password=lqb123456
Skipped  'svn://192.168.200.200/test'
At revision 16.
Summary of conflicts:
   Skipped paths: 1
[root@localhost conf] #

 

3,查看svn中的數據

1
2
3
4
5
6
7
8
9
[root@localhost conf] # svn ls svn://192.168.200.200/test/ --username=lqb --password=lqb123456
ROOT.war
soft/
svn- test .txt
svn.txt
svn.txt.bak
工作文檔.txt.bak
工作文檔.txt.bak.bak
[root@localhost conf] #

 

4,本地數據commit數據到SVN中

1
2
3
4
5
6
7
8
9
[root@localhost svn] # vim 123.log
"123.log"  [New] 3L, 32C written                                           
[root@localhost svn] # svn add 123.log 
A         123.log
[root@localhost svn] # svn ci -m "commit data"
Adding         123.log
Sending        svn.txt
Transmitting  file  data ..
Committed revision 17.

-m [--message] ARG: 指定日志信息ARG 不添加-m參數會報錯。

 

<三>,SVN目錄樹

一般比較規范的SVN它會有三個目錄,分別為:

/svn/trunk: 主干

/svn/branch: 個人或團隊開發的分支

/svn/tag: 標記版本,比如某個版本開發好了。

現在我要創建三個這樣的目錄,然后我要導入到版本庫中去,這里會用到的是import命令
import:將未納入版本控制的文件或目錄樹提交到版本庫。要分清楚它和commit的區別,commit指的是把工作副本的修改提交到版本庫。

1
2
3
4
5
6
7
[root@localhost svndata] # mkdir -p svn/{trunk,branch,tag}
[root@localhost svndata] # svn import /svn/svn svn://192.168.200.200/test --username=lqb --password=lqb123456 -m "import" 
Adding          /svn/svn/trunk
Adding          /svn/svn/tag
Adding          /svn/svn/branch
Committed revision 18.
[root@localhost svndata] #

把主干的東西拷到一個分支

1
2
[root@localhost svndata] # svn copy svn://192.168.200.200/test/trunk svn://192.168.200.200/test/branch/branch -m "create a branch" --username=lqb --password=lqb123456
Committed revision 19.

 

本文出自 “清風明月” 博客,請務必保留此出處http://liqingbiao.blog.51cto.com/3044896/1831236


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM