5.5 KiB
5.5 KiB
本文作者:丁辉
Nfs高可用实现Rsync+Sersync2
节点名称 | IP | 角色 | 同步目录 |
---|---|---|---|
nfs-master-1 | 192.168.1.10 | NFS主节点1 | /data |
nfs-master-2 | 192.168.1.20 | NFS主节点2 | /data |
适用架构: x86
开始部署 rsync
所有节点执行
-
安装 rsync
-
Centos
yum install rsync -y
-
Ubuntu
apt install rsync -y
-
-
配置 rsync 配置文件
备份配置文件
mv /etc/rsyncd.conf /etc/rsyncd.conf.bak
获取配置文件
curl -so /etc/rsyncd.conf https://gitee.com/offends/Linux/raw/main/File/Conf/rsyncd.conf
替换内容如下(根据自己环境配置进行修改)
-
nfs-master-1
sed -i 's#comment = none#comment = backup to nfs-master-2#g' /etc/rsyncd.conf sed -i 's#hosts allow = none#hosts allow = 192.168.1.20/24#g' /etc/rsyncd.conf
-
nfs-master-2
sed -i 's#comment = none#comment = backup to nfs-master-1#g' /etc/rsyncd.conf sed -i 's#hosts allow = none#hosts allow = 192.168.1.10/24#g' /etc/rsyncd.conf
-
-
相互配置认证文件
格式为: '用户:用户密码' (根据自己需求修改)
-
nfs-master-1 和 nfs-master-2
echo 'rsync:password' > /etc/rsync_salve.pass chmod 600 /etc/rsync_salve.pass echo "password" > /etc/rsync.paschmod 600 /etc/rsync_salve.passs chmod 600 /etc/rsync.pass
-
-
启动服务
-
Centos
systemctl enable rsyncd.service systemctl start rsyncd.service
-
Ubuntu
systemctl enable rsync.service systemctl start rsync.service
-
-
同步测试
-
192.168.1.10 传输文件到 192.168.1.20
rsync -arv --delete /data/ rsync@192.168.1.20::data --password-file=/etc/rsync.pass
-
192.168.1.20 传输文件到 192.168.1.10
rsync -arv --delete /data/ rsync@192.168.1.10::data --password-file=/etc/rsync.pass
-
开放防火墙
iptables -A INPUT -p tcp --dport 873 -j ACCEPT
开始部署 Sersync2
-
下载文件
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz
-
解压文件包
tar -zxvf sersync*_64bit_binary_stable_final.tar.gz && mv GNU-Linux-x86/ /usr/local/sersync
-
修改配置文件
mv /usr/local/sersync/confxml.xml /usr/local/sersync/confxml.xml.bak
下载配置文件
curl -so /usr/local/sersync/confxml.xml https://gitee.com/offends/Linux/raw/main/File/Xml/confxml.xml
修改如下内容(清根据自己需求修改配置文件其它参数)
-
nfs-master-1
sed -ri '25s#<remote ip="127.0.0.1" name="tongbu1"/>#<remote ip="192.168.1.20" name="data"/>#g' confxml.xml
-
nfs-master-2
sed -ri '25s#<remote ip="127.0.0.1" name="tongbu1"/>#<remote ip="192.168.1.10" name="data"/>#g' confxml.xml
-
-
配置 Sersync2 纳入 System 管理
curl -so /etc/systemd/system/sersync2.service https://gitee.com/offends/Linux/raw/main/File/Service/sersync2.service
-
启动 sersync2
systemctl daemon-reload systemctl enable sersync2 systemctl start sersync2
Params 参数常用配置之间的优缺点
artuz 选项:
- 优点:
- 完全归档:该选项包括
-a
(archive)选项,它将复制文件的所有属性(包括权限、所有者、时间戳等)并执行递归复制,以保持源目录结构的完整性。 - 保留时间戳:使用
-t
选项,它会保留文件的时间戳信息。 - 仅复制更新的文件:使用
-u
选项,只有当源文件更新时才会复制文件,这可以节省带宽和时间。
- 完全归档:该选项包括
- 不足:
- 复制速度较慢:由于会复制文件的属性和时间戳,可能会导致复制速度较慢,尤其是在大规模文件复制时。
az 选项:
- 优点:
- 启用压缩传输:该选项包括
-z
(compression)选项,它会在传输过程中启用压缩,减少数据传输的大小,特别适用于带宽有限的网络环境。 - 较快的传输速度:由于不复制文件属性和时间戳,传输速度通常较快。
- 启用压缩传输:该选项包括
- 不足:
- 不会保留文件属性:使用
-z
选项时,不会保留文件的属性,因此目标文件可能不会保留与源文件完全相同的属性。 - 不执行递归复制:使用
-z
选项时,不会执行递归复制,只会复制指定的文件或目录,而不包括子目录和文件。
- 不会保留文件属性:使用
问题记录
-
failed to create pid file /var/run/rsyncd.pid: File exists
问题原因, 使用如下命令启动后, 再次启动报错 pid 已存在
rsync --daemon --config=/etc/rsyncd.conf
解决方案
rm -rf /var/run/rsyncd.pid