Server file synchronization mechanism configuration (rsync & Sersync)

Reference article link: http://static.kancloud.cn/curder/linux/78148

In the above reference article, a detailed operation explanation is given for the synchronization deployment process with the master-slave, but for how the three servers synchronize with each other (that is, all three are masters), this article configures the three masters for mutual synchronization.

1. Realize ideas

The three servers are all masters, and the handwritten setting master1 can be synchronized to master2 and master3, and then set master2 and master3 to synchronize to master1 respectively, so as to successfully realize the synchronization mechanism of the three servers.
insert image description here

2. Configuration steps

Directly refer to the section of 2.3.3 Configuring the rsync client on the master , which is configured for the three servers respectively. For the configuration file, refer to 2.3.1.2 Deploying the rsync service (related operations on the slave server) .
Note that the slave and master node password files in the reference article are inconsistent. The master is rsync.password, and the slave is rsyncd.password. It is best to use rsync.password uniformly.

2.1 The rsyncd.conf files of the three masters

  • Three master node ip

    • master1 : 192.168.0.196
    • master2 : 192.168.0.143
    • master3 : 192.168.0.150
  • Below is my Master1 configuration file

# Minimal configuration file for rsync daemon
#See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
# GLOBAL OPTIONS
uid = root                         
gid = root                                  
use chroot = no
read only = false
#limit access to private LANs
# 192.168.0.143———master2的IP,192.168.0.150 ——master3的ip
hosts allow=192.168.0.143/24,192.168.0.150/24
hosts deny=*
ignore errors
max connections = 2000
pid file = /var/run/rsyncd.pid
auth users = rsync_backup
secrets file = /etc/rsyncd.password
#lock file = /var/run/rsync.lock
motd file = /etc/rsyncd/rsyncd.motd
#This will give you a separate log file
log file = /data/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
# MODULE OPTIONS
[master1]  /当前节点名称
comment = synchronize data
# /data/ouna/upload/firmware同步的文件路径
path = /data/ouna/upload/firmware
  • Below is my Master2 configuration file
# Minimal configuration file for rsync daemon
#See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
# GLOBAL OPTIONS
uid = root                         
gid = root                                  
use chroot = no
read only = false
#limit access to private LANs
# 192.168.0.196———master1的IP
hosts allow=192.168.0.196/24
hosts deny=*
ignore errors
max connections = 2000
pid file = /var/run/rsyncd.pid
auth users = rsync_backup
secrets file = /etc/rsyncd.password
#lock file = /var/run/rsync.lock
motd file = /etc/rsyncd/rsyncd.motd
#This will give you a separate log file
log file = /data/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
# MODULE OPTIONS
[master2]  /当前节点名称
comment = synchronize data
# /data/ouna/upload/firmware同步的文件路径
path = /data/ouna/upload/firmware
  • The following is my Master3 configuration file
# Minimal configuration file for rsync daemon
#See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
# GLOBAL OPTIONS
uid = root                         
gid = root                                  
use chroot = no
read only = false
#limit access to private LANs
# 192.168.0.196———master1的IP
hosts allow=192.168.0.196/24
hosts deny=*
ignore errors
max connections = 2000
pid file = /var/run/rsyncd.pid
auth users = rsync_backup
secrets file = /etc/rsyncd.password
#lock file = /var/run/rsync.lock
motd file = /etc/rsyncd/rsyncd.motd
#This will give you a separate log file
log file = /data/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
# MODULE OPTIONS
[master3]  /当前节点名称
comment = synchronize data
# /data/ouna/upload/firmware同步的文件路径
path = /data/ouna/upload/firmware

2.2 The sersync configuration file confxml.xml of the three masters

major changes
insert image description here

Sersync Alibaba Cloud resources: https://www.aliyundrive.com/s/Cpy6z2KigKm

  • master1 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="/data/ouna/upload/firmware">
			<!-- master2的ip master2名称-->
    		<remote ip="192.168.0.143" name="master2"/>
			<!-- master3的ip master3名称-->
    		<remote ip="192.168.0.150" name="master3"/>
    	</localpath>
   
    	<rsync>
    	    <commonParams params="-artuz"/>
			<!-- rsync.password密码授权,如果你创建的是rsyncd.password,则用rsyncd.password-->
    	    <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
    	    <userDefinedPort start="false" port="873"/><!-- port=873 -->
    	    <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>
  • The configuration file confxml.xml of master2
    <?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="/data/ouna/upload/firmware">
			<!-- master1的ip master1名称-->
    		<remote ip="192.168.0.196" name="master1"/>
    	</localpath>
   
    	<rsync>
    	    <commonParams params="-artuz"/>
			<!-- rsync.password密码授权,如果你创建的是rsyncd.password,则用rsyncd.password-->
    	    <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
    	    <userDefinedPort start="false" port="873"/><!-- port=873 -->
    	    <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>
  • master3 configuration 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="/data/ouna/upload/firmware">
			<!-- master1的ip master1名称-->
    		<remote ip="192.168.0.196" name="master1"/>
    	</localpath>
   
    	<rsync>
    	    <commonParams params="-artuz"/>
			<!-- rsync.password密码授权,如果你创建的是rsyncd.password,则用rsyncd.password-->
    	    <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
    	    <userDefinedPort start="false" port="873"/><!-- port=873 -->
    	    <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>

3. After the modification is completed, start it.

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

For other detailed information, please refer to the linked article at the beginning of this article, which will not be described in detail in this article.

Guess you like

Origin blog.csdn.net/qq_42102911/article/details/130086270