GFS分布式文件系统集群部署

1、配置host

10.0.1.20    gfs01
10.9.1.21  gfs02
10.0.1.22   gfs03

 

2、配置yum源

wget http://mirrors.aliyun.com/repo/Centos-7.repo -P /etc/yum.repos.d/
# 配置yum缓存策略。作用缓存yum下来的rpm包,正常不缓存
vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1

将keepcache默认的0改成1。然后保存退出。

原因说明:此处我的三台机器只有gfs01能上外网,另外两台都不能上外网,故其它机器后续的glusterfs的安装都是通过第一台机器yum安装的时候缓存下来的rpm包scp过去进行安装。

更新yum源

yum clean all
yum makecache

3、安装gfs

在三个节点上都需要安装glusterfs

gfs01上

yum install centos-release-gluster -y
yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma

gfs02上安装, gfs01上的包拷贝到gfs02上,并整合到一个目录

scp root@10.0.1.20:/var/cache/yum/x86_64/7/base/packages/*.rpm /soft/gluster/
scp root@10.0.1.20:/var/cache/yum/x86_64/7/extras/packages/*.rpm /soft/gluster/
scp root@10.0.1.20:/var/cache/yum/x86_64/7/updates/packages/*.rpm /soft/gluster/
scp root@10.0.1.20:/var/cache/yum/x86_64/7/centos-gluster6/packages/*.rpm /soft/gluster/
yum -y install *.rpm

gfs03上安装,

scp root@10.0.1.21:/soft/gluster/*.rpm /soft/gluster/
yum -y install *.rpm

没网上传文件自己安装

unzip gluster.zip
cd gluster
yum install *.rpm -y

4、启动glusterFS

三个节点都需要执行:

systemctl start glusterd
systemctl enable glusterd

5、加入集群

在master主机(gfs01)上,将两个slave节点(gfs02和gfs03)加入到gluster集群中

gluster peer probe gfs02
gluster peer probe gfs03

6、查看集群状态

[root@gfs01 ~]# gluster peer status

复制代码
Number of Peers: 2

Hostname: gfs02

Uuid: dfd62cb6-c2d0-45dc-8374-0b3067da11a5

State: Peer in Cluster (Connected)


Hostname: gfs03

Uuid: 24e44cf4-f3fb-4cfc-9f8a-b47f712d50b4

State: Peer in Cluster (Connected)
View Code
复制代码

 7、创建集群存储目录

本次三个主机各挂三块盘/dev/sdb。此章节记得在三台机器上都要做。

8、磁盘分区(。。。略过)

[root@gfs01 data]# fdisk –l

复制代码
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@gfs01 data]# fdisk /dev/sdb

Command (m for help): n   

Select (default p): p

Partition number (1-4, default 1):

First sector (2048-20971519, default 2048):

Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):

Command (m for help): t

Hex code (type L to list all codes): 8e

Command (m for help): w
View Code
复制代码

划一个分区即可,三台主机都做。

创建PV

[root@gfs01 data]# pvcreate /dev/sdb1

创建LV

[root@gfs01 data]# lvcreate -L +10G -n gfs01 vgdata

创建lv,指定大小为10g。

[root@gfs01 data]# lvcreate -l +2559 -n gfs01 vgdata

创建lv,通过指定划分的pe数指定大小为10g。

上面两种方法人选一种即可。

创建集群数据存储目录

[root@gfs01 data]# mkdir /gfs01

格式化lv

[root@gfs01 data]# mkfs.xfs /dev/vgdata/gfs01

挂载lv

[root@gfs01 data]# mount /dev/vgdata/gfs01 /gfs01

查看挂在

[root@gfs01 data]# df -Th

复制代码
ilesystem               Type            Size  Used Avail Use% Mounted on

/dev/mapper/centos-root  xfs              17G   11G  7.0G  60% /

devtmpfs                 devtmpfs        899M     0  899M   0% /dev

tmpfs                    tmpfs           911M     0  911M   0% /dev/shm

tmpfs                    tmpfs           911M  9.6M  902M   2% /run

tmpfs                    tmpfs           911M     0  911M   0% /sys/fs/cgroup

/dev/sda1                xfs            1014M  142M  873M  14% /boot

tmpfs                    tmpfs           183M     0  183M   0% /run/user/0

gfs01:models             fuse.glusterfs   80G     0   80G   0% /opt/gfsmount

/dev/mapper/vgdata-gfs01 xfs              10G   33M   10G   1% /gfs01
View Code
复制代码

 更新fatab

[root@gfs01 data]# vi /etc/fstab

/dev/mapper/vgdata-gfs01 /gfs01                 xfs     defaults        0 0

[root@gfs01 data]# mount -a

9、查看volume 状态

[root@gfs01 yum.repos.d]# gluster volume info
No volumes present

由于还没有创建volume所以显示的是暂无信息

10、创建GlusterFS磁盘

[root@gfs01 data]# gluster volume create gfstest replica 3 gfs01://do1cloud/fileData gfs02://do1cloud/fileData gfs03://do1cloud/fileData force
volume create: gfstest: success: please start the volume to access data

replica 3表明存储3个备份,后面指定服务器的存储目录,一般gfs会要求副本数量大于等于3,否则会有脑裂的提示

11、再次查看volume信息

[root@gfs01 data]# gluster volume info

复制代码
Volume Name: gfstest

Type: Replicate

Volume ID: 8d880cdc-d1a8-44a5-9e87-13b9a0539456

Status: Created

Snapshot Count: 0

Number of Bricks: 1 x 3 = 3

Transport-type: tcp

Bricks:

Brick1: gfs01:/do1cloud/fileData

Brick2: gfs02:/do1cloud/fileData

Brick3: gfs03:/do1cloud/fileData

Options Reconfigured:

transport.address-family: inet

nfs.disable: on

performance.client-io-threads: off
View Code
复制代码

 12、启动集群文件系统

[root@gfs01 data]# gluster volume start gfstest
volume start: gfstest: success

13、gluster性能调优(略过。。。。)

复制代码
开启指定volume的配额

[root@gfs01 data]# gluster volume quota gfstest enable

volume quota : success

限制volume中 / (既总目录) 最大使用 80GB 空间

[root@gfs01 data]# gluster volume quota gfstest limit-usage / 80GB

volume quota : success

设置 cache 大小

[root@gfs01 data]# gluster volume set gfstest performance.cache-size 64MB

volume set: success

开启异步

[root@gfs01 data]# gluster volume set gfstest performance.flush-behind on

volume set: success

设置io线程数

[root@gfs01 data]# gluster volume set gfstest performance.io-thread-count 8

volume set: success

设置io线程数为8.

设置回写

[root@gfs01 data]# gluster volume set gfstest performance.write-behind on

volume set: success

调优之后的volume

[root@gfs01 data]# gluster volume info
View Code
复制代码
复制代码
Volume Name: gfstest

Type: Replicate

Volume ID: 8d880cdc-d1a8-44a5-9e87-13b9a0539456

Status: Started

Snapshot Count: 0

Number of Bricks: 1 x 3 = 3

Transport-type: tcp

Bricks:

Brick1: gfs01:/gfs01

Brick2: gfs02:/gfs01

Brick3: gfs03:/gfs01

Options Reconfigured:

performance.write-behind: on

performance.io-thread-count: 8

performance.flush-behind: on

performance.cache-size: 64MB

features.quota-deem-statfs: on

features.inode-quota: on

features.quota: on

transport.address-family: inet

nfs.disable: on

performance.client-io-threads: off
View Code
复制代码

14、部署Gluster客户端

我们就以gfs01为客户端。

建立挂载点

[root@gfs01 data]# mkdir /opt/gfs01

mount文件系统

[root@gfs01 data]# mount -t glusterfs gfs01:gfstest /opt/gfs01
#持久化
vim /etc/fstab
node01:gfstest  /opt/gfs01 glusterfs  defaults 0 0

检查挂载的文件系统

[root@gfs01 data]# df -Th

复制代码
Filesystem               Type            Size  Used Avail Use% Mounted on

/dev/mapper/centos-root  xfs              17G   11G  7.0G  60% /

devtmpfs                 devtmpfs        899M     0  899M   0% /dev

tmpfs                    tmpfs           911M     0  911M   0% /dev/shm

tmpfs                    tmpfs           911M  9.6M  902M   2% /run

tmpfs                    tmpfs           911M     0  911M   0% /sys/fs/cgroup

/dev/sda1                xfs            1014M  142M  873M  14% /boot

tmpfs                    tmpfs           183M     0  183M   0% /run/user/0

gfs01:models             fuse.glusterfs   80G     0   80G   0% /opt/gfsmount

/dev/mapper/vgdata-gfs01 xfs              10G   33M   10G   1% /gfs01

gfs01:gfstest            fuse.glusterfs   80G     0   80G   0% /opt/gfs01
View Code
复制代码

写入文件到挂载目录

[root@gfs01 gfs01]# pwd
/opt/gfs01
[root@gfs01 gfs01]# vi aaa.txt
this is test by wufan !

检查集群挂载目录,数据是否同步

复制代码
#gfs01主机:
[root@gfs01 gfs01]# pwd
/gfs01
[root@gfs01 gfs01]#ls
aaa.txt

#gfs02主机:
[root@gfs02 gfs01]# ls
aaa.txt
#gfs03主机: [root@gfs03 gfs01]# ls aaa.txt
复制代码

可以看到gluster服务器的每个节点上都有备份,符合之前设置的3个备份的原则

查看Gluster中所有的volume

[root@gfs03 gfs01]# gluster volume list
gfstest
models

删除GlusterFS磁盘

列出有哪些vlume:

[root@gfs03 gfs01]# gluster volume list
gfstest
models

停止valume:

[root@gfs03 gfs01]# gluster volume stop models
Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y
volume stop: models: success

删除volume:

[root@gfs03 gfs01]# gluster volume delete models
Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y
volume delete: models: success

再次查看volume:

[root@gfs03 gfs01]# gluster volume list
gfstest

 

posted @   王竹笙  阅读(649)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示