CentOS7 搭建 SVN 服务器

介绍SVN:

SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS、CVS,它采用了分支管理系统,它的设计目标就是取代CVS。互联网上很多版本控制服务已从CVS迁移到Subversion。说得简单一点SVN就是用于多个人共同开发同一个项目,共用资源的目的。

安装SVN:

[root@centos7 ~]# 
[root@centos7 ~]# yum install -y subversion
出现如下问题:
[root@centos7 ~]# 
[root@centos7 ~]# yum install -y subversion
已加载插件:fastestmirror, langpacks
/var/run/yum.pid 已被锁定,PID 为 4137 的另一个程序正在运行。
Another app is currently holding the yum lock; waiting for it to exit...
  另一个应用程序是:PackageKit
    内存: 99 M RSS (502 MB VSZ)
    已启动: Fri Mar 22 18:57:37 2019 - 00:52之前
    状态  :睡眠中,进程ID:4137
Another app is currently holding the yum lock; waiting for it to exit...
  另一个应用程序是:PackageKit
    内存: 99 M RSS (502 MB VSZ)
    已启动: Fri Mar 22 18:57:37 2019 - 00:54之前
    状态  :睡眠中,进程ID:4137
原因:
这是因为yum处于锁定状态中。可以通过强制关掉yum进程来解决这个问题,直接在终端运行 rm -f /var/run/yum.pid 将该文件删除,然后再次运行yum即可。
解决方法:
[root@centos7 ~]# sudo rm -rf /var/run/yum.pid
[root@centos7 ~]#

创建一个存储 SVN 的目录

新建一个目录用于存储SVN目录、一般存放在 /var/local/

[root@centos7 ~]# cd /usr/local/
[root@centos7 local]
[root@centos7 local]# mkdir svn

新建一个测试仓库

[root@centos7 local]# cd svn/
[root@centos7 svn]# svnadmin create test

然后查看当前目录下、会发现多了一个 test 文件夹、然后进入到 test 下。

[root@centos7 svn]# 
[root@centos7 svn]# ll
# 总用量 4
# drwxr-xr-x. 6 root root 4096 3月  22 21:13 test
[root@centos7 svn]# cd test/
[root@centos7 test]# ll
# 总用量 24
# drwxr-xr-x. 2 root root 4096 3月  22 21:13 conf
# drwxr-sr-x. 6 root root 4096 3月  22 21:13 db
# -r--r--r--. 1 root root    2 3月  22 21:13 format
# drwxr-xr-x. 2 root root 4096 3月  22 21:13 hooks
# drwxr-xr-x. 2 root root 4096 3月  22 21:13 locks
# -rw-r--r--. 1 root root  229 3月  22 21:13 README.txt
[root@centos7 test]# 

以下关于目录的说明:

conf目录:  是这个仓库配置文件(仓库用户访问账户,权限)
format目录:是一个文本文件,里边只放了一个整数,表示当前文件库配置的版本号
hooks目录: 放置hook脚步文件的目录
locks目录: 用来放置subversion的db锁文件和db_logs锁文件的目录,用来追踪存取文件库的客户端

配置测试仓库

[root@centos7 test]# 
[root@centos7 test]# cd conf/
[root@centos7 conf]# ll
# 总用量 12
# -rw-r--r--. 1 root root 1080 3月  22 21:13 authz
# -rw-r--r--. 1 root root  309 3月  22 21:13 passwd
# -rw-r--r--. 1 root root 3090 3月  22 21:13 svnserve.conf
    
1、修改SVN服务的配置文件svnserver.conf
[root@centos7 conf]# vim svnserve.conf
# 修改四处
# 分别为 19、20、27、34行
具体如下:    
 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 auth-access = write     ##注意前边不要有空格,要顶齐
 21 ### The password-db option controls the location of the password
 22 ### database file.  Unless you specify a path starting with a /,
 23 ### the file's location is relative to the directory containing
 24 ### this configuration file.
 25 ### If SASL is enabled (see below), this file will NOT be used.
 26 ### Uncomment the line below to use the default password file.
 27 password-db = passwd    ##注意前边不要有空格,要顶齐
 28 ### The authz-db option controls the location of the authorization
 29 ### rules for path-based access control.  Unless you specify a path
 30 ### starting with a /, the file's location is relative to the the
 31 ### directory containing this file.  If you don't specify an
 32 ### authz-db, no path-based access control is done.
 33 ### Uncomment the line below to use the default authorization file.
 34 authz-db = authz        ##注意前边不要有空格,要顶齐
 35 ### This option specifies the authentication realm of the repository.
 36 ### If two repositories have the same authentication realm, they should
 37 ### have the same password database, and vice versa.  The default realm
 38 ### is repository's uuid.
 39 # realm = My First Repository
 40 ### The force-username-case option causes svnserve to case-normalize
 41 ### usernames before comparing them against the authorization rules in the
 42 ### authz-db file configured above.  Valid values are "upper" (to upper-
 43 ### case the usernames), "lower" (to lowercase the usernames), and
 44 ### "none" (to compare usernames as-is without case conversion, which
 45 ### is the default behavior).
 46 # force-username-case = none
2、配置访问用户及密码
[root@centos7 conf]# 
[root@centos7 conf]# vim passwd
# 按内容中已知的规则添加用户密码
具体如下:
  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 # harry = harryssecret
  8 # sally = sallyssecret
  9 root = root
 10 test1 = test
 11 test2 = test
3、配置新用户的授权文件
[root@centos7 conf]# 
[root@centos7 conf]# vim authz 
具体如下:
  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 [groups]
 22 # harry_and_sally = harry,sally
 23 # harry_sally_and_joe = harry,sally,&joe
 24 
 25 # [/foo/bar]
 26 # harry = rw
 27 # &joe = r
 28 # * =
 29 
 30 # [repository:/baz/fuz]
 31 # @harry_and_sally = rw
 32 # * = r
 33 
 34 admin = root,test1
 35 user = test2
 36 [/svn/test]
 37 @admin = rw
 38 @user = r
 39 * = 
备注:
admin = root,test1  # 创建admin组,组成员为:root,test1
user = test2        # 创建用户组,用户成员:test2
[/svn/test]         # 赋予根权限,为了便于管理和权限的控制,可以把权限细化到版本库中相应的目录
@admin = rw         # admin组有读写的权限
@user = r           # user组只有读的权限
*=                  # 表示除了上面设置的权限用户组以外,其他所有用户都设置空权限,空权限表示禁止访问本目录,这很重要一定要加上。

启动svn服务

[root@centos7 conf]# svnserve -d -r /usr/local/svn/
[root@centos7 conf]# 
# 没有出错边是成功、如果出现以下错误、则需先关闭kill进程、然后重新启动。
# 具体操作如下:
[root@centos7 conf]# svnserve -d -r /usr/local/svn/
# svnserve: E000098: 不能绑定服务器套接字: 地址已在使用
[root@centos7 conf]# 
[root@centos7 conf]# ps aux | grep svn
# root      8682  0.0  0.0 199280  1028 ?        Ss   09:29   0:00 svnserve -d -r /usr/local/svn/
# root     24448  0.0  0.0 112656   968 pts/1    S+   09:31   0:00 grep --color=auto svn
[root@centos7 conf]# 
[root@centos7 conf]# kill 8682
[root@centos7 conf]# ps aux | grep svn
# root     24507  0.0  0.0 112656   968 pts/1    S+   09:32   0:00 grep --color=auto svn
[root@centos7 conf]# 
[root@centos7 conf]# svnserve -d -r /usr/local/svn/
[root@centos7 conf]#

版权声明:本文为laowenBlog原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/laowenBlog/p/10582738.html