迁移FastDFS

迁移FastDFS

停止旧集群服务

[root@node01 fastdfs]# systemctl stop fdfs_tracker
[root@node01 fastdfs]# systemctl stop fdfs_storage
[root@node01 fastdfs]# systemctl stop nginx

把旧集群的配置文件复制到新的集群上,并修改对应的IP地址,路径可以保持不变。

[root@node01 fastdfs]# scp /opt/module/nginx-1.24.0/conf/nginx.conf 192.168.30.102:/opt/module/nginx-1.24.0/conf/
[root@node01 fastdfs]# scp -r /etc/fdfs 192.168.30.102:/etc/
[root@node01 data]# scp -r /opt/fastdfs 192.168.30.102:/opt

配置新集群服务

修改/etc/fdfs目录下的配置文件,主要是IP地址信息,

[root@node2 fdfs]# pwd
/etc/fdfs

# 查找之前的旧IP
[root@node2 fdfs]# find ./ -name "*.conf" | xargs grep 192.168.30.101
./tracker.conf:bind_addr = 192.168.30.101
./storage.conf:bind_addr = 192.168.30.101
./storage.conf:tracker_server = 192.168.30.101:22122
./client.conf:tracker_server = 192.168.30.101:22122
./mod_fastdfs.conf:tracker_server=192.168.30.101:22122

# 替换新的IP
[root@node2 fdfs]# find ./ -name "*.conf" | xargs sed -i 's/192.168.30.101/192.168.30.102/g'

# 修改数据目录下面的配置信息
[root@node2 fdfs]# cd /opt/fastdfs/data/
[root@node2 data]# pwd
/opt/fastdfs/data

[root@node1 data]# find ./ -type f | xargs grep 192.168.30.101
./.data_init_flag:last_ip_addr=192.168.30.101
./storage_servers_new.dat:# storage 192.168.30.101:23000
./storage_servers_new.dat:      ip_addr=192.168.30.101
./storage_sync_timestamp.dat:group1,192.168.30.101,0

[root@node02 data]# find ./ -type f | xargs sed -i 's@192.168.30.101@192.168.30.102@g'

[root@node1 data]# find ./ -type f | xargs grep 192.168.30.102
./.data_init_flag:last_ip_addr=192.168.30.102
./storage_servers_new.dat:# storage 192.168.30.102:23000
./storage_servers_new.dat:      ip_addr=192.168.30.102
./storage_sync_timestamp.dat:group1,192.168.30.102,0

启动新集群服务

# 启动服务
[root@node02 data]# systemctl start fdfs_trackerd
[root@node02 data]# systemctl start fdfs_storaged

[root@node1 data]# ps -ef |grep fdfs
root        951      1  0 7月26 ?       00:01:12 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
root        958      1  0 7月26 ?       00:01:16 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
# 查看集群状态
[root@node1 data]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
server_count=1, server_index=0

tracker server is 192.168.30.101:22122

group count: 1

Group 1:
group name = group1
disk total space = 92,111 MB
disk free space = 89,304 MB

启动Nginx

# 测试Nginx配置
[root@node1 ~]# /opt/module/nginx-1.24.0/sbin/nginx -t
ngx_http_fastdfs_set pid=6583
nginx: the configuration file /opt/module/nginx-1.24.0/conf/nginx.conf syntax is ok
nginx: configuration file /opt/module/nginx-1.24.0/conf/nginx.conf test is successful
# 启动Nginx
[root@node1 ~]# systemctl start nginx
# 下载个文件进行测试
[root@node02 data]# fdfs_download_file /etc/fdfs/client.conf group1/M00/00/0A/ChQUI2DutyGACKWzAADhZvSQ2cY200.png
# 使用curl进行测试
[root@node02 data]# curl -I "http://10.20.20.35/group1/M00/00/00/ChQUD2Dul5mAQKCoAC9azGybwbI681.png"
HTTP/1.1 200 0KServer: nginx/l.21.1
Date: Wed, 14 Jul 2021 10:19:00 GMT
Content-Type: image/pngContent-Length:3103436
Last-Modified: Wed, 14 Jul 2021 07:51:53 GMT
Connection: keep-aliveAccept-Ranges: bytes
FastDFS 是一种轻量级的分布式文件系统,适用于大规模文件存储和访问场景。在进行数据迁移时,通常希望尽可能减少停机时间,同时确保数据的一致性和完整性。根据现有信息,以下是一种可行的 FastDFS 数据迁移方法及步骤: ### 数据迁移方法 FastDFS 支持在线迁移,这意味着迁移过程中源存储节点可以不停机。新部署的 Storage Server 可以作为源 Storage Server 的备份节点,通过 FastDFS文件同步机制将数据从源节点同步到目标节点。 迁移的基本思路是: 1. 部署新的 Tracker Server 和 Storage Server。 2. 将新的 Storage Server 指向源 Tracker Server,并配置为源 Storage Server 同组的备份节点。 3. 利用 FastDFS 内置的同步机制进行数据同步。 4. 数据同步完成后,将源节点停机以避免新数据写入。 5. 修改新 Storage Server 的配置,使其指向新的 Tracker Server。 6. 确认新 Storage Server 的状态正常,完成迁移。 ### 数据迁移步骤 1. **部署新节点**:在目标环境中部署新的 Tracker Server 和 Storage Server 实例,确保网络可达性和端口开放(如 Tracker Server 的 22122 端口)。 2. **配置新 Storage Server**: - 修改新 Storage Server 的配置文件 `storage.conf`,设置 `group_name` 与源节点一致,并将 `tracker_server` 指向源 Tracker Server。 - 设置 `base_path` 和 `store_path` 指向新的存储路径。 3. **启动新 Storage Server**:启动新部署的 Storage Server,它会自动连接源 Tracker Server,并开始从源 Storage Server 同步数据。 4. **监控同步状态**: - 使用 FastDFS 提供的命令行工具(如 `fdfs_monitor`)查看 Storage Server 的状态,确认数据同步是否完成。 - 示例命令: ```bash /usr/bin/fdfs_monitor /etc/fdfs/storage.conf ``` 5. **停止源节点**:在确认数据同步完成后,停止源 Storage Server,以避免在迁移过程中有新的数据写入。 6. **修改新 Storage Server 配置**: - 将新 Storage Server 的 `tracker_server` 配置指向新的 Tracker Server。 - 清空 `sync_src_server` 配置项(可选),以确保新节点不再从源节点同步数据。 7. **重启新 Storage Server**:重启新 Storage Server,使其生效新的配置,并连接到新的 Tracker Server。 8. **验证迁移结果**:通过上传和下载文件的方式,验证新 Storage Server 是否能够正常工作,并确保数据一致性。 ### 文件删除操作(可选) 如果需要清理源节点的数据,可以使用 `fdfs_test` 工具删除文件: ```bash /usr/bin/fdfs_test /etc/fdfs/client.conf delete <group_name> <remote_filename> ``` ### 配置示例 以下是一个典型的 `mod_fastdfs.conf` 配置示例: ```bash base_path=/fastdfs/fdfs_nginx tracker_server=192.168.1.244:22122 url_have_group_name=true store_path_count=1 store_path0=/fastdfs/fdfs_storage/fdfs_storage_0 ``` ### 注意事项 - 在迁移过程中,确保源节点和目标节点之间的网络稳定。 - 迁移前建议备份所有配置文件,以防止配置错误导致服务异常。 - 在生产环境中进行迁移前,建议在测试环境中进行验证。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维小王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值