Files
Linux/存储/NFS/Nfs高可用实现Rsync+Sersync2.md
offends cee91802b3
Some checks failed
continuous-integration/drone Build is failing
synchronization
2025-08-25 15:57:40 +08:00

210 lines
5.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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