CentOS下搭建SVN服務器
一,介紹SVNhtml
SVN是Subversion的簡稱,是一個開放源代碼的版本控制系統,相較於RCS、CVS,它採用了分支管理系統,它的設計目標就是取代CVS。互聯網上不少版本控制服務已從CVS遷移到Subversion。說得簡單一點SVN就是用於多我的共同開發同一個項目,共用資源的目的。 ----百度百科java
二,安裝SVlinux
官網下載: http://subversion.apache.org/packages.htmlgit
SVN客戶端TortoiseSVN :https://tortoisesvn.net/downloads.htmlapache
1,yum install subversion安裝vim
1
|
[root@localhost conf]
# yum install subversion
|
2,新建一個目錄用於存儲SVN目錄windows
1
|
[root@localhost]
mkdir
/svn
|
3,新建一個測試倉庫bash
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