seRsync + Rsync 实时同步

文章目录

1,结构图

2,节点A

2.1 安装rsync

c 复制代码
yum install -y rsync

2.2 安装seRsync

下载这个压缩包sersync2.5.4_64bit_binary_stable_final.tar.gz

解压后,将sersync2复制到系统可执行程序路径:/usr/local/bin/;创建sersync配置目录,并在里面创建配置文件tomcat.xml 和www.xml并写入数据

matlab 复制代码
tar -xvzf sersync2.5.4_64bit_binary_stable_final.tar.gz
cp ./GNU-Linux-x86/sersync2 /usr/local/bin/
mkdir /etc/sersync
vim /etc/sersync/tomcat.xml
vim /etc/sersync/www.xml
  • tomcat.xml具体内容
matlab 复制代码
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <debug start="true"/>
    <fileSystem xfs="false"/>
    <filter start="true">
    <exclude expression="^logs/*"></exclude>
    <exclude expression="^webapps/pcPublish/*"></exclude>
    </filter>
    <inotify>
    <delete start="true"/>
    <createFolder start="true"/>
    <createFile start="true"/>
    <closeWrite start="true"/>
    <moveFrom start="true"/>
    <moveTo start="true"/>
    <attrib start="false"/>
    <modify start="false"/>
    </inotify>


    <sersync>
    <localpath watch="/vdb/eastmoney/apache-tomcat-8.5.27/">
        <remote ip="10.195.24.97" name="tomcat"/>
        <!--<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="rsync" passwordfile="/etc/rsync.pass"/>
        <userDefinedPort start="false" port="873"/><!-- port=874 -->
        <timeout start="false" time="100"/><!-- timeout=100 -->
        <ssh start="false"/>
    </rsync>
    <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
    <crontab start="false" schedule="720"><!--600mins-->
        <crontabfilter start="true">
            <exclude expression="^logs/*"></exclude>
            <exclude expression="^webapps/pcPublish/*"></exclude>
        </crontabfilter>
    </crontab>
    <plugin start="false" name="command"/>
    </sersync>
</head>

-www.xml具体内容

matlab 复制代码
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <debug start="true"/>
    <fileSystem xfs="false"/>
    <filter start="true">
    <exclude expression="^load-control.html*"></exclude>
    </filter>
    <inotify>
    <delete start="true"/>
    <createFolder start="true"/>
    <createFile start="true"/>
    <closeWrite start="true"/>
    <moveFrom start="true"/>
    <moveTo start="true"/>
    <attrib start="false"/>
    <modify start="false"/>
    </inotify>


    <sersync>
    <localpath watch="/vdb/eastmoney/data0/htdocs/www/">
        <remote ip="10.195.24.97" name="www"/>
        <!--<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="rsync" passwordfile="/etc/rsync.pass"/>
        <userDefinedPort start="false" port="873"/><!-- port=874 -->
        <timeout start="false" time="100"/><!-- timeout=100 -->
        <ssh start="false"/>
    </rsync>
    <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
    <crontab start="false" schedule="720"><!--600mins-->
        <crontabfilter start="true">
            <exclude expression="^load-control.html*"></exclude>
        </crontabfilter>
    </crontab>
    <plugin start="false" name="command"/>
    </sersync>
</head>

2.3, 创建seRsync的守护进程用systemd管理并启动

创建sersyncd4tomcat.servicesersyncd4www.service到systemd配置文件路径:/usr/lib/systemd/system/

  • sersyncd4tomcat.service 具体内容
matlab 复制代码
[Unit]
Description=Client for rsync
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/sersync2 -rdo /etc/sersync/tomcat.xml
ExecReload=pidof sersync2|xargs kill -1
ExecStop=pidof sersync2|xargs kill -3
[Install]
WantedBy=multi-user.target
  • sersyncd4www.service具体内容
matlab 复制代码
[Unit]
Description=Client for rsync
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/sersync2 -rdo /etc/sersync/www.xml
ExecReload=pidof sersync2|xargs kill -1
ExecStop=pidof sersync2|xargs kill -3
[Install]
WantedBy=multi-user.target

2.4,上传rsync.pass密码文件到配置文件目录:/etc/

rsync.pass密码文件具体内容是

matlab 复制代码
r_SynC-2021#@2021-RsyN_c

密码文件中,"r_SynC-2021#@2021-RsyN_c"与同步逻辑下游节点B的rsync配置文件相对应。

为节点B的rsyncd.conf中"auth users"字段配置的同步用rsync用户密码,节点B的密码保存在节点B的rsync.pass密码文件中。(非操作系统用户)

rsync.pass权限应为600

matlab 复制代码
chmod 600 /etc/rsync.pass

2.5 ,重新加载systemd,启动sersyncd守护进程并配置开机自启

bash 复制代码
systemctl daemon-reload
systemctl enable sersyncd4tomcat
systemctl enable sersyncd4www
systemctl start sersyncd4tomcat
systemctl start sersyncd4www

3,节点B

3.1 ,安装Rsync

bash 复制代码
yum install rsync -y
vim /etc/rsyncd.conf
vim /etc/rsync.pass

3.2创建Rsync配置文件rsyncd.conf、密码文件rsync.pass到配置文件目录:/etc/

  • rsyncd.conf内容长这样:
bash 复制代码
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
lock file = /var/run/rsyncd.lock
motd file = /etc/rsyncd.motd
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
uid = root
gid = root
port = 873
read only = no
write only = yes
list = no
auth users = rsync
secrets file = /etc/rsync.pass
use chroot = no
max connections = 300
hosts allow = 10.195.24.97
hosts deny = 0.0.0.0/0
timeout = 300
[tomcat]
path = /vdb/eastmoney/apache-tomcat-8.5.27/
exclude = logs/ webapps/load-control.html* webapps/pcPublish
[www]
path = /vdb/eastmoney/data0/htdocs/www/
exclude = load-control.html*

-rsync.pass内容长这样:

bash 复制代码
r_SynC-2021#@2021-RsyN_c
rsync:r_SynC-2021#@2021-RsyN_c
  • 密码文件中,第1行的"r_SynC-2021#@2021-RsyN_c"与同步逻辑下游节点C的rsync配置文件相对应。为节点C的rsyncd.conf中"auth users"字段配置的同步用rsync用户密码,节点C的密码保存在节点C的rsync.pass密码文件中。(非操作系统用户)
  • 密码文件中,第2行的"rsync:r_SynC-2021#@2021-RsyN_c"与同步逻辑上游节点A的sersync配置文件相对应。为节点A的tomcat.xml和www.xml中head.rsync.auth的user用户和passoredfile指定密码文件中的密码。
    写法为<上游同步用用户>:<上游同步用用户密码>(非操作系统用户)
    rsync.pass权限应为600
bash 复制代码
chmod 600 /etc/rsync.pass

3.3,启动Rsyncd

启动rsyncd守护进程并配置开机自启。

bash 复制代码
systemctl enable rsyncd
systemctl start rsyncd

3.4, 安装seRsync

同样地把刚才解压的那个sersync2文件复制到节点B的系统可执行程序路径:/usr/local/bin/;创建sersync配置目录/etc/sersync/并上传配置文件tomcat.xmlwww.xml

  • tomcat.xml 内容长这样:
bash 复制代码
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <debug start="true"/>
    <fileSystem xfs="false"/>
    <filter start="true">
    <exclude expression="^logs/*"></exclude>
    <exclude expression="^webapps/pcPublish/*"></exclude>
    </filter>
    <inotify>
    <delete start="true"/>
    <createFolder start="true"/>
    <createFile start="true"/>
    <closeWrite start="true"/>
    <moveFrom start="true"/>
    <moveTo start="true"/>
    <attrib start="false"/>
    <modify start="false"/>
    </inotify>


    <sersync>
    <localpath watch="/vdb/eastmoney/apache-tomcat-8.5.27/">
        <remote ip="10.205.204.199" name="tomcat"/>
        <!--<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="rsync" passwordfile="/etc/rsync.pass"/>
        <userDefinedPort start="false" port="873"/><!-- port=874 -->
        <timeout start="false" time="100"/><!-- timeout=100 -->
        <ssh start="false"/>
    </rsync>
    <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
    <crontab start="false" schedule="720"><!--600mins-->
        <crontabfilter start="true">
            <exclude expression="^logs/*"></exclude>
            <exclude expression="^webapps/pcPublish/*"></exclude>
        </crontabfilter>
    </crontab>
    <plugin start="false" name="command"/>
    </sersync>
</head>

-www.xml 内容长这样

bash 复制代码
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <debug start="true"/>
    <fileSystem xfs="false"/>
    <filter start="true">
    <exclude expression="^load-control.html*"></exclude>
    </filter>
    <inotify>
    <delete start="true"/>
    <createFolder start="true"/>
    <createFile start="true"/>
    <closeWrite start="true"/>
    <moveFrom start="true"/>
    <moveTo start="true"/>
    <attrib start="false"/>
    <modify start="false"/>
    </inotify>


    <sersync>
    <localpath watch="/vdb/eastmoney/data0/htdocs/www/">
        <remote ip="10.205.204.199" name="www"/>
        <!--<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="rsync" passwordfile="/etc/rsync.pass"/>
        <userDefinedPort start="false" port="873"/><!-- port=874 -->
        <timeout start="false" time="100"/><!-- timeout=100 -->
        <ssh start="false"/>
    </rsync>
    <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
    <crontab start="false" schedule="720"><!--600mins-->
        <crontabfilter start="true">
            <exclude expression="^load-control.html*"></exclude>
        </crontabfilter>
    </crontab>
    <plugin start="false" name="command"/>
    </sersync>
</head>

3.5 创建seRsync的守护进程用systemd管理并启动

上传sersyncd4tomcat.service和sersyncd4www.service到systemd配置文件路径:/usr/lib/systemd/system/

  • sersyncd4tomcat.service内容长这样:
bash 复制代码
[Unit]
Description=Client for rsync
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/sersync2 -rdo /etc/sersync/tomcat.xml
ExecReload=pidof sersync2|xargs kill -1
ExecStop=pidof sersync2|xargs kill -3
[Install]
WantedBy=multi-user.target
  • sersyncd4www.service内容长这样:
bash 复制代码
[Unit]
Description=Client for rsync
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/sersync2 -rdo /etc/sersync/www.xml
ExecReload=pidof sersync2|xargs kill -1
ExecStop=pidof sersync2|xargs kill -3
[Install]
WantedBy=multi-user.target
  • 重新加载systemd,启动sersyncd守护进程并配置开机自启。
bash 复制代码
systemctl daemon-reload
systemctl enable sersyncd4tomcat
systemctl enable sersyncd4www
systemctl start sersyncd4tomcat
systemctl start sersyncd4www

4,节点C

4.1 安装Rsync

bash 复制代码
yum install -y rsync

4.2、配置Rsync

上传Rsync配置文件rsyncd.conf 、密码文件rsync.pass 到配置文件目录:/etc/

  • rsyncd.conf 内容长这样:
bash 复制代码
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
lock file = /var/run/rsyncd.lock
motd file = /etc/rsyncd.motd
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
uid = root
gid = root
port = 873
read only = no
write only = yes
list = no
auth users = rsync
secrets file = /etc/rsync.pass
use chroot = no
max connections = 300
hosts allow = 10.195.24.97
hosts deny = 0.0.0.0/0
timeout = 300
[tomcat]
path = /vdb/eastmoney/apache-tomcat-8.5.27/
exclude = logs/ webapps/load-control.html* webapps/pcPublish
[www]
path = /vdb/eastmoney/data0/htdocs/www/
exclude = load-control.html*
  • rsync.pass 内容长这样:
bash 复制代码
rsync:r_SynC-2021#@2021-RsyN_c

rsync.pass权限应为600

bash 复制代码
chmod 600 /etc/rsync.pass

密码文件中,"rsync:r_SynC-2021#@2021-RsyN_c"与同步逻辑上游节点B的sersync配置文件相对应。为节点B的tomcat.xml和www.xml中head.rsync.auth的user用户和passoredfile指定密码文件中的密码。

写法为<上游同步用用户>:<上游同步用用户密码>(非操作系统用户)

4.3、启动Rsync

启动rsyncd守护进程并配置开机自启。

bash 复制代码
systemctl enable rsyncd
systemctl start rsyncd
相关推荐
Komorebi.py43 分钟前
【Linux】-学习笔记05
linux·笔记·学习
Mr_Xuhhh1 小时前
重生之我在学环境变量
linux·运维·服务器·前端·chrome·算法
中云DDoS CC防护蔡蔡2 小时前
微信小程序被攻击怎么选择高防产品
服务器·网络安全·微信小程序·小程序·ddos
HPC_fac130520678163 小时前
以科学计算为切入点:剖析英伟达服务器过热难题
服务器·人工智能·深度学习·机器学习·计算机视觉·数据挖掘·gpu算力
yaoxin5211234 小时前
第二十七章 TCP 客户端 服务器通信 - 连接管理
服务器·网络·tcp/ip
内核程序员kevin4 小时前
TCP Listen 队列详解与优化指南
linux·网络·tcp/ip
sinat_384241098 小时前
使用 npm 安装 Electron 作为开发依赖
服务器
朝九晚五ฺ8 小时前
【Linux探索学习】第十四弹——进程优先级:深入理解操作系统中的进程优先级
linux·运维·学习
自由的dream8 小时前
Linux的桌面
linux
xiaozhiwise9 小时前
Makefile 之 自动化变量
linux