nfs+sersync

一台服务器 ServerA ,该服务器上有一个本地目录 /mnt/nfsdata ,此目录通过 NFS 挂载了远程服务器 ServerNFS 上的目录 /data/shared 。需要对 ServerA 上的/mnt/nfsdata 中的数据进行实时备份。为此,在另一台服务器 ServerB 上部署sersync2 ,以监控和同步 ServerA 上的 /mnt/nfsdata 数据至 ServerB /backup/data 目录。

 

 

方案核心架构理解

  1. 数据流向: ServerNFS:/data/shared -> (通过NFS) -> ServerA:/mnt/nfsdata -> (通过Sersync) -> ServerB:/backup/data

  2. 角色分配:

    • ServerA: 作为NFS客户端和Sersync的客户端。它挂载远程NFS目录,并运行Sersync进程来监控本地目录(即挂载点)的变化。

    • ServerB: 作为备份目标服务器,通常也是Rsync守护进程(rsyncd)的服务端。

  3. 工作原理: Sersync利用Linux内核的inotify机制监控/mnt/nfsdata目录的任何变化(如文件创建、修改、删除)。一旦检测到变化,它立即调用Rsync工具,通过SSH或Rsync自有协议,将变化的数据同步到ServerB。

 

环境配置

10.0.0.201      ServerNFS    openeuler24.03 LTS

10.0.0.205        Backup        ubuntu20.04.6  LTS

10.0.0.204         ServerA       ubuntu20.04.6  LTS

前置操作

#关闭selinux
vim /etc/selinux/config

SELINUX=disabled    

setenfoce 0

#关闭防火墙

systemctl --disable now firewalld

systemctl --disable now ufw

 

#10.0.0.201      ServerNFS    openeuler24.03 LTS

sudo apt install nfs-kernel-server

mkdir /data/shared -p

useradd -u 1111 -s /usr/bin/nologin -M nfsuser

chown nfsuser:nfsuser  /data/shared -R

 

 

vim /etc/exports

/data/shared  10.0.0.204(rw,anongid=1111,anonuid=1111)

 

 

exportfs -r

 

 

 

Backup

apt install -y rnync

 

vim /etc/rsyncd.conf

uid=root

gid=root

max connection=0 log file=/var/log/rsyncd.log pid file=/var/run/rsyncd.pid lock file=/var/run/rsyncd.lock

[dir1]

path=/backup/data

comment=rsync dir1

read only=no

auth users=rsyncer

secrets file=/etc/rsyncd.pwd

 

 

vim /etc/rsyncd.pwd

 

rsyncer:123456

 

chmod 600 /etc/rsyncd.pwd

 

systemctl restart rsync

ServerA

# 挂载NFS磁盘

 

mount 10.0.0.204:/data/shared /mnt/nfsdata

 

# 下载并部署sersync2

 

wget https://storage.googleapis.com/google-code-archivedownloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.g z t ar xf sersync2.5.4_64bit_binary_stable_final.tar.gz

 

vim GNU-Linux-x86/confxml.xml

 

# 修改下面几行

 

<sersync>

 

<localpath watch="/mnt/nfsdata/">

 

<remote ip="10.0.0.204" name="dir1"/> <!--<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="rsyncer" passwordfile="/etc/rsyncd.pwd"/> <userDefinedPort start="false" port="874"/><!-- 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="600"><!--600mins-->

 

<crontabfilter start="false">

 

<exclude expression="*.php"></exclude>

 

<exclude expression="info/*"></exclude>

</crontabfilter> </crontab>

<plugin start="false" name="command"/>

</sersync>

 

echo 123456 > /etc/rsyncd.pwd

chmod 600 /etc/rsyncd.pwd

 

cd GNU-Linux-x86

./sersync2 -dro ./confxml

# 测试

ServerA /mnt/nfsdata目录下创建文件, 观察NFSServer上的/data/sharedBackup上的/backup/data上是否都有文件


posted on 2025-09-12 10:32  jun_li123  阅读(13)  评论(0)    收藏  举报

导航