First, why use rsync + sersync architecture?
1, sersync is based on inotify development, inotify-tools similar tools
2, sersync can record a file or directory is changed to listen directory (add, delete, modify) the specific name of a file or a directory, and then use rsync to synchronize the time, only sync changes
Two, rsync + difference inotify-tools and rsync + sersync architecture?
1、rsync+inotify-tools
a, inotify directory is recorded only in monitor changes (add, delete, change) which is not the particular file or which directory record change;
b, rsync synchronization of the time, does not know which specific file or directory changes, each time the entire directory synchronization, when a large amount of data, the entire directory synchronization is very time-consuming (rsync to the entire directory Find traverse the reference document), and therefore inefficient
2、rsync+sersync
a, sersync can record (add, delete, change) the specific name of a file or directory changes being monitored directory;
B, rsync file or directory in the synchronization, synchronization only changes (changes each time data corresponding to the entire synchronization of catalog data is small enough, when traversing rsync file lookup contrast, very fast), and therefore, high efficiency.
to sum up:
When a small amount of data directory synchronization, it is recommended to use rsync + inotify
When the directory synchronization of large amounts of data (hundreds of G 1T even more than) a lot of files, it is recommended to use rsync + sersync
#Rsync server configuration
1. deployment rsync service
yum install rsync # install rsync, if they think yum version is too low can also install the source code
2.vim /etc/rsyncd.conf # default rsync no configuration file, create a file in # and characters only comment, please use all annotations Clear
Server #Rsync |
3 , create a user authentication file
echo "rsync_backup: 123456"> / etc / rsync.password # configuration file, add the following |
4 , set file permissions
chmod 600 /etc/rsync.password
5. Start the daemon and writes the boot from the start
rsync --daemon |
6. Create a relevant directory to be synchronized
mkdir -p /data/{www,bbs,blog}
#rsync client configuration
1. Installation the rsync , as above
2. Create a rsync configuration file, the client can be created without content
touch /etc/rsyncd.conf
3. Configure rsync client permissions Certification:
echo "123456">/etc/rsync.password
chmod 600 /etc/rsync.password
4. Create a data to be synchronized, to create some data on the client
mkdir -p /data/{www,bbs,blog}
touch /data/www/www.log /data/bbs/bbs.log /data/blog/blog.log
5. Test rsync is synchronized
rsync -avzP /data/www/ [email protected]::www --password-file=/etc/rsync.password |
# This step must succeed to the next step
6. deploying sersync Service
tar fxz sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/
cd /usr/local/
mv GNU-Linux-x86 sersync
7.配置sersync
cp sersync/confxml.xml sersync/confxml.xml-bak
vim sersync/confxml.xml
修改24--28行
|
8.开启sersync守护进程同步数据
/usr/local/sersync/bin/sersync -d -r -o /usr/local/sersync/conf/confxml.xml
配置sersync环境变量
echo"PATH=$PATH:/usr/local/sersync/">>/etc/profile
source /etc/profil
启动命令后返回结果如下为正常:**
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d run as a daemon
option: -r rsync all the local files to the remote servers before the sersync work
option: -o config xml name: ./confxml.xml
daemon thread num: 10
parse xml config file
XML Parsing error inside file './confxml.xml'.
Error: File not found
At line 0, column 0.
同步测试
[root@panwenbin1-sa GNU-Linux-x86]# ./sersync2 -d -r -o ./confxml-www.xml
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d run as a daemon
option: -r rsync all the local files to the remote servers before the sersync work
option: -o config xml name: ./confxml-www.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
daemon start,sersync run behind the console
use rsync password-file :
user is rsync_backup
passwordfile is /etc/rsync.password
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /data/www && rsync -artuz -R --delete ./ --timeout=100 [email protected]::www --password-file=/etc/rsync.password >/dev/null 2>&1
run the sersync:
watch path is: /data/www
9.多实例情况
1、配置多个confxml.xml文件(比如:www、bbs、blog....等等)
confxml-bbs.xml confxml-blog.xml confxml-www.xml(按照单个实例配置即可)
2、根据不同的需求同步对应的实例文件
rsync -avzP /data/www/ [email protected]::www/ --password-file=/etc/rsync.password
rsync -avzP /data/bbs/ [email protected]::bbs/ --password-file=/etc/rsync.password
rsync -avzP /data/test/ [email protected]::blog/ --password-file=/etc/rsync.passwor
分别启动即可
rsync缺点:
1.大量小文件同步时,比对时间长,有时候rsync进程会停止
2.同步大文件,10G这样的大文件有时也会有问题,会中断。未完整同步之前是隐藏文件,可通过参数续传
sersync的参数信息
参数-d:启用守护进程模式 参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍 c参数-n: 指定开启守护线程的数量,默认为10个 参数-o:指定配置文件,默认使用confxml.xml文件 参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块 参数-m:单独启用其他模块,使用 -m socket 开启socket模块 参数-m:单独启用其他模块,使用 -m http 开启http模块 不加-m参数,则默认执行同步程序