1, to achieve the purpose:
Synchronize the data in the/data directory in host A in real time to the/data directory in Host B
2. Download the required software
sersync2.5.4
Https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz
3. Configuration
On Host A:
After decompression only two files, SERSYNC2, command execution file; confxml.xml, config file
[Email protected] sersync]# pwd
/usr/local/sersync
[[email protected] sersync]# ls
Confxml.xml SERSYNC2
View the Help information for the command execution file;
[Email protected] sersync]#./sersync2-h
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
_______________________________________________________
Parameter-D: Enable daemon mode
Parameter-r: Push the monitoring directory and the remote host with the rsync command before monitoring
C parameter-N: Specifies the number of daemon threads to open, default is 10
Parameter-o: Specifies the configuration file, using the Confxml.xml file by default
Parameter-M: separate enable other modules, use-M refreshcdn to turn on Refresh CDN Module
Parameter-M: enable other modules separately and open the socket module using the-m socket
Parameter-M: separate enable other modules, use-M http to turn on HTTP module
The Synchronizer is executed by default without the-m parameter
________________________________________________________________
With the help of the command, you know that you want to implement the synchronization function, as long as you execute the following command.
./sersync2-d-R
If you have multiple directories that need to be synchronized, you can specify a different profile with the-o option as long as there are multiple processes. For example, on-line configuration:
/usr/local/sersync/bin/sersync-d-o/usr/local/sersync/conf/download.xml
/usr/local/sersync/bin/sersync-d-o/usr/local/sersync/conf/ddbill.xml
/usr/local/sersync/bin/sersync-d-o/usr/local/sersync/conf/dinpay.xml
Configuration file confxml.xml parameter configuration
Implementing sync Main configuration 23-44 rows, <sersync>.....</sersync> content
The contents of the default configuration file are as follows:
<sersync> < Localpath watch= "/opt/tongbu" > <remote ip= "127.0.0.1" name= "tongbu1"/> <!--<remote ip= "192.168.8.39" name= "Tongbu"/>--> <!--<remote ip= " 192.168.8.40 " name=" Tongbu "/>--> </ localpath> <rsync> <commonparams params= "-artuz"/> <auth start= "false" users= "root" passwordfile= "/etc/rsync.pas"/>&NBsp; <userdefinedport start= " False " port=" 874 "/><!-- port=874 --> <timeout start= "false" time= "/><"!-- timeout=100 -- > <ssh start= "false"/ > </rsync> <faillog path= "/tmp/rsync_fail_log.sh" timetoexecute= "/><!--Default every 60mins execute once--> < Crontab start= "false" schedule= "><!--600mins--> <crontabfilter start= "false" > <exclude expression= "*.php" ></exclude> <exclude expression= "info/*" ></exclude> </crontabfilter> </crontab> <plugin start= "false" name= "command"/> </sersync>
Simple implementation of the function, in fact, as long as configuration
<localpath watch= "/opt/tongbu" > <remote ip= "127.0.0.1" name= "tongbu1"/> <!--<rem OTE ip= "192.168.8.39" name= "Tongbu"/>--> <!--<remote ip= "192.168.8.40" name= "Tongbu"/>--> </localpath>
These are just a few lines.
Watch is followed by the local directory to be synchronized to the remote
IP is followed by the IP address of the remote host; Name followed by the module name in the rsyncd.conf file in rsync daemon mode in the remote host
If you want to sync to more than one machine, write a <remote> label on each machine
The configuration file in host A is modified as follows:
[Email protected] sersync]# sed-n ' 24,28p ' confxml.xml
<localpath watch= "/data" >
<remote ip= "192.168.2.175" name= "Data"/>
</localpath>
<rsync>
<commonparams params= "-artuz"/>
[Email protected] sersync]#
On Host B:
Configure the/data directory as the module name and directory in Rsync daemon.
rsyncd.conf simple configuration is as follows
[Email protected] data]# cat/etc/rsyncd.conf
Uid=root
Gid=root
Max connections=36000
Use Chroot=no
Log File=/var/log/rsyncd.log
PID File=/var/run/rsyncd.pid
Lock File=/var/run/rsyncd.lock
[Data]
Path=/data
#ignore Errors (Open will report an error in the log)
Read Only = no
Hosts allow = 192.168.2.0/24
Hosts deny = *
After the configuration file has been modified, you can start the rsync daemon mode
[Email protected] data]# rsync--daemon
[Email protected] data]# Ss-tlnp|grep 873
0 5::: 873:::* Users: (("rsync", 10042,5)
0 5 *:873 *:* Users: (("rsync", 10042,4)
[Email protected] data]#
So the Host B is configured to complete ~
Now go back to host A to execute the./sersync2-d-r command to start real-time synchronization.
[Email protected] sersync]#/sersync2-d-R
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
Daemon Thread Num:10
Parse XML config file
Host Ip:localhost host port:8008
Daemon Start,sersync run behind the console
Config XML parse success
Please set/etc/rsyncd.conf Max connections=0 manually
Sersync working thread 1 (primary thread) + 1 (fail retry thread) + Ten (daemon sub threads)
Max Threads Numbers is:22 = (Thread pool nums) + ten (Sub threads)
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 && rsync-artuz-r--delete./192.168.2.175::d ata >/dev/null 2>&1
Run the Sersync:
Watch path is:/data
[Email protected] sersync]# Ps-ef|grep SERSYNC2
Root 21640 1 0 03:30? 00:00:00./sersync2-d-R
4. Demo
Now we go to the/data directory in host A and Host B to do some simple demo operations
[[email protected]/-19:38:31] #ls/data
[Email protected]/-19:38:38]#
[[email protected]/-19:38:32] #ls/data
[Email protected]/-19:38:42]#
Increase
[[email protected]/-19:39:48] #cd data
[[email protected] data-19:39:53] #touch 1 2 3 4 5
[[email protected] data-19:40:15] #ls
1 2 3) 4 5
[Email protected] data-19:40:21]#
[[email protected]/-19:39:49] #cd data
[[email protected] data-19:39:56] #ls
1 2 3) 4 5
[Email protected] data-19:40:23]#
By deleting
[[email protected] data-19:41:43] #rm 1 2 3-f
[[email protected] data-19:41:49] #ls
4 5
[Email protected] data-19:41:50]#
[[email protected] data-19:40:23] #ls
4 5
Change
[[email protected] data-19:41:50] #echo 44444444 > 4
[[email protected] data-19:48:38] #echo 55555555 > 5
[[email protected] data-19:48:46] #cat 4 5
44444444
55555555
[Email protected] data-19:48:53]#
[[email protected] data-19:49:14] #cat 4
44444444
[[email protected] data-19:49:16] #cat 5
55555555
[Email protected] data-19:49:18]#
Sersync file Real-time synchronization