使用 GlusterFS 轻松同步跨主机文件夹

因为昨晚我是直接写 Dockerfile 的,之前也没用过 GlusterFS,导致基于 Docker 的 GlusterFS 镜像运行得不好。今晚按照常规的方法在服务器跑一遍,摸索下操作过程,然后再改进 Docker 镜像。

web1:172.16.168.1
web2:172.16.168.2


编辑 hosts 文件

vi /etc/hosts
172.16.168.1 web1
172.16.168.2 web2

安装 GlusterFS

yum -y install glusterfs-server
# or
apt -y install glusterfs-server

互联两台服务器

在 web1 上执行:

gluster peer probe web2
peer probe: success.

在 web2 上执行:

gluster peer probe web1
peer probe: success.

创建共享卷

在 web1 与 web2 上创建存储 GlusterFS 管理的文件的目录。

mkdir /gluster-storage

在 web1 上,创建可复制的 GlusterFS 卷 volume1,执行:

gluster volume create volume1 replica 2 transport tcp web1:/gluster-storage web2:/gluster-storage force

在 web1 上,启动创建的 GlusterFS 卷:

gluster volume start volume1
volume start: volume1: success

查看创建与启动的 GlusterFS 卷,执行:

$ gluster volume info
Volume Name: volume1
Type: Replicate
Volume ID: 53ac1214-5dfd-4c6f-82f5-31b16b052cc9
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: web1:/gluster-storage
Brick2: web2:/gluster-storage

最后一步mount就看你喜欢了:

mount.glusterfs web1:/gluster-storage /mnt/mydisvol

参考:

  • https://talk.ninghao.net/t/shi-yong-glusterfs-zai-liang-tai-fu-wu-qi-zhi-jian-chuang-jian-gong-xiang-de-wen-jian-xi-tong/787
  • http://rickymax.wikidot.com/build-glusterfs
  • https://gluster.readthedocs.io/en/latest/Administrator%20Guide/Setting%20Up%20Volumes/

你可能感兴趣的:(使用 GlusterFS 轻松同步跨主机文件夹)