搭建兩個實時同步的SVN服務器

服務器系統版本:
# 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章