首页 > 代码库 > rsync+sersync

rsync+sersync

Environmental introduction
System Kernel  : 2.6.32-642.4.2.el6.x86_64
Source Server  : 192.168.7.1
Target Server  : 192.168.7.10
Target Server Configure
1、Close SElinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
2、configure iptables server
iptables -A INPUT -p tcp --dport 873 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 873 -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart
3、Install Rsync server software
yum -y install rsync xinetd
sed -n s/"disable.*= yes"/"disable         = no"/p /etc/xinetd.d/rsync
sed -n s/server_args.* = --daemon/server_args     = --daemon --config=\/etc\/rsyncd.conf/p  /etc/xinetd.d/rsync
/etc/init.d/xinetd start
4、Create rsync configuration file and configure
touch /etc/rsyncd.conf
cat >> /etc/rsyncd.conf << END
log file = /var/log/rsyncd/rsyncd.log 
pidfile = /var/run/rsyncd.pid         
lock file = /var/run/rsync.lock       
secrets file = /etc/rsync.pass       
motd file = /etc/rsyncd.Motd          
[vick1]                        
path = /home/vick1
comment = vick1
uid = root                            
pid = root                            
port 873                              
use chroot = no                       
read only = no                        
list = no                             
max connections = 200                 
timeout = 600                         
auth users = vick             
hosts allow = 192.168.7.1
END 
5、Create user authentication file
touch /etc/rsync.pass
echo "vick:123456" >> /etc/rsync.pass
6、Set files permissions
chmod 600 /etc/rsync.pass
chmod 600 /etc/rsyncd.conf
7、start-up rsync
/etc/init.d/xinetd start

Source server rsync client configure

1、Close SElinux

sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0

2、configure iptables server
iptables -A INPUT -p tcp --dport 873 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 873 -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart

3、Install Rsync server software
yum -y install rsync xinetd
sed -n s/"disable.*= yes"/"disable         = no"/p /etc/xinetd.d/rsync
/etc/init.d/xinetd start
4、create password file
touch /etc/sync.pass
echo "123456" >> /etc/sync.pass
chmod 600 /etc/sync.pass
5、Test single point synchronization
rsync -avH --port=873 --progress --delete  /home/vick1/  vick@192.168.7.10::vick1 --password-file=/etc/sync.pass
Install sersync tools real time trigger Rsync synchronization
1、Check whether the server kernel supports inotify
-rw-r--r-- 1 root root 0 May  2 14:33 max_queued_events
-rw-r--r-- 1 root root 0 May  2 14:33 max_user_instances
-rw-r--r-- 1 root root 0 May  2 14:33 max_user_watches

 Notes: Make a list of three documents that show the kernel supports inotify

2、 Modify kernel parameters
cat >> /etc/sysctl.conf << END
fs.inotify.max_queued_events=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535
END
sysctl -p
Notes:
Max_queued_events:inotify queue maximum length, if the value is too small, there will be * * * Event Overflow * * error,
resulting in inaccurate monitoring files Queue
max_user_watches:The number of files to synchronize,can use find /home/vick1 -type d|wc -l statistics,
must ensure that the max_user_watches value is greater than the statistical results

max_user_instances:Create maximum value of inotify instance for each user

 3、Install and configure sersync services 
Download sersync software
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz --no-check-certificate
tar -zxvf    sersync2.5.4_64bit_binary_stable_final.tar.gz
mv GNU-Linux-x86 /usr/local/sersync

  Configure sersync services

      Configure an instance and specify a synchronization directory,user and password

cp /usr/local/sersync/confxml.xml /usr/local/sersync/confxml.xml.bak 
vim /usr/local/sersync/confxml.xml

<?xml version="1.0" encoding="ISO-8859-1"?> <head version="2.5"> <host hostip="localhost" port="8008"></host> <debug start="false"/> <fileSystem xfs="false"/> <filter start="false"> <exclude expression="(.*)\.svn"></exclude> <exclude expression="(.*)\.gz"></exclude> <exclude expression="^info/*"></exclude> <exclude expression="^static/*"></exclude> </filter> <inotify> <delete start="true"/> <createFolder start="true"/> <createFile start="false"/> <closeWrite start="true"/> <moveFrom start="true"/> <moveTo start="true"/> <attrib start="false"/> <modify start="false"/> </inotify> <sersync> <localpath watch="/home/vick1"> <remote ip="192.168.7.10" name="vick1"/> <!--<remote ip="192.168.8.39" name="tongbu"/>--> <!--<remote ip="192.168.8.40" name="tongbu"/>--> </localpath> <rsync> <commonParams params="-artuz"/> <auth start="true" users="vick" passwordfile="/etc/sync.pass"/> <userDefinedPort start="false" port="874"/><!-- port=874 --> <timeout start="true" time="100"/><!-- timeout=100 --> <ssh start="false"/> </rsync> <failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> <crontab start="false" schedule="600"><!--600mins--> <crontabfilter start="false"> <exclude expression="*.php"></exclude> <exclude expression="info/*"></exclude> </crontabfilter> </crontab> <plugin start="false" name="command"/> </sersync> <plugin name="command"> <param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix--> <filter start="false"> <include expression="(.*)\.php"/> <include expression="(.*)\.sh"/> </filter> </plugin> <plugin name="socket"> <localpath watch="/opt/tongbu"> <deshost ip="192.168.138.20" port="8009"/> </localpath> </plugin> <plugin name="refreshCDN"> <localpath watch="/data0/htdocs/cms.xoyo.com/site/"> <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/> <sendurl base="http://pic.xoyo.com/cms"/> <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/> </localpath> </plugin> </head>

/usr/local/sersync/sersync2 -d -r -o  /usr/local/sersync/confxml.xml

  The final test is successful synchronization,The configuration is over here

 

Extand:
Add script to monitor whether sersync is running properly
touch /home/script/chech_sersync.sh

cat >> /home/script/chech_sersync.sh << END
#!/bin/sh

sersync="/usr/local/sersync/sersync2"

confxml="/usr/local/sersync/confxml.xml"

status=$(ps aux |grep sersync2|grep -v grep|wc -l)

if [ $status -eq 0 ];

then

$sersync -d -r -o $confxml &

else

exit 0;

fi
END

 

 

 

 
 
 

 
 
 
 

rsync+sersync