Svn + rsync real-time release program

Source: Internet
Author: User
Tags inotify svn update

Idea: The svn server hook triggers the rsync synchronization script to synchronize the rsync defined modules on the web server.

======================================= WEB Server (RSYNC) ======================================
Step 1: Install rsync
Yum-y install rsync
Step 2: Configure
# This file is not available by default.
# Vim/etc/rsyncd. conf
Uid = root
Gid = root
Use chroot = no
Max connections = 200
Timeout = 600
Pid file =/var/run/rsyncd. pid
Lock file =/var/run/rsync. lock
Log file =/var/log/rsyncd. log
Path =/data/web/
# Exclude = conf/*. php
Comment = this ia
Ignore errors
Read only = false
List = false
Hosts allow =
Hosts deny = *
Auth users = test
Secrets file =/shell/rsync-passwd/rsync. passwd
Note: When use chroot = no, if the file master or group of DES after synchronization has one, the display name, even if the ID is different;
When use chroot = yes, if the two machines have different IDs with the same name, the server only displays the src id, causing permission problems.
Edit the rsync user authentication configuration file
# Cat/shell/rsync-passwd/rsync. passwd
Test: test123
# Chmod 600/shell/rsync-passwd/rsync. passwd
Step 3: Start the rsync Service
/Usr/bin/rsync -- daemon
Echo "/usr/bin/rsync -- daemon">/etc/rc. local
Step 4: test the client (on
# Cat/shell/rsync-passwd/rsync. passwd
Test: test123
# Chmod 600/shell/rsync-passwd/rsync. passwd
Rsync-vzrtopgl -- progress -- delete -- exclude =. svn/data/web/ -- password-file =/shell/rsync-passwd/rsync. passwd
RSYNC_PASSWORD = test123 rsync-vzrtopgl -- progress -- delete -- exclude =. svn/data/web/
Note: you do not need to restart the service to modify the configuration file and user password.

========================== SVN server ============ ==============================
Step 1: Install subversion
Tar zxvf subversion-1.7.4.tar.gz
Cd subversion-1.7.4
# Download apr and run buildconf to generate the required file
Svn co (apr)
# Download apr-util and run buildconf to generate the required file
Svn co (apr-util)
# Download sqlite3.c, decompress it, and put it in the source code directory of the subversion unzip. only ensure that sqlite3.c is available.
# Ll sqlite-amalgamation/
Total 5004
-Rw-r -- 1 root 5121966 Dec 17 :34 sqlite3.c
./Configure -- prefix =/usr/local/svn
Make & make install
Step 2: Create the svn database and Configure permissions
1. Create a database
/Usr/local/svn/bin/svnadmin create/data/svndata/
/Usr/local/svn/bin/svnadmin create/data/svndata/B
/Usr/local/svn/bin/svnadmin create/data/svndata/
2. Configure the password and permission File
# Cat/data/svnpasswd/passwd
Aaa = aaapwd
Bbb = bbbpwd
Ccc = cccpwd
Xxx = xxxpwd
Yyy = yyypwd
Zzz = zzzpwd
# Cat/data/svnpasswd/authz
[Groups] = aaa
B = bbb = ccc
Other = xxx, yyy, zzz
@ = r w
Xxx = r
* =
@ B = rw
Yyy = r
* =
@ = rw
@ Other = r
* =
3. configure all svn databases to use the above users and permissions to centrally manage permissions.
Modify conf/svnserve. conf in all libraries as follows:
Anon-access = none
Auth-access = write
Password-db =/data/svnpasswd/passwd
Authz-db =/data/svnpasswd/authz
# Realm = My First Repository
# Force-username-case = none
# Use-sasl = true
# Min-encryption = 0
# Max-encryption = 256
4. Start the service
/Usr/local/svn/bin/svnserve-d -- listen-port 4399-r/data/svndata
Echo "/usr/local/svn/bin/svnserve-d -- listen-port 4399-r/data/svndata">/etc/rc. local
5. Configure the hook file (the first database is configured separately as needed). The post-commit script is triggered each time a commit is triggered. Make sure you have the execution permission.
Copy the template file as post-commit.
Chmod 700 post-commit
[Root @ CentOS-6 ~] # Cat/data/svndata/
#! /Bin/sh
# The following variable is actually the absolute path of the svn library and is not used.
# REPOS = "$1"
# The following variable is actually the version after each commit and is not used.
# REV = "$2"
Export LANG = en_US.UTF-8
/Usr/local/svn/bin/svn update -- username aaa -- password "aaapwd"/data/web/
If [$? -Eq 0]
Chown-R root. dev/data/web/
/Bin/bash/shell/rsync-script/ sh>/dev/null 2> & 1
6. Configure the script triggered by the hook File
[Root @ centos-6 ~] # Cat/shell/rsync-script/ sh
IP = ""
Auth_module = ""
Localdir = "/data/web/ /"
Auth_user = "test"
Passwd_file = "/shell/rsync-passwd/rsync. passwd"
Exc = "-- exclude =. svn"
Rsync-vzrtopgl -- progress -- delete $ {Exc }$ {Localdir} $ Auth_user $ {IP }::$ {Auth_module} -- password-file =$ {Passwd_file}
To access the rsync password file, the permission must be 600, root. root
[Root @ centos-6 ~] # Cat/shell/rsync-passwd/rsync. passwd
7. Test
The client submits a file in database to check whether the file is synchronized to the web directory defined by the rsync server in real time.
Note: you do not need to restart the service to add a database, modify permissions, and password.

Rsync details: click here
Rsync: click here

Recommended reading:

Monitor host files and directories using inotifywait

Using inotify + rsync for Linux File batch update

Inotify-tools + rsync real-time file synchronization installation and configuration

Complete rsync synchronization Configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.