If you want to setup two subversion server , one master and another as read only slave with password and acl protected so keep reading. Let's suppose you have two subversion server , as below...
SVN-M(master)
Hostname: svn-m.example.com
IPAddress: 10.10.10.1/24
SVN-S (slave)
Hostname: svn-s.example.com
IPAddess: 10.10.10.2/24
Setup yum repository:
Download any one RPM according to your OS and system architecture .....
(for RHEL5 32 bit version)
wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
OR
(for RHEL5 64 bit version)
wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
Setup Master SVN Server:
1) Install Apache Webserver and Subversion .
yum install httpd httpd-devel subversion mod_dav_svn -y
2) Create SVN Repository:
I like fsfs filesystem based SVN repository over BDB based . To know more difference between fsfs and BDB go through following article
http://svnbook.red-bean.com/en/1.1/ch05.html#svn-ch-5-sect-1.3
(Read "Repository Data-Stores" section )
mkdir -p /var/www/svn ( -p to create parent directory if it doesn't exist)
svnadmin create --fs-type=fsfs /var/www/svn/repos
Note:check httpd.conf User and Group section to know user and group by which apache is running as follows and then change owner and group owner according to that )
grep ^User /etc/httpd/conf/httpd.conf
OutPut: User apache
grep ^Group /etc/httpd/conf/httpd.conf
OutPut: Group apache
chown -R apache:apache /var/www/svn/repos
3) Configure Apache Webserver for Master subversion:
Enable name based virtual hosting in
vi /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
vi /etc/httpd/conf.d/subversion.conf
-------------------------------------------------------------------------------------------------------------------------------------
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
<VirtualHost *:80>
ServerName svn-m.example.com
<Location /repos>
DAV svn
SVNPath /var/www/svn/repos
AuthType Basic
AuthName "Authorization Realm"
AuthUserFile /var/www/svn/.htpasswd
AuthzSVNAccessFile /etc/svn-acl-conf
Require valid-user
</Location>
</VirtualHost>
-------------------------------------------------------------------------------------------------------------------------------------
4) Create SVN user :
htpasswd -cm /var/www/svn/.htpasswd test
Note: -c to create file first time and -m for md5 hashed password. Don't use -c second time while creating user otherwise it will overwrite existing file.
5) Create Subversion Access control list file for Master:
vi /etc/svn-acl-conf
-------------------------------------------------------------------------------------------------------------------------------------
[repos:/]
administrator = rw
* = r
-------------------------------------------------------------------------------------------------------------------------------------
Note: Only administrator can write to repository and everyone else can only read to repository.
6) Create SVN Repository Layout:
mkdir -p /tmp/productname/{trunk,stable,branches,releases}
svn import /tmp/productname/ file:///var/www/svn/repos/productname -m "Creating Productname Layout"
To know more about SVN Repository Layout , Please go through following link...
http://svnbook.red-bean.com/en/1.4/svn.tour.importing.html#svn.tour.importing.layout
Now make host entry as follows in /etc/hosts on client side and point http://svn-m.example.com/repos in your browser and you will get username password box.Now login by previously created usernane.
10.10.10.1 svn-m.example.com
Here your master SVN server is ready...... :)
Setup Slave SVN Server:
Step 1 and 2 same as Master.
3) Configure Apache Webserver for Slave subversion:
Enable name based virtual hosting in
vi /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
vi /etc/httpd/conf.d/subversion.conf
-------------------------------------------------------------------------------------------------------------------------------------
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
<VirtualHost *:80>
ServerName svn-s.example.com
<Location /repos>
DAV svn
SVNPath /var/www/svn/repos
AuthType Basic
AuthName "Authorization Realm"
AuthUserFile /var/www/svn/.htpasswd
AuthzSVNAccessFile /etc/svn-acl-conf
Require valid-user
</Location>
</VirtualHost>
-------------------------------------------------------------------------------------------------------------------------------------
4) Step 4 is same as master
5) Create Subversion Access control list file for Slave:
-------------------------------------------------------------------------------------------------------------------------------------
[repos:/]
svnmirror = rw
* = r
-------------------------------------------------------------------------------------------------------------------------------------
Imp Note: Please don't give write access to anyother user than svnmirror , only svnmirror should be able to write on slave no one else.
6) Make Mirror Repository Revision Properties Modifiable by Synchronizing User:
cd /var/www/svn/repos/hooks
vi pre-revprop-change
-------------------------------------------------------------------------------------------------------------------------------------
#!/bin/sh
USER="$3"
if [ "$USER" = "svnmirror" ]; then exit 0; fi
echo "Only the svnmirror user may change revision properties as this is a read-only, mirror repository." >&2
exit 1
-------------------------------------------------------------------------------------------------------------------------------------
7) Create svnmirror user on master
htpasswd -bm /var/www/svn/.htpasswd svnmirror svn
Note: -b option is used to supply password on command line, here svnmirror user password is "svn". You can just remove -b option can type when it will ask for password.
8) Register mirror repository for synchronization
svnsync initialize file:///var/www/svn/repos http://svn-m.example.com/repos --username=svnmirror
It will ask svnmirror password that we created on master in our case this is "svn"
If everything is configured properly, you should see some output like this
Copied properties for revision 0.
Now we have registered our svn-s , slave i.e. mirror repository with master repository , now we should do initial synchronization so that mirror (slave) and master repository are synchronized .
svnsync synchronize file:///var/www/svn/ repos --username=svnmirror
you should see output like this.
Committed revision 1.
Copied properties for revision 1.
9) Create SVN user on Slave:
htpasswd -bm /var/www/svn/.htpasswd svnslavetest svnslavetest
Now make host entry in /etc/hosts on client side and point your http://svn-s.example.com/repos in your browser.You should get username and password pop-up just use previously created username and password
UserName: svnslavetest
Password: svnslavetest
10.10.10.2 svn-s.example.com
9) Automate Synchronization with cron
vi /etc/crontab
*/5 * * * * root svnsync synchronize file:///var/www/svn/ repos --username=svnmirror --password=svn > /tmp/svnsync.log
Now every 5 minute mirror repository will synchronize with master.
cool :)
Please send me your feedback and suggestions.
Thanks
3 comments:
Abhishek,
Great job, best description I've found.
help: one key step for newbies like is, should I be in su mode or 'sudo' each time?
Secondly: I want to set this for now locally on my PC. so I'm setting the server name as 'localhost' does this work?
//windsword
If you allow me a question, why create this under /var/?
and on step 8 I get an error when I type: "sudo svnsync initialize file:///var/www/svn/repos http://localhost:8080/repos --username=svnmirror"
svnsync: 'pre-revprop-change' hook failed with error output:
To start out without an svnmirror, do I need the same an abridged version of the instructions?
Lastly, step 3 also talks about setting: "NameVirtualHost *:80" but I already have the following, 'Listen 8080'
should I append to the
"/etc/httpd/conf/httpd.conf" the line you mentioned: "NameVirtualHost *:80" ??
// windsword
I followed the doc http://abhishekkumarsingh.blogspot.c...cation-on.html for SVN Replication.
I followed line by line but stuck with this error :
Code:
[root@askr hooks]# svnsync initialize file:///var/www/svn/repos http://10.14.236.92/repos --username=svnmirror
svnsync: Revprop change blocked by pre-revprop-change hook (exit code 255) with no output.
Help.
Post a Comment