环境部署准备

hostnameIPserver
Master172.16.0.1sersync+rsync
Slave1172.16.0.14rsync
Slave2172.16.0.17rsync
--全部机器关闭selinux和防火墙
setenforce 0
systemctl stop firewalld

安装软件

--安装'sersync'和'rsync','sersync'只需要在'Master'上安装
yum install rsync
wget https://www.endvv.com/wj/45/sersync2.5.4_64bit_binary_stable_final.tar.gz

--解压安装包
tar -zxf /sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/
mv /usr/local/GNU-Linux-x86/ /usr/local/sersync  #不需要编译安装

--设置权限
chown -R 777 /usr/local/sersync

安装rsync

--在'slave1'和'slave2'安装
yum install rsync

配置rsync

--'slave1'和'slave2'配置一样的
--编辑配置文件
vim /etc/rsyncd.conf   #需要自己创建这个文件
uid=user  #指定rsync进程以什么身份在后台运行,必须是系统用户
gid=user  #指定rsync进程以什么组身份在后台运行
port=873   #用于通信的TCP端口,默认是873
fake super=yes  #服务端操作系统的用户可以不用root
log file = /var/log/rsyncd.log   #rsync服务运行日志文件
[docs]     #模块名称,自定义的
comment=docs         #模块说明文字
path=/docs           #同步的目录名,必须是uid参数指定的用户和gid参数指定的组
read only=false      #read only=ture|false如果为true,则不能上传到该模块指定目录
max connections=0    #指定最大连接数,默认为0表示没有限制
auth users=user      #允许登录的客户端认证用户
secrets file=/etc/rsync.passwd     #指定rsync客户端用户认证的密码文件

--创建用户
useradd user

--创建密码文件
echo "user:123456">>/etc/rsync.passwd  
chmod 600 /etc/rsync.passwd  #密码文件权限必须设置600

--创建同步目录
mkdir /docs
chown user:user /docs

启动rsync

systemctl start rsyncd

配置 sersync

编辑配置文件

vim /usr/local/sersync/confxml.xml 
24 <localpath watch="/docs">   #本地需要监视的目录
25   <remote ip="172.16.0.14" name="docs"/>  #同步到哪台机器上 docs是模块名称
26   <remote ip="172.16.0.17" name="docs"/>  #同步到哪台机器上 docs是模块名称
27   <!--<remote ip="192.168.8.39" name="tongbu"/>-->
28   <!--<remote ip="192.168.8.40" name="tongbu"/>-->
29 </localpath>
30 <rsync>
31   <commonParams params="-artuz"/>  #配置选项
32   <auth start="true" users="user" passwordfile="/etc/rsync.passwd"/>#修改用户名和密码文件路径
33   <userDefinedPort start="false" port="874"/><!-- port=874 -->  
34   <timeout start="false" time="100"/><!-- timeout=100 --> #超时100分钟后是否重新同步
35   <ssh start="false"/>
36 </rsync>  #下面这一行指定如果同步失败,记录到哪个文件,以便在60分钟后尝试重传
37  <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
38  <crontab start="false" schedule="600"><!--600mins-->  #指定多长时间间隔执行一次完整同步
39  <crontabfilter start="false">   
40  <exclude expression="*.php"></exclude>  #可以过滤哪些不同步
41  <exclude expression="info/*"></exclude>
42 </crontabfilter>
--创建同步目录
mkdir /docs
head -c 100000000 /dev/zero > testa  
head -c 100000000 /dev/zero > testb

--创建密码文件
echo "123456">>/etc/rsync.passwd

--查看sersync参数
/usr/local/sersync/sersync2 -h

启动sersync

/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml &

验证

--查看是否同步成功
--在'slave1'和'slave2'查看
[root@slav1 /]# ll -a /docs/
总用量 195324
drwxr-xr-x.  2 user user        32 10月  8 03:13 .
dr-xr-xr-x. 24 root root      4096 10月  8 02:45 ..
-rw-r--r--.  1 user user 100000000 10月  8 02:53 testa
-rw-r--r--.  1 user user 100000000 10月  8 02:53 testb

[root@slav2 /]# ll -a /docs/
总用量 195324
drwxr-xr-x.  2 user user        32 10月  8 03:13 .
dr-xr-xr-x. 36 root root      4096 10月  7 03:50 ..
-rw-r--r--.  1 user user 100000000 10月  8 02:53 testa
-rw-r--r--.  1 user user 100000000 10月  8 02:53 testb
Last modification:December 30, 2020
If you think my article is useful to you, please feel free to appreciate