FTP迁移基于rsync跨节点同步文件夹

1. 新建 FTP 服务器

  • 在同网段 192.168.x.x 新建一台 FTP 服务器
  • 系统:CentOS Linux 7.4 及以上
  • 磁盘存储:1TB
  • 配置与现有应用服务一致的网络策略,确保可访问
  • 作为 FTP 备机,后续替换现有服务器

2. 清理历史无用文件

  • 建议删除不需要的历史文件,以减少迁移数据量

3. 文件同步(rsync)

⚠️ 注意 inode 使用率,避免因 inode 不足导致拷贝失败

3.1 安装 rsync

1
yum install -y rsync

3.2 在新 FTP 服务器配置 rsyncd

配置文件:/etc/rsyncd.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
port = 873
uid = weblogic
gid = weblogic
use chroot = no
max connections = 20
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

[xy]
path = /xxx/xy/
ignore errors
read only = no
list = no
hosts allow = 192.168.17.0/24

[xz]
path = /xxx/xz/
ignore errors
read only = no
list = no
hosts allow = 192.168.17.0/24


启动服务:

1
2
systemctl start rsyncd
systemctl enable rsyncd

3.3 在旧 FTP 服务器执行同步

配置 /etc/rsyncd.conf(简化版):

1
2
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log

执行同步命令:

1
2
3
rsync -auvz --delete /xxx/xy/ weblogic@192.168.17.119::xy

rsync -auvz --delete /xxx/xz/ weblogic@192.168.17.119::xz

说明:

  • --delete:保持两端目录一致,源端删除则目标端也删除
  • 首次执行:全量同步
  • 后续执行:增量同步(仍会扫描所有文件,耗时较长)

4. 切换 FTP

  1. 选择合适时机切换
  2. 修改数据库表中与 FTP 相关的配置
  3. 修改各应用配置文件中的 FTP 地址,指向新服务器
  4. 重启相关应用服务,验证正常