Linux下使用svn创建仓库

假设已经Linux搭建了svn服务器

创建仓库

语法:svnadmin create /directory
我是在 /data/svnrepos下新建myproject仓库

1
2
3
cd /data
mkdir svnrepos
svnadmin create /data/svnrepos/myproject

仓库创建成功以后,会出现一个仓库名字的文件夹 文件夹下面有以下几个文件和目录

1
2
3
4
5
6
7
myproject
|-conf
|-db
|-format
|-hooks
|-locks
|-README.txt

其中conf文件夹下面包含三个重要文件 authz passwd svnserve.conf

1
2
3
4
conf
|-authz
|-passwd
|-svnserve.conf

修改配置文件

增加用户

修改passwd文件
passwd的配置语法格式: 用户名=密码

1
2
3
4
5
6
7
8
9
10
11
# vi 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
xiaozhang = 123 #修改处

之后可以通过帐号xiaozhang密码123进行操作。

配置用户权限

修改authz文件
注意:

  • 权限配置文件中出现的用户名必须已在用户配置文件中定义。
  • 对权限配置文件的修改立即生效,不必重启svn。

用户组格式:

1
2
[groups]
<用户组名> = <用户1>,<用户2>

其中,1个用户组可以包含1个或多个用户,用户间以逗号分隔。
版本库目录格式:

1
2
3
[<版本库>:/项目/目录]
@<用户组名> = <权限>
<用户名> = <权限>

其中,方框号内部分可以有多种写法:
/表示根目录及以下。根目录是svnserve启动时指定的,我们指定为/data/svnrepos/myproject。这样,/就是表示对全部版本库设置权限。
repos1:/ 表示对版本库1设置权限
repos2:/a 表示对版本库2中的a项目设置权限
repos2:/a/b 表示对版本库2中的a项目的b目录设置权限
权限主体可以是用户组、用户或,用户组在前面加@,表示全部用户。权限可以是w、r、wr和空,空表示没有任何权限。

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
# 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

[/] #修改处
xiaozhang = rw #修改处

意思是,在根目录下xiaozhang用户拥有读写权限。

修改svn启动项参数

修改svnserve.conf文件
svn服务配置文件为版本库目录中的文件conf/svnserve.conf。该文件仅由一个[general]配置段组成

[general]配置段中配置行格式如下:
<配置项> = <值>

配置项分为以下5项:
1.anon-access 控制非鉴权用户访问版本库的权限。取值范围为”write”、”read”和”none”。
即”write”为可读可写,”read”为只读,”none”表示无访问权限。
缺省值:read

2.auth-access 控制鉴权用户访问版本库的权限。取值范围为”write”、”read”和”none”。
即”write”为可读可写,”read”为只读,”none”表示无访问权限。
缺省值:write

3.password-db 指定用户名口令文件名。除非指定绝对路径,否则文件位置为相对conf
目录的相对路径。
缺省值:passwd

4.authz-db 指定权限配置文件名,通过该文件可以实现以路径为基础的访问控制。
除非指定绝对路径,否则文件位置为相对conf目录的相对路径。
缺省值:authz

5.realm 指定版本库的认证域,即在登录时提示的认证域名称。若两个版本库的
认证域相同,建议使用相同的用户名口令数据文件。
缺省值:一个UUID(Universal Unique IDentifier,全局唯一标示)

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
46
47
48
# 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 = none #修改处
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

[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

启动服务

语法:svnserve -d -r svn仓库目录
svnserve -d -r /data/svnrepos/myproject/
如果启动提示svnserve: Can't bind server socket: Address already in use,是由于已经启动了svn,你的配置文件应该已经生效了。

查看svn进程
ps -ef|grep svn

访问svn服务

使用svn客户端 输入地址 svn://ip/myproject 就可以访问到这个仓库。

坚持原创技术分享,您的支持将鼓励我继续创作!