1,结构图
2,节点A
2.1 安装rsync
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并写入数据
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具体内容
<?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具体内容
<?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.service
和 sersyncd4www.service
到systemd配置文件路径:/usr/lib/systemd/system/
sersyncd4tomcat.service
具体内容
[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
具体内容
[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
密码文件具体内容是
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
chmod 600 /etc/rsync.pass
2.5 ,重新加载systemd,启动sersyncd守护进程并配置开机自启
systemctl daemon-reload
systemctl enable sersyncd4tomcat
systemctl enable sersyncd4www
systemctl start sersyncd4tomcat
systemctl start sersyncd4www