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
[A.test.cn]
Path =/data/web/a.test.cn/
# Exclude = conf/*. php
Comment = this ia a.test.cn
Ignore errors
Read only = false
List = false
Hosts allow = 172.31.0.12
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 172.31.0.12)
# Cat/shell/rsync-passwd/rsync. passwd
Test: test123
# Chmod 600/shell/rsync-passwd/rsync. passwd
Rsync-vzrtopgl -- progress -- delete -- exclude =. svn/data/web/a.test.cn/test@172.31.0.15: a.test.cn -- password-file =/shell/rsync-passwd/rsync. passwd
Or
RSYNC_PASSWORD = test123 rsync-vzrtopgl -- progress -- delete -- exclude =. svn/data/web/a.test.cn/test@172.31.0.15: a.test.cn
(Complete)
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 http://svn.apache.org/repos/asf/apr/apr/branches/1.3.x (apr)
./Apr/buildconf
# Download apr-util and run buildconf to generate the required file
Svn co http://svn.apache.org/repos/asf/apr/apr-util/branches/1.3.x (apr-util)
./Apr-util/buildconf
# 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
Mkdir/data/svndata
/Usr/local/svn/bin/svnadmin create/data/svndata/a.test.cn
/Usr/local/svn/bin/svnadmin create/data/svndata/B .test.cn
/Usr/local/svn/bin/svnadmin create/data/svndata/c.test.cn
2. Configure the password and permission File
Mkdir/data/svnpasswd
# Cat/data/svnpasswd/passwd
[Users]
Aaa = aaapwd
Bbb = bbbpwd
Ccc = cccpwd
Xxx = xxxpwd
Yyy = yyypwd
Zzz = zzzpwd
# Cat/data/svnpasswd/authz
[Groups]
A.test.cn = aaa
B .test.cn = bbb
C.test.cn = ccc
Other = xxx, yyy, zzz
[A.test.cn:/]
@ A.test.cn = r w
Xxx = r
* =
[B .test.cn:/]
@ B .test.cn = rw
Yyy = r
* =
[C.test.cn:/]
@ C.test.cn = 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:
[General]
Anon-access = none
Auth-access = write
Password-db =/data/svnpasswd/passwd
Authz-db =/data/svnpasswd/authz
# Realm = My First Repository
# Force-username-case = none
[Sasl]
# 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/a.test.cn/hooks/post-commit
#! /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/a.test.cn
If [$? -Eq 0]
Then
Chown-R root. dev/data/web/atest.cn
/Bin/bash/shell/rsync-script/a.test.cn. sh>/dev/null 2> & 1
Fi
6. Configure the script triggered by the hook File
[Root @ centos-6 ~] # Cat/shell/rsync-script/a.test.cn. sh
#/Bin/bash
IP = "172.31.0.15"
Auth_module = "a.test.cn"
Localdir = "/data/web/a.test.cn /"
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
Test123
7. Test
The client submits a file in the.test.cn database to check whether the file is synchronized to the web directory defined by the rsync server in real time.
(Complete)
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