搭建GFS分布式文件系统

简介: 搭建GFS分布式文件系统

一:GlusterFS部署

1.1:部署群集环境

实验top

1:准备环境(以node1为例,其他节点步骤略,请自行配置)

(1)按照表中所示,为node节点添加相应数量和大小的磁盘,并重启系统

(2)为所有节点的新磁盘分区

(3)安装的是老版本,所以可以做条带卷

用fdisk命令为每个磁盘分区

node1-4:

[root@localhost ~]# fdisk /dev/sdb

[root@localhost ~]# fdisk /dev/sdc

[root@localhost ~]# fdisk /dev/sdd

[root@localhost ~]# fdisk /dev/sde

(2)为每个节点的每个磁盘格式化

node1-4:

[root@localhost ~]# mkfs -t ext4 /dev/sdb1

[root@localhost ~]# mkfs -t ext4 /dev/sdc1

[root@localhost ~]# mkfs -t ext4 /dev/sdd1

[root@localhost ~]# mkfs -t ext4 /dev/sde1

(3)创建挂载点

node1-4:

[root@localhost ~]# mkdir /b1

[root@localhost ~]# mkdir /c1

[root@localhost ~]# mkdir /d1

[root@localhost ~]# mkdir /e1

(4)挂载磁盘

node1-4:

[root@localhost ~]# mount /dev/sdb1 /b1

[root@localhost ~]# mount /dev/sdc1 /c1

[root@localhost ~]# mount /dev/sdd1 /d1

[root@localhost ~]# mount /dev/sde1 /e1

(5)修改fstab文件,使挂载永久生效

[root@localhost ~]# vi /etc/fstab

在末尾添加

/dev/sdb1       /b1     ext4     defaults  0 0

/dev/sdc1       /c1     ext4     defaults  0 0

/dev/sdd1       /d1    ext4     defaults  0 0

/dev/sde1       /e1     ext4     defaults  0 0

2:在所有节点上关闭防火墙和selinux

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# setenforce 0

3:在所有节点上修改hosts文件

node1-4:

[root@localhost ~]# vi /etc/hosts

192.168.1.10  node1

192.168.1.11  node2

192.168.1.12  node3

192.168.1.13  node4

4:在所有节点安装软件

(1)配置yum仓库

将GFS所需的rpm仓库的gfsrepo目录拷贝到linux系统的/opt下,并修改仓库文件(暂时注释)

node1-4:

[root@localhost ~]# vi /etc/yum.repos.d/CentOS-Media.repo

#[c7-media]

#name=CentOS-$releasever - Media

#baseurl=file:///media/cdrom/

#gpgcheck=1

#enabled=1

#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[gfsrepo]

name=GFS

baseurl=file:///root/GFS

gpgcheck=0

enabled=1

[root@localhost ~]# yum clean all

(2)在所有节点上安装gfs

node1-4:

[root@localhost ~]# yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma

5:在所有节点上启动GFS

node1-4:

[root@localhost ~]# systemctl start glusterd.service

[root@localhost ~]# systemctl enable glusterd.service

6:添加节点(只在node1节点上)

[root@localhost ~]# gluster peer probe node1

peer probe: success. Probe on localhost not needed

[root@localhost ~]# gluster peer probe node2

peer probe: success.

[root@localhost ~]# gluster peer probe node3

peer probe: success.

[root@localhost ~]# gluster peer probe node4

peer probe: success.

7:在每个节点上查看状态

node1-4:

[root@localhost ~]# gluster peer status

Number of Peers: 3

Hostname: node2

Uuid: 469be571-b52a-4a89-a30a-c3a770753b0e

State: Peer in Cluster (Connected)

Hostname: node3

Uuid: 24742939-afc6-4243-a8a8-1aa57a336128

State: Peer in Cluster (Connected)

Hostname: node4

Uuid: dbc703a3-1e22-42cd-bedf-da3541bce983

State: Peer in Cluster (Connected)

1.2:创建卷

1:创建分布式卷(在node1上)

[root@localhost ~]# gluster volume create dis-volume node1:/e6 node2:/e6 force

注释:#利用node1和node2上的两块磁盘创建;dis-vol为磁盘名;force表示强制

[root@localhost ~]# gluster volume info dis-volume   #查看状态

Volume Name: dis-volume

Type: Distribute

Volume ID: 40946bd8-cc79-406a-be3c-5c03dd2a207e

Status: Created

Snapshot Count: 0

Number of Bricks: 2

Transport-type: tcp

Bricks:

Brick1: node1:/e6

Brick2: node2:/e6

Options Reconfigured:

transport.address-family: inet

nfs.disable: on

[root@localhost ~]# gluster volume start dis-volume   #启动

2:创建条带卷

[root@localhost ~]# gluster volume create stripe-volume stripe 2 node1:/d5 node2:/d5 force

[root@localhost ~]# gluster volume info stripe-volume

Volume Name: stripe-volume

Type: Stripe

Volume ID: d8e335d5-47d5-484f-804b-bb36ed522bf6

Status: Created

Snapshot Count: 0

Number of Bricks: 1 x 2 = 2

Transport-type: tcp

Bricks:

Brick1: node1:/d5

Brick2: node2:/d5

Options Reconfigured:

transport.address-family: inet

nfs.disable: on

[root@localhost ~]# gluster volume start stripe-volume

3:创建复制卷

[root@localhost ~]# gluster volume create rep-volume replica 2 node3:/d5 node4:/d5 force

[root@localhost ~]# gluster volume info rep-volume

Volume Name: rep-volume

Type: Replicate

Volume ID: b5d1afda-ab03-47a7-82b9-2786648a9b3a

Status: Created

Snapshot Count: 0

Number of Bricks: 1 x 2 = 2

Transport-type: tcp

Bricks:

Brick1: node3:/d5

Brick2: node4:/d5

Options Reconfigured:

transport.address-family: inet

nfs.disable: on

[root@localhost ~]# gluster volume start rep-volume

4:创建分布式条带卷

[root@localhost ~]# gluster volume create dis-stripe stripe 2 node1:/b3 node2:/b3 node3:/b3 node4:/b3 force

[root@localhost ~]# gluster volume info dis-stripe

Volume Name: dis-stripe

Type: Distributed-Stripe

Volume ID: ff516167-7840-485a-8d3a-1630bd4d174d

Status: Created

Snapshot Count: 0

Number of Bricks: 2 x 2 = 4

Transport-type: tcp

Bricks:

Brick1: node1:/b3

Brick2: node2:/b3

Brick3: node3:/b3

Brick4: node4:/b3

Options Reconfigured:

transport.address-family: inet

nfs.disable: on

[root@localhost ~]# gluster volume start dis-stripe

5:创建分布式复制卷

[root@localhost ~]# gluster volume create dis-rep replica 2 node1:/c4 node2:/c4 node3:/c4 node4:/c4 force

[root@localhost ~]# gluster volume info dis-rep

Volume Name: dis-rep

Type: Distributed-Replicate

Volume ID: 197055f7-37d8-419f-bb22-9f05c7e1a032

Status: Created

Snapshot Count: 0

Number of Bricks: 2 x 2 = 4

Transport-type: tcp

Bricks:

Brick1: node1:/c4

Brick2: node2:/c4

Brick3: node3:/c4

Brick4: node4:/c4

Options Reconfigured:

transport.address-family: inet

nfs.disable: on

[root@localhost ~]# gluster volume start dis-rep

1.3:部署GFS客户端

1:安装客户端软件

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# setenforce 0

[root@localhost ~]# systemctl disable firewalld

[root@localhost ~]# yum -y install glusterfs glusterfs-fuse

2:创建挂载目录

[root@localhost ~]# mkdir -p /test/{dis,stripe,rep,dis_and_stripe,dis_and_rep}

[root@localhost ~]# ls /test

dis  dis_and_stripe  dis_rep  rep  stripe

3:修改hosts文件

[root@localhost ~]# vi /etc/hosts

192.168.8.134  node1

192.168.8.136  node2

192.168.8.139  node3

192.168.8.141  node4

4:挂载Gluster文件系统

[root@localhost ~]# mount -t glusterfs node1:dis-volume /test/dis

[root@localhost ~]# mount -t glusterfs node1:stripe-volume /test/stripe/

[root@localhost ~]# mount -t glusterfs node1:rep-volume /test/rep

[root@localhost ~]# mount -t glusterfs node1:dis-stripe /test/dis_and_stripe/

[root@localhost ~]# mount -t glusterfs node1:dis-rep /test/dis_and_rep/

[root@localhost ~]# df -h

文件系统             容量  已用  可用 已用% 挂载点

/dev/mapper/cl-root   95G  4.0G   91G    5% /

devtmpfs             473M     0  473M    0% /dev

tmpfs                489M  144K  489M    1% /dev/shm

tmpfs                489M  7.1M  482M    2% /run

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

/dev/sda1           1014M  173M  842M   18% /boot

tmpfs                 98M   12K   98M    1% /run/user/0

/dev/sr0             4.1G  4.1G     0  100% /media/cdrom

node1:dis-volume      12G   49M   11G    1% /test/dis

node1:rep-volume     4.8G   21M  4.6G    1% /test/rep

node1:dis-stripe      12G   37M   11G    1% /test/dis_and_stripe

node1:dis-rep        7.8G   33M  7.3G    1% /test/dis_and_rep

node1:stripe-volume  9.6G   41M  9.1G    1% /test/stripe

5:修改fstab配置文件

[root@localhost ~]# vi /etc/fstab

在末尾添加:

node1:dis-volume     /test/dis             glusterfs  defaules,_netdev  0 0

node1:stripe-volume  /test/stripe          glusterfs  defaules,_netdev  0 0

node1:rep-volume     /test/rep             glusterfs  defaules,_netdev  0 0

node1:dis-stripe     /test/dis_and_stripe  glusterfs  defaules,_netdev  0 0

node1:dis-rep        /test/dis_and_rep     glusterfs  defaules,_netdev  0 0

1.4:在客户端测试Gluster文件系统

1:在卷中写入文件

(1)创建测试文件

[root@localhost ~]# dd if=/dev/zero of=/root/demo1.log bs=1M count=43

[root@localhost ~]# dd if=/dev/zero of=/root/demo2.log bs=1M count=43

[root@localhost ~]# dd if=/dev/zero of=/root/demo3.log bs=1M count=43

[root@localhost ~]# dd if=/dev/zero of=/root/demo4.log bs=1M count=43

[root@localhost ~]# dd if=/dev/zero of=/root/demo5.log bs=1M count=43

(2)卷中写入文件

[root@localhost ~]# cp demo* /test/dis/

[root@localhost ~]# cp demo* /test/stripe/

[root@localhost ~]# cp demo* /test/rep/

[root@localhost ~]# cp demo* /test/dis_and_stripe/

[root@localhost ~]# cp demo* /test/dis_and_rep/

2:查看文件分布

(1)在node1和node2中查看分布式卷文件分布

node1:

[root@localhost ~]# ll -h /e6

总用量 173M

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo1.log

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo2.log

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo3.log

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo4.log

node2:

[root@localhost ~]# ll -h /e6

总用量 44M

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo5.log

(2)在node1和node2中查看条带卷文件分布

node1:

[root@localhost ~]# ll -h /d5

总用量 108M

-rw-r--r--. 2 root root 22M 4月  17 22:06 demo1.log

-rw-r--r--. 2 root root 22M 4月  17 22:06 demo2.log

-rw-r--r--. 2 root root 22M 4月  17 22:06 demo3.log

-rw-r--r--. 2 root root 22M 4月  17 22:06 demo4.log

-rw-r--r--. 2 root root 22M 4月  17 22:06 demo5.log

node2:

[root@localhost ~]# ll -h /d5

总用量 108M

-rw-r--r--. 2 root root 22M 4月  17 22:06 demo1.log

-rw-r--r--. 2 root root 22M 4月  17 22:06 demo2.log

-rw-r--r--. 2 root root 22M 4月  17 22:06 demo3.log

-rw-r--r--. 2 root root 22M 4月  17 22:06 demo4.log

-rw-r--r--. 2 root root 22M 4月  17 22:06 demo5.log

(3)在node3和node4中查看复制卷文件分布

node3:

[root@localhost ~]# ll -h /d5

总用量 216M

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo1.log

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo2.log

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo3.log

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo4.log

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo5.log

node4:

[root@localhost ~]# ll -h /d5

总用量 216M

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo1.log

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo2.log

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo3.log

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo4.log

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo5.log

(4)在node1、node2、node3、node4中查看分布式条带文件分布

node1:

[root@localhost ~]# ll -h /b3

总用量 87M

-rw-r--r--. 2 root root 22M 4月  17 22:07 demo1.log

-rw-r--r--. 2 root root 22M 4月  17 22:07 demo2.log

-rw-r--r--. 2 root root 22M 4月  17 22:07 demo3.log

-rw-r--r--. 2 root root 22M 4月  17 22:07 demo4.log

node2:

[root@localhost ~]# ll -h /b3

总用量 87M

-rw-r--r--. 2 root root 22M 4月  17 22:07 demo1.log

-rw-r--r--. 2 root root 22M 4月  17 22:07 demo2.log

-rw-r--r--. 2 root root 22M 4月  17 22:07 demo3.log

-rw-r--r--. 2 root root 22M 4月  17 22:07 demo4.log

node3:

[root@localhost ~]# ll -h /b3

总用量 22M

-rw-r--r--. 2 root root 22M 4月  17 22:07 demo5.log

node4:

[root@localhost ~]# ll -h /b3

总用量 22M

-rw-r--r--. 2 root root 22M 4月  17 22:07 demo5.log

(5)在node1、node2、node3、node4中查看分布式复制卷文件分布

node1:

[root@localhost ~]# ll -h /c4

总用量 173M

-rw-r--r--. 2 root root 43M 4月  17 22:06 demo1.log

-rw-r--r--. 2 root root 43M 4月  17 22:07 demo2.log

-rw-r--r--. 2 root root 43M 4月  17 22:07 demo3.log

-rw-r--r--. 2 root root 43M 4月  17 22:07 demo4.log

node2:

[root@localhost ~]# ll -h /c4

总用量 173M

-rw-r--r--. 2 root root 43M 4月  17 22:07 demo1.log

-rw-r--r--. 2 root root 43M 4月  17 22:07 demo2.log

-rw-r--r--. 2 root root 43M 4月  17 22:07 demo3.log

-rw-r--r--. 2 root root 43M 4月  17 22:07 demo4.log

node3:

[root@localhost ~]# ll -h /c4

总用量 44M

-rw-r--r--. 2 root root 43M 4月  17 22:07 demo5.log

node4:

[root@localhost ~]# ll -h /c4

总用量 44M

-rw-r--r--. 2 root root 43M 4月  17 22:07 demo5.log

3:破坏性测试

(1)关闭或挂起node2节点,在客户端上测试各个文件是否可以正常使用

(2)再关闭或挂起node4,在客户端继续测试各个文件的读取

可以发现:

1.分布式卷所有文件都在;

2.复制卷所有文件都在;

3.挂载分布式条带卷只有 demo5.log 一个文件了,丢失了4个;

4.挂载分布式复制卷所有文件都在;

5.条带卷所有文件都丢失了。

相关文章
|
7月前
|
存储 运维 算法
GFS分布式文件系统
GFS分布式文件系统
94 0
|
存储 负载均衡 安全
分布式文件系统实战,使用MinIO构建分布式文件系统!
随着文件数据的越来越多,传统的文件存储方式通过tomcat或nginx虚拟化的静态资源文件在单一的服务器节点内已经无法满足系统需求,也不利于文件的管理和维护,这就需要一个系统来管理多台计算机节点上的文件数据,这就是分布式文件系统。
3796 0
分布式文件系统实战,使用MinIO构建分布式文件系统!
|
9月前
|
存储 监控 Linux
分布式文件系统Moosefs
MooseFS是一个具备冗余容错功能的分布式网络文件系统,它将数据分别存放在多个物理服务器或单独磁盘或分区上,确保一份数据有多个备份副本。对于访问的客户端或者用户来说,整个分布式网络文件系统集群看起来就像一个资源一样。
|
存储 分布式计算 负载均衡
GFS 分布式文件系统(上)
GlusterFS简介 a) GlusterFS是一-个开源的分布式文件系统。 由存储服务器、客户端以及NFS/Samba存储网关(可选,根据需要选择使用)组成。 无元数据服务器组件,这有助于提升整个系统的性能、可靠性和稳定性。
GFS 分布式文件系统(上)
|
存储 缓存 负载均衡
|
存储 分布式计算 关系型数据库
GFS分布式文件系统(二)
GFS分布式文件系统(二)
|
存储
GFS 分布式文件系统(下)
GlusterFS利用双重特性来提供高容量存储解决方案。
GFS 分布式文件系统(下)
|
Linux 测试技术 存储