首先,感谢jsntghf和星辰的天空的好文分享,不是他们的文章,我估计需要花费更多的精力和时间。在这里我只是对他们文章的润色和自己测试遇到问题的标注。
Mac自带了svn服务器和客户端,所以只需要简单配置一下就可以使用
1. 创建svn repository
Shell代码
- svnadmin create /Users/mac22/svn/repository
- svnadmin: E000002: Repository creation failed
- svnadmin: E000002: Could not create top-level directory
- svnadmin: E000002: Can't create directory '/Users/mac22/svn/repository': No such file or directory
注:mac22是当前登录的用户名,你需要把它更换成你自己的用户名,在创建的时候确保已经svn/repository已经存在,上面的错误就是我没有创建svn/repository造成的
如果在终端输入svnadmin create /Users/mac22/svn/repository 代码,无提示说明创建成功,如下图所示:
2. 配置svn用户权限/Users/mac22/svn/repository/conf/目录下存在3个文件: authz、passwd、snvserve.conf
你可以选择使用文本编辑打开,也可以使用终端打开,我这里选择了后者
Shell 代码
- martins-mac:conf mac22$ cd /Users/mac22/svn/repository/conf
- martins-mac:conf mac22$ ls
- authz passwd svnserve.conf
- martins-mac:conf mac22$ vi authz
解释一下主要的几个命令:cd:进入某一个目录;ls:浏览当前目录的子目录 vi: 对文件进行编辑
authz 用户权限分配内容显示如下,然后按"i"键进行编辑:
- ### 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]
- # admins是组名,admin是组员,可以写多个,用”,“分隔.如admins=admin,master
- admins=admin
- # harry_and_sally = harry,sally
- # harry_sally_and_joe = harry,sally,&joe
-
- # [/foo/bar]
- # harry = rw
- # &joe = r
- # * =
- # 设置/目录权限
- [/]
- # 这里的意思是admins组的成员都有rw的权限,rw是读写得权限,也可以写成admin=rw,只赋予某一个用户有读写权限
- @admins=rw
-
- # 这里如果不写的意思是,下一级目录的用户不具备继承关系,也就是没有访问/的权限,* = r,就是别>的用户只能远观了, * = rw,就让其他的用户也有继承关系了,就是也可具备读写权限
- * =
-
-
- # [repository:/baz/fuz]
- # @harry_and_sally = rw
- # * = r
- ~
编辑之后,切换到英文输入法,然后点击esc,接着输入:wq保存,如果输入有误可以输入:q不保存直接退出
在终端输入vi passwd编辑passwd,svn用户和密码内容如下:
- ### 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]
- # authz 的用户名对应起来,后面是用户密码
- admin=123456
-
- # harry = harryssecret
- # sally = sallyssecret
修改之后记得保存
在终端输入vi svnserve.conf编辑svnserve.conf,svn的配置信息内容如下:
- ### 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 匿名用户有读的权限
- # 禁用匿名用户读的权限
- 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.
- # 这里需要放开注释,关联passwd.
- 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
- 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
3. 启动服务器
Shell 代码
- martins-mac:conf mac22$ svnserve -d -r /Users/mac22/svn/repository/
- martins-mac:conf mac22$
svnserve 启动svn服务;
-d 标示svnserve将会作为一个服务程序运行在后台 -r 标示将/Users/mac22/svn/repository/作为根目录(网络搜索的,忘求证)
4. 向svn库导入一个根目录
Shell代码
- martins-mac:conf mac22$ svn import /Users/mac22/svnroot/ svn://localhost:3690/svnroot --username admin --password 123456 -m "Initial import"
-
- Committed revision 1.
- martins-mac:conf mac22$
如果出现上面Committed revision 1.说明根目录创建成功
注:因为我之前已经创建了一个svn,所以这里为了区分用了一个端口3690,如果你之前没有创建过,就不需要用端口,直接svn://localhost/svnroot
5. 签出根目录
Shell代码
- martins-mac:conf mac22$ cd /Users/mac22/svncheckout/
- martins-mac:svncheckout mac22$ svn checkout svn://localhost/svnroot --username=admin --password=123456
- Checked out revision 1.
- martins-mac:svncheckout mac22$
解释一下上面代码,先进入你需要签出的目录,然后执行签出,成功之后,会看到如下图所示:
6. 其他svn客户端连接
我个人推荐使用CornerStone,虽然界面不太漂亮,但是比较实用
1. 添加Repository
2. 配置svn server
3. 等待片刻,提示成功,显示一下界面
到这里要告一段落,下篇将把用户权限控制补上,如有不便请见谅。如果有建议和问题请回复,谢谢!