CentOS 下搭建SVN

CentOS 7下搭建配置SVN服务器

1. 安装

CentOS通过yum安装subversion。

$ sudo yum install subversion

 subversion安装在/bin目录:

$ which svnserve
/bin/svnserve

检查一下subversion是否安装成功。

$ svnserve --version
svnserve, version 1.7.14 (r1542130)
  compiled Nov 20 2015, 19:25:09

Copyright (C) 2013 The Apache Software Foundation.
This software consists of contributions made by many people; see the NOTICE
file for more information.
Subversion is open source software, see http://subversion.apache.org/

The following repository back-end (FS) modules are available:

* fs_base : Module for working with a Berkeley DB repository.
* fs_fs : Module for working with a plain file (FSFS) repository.

Cyrus SASL authentication is available.
 ===========================================================================
以下两种命令均可以查看安装包情况
rpm -qi subversion
yum info subversion

2. 建立版本库

subversion默认以/var/svn作为数据根目录,可以通过/etc/sysconfig/svnserve修改这个默认位置。

$ systemctl cat svnserve.service
# /usr/lib/systemd/system/svnserve.service
[Unit]
Description=Subversion protocol daemon
After=syslog.target network.target

[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/svnserve
ExecStart=/usr/bin/svnserve --daemon --pid-file=/run/svnserve/svnserve.pid $OPTIONS

[Install]
WantedBy=multi-user.target

$ cat /etc/sysconfig/svnserve
# OPTIONS is used to pass command-line arguments to svnserve.

# Specify the repository location in -r parameter:
OPTIONS="-r /var/svn"

我们修改/etc/sysconfig/svnserver将默认目录指定到/opt/svn。

$ cat /etc/sysconfig/svnserve
OPTIONS="-r /opt/svn"

使用svnadmin建立版本库spring-hello-world。

$ sudo mkdir -p /opt/svn
$ sudo svnadmin create /opt/svn/spring-hello-world

$ ll /opt/svn/
drwxr-xr-x. 6 root root 80 Nov 10 14:42 spring-hello-world

$ ll /opt/svn/spring-hello-world/
drwxr-xr-x. 2 root root  51 Nov 10 14:42 conf
drwxr-sr-x. 6 root root 4096 Nov 10 14:42 db
-r--r--r--. 1 root root    2 Nov 10 14:42 format
drwxr-xr-x. 2 root root 4096 Nov 10 14:42 hooks
drwxr-xr-x. 2 root root  39 Nov 10 14:42 locks
-rw-r--r--. 1 root root  229 Nov 10 14:42 README.txt

3. 配置

编辑用户文件passwd,新增两个用户:admin和guest。

$ cat /opt/svn/spring-hello-world/conf/passwd 
[users]
admin = admin
guest = guest

编辑权限文件authz,用户admin设置可读写权限,guest设置只读权限。

$ cat /opt/svn/spring-hello-world/conf/authz 
[/]
admin = rw
guest = r

编辑svnserve.conf:

$ cat /opt/svn/spring-hello-world/conf/svnserve.conf 
[general]
anon-access = none                     #控制非鉴权用户访问版本库的权限
auth-access = write                    #控制鉴权用户访问版本库的权限
password-db = passwd                   #指定用户名口令文件名
authz-db = authz                       #指定权限配置文件名
realm = spring-hello-world             #指定版本库的认证域,即在登录时提示的认证域名称

 4. SVN服务

启动SVN服务。

$ sudo systemctl start svnserve.service

或者 svnserve -d -r /opt/svn/

检查服务是否启动成功。

$ ps aux | grep svn
root      16349  0.0  0.1 162180   900 ?        Ss   15:01   0:00 /usr/bin/svnserve --daemon --pid-file=/run/svnserve/svnserve.pid -r /opt/svn

通过netstat可以看到SVN打开了3690端口。

$ sudo netstat -tnlp
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      16349/svnserve 

 5. 客户端测试

客户端可以通过TortoriseSVN测试。

这时候可能会防火墙问题。如果是防火墙问题,会提示无法连接。

客户端用telnet无法连接。

C:Temp>telnet 192.168.12.59 360

用systemctl检查服务器的防火墙配置:

$ firewall-cmd --list-all
public (default, active)
  interfaces: eno16777736 eno33554984
  sources: 
  services: dhcpv6-client ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 

可以看到,没有telnet服务和3690端口。增加telnet服务器和3690端口:

$ sudo firewall-cmd --permanent --add-service=telnet
$ sudo firewall-cmd --permanent --add-port=3690/tcp
$ sudo firewall-cmd --reload

客户端再用telnet,应该就可以了。

 ===========================================================================

常见问题:

1、不知道该怎么设置 svn://url 这个路径

2、三个需要设置的文件,其中authz这个里面的[repos:/]这个到底该怎么设置

3、认证失败问题出在哪里?

4、svn import 目录1 "svn://localhost/目录2" -m "first version" 目录2到底怎么设置?

5、import 的时候出现“条目从本地编码转换到UTF8失败”

6、服务器端都没问题了,但是客户端不能连接主机

下面就根据这几个问题,一一解答:

1、svn可以分为单个或多个版本库,假设:

     版本库目录为 /data/svndata/repos1

     启动程序如果是:svnserve -d -r /data/svndata/repos1  

                            这代表你当前svn只为repos1这个版本库工作,客户端访问直接svn://IP/ 就可以了,后面不跟目录

     启动程序如果是:svnserve -d -r /data/svndata/            

                            这代表你当前svn可以多版本库运行,客户端访问就需要加上 svn://IP/repos1 这样才能访问repos1版本库


2、第一个问题是对应的

     如果是一个版本库,那应该设置成如下:

     [groups]

     admin = user1,user2

     [/]

     @admin=rw

     如果是多个版本库,那就应该设置成这样:

     [groups]

     admin = user1,user2

     [repos1:/]

     @admin=rw

3、认证失败的问题,就是对上述两个问题没有相对应的设置好,要么都安一个版本库设置,要么都安多个版本库设置,只要对应设置好,应该就是没有问题的。

4、目录2是由svn建立的,不用自己去设置,假设:

     svn import /tmp/ceshi "svn://localhost/a/b/c" -m "first version"

     这样的话,当你checkout的时候,你本地的目录就应该是: /a/b/c

5、网上说是LANG没设置好,也有可能是导入的源文件中有些文件自身的文件名乱码

6、服务器都设置好了,那要是客户端还连不上,就是防火墙的问题了,去/etc/sysconfig/iptables 设置一下,打开默认的3690端口就可以了

转自---------------------https://www.cnblogs.com/tdalcn/p/6937714.html

参考资料---------------https://www.cnblogs.com/lxwphp/p/8031811.html

原文地址:https://www.cnblogs.com/tudachui/p/9515812.html