mac下配置svn服务器详解及用户的权限管理

来源:互联网 发布:mac怎么切换苹果系统 编辑:程序博客网 时间:2024/06/07 20:10

首先,感谢jsntghf和星辰的天空的好文分享,不是他们的文章,我估计需要花费更多的精力和时间。在这里我只是对他们文章的润色和自己测试遇到问题的标注。

Mac自带了svn服务器和客户端,所以只需要简单配置一下就可以使用

1. 创建svn repository

Shell代码

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. svnadmin create /Users/mac22/svn/repository  
  2. svnadmin: E000002: Repository creation failed  
  3. svnadmin: E000002: Could not create top-level directory  
  4. 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 代码

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. martins-mac:conf mac22$ cd /Users/mac22/svn/repository/conf  
  2. martins-mac:conf mac22$ ls  
  3. authz   passwd  svnserve.conf  
  4. martins-mac:conf mac22$ vi authz  

解释一下主要的几个命令:cd:进入某一个目录;ls:浏览当前目录的子目录 vi: 对文件进行编辑


authz 用户权限分配内容显示如下,然后按"i"键进行编辑:

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. ### This file is an example authorization file for svnserve.  
  2. ### Its format is identical to that of mod_authz_svn authorization  
  3. ### files.  
  4. ### As shown below each section defines authorizations for the path and  
  5. ### (optional) repository specified by the section name.  
  6. ### The authorizations follow. An authorization line can refer to:  
  7. ###  - a single user,  
  8. ###  - a group of users defined in a special [groups] section,  
  9. ###  - an alias defined in a special [aliases] section,  
  10. ###  - all authenticated users, using the '$authenticated' token,  
  11. ###  - only anonymous users, using the '$anonymous' token,  
  12. ###  - anyone, using the '*' wildcard.  
  13. ###  
  14. ### A match can be inverted by prefixing the rule with '~'. Rules can  
  15. ### grant read ('r') access, read-write ('rw') access, or no access  
  16. ### ('').  
  17.   
  18. [aliases]  
  19. # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average  
  20.   
  21. # 用户组  
  22. [groups]   
  23. # admins是组名,admin是组员,可以写多个,用”,“分隔.如admins=admin,master  
  24. admins=admin   
  25. # harry_and_sally = harry,sally  
  26. # harry_sally_and_joe = harry,sally,&joe  
  27.   
  28. # [/foo/bar]  
  29. # harry = rw  
  30. # &joe = r  
  31. # * =  
  32. # 设置/目录权限  
  33. [/]  
  34. # 这里的意思是admins组的成员都有rw的权限,rw是读写得权限,也可以写成admin=rw,只赋予某一个用户有读写权限  
  35. @admins=rw   
  36.   
  37. # 这里如果不写的意思是,下一级目录的用户不具备继承关系,也就是没有访问/的权限,* = r,就是别>的用户只能远观了, * = rw,就让其他的用户也有继承关系了,就是也可具备读写权限  
  38. * =   
  39.   
  40.   
  41. # [repository:/baz/fuz]  
  42. # @harry_and_sally = rw  
  43. # * = r  
  44. ~      

编辑之后,切换到英文输入法,然后点击esc,接着输入:wq保存,如果输入有误可以输入:q不保存直接退出


在终端输入vi passwd编辑passwd,svn用户和密码内容如下:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. ### This file is an example password file for svnserve.  
  2. ### Its format is similar to that of svnserve.conf. As shown in the  
  3. ### example below it contains one section labelled [users].  
  4. ### The name and password for each user follow, one account per line.  
  5.   
  6. [users]  
  7. # authz 的用户名对应起来,后面是用户密码  
  8. admin=123456   
  9.   
  10. harry = harryssecret  
  11. sally = sallyssecret  

修改之后记得保存

在终端输入vi svnserve.conf编辑svnserve.conf,svn的配置信息内容如下:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. ### This file controls the configuration of the svnserve daemon, if you  
  2. ### use it to allow access to this repository.  (If you only allow  
  3. ### access through http: and/or file: URLs, then this file is  
  4. ### irrelevant.)  
  5.   
  6. ### Visit http://subversion.apache.org/ for more information.  
  7.   
  8. [general]  
  9. ### The anon-access and auth-access options control access to the  
  10. ### repository for unauthenticated (a.k.a. anonymous) users and  
  11. ### authenticated users, respectively.  
  12. ### Valid values are "write", "read", and "none".  
  13. ### Setting the value to "none" prohibits both reading and writing;  
  14. ### "read" allows read-only access, and "write" allows complete   
  15. ### read/write access to the repository.  
  16. ### The sample settings below are the defaults and specify that anonymous  
  17. ### users have read-only access to the repository, while authenticated  
  18. ### users have read and write access to the repository.  
  19. anon-access = read 匿名用户有读的权限  
  20. # 禁用匿名用户读的权限   
  21. anon-access = none  
  22. # 登录用户的写的权限  
  23. auth-access = write  
  24. ### The password-db option controls the location of the password  
  25. ### database file.  Unless you specify a path starting with a /,  
  26. ### the file's location is relative to the directory containing  
  27. ### this configuration file.  
  28. ### If SASL is enabled (see below), this file will NOT be used.  
  29. ### Uncomment the line below to use the default password file.  
  30. # 这里需要放开注释,关联passwd.    
  31. password-db = passwd  
  32. ### The authz-db option controls the location of the authorization  
  33. ### rules for path-based access control.  Unless you specify a path  
  34. ### starting with a /, the file's location is relative to the the  
  35. ### directory containing this file.  If you don't specify an  
  36. ### authz-db, no path-based access control is done.  
  37. ### Uncomment the line below to use the default authorization file.  
  38. # 这里需要放开注释,关联authz  
  39. authz-db = authz  
  40. ### This option specifies the authentication realm of the repository.  
  41. ### If two repositories have the same authentication realm, they should  
  42. ### have the same password database, and vice versa.  The default realm  
  43. ### is repository's uuid.  
  44. realm = My First Repository  
  45. ### The force-username-case option causes svnserve to case-normalize  
  46. ### usernames before comparing them against the authorization rules in the  
  47. ### authz-db file configured above.  Valid values are "upper" (to upper-  
  48. ### case the usernames), "lower" (to lowercase the usernames), and  
  49. ### "none" (to compare usernames as-is without case conversion, which  
  50. ### is the default behavior).  
  51. force-username-case = none  
  52.   
  53. [sasl]  
  54. ### This option specifies whether you want to use the Cyrus SASL  
  55. ### library for authentication. Default is false.  
  56. ### This section will be ignored if svnserve is not built with Cyrus  
  57. ### SASL support; to check, run 'svnserve --version' and look for a line  
  58. ### reading 'Cyrus SASL authentication is available.'  
  59. use-sasl = true  
  60. ### These options specify the desired strength of the security layer  
  61. ### that you want SASL to provide. 0 means no encryption, 1 means  
  62. ### integrity-checking only, values larger than 1 are correlated  
  63. ### to the effective key length for encryption (e.g. 128 means 128-bit  
  64. ### encryption). The values below are the defaults.  
  65. min-encryption = 0  
  66. max-encryption = 256  


3. 启动服务器

Shell 代码

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. martins-mac:conf mac22$ svnserve -d -r /Users/mac22/svn/repository/  
  2. martins-mac:conf mac22$   
svnserve 启动svn服务; -d 标示svnserve将会作为一个服务程序运行在后台 -r 标示将/Users/mac22/svn/repository/作为根目录(网络搜索的,忘求证)

4. 向svn库导入一个根目录

Shell代码

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. martins-mac:conf mac22$ svn import /Users/mac22/svnroot/ svn://localhost:3690/svnroot --username admin --password 123456 -m "Initial import"  
  2.   
  3. Committed revision 1.  
  4. martins-mac:conf mac22$   
如果出现上面Committed revision 1.说明根目录创建成功

注:因为我之前已经创建了一个svn,所以这里为了区分用了一个端口3690,如果你之前没有创建过,就不需要用端口,直接svn://localhost/svnroot


5. 签出根目录

Shell代码

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. martins-mac:conf mac22$ cd /Users/mac22/svncheckout/  
  2. martins-mac:svncheckout mac22$ svn checkout svn://localhost/svnroot --username=admin --password=123456  
  3. Checked out revision 1.  
  4. martins-mac:svncheckout mac22$   
解释一下上面代码,先进入你需要签出的目录,然后执行签出,成功之后,会看到如下图所示:



6. 其他svn客户端连接


我个人推荐使用CornerStone,虽然界面不太漂亮,但是比较实用

1. 添加Repository


2. 配置svn server



3. 等待片刻,提示成功,显示一下界面


到这里要告一段落,下篇将把用户权限控制补上,如有不便请见谅。如果有建议和问题请回复,谢谢!

0 0