Centos6.8下搭建SVN服务器

一、SVN简介

Subversion是一个自由,开源的版本控制系统。Subversion将文件存放在中心版本库里。这个版本库很像一个普通的文件服务器,不同的是,它可以记录每一次文件和目录的修改情况。这样就可以籍此将数据恢复到以前的版本,并可以查看数据的更改细节。Subversion是Apache基金会下的一个项目,官网 https://subversion.apache.org/

二、编译安装

  1. # yum -y install subversion
  2.  
  3. 已加载插件:fastestmirror, refresh-packagekit, security
  4. 设置安装进程
  5. Determining fastest mirrors
  6. epel/metalink                                            | 5.0 kB     00:00     
  7.  * base: mirrors.tuna.tsinghua.edu.cn
  8.  * epel: mirrors.neusoft.edu.cn
  9.  * extras: mirrors.sina.cn
  10.  * updates: mirrors.tuna.tsinghua.edu.cn
  11. base                                                     | 3.7 kB     00:00     
  12. epel                                                     | 4.3 kB     00:00     
  13. http://mirrors.neusoft.edu.cn/epel/6/x86_64/repodata/fbb9fc8bfc22c43a2d3c8732e05e3177ae610c87f0354fbf4e3f085b9084b371-primary.sqlite.bz2: [Errno 12] Timeout on http://mirrors.neusoft.edu.cn/epel/6/x86_64/repodata/fbb9fc8bfc22c43a2d3c8732e05e3177ae610c87f0354fbf4e3f085b9084b371-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds')
  14. 尝试其他镜像。
  15. epel/primary_db                                          | 5.8 MB     00:06     
  16. extras                                                   | 3.4 kB     00:00     
  17. extras/primary_db                                        |  37 kB     00:00     
  18. updates                                                  | 3.4 kB     00:00     
  19. updates/primary_db                                       | 749 kB     00:00     
  20. 解决依赖关系
  21. --> 执行事务检查
  22. ---> Package subversion.x86_64 0:1.6.11-15.el6_7 will be 安装
  23. --> 处理依赖关系 perl(URI) >= 1.17,它被软件包 subversion-1.6.11-15.el6_7.x86_64 需要
  24. --> 执行事务检查
  25. ---> Package perl-URI.noarch 0:1.40-2.el6 will be 安装
  26. --> 完成依赖关系计算
  27.  
  28. 依赖关系解决
  29.  
  30. ================================================================================
  31.  软件包             架构           版本                      仓库          大小
  32. ================================================================================
  33. 正在安装:
  34.  subversion         x86_64         1.6.11-15.el6_7           base         2.3 M
  35. 为依赖而安装:
  36.  perl-URI           noarch         1.40-2.el6                base         117 k
  37.  
  38. 事务概要
  39. ================================================================================
  40. Install       2 Package(s)
  41.  
  42. 总下载量:2.4 M
  43. Installed size: 12 M
  44. 下载软件包:
  45. (1/2): perl-URI-1.40-2.el6.noarch.rpm                    | 117 kB     00:00     
  46. (2/2): subversion-1.6.11-15.el6_7.x86_64.rpm             | 2.3 MB     00:02     
  47. --------------------------------------------------------------------------------
  48. 总计                                            1.0 MB/s | 2.4 MB     00:02     
  49. 运行 rpm_check_debug 
  50. 执行事务测试
  51. 事务测试成功
  52. 执行事务
  53.   正在安装   : perl-URI-1.40-2.el6.noarch                                   1/2 
  54.   正在安装   : subversion-1.6.11-15.el6_7.x86_64                            2/2 
  55.   Verifying  : perl-URI-1.40-2.el6.noarch                                  1/2 
  56.   Verifying  : subversion-1.6.11-15.el6_7.x86_64                           2/2 
  57.  
  58. 已安装:
  59.   subversion.x86_64 0:1.6.11-15.el6_7                                           
  60.  
  61. 作为依赖被安装:
  62.   perl-URI.noarch 0:1.40-2.el6                                                  
  63.  
  64. 完毕!

三、配置SVN

1、创建SVN版本库

# mkdir -p /etc/svn/repos                        ##创建版本库
# svnadmin create /etc/svn/repos/                ##创建SVN版本库
# ls -la /etc/svn/repos/
总用量 32
drwxr-xr-x. 6 root root 4096 7月   8 17:49 .
drwxr-xr-x. 3 root root 4096 7月   8 17:49 ..
drwxr-xr-x. 2 root root 4096 7月   8 17:49 conf    ##存储版本库配置文件的目录
drwxr-sr-x. 6 root root 4096 7月   8 17:49 db      ##SVN所要管理的所有受版本控制的数据
-r--r--r--. 1 root root    2 7月   8 17:49 format  ##用来表示版本库布局版本号的整数
drwxr-xr-x. 2 root root 4096 7月   8 17:49 hooks   ##存储钩子脚本模版的目录
drwxr-xr-x. 2 root root 4096 7月   8 17:49 locks   ##存储SVN版本库锁定数据的目录
-rw-r--r--. 1 root root  229 7月   8 17:49 README.txt

2、配置版本库

# cat /etc/svn/repos/conf/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 = 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 ##认证命名空间,SVN会在认证提示里显示,且作为凭证缓存的关键字

[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、配置passwd

# cat /etc/svn/repos/conf/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  ##前面用户名,后面密码
所以可以这样输入:

vi passwd
[users]
yujiankd = 123456
#用户名=密码

4、配置authz权限

vi authz
[svntest:/]
yujiankd = rw
# 给svntest的版本库repositary添加一个用户zhangskd,权限为读写。


5、配置svnserve.conf

vi svnserve.conf
取消一些注释
[general]
anon-access = none                    #非授权用户无法访问
auth-access = write                   #授权用户有写权限
password-db = passwd                  #密码数据所在目录
authz-db = authz                      #认证数据所在目录

四、启动SVN的独立服务器

1. 启动svnserve,并制定SVN的根目录

svnserve -d -r /opt/svn  

2. 查看服务是否启动

  1. ps aux | grep svnserve
  2. netstat -tunlp | grep svnserve 
  3. svnserve的几个参数说明:
  4. svnserve — serve for the svn repository access method
  5. svnserve allows access to subversion repositaries using the svn network protocol.
  6. -d, --daemon
  7.         Causes svnserve to run in daemon mode. svnserve backgrounds itself and accepts
  8.         and serves TCP/IP connections on the svn port (3690, by default).
  9. --listen-port=port
  10.         Causes svnserve to listen on port when run in daemon mode.
  11. -r root, --root=root
  12.         Sets the virtual root for repositaries served by svnserve. The pathname in URLs
  13.         provided by the client will be interpreted relative to this root, and will not be allowed
  14.         to escape this root.

(五)测试SVN的独立服务器

1. Windows下用TortoiseSVN测试
新建一个svntest目录,右键选择Checkout,在URL of repositary中输入svnserve的IP和
访问项目的名字:

svn://192.168.1.1/svntest 

然后跳出验证窗口,输入配置的用户名和密码即可。
注意:如果服务器没关闭防火墙就会出现不能连接!

service iptables stop 

2. CentOS下测试

svn checkout svn://192.168.1.1/svntest 

发布日期:

所属分类: Linux/Centos/Os, 后端 标签: