搭建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的过程中,这个疑问一直伴随着我。
个人理解主要是这几点:
- svn和git虽然都是版本控制,但是git更加偏向于分布式、而svn更加偏向于集中式。git的commit首先是对本地工作区的commit,然后再通过push推到集中的服务器上。而svn的每一次commit都类似于直接进行push,那么如果断网,无法push到远程的集中式代码库,就不能进行正常的工作。
- svn对中文的支持很好,可视化界面也更加优秀。相较而言,git则更加偏向技术这边。svn支持项目管理,而git更加支持代码管理。
- 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