CentOS7 下搭建svn服务器

一、yum安装subversion
    1. 安装

subversion yum install subversion


    2. 查看安装版本,检查安装是否成功

svnserve --version


    3. 查看安装位置  

rpm -ql subversion

二、创建版本库
        1. 创建用于存放版本库的目录

mkdir -p /www/sdb1/subversion

        2. 创建svn版本库

svnadmin create /www/sdb1/subversion

        3. 创建完后,版本库目录下会生成一些文件,进入conf目录下

            conf目录中authz文件是权限控制文件;

            conf目录中passwd是帐号密码文件;

            conf目录中svnserve.conf是SVN服务配置文件

                

  4. 修改passwd文件,加入用户,格式就是“用户名=密码”,如:  admin = 123

扫描二维码关注公众号,回复: 994714 查看本文章

  5. 修改authz文件,加入用户权限:

    [/] 

    admin = rw

   这就表示admin用户对版本库根目录有读写权限(即最高权限了),权限配置方式在authz文件注释中有详细说明

  6. svnserve.conf里面常用的配置有设置匿名用户(默认可读)、授权用户(默认读写)的读写权限,以及指定账号文件(默认passwd)、权限文件(默认authz)的路径等

        

### 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.apache.org/ for more information.

[general]
### The anon-access and auth-access options control access to the
### repository for unauthenticated (a.k.a. anonymous) users and
### authenticated users, respectively.
### Valid values are "write", "read", and "none".
### Setting the value to "none" prohibits both reading and writing;
### "read" allows read-only access, and "write" allows complete 
### read/write access to the repository.
### The sample settings below are the defaults and specify that anonymous
### users have read-only access to the repository, while authenticated
### users have read and write access to the repository.
# 匿名用户权限(none:拒绝, write:读写, read:只读权限)
anon-access = none
# 鉴权用户访问
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
### The force-username-case option causes svnserve to case-normalize
### usernames before comparing them against the authorization rules in the
### authz-db file configured above.  Valid values are "upper" (to upper-
### case the usernames), "lower" (to lowercase the usernames), and
### "none" (to compare usernames as-is without case conversion, which
### is the default behavior).
# force-username-case = none

[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

  7. 启动svn版本库 svnserve -d -r  /www/sdb1/subversion

   其中,-r 的作用是设置根目录路径,比如这样设置后在访问时输入svn://x.x.x.x/就会直接到我的svn目录下(当然在svn目录下是找不到版本库的)。换句说话,如果启动版本库时命令为svnserve -d -r  /www/sdb1/subversion,则访问svn://x.x.x.x/就能直接到版本库内。

三、开启和关闭服务


svnserve -d -r /www/sdb1/subversion #开启
killall svnserve #关闭
ps aux | grep svnserve #查看是否运行


四、常见问题
  1. 注意打开端口的访问权限。svn服务的默认端口为3690 

        CentOS7 之前版本iptables 防火墙:

CentOS7 之前版本iptables 防火墙
iptables -I INPUT -i eth0 -p tcp --dport 3690 -j ACCEPT #开放端口 
service iptables save #保存 iptables 规则(如不能保存请使用其他方法保存)

        CentOS7  版本 firewalld 防火墙:

CentOS7  版本 firewalld 防火墙:
添加(--permanent永久生效,没有此参数重启后失效)
firewall-cmd --zone=public --add-port=80/tcp --permanent    
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp

        2. 客户端svn上传后,原始文件在服务器的什么位置
        SVN服务器端不是简单将上传的文件一个一个存放起来的;SVN服务器端默认采用的FSFS格式是将每次commit的内容增量方式存放的,每个增量包存成1个文件,这个增量包中包括了这次commit的全部数据。也就是说你不可能在服务器端存放该版本库的文件夹下找到你上传的某个文件。

        SVN服务器版本库有两种格式,

            一种为FSFS,

            一种为BDB

        把文件上传到SVN版本库后,上传的文件不再以文件原来的格式存储,而是被svn以它自定义的格式压缩成版本库数据,存放在版本库中。

        如果是FSFS格式,这些数据存放在版本库的db目录中,里面的revs和revprops分别存放着每次提交的差异数据和日志等信息 。
        3. 怎把指定文件夹上传到SVN服务器
        一般来说新建项目是在服务器端操作的,每个项目作为一个独立的版本库进行管理。当然你可以可以把这个项目当作服务器上某个版本库下面的一个文件夹进行管理,但是会导致这个项目的版本号看起来是不连续的,因为SVN是用版本号标注整个版本库的状态。
        你如果确定想把这个项目当成某个版本库的一个文件夹进行管理的话,那么就这么做:
        首先,用TSVN检出那个版本库到本地;然后,将这个项目复制到本地这个版本库的某个文件夹下面;
最后,用TSVN增加并提交这个文件夹。

        SVN在服务器端的存储方式和客户端是不一样的,所以在服务器端是看不到源文件的。服务器端有两种存储方式FSFS和BDB,目前默认都是FSFS。

        要导入文件有两种做法:
        1、用import指令,将客户端文件夹导入到服务器端
        2、先checkout空库到客户端,然后将要导入的文件夹放入客户端checkout产生的空文件夹,然后执行add将这些文件夹纳入SVN控制,最后执行commit上传到服务器

猜你喜欢

转载自my.oschina.net/u/3375733/blog/1817509