原文地址:CentOS 7搭建SVN服务器

安装步骤如下:

安装 subversion

  1. # 安装 subversion
  2. $ yum install subversion
  3. # 测试当前版本
  4. $ svnserve --version
  5. svnserve, version 1.7.14 (r1542130)
  6. compiled Nov 20 2015, 19:25:09
  7. Copyright (C) 2013 The Apache Software Foundation.
  8. This software consists of contributions made by many people; see the NOTICE
  9. file for more information.
  10. Subversion is open source software, see http://subversion.apache.org/
  11. The following repository back-end (FS) modules are available:
  12. * fs_base : Module for working with a Berkeley DB repository.
  13. * fs_fs : Module for working with a plain file (FSFS) repository.
  14. Cyrus SASL authentication is available.

创建版本库

  1. # 创建文件夹
  2. $ mkdir -p /data/svn/tech
  3. # 创建版本库
  4. $ svnadmin create /data/svn/tech

执行以上命令之后会生成如下文件,每个文件介绍如下

  1. ├── conf
  2. ├── authz # 权限控制文件
  3. ├── passwd # 密码文件
  4. └── svnserve.conf # SVN服务配置文件
  5. ├── db
  6. ├── current
  7. ├── format
  8. ├── fsfs.conf
  9. ├── fs-type
  10. ├── min-unpacked-rev
  11. ├── revprops
  12. └── 0
  13. └── 0
  14. ├── revs
  15. └── 0
  16. └── 0
  17. ├── transactions
  18. ├── txn-current
  19. ├── txn-current-lock
  20. ├── txn-protorevs
  21. ├── uuid
  22. └── write-lock
  23. ├── format
  24. ├── hooks
  25. ├── post-commit.tmpl
  26. ├── post-lock.tmpl
  27. ├── post-revprop-change.tmpl
  28. ├── post-unlock.tmpl
  29. ├── pre-commit.tmpl
  30. ├── pre-lock.tmpl
  31. ├── pre-revprop-change.tmpl
  32. ├── pre-unlock.tmpl
  33. └── start-commit.tmpl
  34. ├── locks
  35. ├── db.lock
  36. └── db-logs.lock
  37. └── README.txt

配置账号密码

设置帐号密码

  1. # 在[users]块中添加用户和密码,格式:帐号=密码
  2. $ vim conf/passwd
  3. [users]
  4. user01=123456

设置权限

  1. $ vim conf/authz

在末尾添加如下代码:

  1. [/]
  2. user01=rw

这里的意思是根目录对 user01 用户可写,
添加完成之后代码如下所示

  1. ...
  2. # [repository:/baz/fuz]
  3. # @harry_and_sally = rw
  4. # * = r
  5. [/]
  6. user01=rw

配置服务器信息

修改svnserve.conf文件

  1. $ vim conf/svnserve.conf

打开下面几个注释

  1. auth-access = write # 授权用户可i读写
  2. password-db = passwd # 使用哪个文件作为账号文件
  3. authz-db = authz # 使用哪个文件作为权限文件
  4. realm = My Svn Repo # 认证空间名

启动svn版本库

  1. # 启动版本库
  2. $ svnserve -d -r /data/svn/svnrepos
  3. # 停止 svn 服务
  4. $ killall svnserve

(停止SVN命令 killall svnserve**)

修改启动的端口号

基于svnserve的,默认端口为3690,有时候,我们会因为防火墙或其它原因,需要修改这些默认端口。

下面根据不同的配置讲讲如何改变这些默认端口。

通过 svnserve -d -r /data/svn/repos 来提供服务

svnserve 加上 --listen-port 参数,比如 svnserve -d -r /data/svn/repos --listen-port 81(注:—listen-port中间无隔)

到此,在CentOS 7上搭建SVN服务器已经完成

安装 apache / dav 模块支持 apache 访问

  1. yum install httpd mod_dav_svn

修改 apache 端口号, 并不对外访问, 监听本地的 9278 端口

/etc/httpd/conf/httpd.conf

  1. port 127.0.0.1:9278

svn 配置

  1. <Location /svn>
  2. DAV svn
  3. SVNPath /svn/root/path
  4. AuthType Basic
  5. AuthName "Authorization Realm"
  6. AuthUserFile /svn/root/path/conf/passwdfile
  7. AuthzSVNAccessFile /svn/root/path/conf/authz
  8. Require valid-user
  9. </Location>

附录

conf/svnserve.conf 文件

  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. ### Visit http://subversion.apache.org/ for more information.
  6. [general]
  7. ### The anon-access and auth-access options control access to the
  8. ### repository for unauthenticated (a.k.a. anonymous) users and
  9. ### authenticated users, respectively.
  10. ### Valid values are "write", "read", and "none".
  11. ### Setting the value to "none" prohibits both reading and writing;
  12. ### "read" allows read-only access, and "write" allows complete
  13. ### read/write access to the repository.
  14. ### The sample settings below are the defaults and specify that anonymous
  15. ### users have read-only access to the repository, while authenticated
  16. ### users have read and write access to the repository.
  17. anon-access = none
  18. auth-access = write
  19. ### The password-db option controls the location of the password
  20. ### database file. Unless you specify a path starting with a /,
  21. ### the file's location is relative to the directory containing
  22. ### this configuration file.
  23. ### If SASL is enabled (see below), this file will NOT be used.
  24. ### Uncomment the line below to use the default password file.
  25. password-db = passwd
  26. ### The authz-db option controls the location of the authorization
  27. ### rules for path-based access control. Unless you specify a path
  28. ### starting with a /, the file's location is relative to the the
  29. ### directory containing this file. If you don't specify an
  30. ### authz-db, no path-based access control is done.
  31. ### Uncomment the line below to use the default authorization file.
  32. authz-db = authz
  33. ### This option specifies the authentication realm of the repository.
  34. ### If two repositories have the same authentication realm, they should
  35. ### have the same password database, and vice versa. The default realm
  36. ### is repository's uuid.
  37. realm = Liexiang Repository
  38. ### The force-username-case option causes svnserve to case-normalize
  39. ### usernames before comparing them against the authorization rules in the
  40. ### authz-db file configured above. Valid values are "upper" (to upper-
  41. ### case the usernames), "lower" (to lowercase the usernames), and
  42. ### "none" (to compare usernames as-is without case conversion, which
  43. ### is the default behavior).
  44. # force-username-case = none
  45. [sasl]
  46. ### This option specifies whether you want to use the Cyrus SASL
  47. ### library for authentication. Default is false.
  48. ### This section will be ignored if svnserve is not built with Cyrus
  49. ### SASL support; to check, run 'svnserve --version' and look for a line
  50. ### reading 'Cyrus SASL authentication is available.'
  51. # use-sasl = true
  52. ### These options specify the desired strength of the security layer
  53. ### that you want SASL to provide. 0 means no encryption, 1 means
  54. ### integrity-checking only, values larger than 1 are correlated
  55. ### to the effective key length for encryption (e.g. 128 means 128-bit
  56. ### encryption). The values below are the defaults.
  57. # min-encryption = 0
  58. # max-encryption = 256