文章目录
  1. 1. 初始环境
  2. 2. 安装必须的软件
  3. 3. 基本的SVN服务器配置
  4. 4. 配置SVN服务器的HTTP支持
  5. 5. 常用操作
  6. 6. 参考文献

初始环境

系统:CentOS 6.7

安装必须的软件

  1. 安装SVN服务器
    如果已安装,使用svnserve --version查看版本
    如果未安装,运行yum -y install subversion命令

  2. 支持WEB方式管理SVN服务器
    如果要支持web方式访问,还需要安装httpd mod_dav_svn mod_perl, 运行yum -y install httpd mod_dav_svn mod_perl命令。

基本的SVN服务器配置

  1. 新建一个目录用于存储SVN所有文件
    mkdir /mnt/disk1/svnserver
    注:此目录最好不要在系统盘下,防止系统盘爆满。这和Windows下尽量不要将程序安装到C盘道理类似。
  2. 新建一个版本仓库test
    svnadmin create /mnt/disk1/svnserver/test
    可以看到test版本库中的文件目录结构如下:

    1
    2
    3
    4
    5
    6
    7
    8
    [root@node67 svnserver]# ll /mnt/disk1/svnserver/test
    total 24
    drwxr-xr-x 2 root root 4096 Dec 13 15:06 conf
    drwxr-sr-x 6 root root 4096 Dec 13 15:06 db
    -r--r--r-- 1 root root 2 Dec 13 15:06 format
    drwxr-xr-x 2 root root 4096 Dec 13 15:06 hooks
    drwxr-xr-x 2 root root 4096 Dec 13 15:06 locks
    -rw-r--r-- 1 root root 229 Dec 13 15:06 README.txt
  3. 初始化版本仓库中的目录

    • 建立标准临时目录:mkdir project project/trunks project/branches project/tags
    • 初始化标准SVN目录: svn import project/ file:///mnt/disk1/svnserver/test -m “初始化标准SVN目录”
    • 删除临时建立的目录:rm -rf project
      结果如下:
      1
      2
      3
      4
      5
      6
      7
      8
      [root@node67 svnserver]# mkdir project project/trunks project/branches project/tags
      [root@node67 svnserver]# svn import project/ file:///mnt/disk1/svnserver/test -m “初始化标准SVN目录”
      Adding project/branches
      Adding project/trunks
      Adding project/tags

      Committed revision 1.
      [root@node67 svnserver]# rm -rf project
  4. 添加用户
    要添加SVN用户非常简单,只需在/mnt/disk1/svnserver/test/conf/passwd文件添加一个形如“username=password”的条目就可以了。(注:明文存储在checkout的时候会有警告)

    1
    2
    3
    4
    5
    [users]
    # harry = harryssecret
    # sally = sallyssecret
    test1 = 123456
    test2 = 123456
  5. 修改用户访问策略
    此处配置用户的访问策略,由于是自己搭建的临时服务器,只做测试用,因此无需访问控制,暂时忽略。如果有需要的话参考参考文献2中的用户访问策略

  6. 修改svnserve.conf文件,让用户和策略配置升效.
    /mnt/disk1/svnserver/test/conf/svnserve.conf内容如下:

    1
    2
    3
    4
    5
    [general]
    anon-access = none
    auth-access = write
    password-db = /mnt/disk1/svnserver/test/conf/passwd
    # authz-db = /mnt/disk1/svnserver/test/conf/authz
  7. 启动服务器
    svnserve -d -r /mnt/disk1/svnserver
    注意:如果修改了svn配置,需要重启svn服务,步骤如下:

    1
    2
    3
    # ps -aux|grep svnserve
    # kill -9 ID号
    # svnserve -d -r /mnt/disk1/svnserver
  8. 测试服务器
    在另一台服务器上测试是否能checkout前面建立的test库

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    [root@master66 qiuxing]# svn co svn://node67/test
    Authentication realm: <svn://node67:3690> 8255e3be-93e8-4b65-b49c-dfad7d2647bf
    Password for root:
    Authentication realm: <svn://node67:3690> 8255e3be-93e8-4b65-b49c-dfad7d2647bf
    Username: tes^Csvn: Caught signal
    You have mail in /var/spool/mail/root
    [root@master66 qiuxing]# svn co svn://node67/test
    Authentication realm: <svn://node67:3690> 8255e3be-93e8-4b65-b49c-dfad7d2647bf
    Password for root:
    Authentication realm: <svn://node67:3690> 8255e3be-93e8-4b65-b49c-dfad7d2647bf
    Username: test1
    Password for test1:

    ATTENTION! Your password for authentication realm:

    <svn://node67:3690> 8255e3be-93e8-4b65-b49c-dfad7d2647bf

    can only be stored to disk unencrypted! You are advised to configure
    your system so that Subversion can store passwords encrypted, if
    possible. See the documentation for details.

    You can avoid future appearances of this warning by setting the value
    of the store-plaintext-passwords option to either yes or no in
    /root/.subversion/servers.


    Store password unencrypted (yes/no)? yes
    A test/branches
    A test/trunks
    A test/tags
    Checked out revision 1.
    [root@master66 qiuxing]# ll test/
    total 12
    drwxr-xr-x 3 root root 4096 Dec 13 15:50 branches
    drwxr-xr-x 3 root root 4096 Dec 13 15:50 tags
    drwxr-xr-x 3 root root 4096 Dec 13 15:50 trunks

可以看到我们的svn服务已经搭建起来了,接下来就是要让svn服务支持http协议。

配置SVN服务器的HTTP支持

  1. 修改目录权限以便web容器能够访问
    chown -R apache:apache /mnt/disk1/svnserver
  2. 新建密码加密的用户
    由于SVN服务器的密码是明文的,HTTP服务器不与支持,所以之前建立的用户test1,test2应该删除掉,使用htpasswd -c /mnt/disk1/svnserver/test/conf/passwd qiuxing重新创建密码加密的用户。
    使用-c会重新创建一个passwd文件,之前创建的用户就被覆盖掉了,新增的时候不要加此参数.
    创建的过程中需要输入两次密码,保证一致即可。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [root@node67 svnserver]# htpasswd -c /mnt/disk1/svnserver/test/conf/passwd qiuxing
    New password:
    Re-type new password:
    Adding password for user qiuxing
    [root@node67 svnserver]# htpasswd /mnt/disk1/svnserver/test/conf/passwd test1
    New password:
    Re-type new password:
    Adding password for user test1
    [root@node67 svnserver]# cat /mnt/disk1/svnserver/test/conf/passwd
    qiuxing:UhuNOFkEs18KU
    test1:njv9TPfwUOMhs

可以看到,密码都是加密的了,而且用户名和密码使用:分割而不是=

  1. 修改httpd.conf,添加关于SVN服务器的内容
    确保/etc/httpd/conf/httpd.conf 包含这一行:Include conf.d/*.conf
    编辑/etc/httpd/conf.d/subversion.conf,在最后添加如下信息:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    <Location /test>
    DAV svn
    SVNPath /mnt/disk1/svnserver/test
    AuthType Basic
    AuthName "svn for test"
    AuthUserFile /mnt/disk1/svnserver/passwd
    Satisfy all
    Require valid-user
    </Location>
  2. 重启Web服务器:
    service httpd restart

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [root@node67 test]# service httpd restart
    Stopping httpd: [ OK ]
    Starting httpd: httpd: Could not reliably determine the server s fully qualified domain name, using 10.17.139.67 for ServerName
    [ OK ]
    You have mail in /var/spool/mail/root
    可以看到这里有个警告,编辑/etc/httpd/conf/httpd.conf,添加一行ServerName node67:80。node67需要改成你自己的主机名
    [root@node67 test]# vim /etc/httpd/conf/httpd.conf
    You have mail in /var/spool/mail/root
    [root@node67 test]# service httpd restart
    Stopping httpd: [ OK ]
    Starting httpd: [ OK ]
  3. 用浏览器访问http://node67/test/测试
    输入用户名密码(此处是qiuxing/123)
    即可看到trunk,branches和tags 3个目录

常用操作

  1. 新建仓库(repo)
    newRepo.sh

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40

    if [[ $# < 1 ]];then
    echo "Usage $0 newRepoName"
    fi

    repo=$1
    rootSvnDir=/mnt/disk1/svnserver

    echo "1. 创建新的仓库:$repo"
    svnadmin create /mnt/disk1/svnserver/$repo

    echo "2. 初始化标准SVN目录"
    mkdir project project/trunks project/branches project/tags
    svn import project/ file://$rootSvnDir/$repo -m “初始化标准SVN目录”
    rm -rf project

    echo "3. 给已有用户添加$repo的读写权限"
    echo " " >> $rootSvnDir/$repo/conf/svnserve.conf
    echo "[general]" >> $rootSvnDir/$repo/conf/svnserve.conf
    echo "anon-access = none" >> $rootSvnDir/$repo/conf/svnserve.conf
    echo "auth-access = write" >> $rootSvnDir/$repo/conf/svnserve.conf
    echo "password-db = $rootSvnDir/$repo/conf/passwd" >> $rootSvnDir/$repo/conf/svnserve.conf

    echo "4. 配置Apache以便web访问"
    echo " " >> /etc/httpd/conf.d/subversion.conf
    echo "<Location /$repo>" >> /etc/httpd/conf.d/subversion.conf
    echo " DAV svn" >> /etc/httpd/conf.d/subversion.conf
    echo " SVNPath $rootSvnDir/$repo" >> /etc/httpd/conf.d/subversion.conf
    echo " AuthType Basic" >> /etc/httpd/conf.d/subversion.conf
    echo " AuthName \"svn for $repo\"" >> /etc/httpd/conf.d/subversion.conf
    echo " AuthUserFile /mnt/disk1/svnserver/passwd" >> /etc/httpd/conf.d/subversion.conf
    echo " Satisfy all" >> /etc/httpd/conf.d/subversion.conf
    echo " Require valid-user" >> /etc/httpd/conf.d/subversion.conf
    echo "</Location>" >> /etc/httpd/conf.d/subversion.conf

    echo "5. 修改根目录权限以便web访问"
    chown -R apache:apache $rootSvnDir

    echo "6. 重启服务"
    service httpd restart
  2. 添加用户
    newUser.sh

    1
    2
    3
    4
    5
    6
    7
    if [[ $# < 1 ]];then
    echo "Usage $0 newUserName"
    fi

    user=$1
    rootSvnDir=/mnt/disk1/svnserver
    htpasswd $rootSvnDir/passwd $user

参考文献

  1. how-to-setup-a-svn-server-on-centos-6
  2. (总结)CentOS Linux搭建SVN Server配置详解
文章目录
  1. 1. 初始环境
  2. 2. 安装必须的软件
  3. 3. 基本的SVN服务器配置
  4. 4. 配置SVN服务器的HTTP支持
  5. 5. 常用操作
  6. 6. 参考文献