服务器系统版本:
# cat /etc/redhat-release
CentOS release 6.4 (Final)

结构:
SVN服务器1 主库
IP 192.168.16.201
SVN服务器2 从库
IP 192.168.16.202

搭建目标:
在SVN服务器1上执行svn ci操作,SVN服务器2上的版本库会同步更新。

说明:

本文只涉及到搭建简单的SVN服务器,并不涉及配置Apache的高级配置以及SVN结合LDAP认证登陆。
1.搭建两个SVN服务器
###在这一部分,如无特殊说明,所有操作需在两台服务器上执行
1.1 安装相关软件
yum install -y mod_dav_svn subversion httpd
1.2 设置apache
# vim /etc/httpd/conf/httpd.conf    #根据需求做出更改,在这里使用默认配置文件
# /etc/init.d/httpd start
# chkconfig httpd on
1.3 修改Subversion相关文件
# cd /etc/httpd/conf.d/
# vim subversion.conf
-------------------------------------------------------
# 取消下面两行的注释

LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so

#添加下面这段话

<Location /repos>
        DAV svn
        SVNPath /var/www/svn/repos
        AuthType Basic
        AuthName "Subversion repos"
        AuthUserFile /etc/svn-auth-conf
        Require valid-user
</Location>

---------------------------------------------------------
1.4 添加svn账户
# 尽量保证账户信息一致
# htpasswd -cm /etc/svn-auth-conf weifl
New password:
Re-type new password:
Adding password for user weifl
1.5 设置版本库
# cd /var/www/
# mkdir svn
# cd svn
# svnadmin create repos
# chown -R apache.apache repos
# /etc/init.d/httpd restart

###1.6-1.7的内容仅需在服务器1上执行,服务器2无需执行
1.6 分配版本库
# 查看svn的用法
# svn --help
# 创建示范目录
# cd /tmp
# mkdir mytestproj
# cd mytestproj
# mkdir configurations options main
# touch configurations/testconf1.cfg options/testopt1.cfg main/mainfile1.cfg
1.7 初始化版本库
# svn import /tmp/mytestproj/ file:///var/www/svn/repos/mytestproj -m "Initial repository layout for mytestproj"
Adding         /tmp/mytestproj/main
Adding         /tmp/mytestproj/main/mainfile1.cfg
Adding         /tmp/mytestproj/configurations
Adding         /tmp/mytestproj/configurations/testconf1.cfg
Adding         /tmp/mytestproj/options
Adding         /tmp/mytestproj/options/testopt1.cfg

Committed revision 1.

2.配置SVN服务器2
# cd /var/www/svn/repos/hooks/
# cp pre-revprop-change.tmpl pre-revprop-change
# vim pre-revprop-change
-------------------------------------
echo "Changing revision properties other than svn:log is prohibited" >&2
exit 0        #将1改为0
-------------------------------------
# chmod +x pre-revprop-change


3.配置SVN服务器1
3.1 初始化从库
svnsync init http://192.168.16.202/repos/ http://192.168.16.201/repos/ --source-username weifl --source-password weifl --sync-username weifl --sync-password weifl
-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <http://192.168.16.202:80> Subversion repos

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
Copied properties for revision 0.

3.2 同步从库
svnsync sync --non-interactive http://192.168.16.202/repos/ --source-username weifl --source-password weifl --sync-username weifl --sync-password weifl
Transmitting file data ...
Committed revision 1.
Copied properties for revision 1.

3.3 自动同步
# cd /var/www/svn/repos/hooks
# cp post-commit.tmpl post-commit
# vim post-commit
-------------------------------------
# 注释掉所有文字,在最后添加下面内容
echo off
svnsync sync --non-interactive http://192.168.16.202/repos/ --source-username weifl --source-password weifl --sync-username weifl --sync-password weifl
-------------------------------------
# chmod +x post-commit

4.测试
以下操作在任一客户端执行上进行
# 在ubuntu中第一次测试需安装subversion
$ sudo apt-get install -y subversion
$ cd /tmp/
$ svn co http://192.168.16.201/repos/mytestproj/
Authentication realm: <http://192.168.16.201:80> Subversion repos
Password for 'flong':

Authentication realm: <http://192.168.16.201:80> Subversion repos
Username: weifl
Password for 'weifl': *****

A    mytestproj/main
A    mytestproj/main/mainfile1.cfg
A    mytestproj/configurations
A    mytestproj/configurations/testconf1.cfg
A    mytestproj/options
A    mytestproj/options/testopt1.cfg
Checked out revision 1.

$ cd mytestproj/configurations/
$ touch t1.txt
$ svn add t1.txt
A         t1.txt
$ svn ci -m "This is a test" t1.txt
Adding         t1.txt
Transmitting file data .
Committed revision 2.

访问http://192.168.16.201/repos/和http://192.168.16.202/repos/可发现,主库和从库版本始终保持一致。

参考链接:
http://wiki.centos.org/zh/HowTos/Subversion
http://lcinx.blog.163.com/blog/static/4349426720121015114526176/
http://blog.sina.com.cn/s/blog_48aa22a80100k9yu.html
http://m.oschina.net/blog/201567