The configuration of rsync under Linux for folder synchronization
http://blog.csdn.net/cymm_liu/article/details/31347531
Objective: to [88]_a of the host /data/home/web sync to [27]_b of the host /data/home/qy Catalogue
B
Host as
rsync
Server
# Check if the system has rsync packages installed
[Email protected] home]# Rpm-qa |greprsync
rsync-2.6.9
if not, go to yum or apt-get install or go to the website server
1. custom boot mode, configured as follows:
new or configured rsyncd.conf
[Email protected] etc]# vim rsyncd.conf
UID = www
GID = www
Use chroot = no
Port = 873
Max connections = 10
PID file =/var/run/rsyncd.pid
#log file =/var/log/rsyncd.log
Hosts allow = 110.163.200.119
Hosts deny = *
## The above section is a global configuration, the following module can have multiple
[web]
Path =/data/home/qy/
Ignore errors = yes
Read Only = no
Write only = no
List = no
Auth users = www
Secrets file =/etc/rsync.pass
# # above configuration instructions:
#port can not add, because the default is 873 port, can be changed to another port
#auth Users What account is used for synchronization verification, this user and /etc/password It 's no matter.
#secrets file holds rsync plaintext password files, for security purposes, this file permissions modified to :wei:huashuo_rsync, the middle of the space is not separated by a colon.
# "[QY]" is a custom module name, here is equivalent to a delimiter, if you want to synchronize multiple folders here to differentiate , English name is called module, note the directory permissions
Configuring Auto-start vi/etc/rc.d/rc.local
/usr/bin/rsync--daemon--config/etc/rsyncd.conf
system default boot mode:
AddRsyncService Scripts
Vi/etc/xinetd.d/rsync
#will beDisable=yesinsteadNo
Service rsync
{
Disable = no
Socket_type =stream
Wait =no
User =root
Server =/usr/bin/rsync
Server_args =--daemon
Log_on_failure +=userid
}
RHELinstallation is defaultrsync,Edit/etc/xinetd.d/rsyncafter useService xinetd Restartto start.
Ahost as client, configure
2. web.rsync.sh File script:
#!/bin/sh
# # Defining conditions
Hosts= "110.144.80.16"
Src= "/data/home/web/"
Exclude_files= "/usr/mybin/qy.exclude.ini"
Module=web
User=www
# # to synchronize the local src directory to the path of the Rsync server module,the INI file specifies where filtering is not synchronized, the "Web" module is ysync Name of the server-side definition
/usr/local/inotify/bin/inotifywait-mrq--timefmt '%y-%m-%d%h:%m:%s '--format '%T%w%f%e ' \
-E Close_write,delete,create,attrib $src | While read files
Do
For I in $hosts
Do
/USR/BIN/RSYNC-VZRTOPG--exclude-from= $exclude _files--delete--progress--password-file=/etc/client.rsync.pass $ src [email protected] $i:: $module
Exitcode=$?
if [$EXITCODE! = 0]; Then
echo "${files} rsync Error:" $EXITCODE >>/var/log/inotify.log 2>&1
Break
Fi
Done
Done
Only the rsync server password is in the #/etc/client.rsync.pass file .
Create a file that filters out of sync
Vi/usr/mybin/qy.exclude.ini
*.zip
*.gz
*.tar.gz
*.sql
*.tgz
*.rar
log/*
i/tmp/*
blog/
memcached/
system/conf_main.php
Start the automatic synchronization script
nohup/root/web.rsync.sh >>/dev/null 2>&1 &
The configuration of rsync under Linux for folder synchronization