Sersync implementing trigger file synchronization instead of INotify and rsync

Source: Internet
Author: User

Sersync implementing trigger file synchronization instead of INotify and rsync

Reference articles

Http://blog.chinaunix.net/uid-20639775-id-3011124.html

Http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=10738&page=1&extra= #pid113148

http://zyan.cc/sersync/

Mrsync https://sourceforge.net/projects/mrsync/


Server-side
1, install rsync on both sides to do
Yum Install-y rsync
Vi/etc/rsyncd.conf #服务器端
port=873
Log File=/var/log/rsync.log
PID File=/var/run/rsyncd.pid
#address =192.168.0.10
Max connections=10
Timeout = 300
[Webbak]
Path=/tmp/www/wordpress
Use Chroot=true
Read Only=no
List=false
Uid=root
Gid=root
#auth Users=test
#secrets file=/etc/rsyncd.passwd
Hosts allow=192.168.1.109
#hosts deny = 0.0.0.0/32

echo "Rsync--daemon" >>/etc/rc.local
#启动服务
Rsync--daemon


2, install Inotify-tools tools, real-time trigger rsync synchronization
Both machines have to be done.
Installing Inotify-tools
Yum install-y make GCC gcc-c++
cd/mydata/download/
Wget-c http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
Tar zxvf inotify-tools-3.14.tar.gz
CD inotify-tools-3.14
Mkdir-p/usr/local/inotify
./configure--prefix=/usr/local/inotify
Make
Make install
Setting system environment variables, adding soft connections
echo "path= $PATH:/usr/local/inotify/bin" >>/etc/profile.d/inotify.sh
Source/etc/profile.d/inotify.sh #使设置立即生效
echo "/usr/local/inotify/lib" >/etc/ld.so.conf.d/inotify.conf && ldconfig
Ln-s/usr/local/inotify/include/usr/include/inotify
Modify inotify default parameter (inotify default kernel parameter value is too small)
Vi/etc/sysctl.conf
fs.inotify.max_queued_events=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535
/sbin/sysctl-p

Client

3. Installation Configuration Sersync
Cd/download
Wget-c http://files.cnblogs.com/files/MYSQLZOUQI/sersync2.5.4_64bit_binary_stable_final.tar.gz
TAR-ZXVF sersync2.5.4_64bit_binary_stable_final.tar.gz
MV Gnu-linux-x86/usr/local/sersync
Vi/usr/local/sersync/confxml.xml
<?xml version= "1.0" encoding= "Iso-8859-1"?>
<debug start= "false"/>
<filesystem xfs= "false"/>
<filter start= "false" >
<exclude expression= "(. *) \wp-config.php" ></exclude>
<!--<exclude expression= "(. *) \.gz" ></exclude>-->
<!--<exclude expression= "^info/*" ></exclude>-->
</filter>
<inotify>
<delete start= "true"/>
<createfolder start= "true"/>
<createfile start= "false"/>
<closewrite start= "true"/>
<movefrom start= "true"/>
<moveto start= "true"/>
<attrib start= "true"/>
<modify start= "true"/>
</inotify>

<sersync>
<localpath watch= "/tmp/www/wordpress" >
<remote ip= "192.168.1.106" name= "Webbak"/>
<!--<remote ip= "192.168.1.12" name= "Tongbu"/>-->
<!--<remote ip= "192.168.1.13" name= "Tongbu"/>-->
</localpath>
<rsync>
<commonparams params= "-az"/>
<auth start= "false" users= "root" passwordfile= "/etc/rsync.pas"/>
<userdefinedport start= "false" port= "874"/><!--port=874--
<timeout start= "false" Time= "" "/><!--timeout=100--
<ssh start= "false"/>
</rsync>
<faillog path= "/tmp/sersync_fail_log.sh" timetoexecute= "/><!--default every 60min execute once-->
<crontab start= "true" schedule= "720" ><!--720mins-->
<crontabfilter start= "true" >
<exclude expression= "wp-config.php" ></exclude>
<!--<exclude expression= "*.gz" ></exclude>-->
<!--<exclude expression= "info/*" ></exclude>-->
</crontabfilter>
</crontab>

</sersync>


Add the command to the/etc/rc.local and restart the system later to sync normally
Vi/etc/rc.local
/usr/local/sersync/sersync2-d-r-o/usr/local/sersync/confxml.xml

First Test the rsync sync is ok
RSYNC-AV/TMP/YUM_SAVE_TX-2015-12-31-13-13X5ANWV.YUMTX 192.168.1.106::webbak

4, script monitoring Sersync
Because sometimes the Sersync script will automatically turn off, so you need to write a script automatically to detect the existence of the process, does not exist on the start, the script content is as follows:
vi/root/check_sersync.sh
#!/bin/bash
#Purpose: Check Sersync Whether it is alive
#Author: Steven
Sersync= "/usr/local/sersync/sersync2"
Conf_file= "/usr/local/sersync/confxml.xml"
status=$ (PS aux |grep ' sersync2 ' |grep-v ' grep ' |wc-l)
If [$STATUS-eq 0];
Then
$SERSYNC-D-r-o $CONF _file &
Else
Exit 0;
Fi

After the script is written, add it to the scheduled task.
Crontab-e
*/1 * * * */bin/sh/root/check_sersync.sh >/dev/null 2>&1

Sersync implementing trigger file synchronization instead of INotify and rsync

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: info-contact@alibabacloud.com 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.