入職擴充學習--SVN

sayWhat_sayHello發表於2019-04-17

搭建SVN伺服器

RedHat Linux安裝svn:

yum install svn

判斷是否安裝成功:

svn --version

建立版本庫:

[root@VM_0_6_centos ~]# mkdir test;
[root@VM_0_6_centos ~]# cd test/
[root@VM_0_6_centos test]# svnadmin create svn;
[root@VM_0_6_centos test]# ll svn/
total 24
drwxr-xr-x 2 root root 4096 Apr 10 20:18 conf
drwxr-sr-x 6 root root 4096 Apr 10 20:18 db
-r--r--r-- 1 root root    2 Apr 10 20:18 format
drwxr-xr-x 2 root root 4096 Apr 10 20:18 hooks
drwxr-xr-x 2 root root 4096 Apr 10 20:18 locks
-rw-r--r-- 1 root root  229 Apr 10 20:18 README.txt

使用命令svnserve啟動服務

svnserve -d -r 目錄 --listen-port 埠號

–listen-port: 指定SVN監聽埠,不加此引數,SVN預設監聽3690

如果目錄指定的是create時的目錄,建立的是單庫svnserve。即:

svnserver -d -r svn

進入svn資料夾,會看到以下檔案:

[root@VM_0_6_centos test]# cd svn/
[root@VM_0_6_centos svn]# ls
conf  db  format  hooks  locks  README.txt

[root@VM_0_6_centos svn]# cd conf/
[root@VM_0_6_centos conf]# ls
authz  passwd  svnserve.conf

其中conf是我們關注的重點:

authz是授權檔案、passwd是密碼檔案、svnserve.conf則是svn伺服器的配置檔案。

先從passwd檔案開始看,passwd檔案定義了對svn伺服器的使用者密碼。例如:

[root@VM_0_6_centos conf]# cat 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]
user1=123
user2=123
# harry = harryssecret
# sally = sallyssecret

定義了使用者user1和user2,以及密碼123。

檢視authz檔案,其中註釋部分需要留意:

[root@VM_0_6_centos conf]# cat 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=user1
dev=user2
[/]
@admin=rw
user2=r

# 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]指示將等號後面的使用者成組。即類似於admin=user1,user2,user3,在下面部分則直接使用 @admin 呼叫。

後面部分指的是許可權的分配部分,/ 代表是整個目錄下的許可權分配,可以對使用者組、使用者、別名、*(代表任何人)進行許可權分配,包括’r,rw,w’和’’(無許可權)

接著看svnserve.conf檔案,看的時候直接看沒註釋的部分:

[root@VM_0_6_centos conf]# cat 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.apache.org/ for more information.

[general]
### The anon-access and auth-access options control access to the
### repository for unauthenticated (a.k.a. anonymous) users and
### authenticated users, respectively.
### Valid values are "write", "read", and "none".
### Setting the value to "none" prohibits both reading and writing;
### "read" allows read-only access, and "write" allows complete 
### read/write access to the repository.
### The sample settings below are the defaults and specify that anonymous
### users have read-only access to the repository, while authenticated
### users have read and write access to the repository.
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 = My First Repository
### The force-username-case option causes svnserve to case-normalize
### usernames before comparing them against the authorization rules in the
### authz-db file configured above.  Valid values are "upper" (to upper-
### case the usernames), "lower" (to lowercase the usernames), and
### "none" (to compare usernames as-is without case conversion, which
### is the default behavior).
# force-username-case = none

[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

anon-access = read代表匿名許可權只能讀,auth-access = write代表授權使用者可以進行寫操作。
password-db = passwd指定了密碼檔案的位置,authz-db = authz同理。realm指定版本庫的認證域,即在登入時提示的認證域名稱。
若兩個版本庫的 認證域相同,建議使用相同的使用者名稱口令資料檔案。預設是一個UUID。
簡單認證與安全層 (SASL) 是一個在網路協議中用來認證和資料加密的構架,一般不用。

SVN的基本使用

svn的使用一般都在windows下,首先Tortoisesvn下載Tortoisesvn和語言包:
https://tortoisesvn.net/downloads.html 按步驟安裝。

svn的使用其實概念上和git很類似。具體的命令在這裡我不多說。其中svn和git的區別有一點是svn對中文支援更加友好,入門的門檻相當於git會更加低一些,對許多非職能部門的小姐姐來說也可以快速上手,如果按上面的搭建好svn的伺服器,我們在windows下右鍵就可以直接使用,這裡建議看文末的參考文件。

在學習了基本使用後我產生了一個疑問:
客戶端svn上傳後,原始檔案在伺服器的什麼位置? 參考如下文章,一般情況下原始檔案會變成FSFS格式的自定義壓縮檔案,然後存在db下的revs和revprops資料夾。
https://blog.csdn.net/qq_29945729/article/details/52936900

git和svn的區別

其實在學習svn的過程中,這個疑問一直伴隨著我。

個人理解主要是這幾點:

  1. svn和git雖然都是版本控制,但是git更加偏向於分散式、而svn更加偏向於集中式。git的commit首先是對本地工作區的commit,然後再通過push推到集中的伺服器上。而svn的每一次commit都類似於直接進行push,那麼如果斷網,無法push到遠端的集中式程式碼庫,就不能進行正常的工作。
  2. svn對中文的支援很好,視覺化介面也更加優秀。相較而言,git則更加偏向技術這邊。svn支援專案管理,而git更加支援程式碼管理。
  3. svn裡分支(branch)是一個完整的目錄,且這個目錄擁有完整的實際檔案。而git裡的分支在融合前不會對實際檔案造成改變。

參考文件

http://www.runoob.com/svn/svn-tutorial.html
https://blog.csdn.net/mine_song/article/details/70770467
https://blog.csdn.net/hellow__world/article/details/72529022
https://help.github.com/en/articles/what-are-the-differences-between-subversion-and-git

相關文章