サーバーファイル同期メカニズムの構成 (rsync および Sersync)

参考記事リンク:http://static.kancloud.cn/curder/linux/78148

上記参考記事では、マスター・スレーブによる同期デプロイメントプロセスについて詳細な動作説明が行われていますが、3台のサーバーがどのように同期するか(つまり、3台すべてがマスター)については、この記事では3つのマスターを構成します。相互同期。

1. アイデアを実現する

3 つのサーバーはすべてマスターであり、手書き設定の master1 を master2 と master3 に同期し、次に master2 と master3 をそれぞれ master1 に同期するように設定することで、3 つのサーバーの同期メカニズムを正常に実現できます。
ここに画像の説明を挿入

2. 設定手順

3台のサーバそれぞれに設定する「2.3.3 マスタでのrsyncクライアントの設定」を直接参照し、設定ファイルについては「2.3.1.2 rsyncサービスのデプロイ(スレーブサーバでの関連操作)」を参照してください。
参考記事のスレーブ ノードとマスター ノードのパスワード ファイルは一致していないことに注意してください。マスターは rsync.password、スレーブは rsyncd.password です。rsync.password を統一して使用することをお勧めします。

2.1 3 つのマスターの rsyncd.conf ファイル

  • 3 つのマスター ノード IP

    • マスター1 : 192.168.0.196
    • マスター2 : 192.168.0.143
    • マスター3 : 192.168.0.150
  • 以下は私のMaster1設定ファイルです

# 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
  • 以下は私のMaster2設定ファイルです
# 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
  • 以下は私のMaster3構成ファイルです
# 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 3 つのマスターの sersync 設定ファイル confxml.xml

主な変更点
ここに画像の説明を挿入

Sersync Alibaba Cloud リソース: https://www.aliyundrive.com/s/Cpy6z2KigKm

  • マスター1 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>
  • master2の設定ファイル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>
  • master3 構成 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. 変更が完了したら、起動します。

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

その他の詳細な情報については、この記事では詳しく説明しませんので、この記事の冒頭にあるリンク先の記事を参照してください。

おすすめ

転載: blog.csdn.net/qq_42102911/article/details/130086270