GlusterFS---分布式文件系统~~

简介

  • 文件系统组成
  • 文件系统接口
  • 对对像管理的软件集合
  • 对象及属性

文件系统作用

从系统角度来看,文件系统是对文件存储设备的空间进行组织和分配,负责文件存储并对存入的文件进行保护和检索的系统。
具体地说,它负责为用户建立文件,存入、读出、修改、转储文件,控制文件的存取

GFS是由三个组件

存储服务器
客户端
NFS/Samba存储网关组成

文件系统的挂载使用

除根文件系统以外的文件系统创建后要使用需要先挂载至挂载点后才可以被访问,挂载点即分区设备文件关联的某个目录文件
类比:NES

实操

四台GFS同时操作

##用脚本进行磁盘分区并挂载
vim /opt/fdisk.sh
#!/bin/bash
echo "the disks exist list:"
##grep出系统所带磁盘
fdisk -l |grep '磁盘 /dev/sd[a-z]'    
echo "=================================================="
PS3="chose which disk you want to create:"
 ##选择需要创建的磁盘编号
select VAR in `ls /dev/sd*|grep -o 'sd[b-z]'|uniq` quit   
do
    case $VAR in
    sda)
 ##本地磁盘就退出case语句
        fdisk -l /dev/sda   
        break ;;
    sd[b-z])
        #create partitions
        echo "n    ##创建磁盘
                p
                
                
           
                w"  | fdisk /dev/$VAR
 
        #make filesystem
##格式化
        mkfs.xfs -i size=512 /dev/${VAR}"1" &> /dev/null    
	#mount the system
        mkdir -p /data/${VAR}"1" &> /dev/null
###永久挂载
        echo -e "/dev/${VAR}"1" /data/${VAR}"1" xfs defaults 0 0\n" >> /etc/fstab
###使得挂载生效
        mount -a &> /dev/null
        break ;;
    quit)
        break;;
    *)
        echo "wrong disk,please check again";;
    esac
done

##给予权限,执行脚本
chmod +x /opt/fdisk.sh
cd /opt/
sh -x fdisk.sh						#连续四次,交互过程填写1234
[root@node4 opt]# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda3      xfs       197G  5.4G  192G   3% /
devtmpfs       devtmpfs  895M     0  895M   0% /dev
tmpfs          tmpfs     910M     0  910M   0% /dev/shm
tmpfs          tmpfs     910M   11M  900M   2% /run
tmpfs          tmpfs     910M     0  910M   0% /sys/fs/cgroup
/dev/sda1      xfs       197M  152M   45M  78% /boot
tmpfs          tmpfs     182M  4.0K  182M   1% /run/user/42
tmpfs          tmpfs     182M   36K  182M   1% /run/user/0
/dev/sdb1      xfs        20G   33M   20G   1% /data/sdb1
/dev/sdc1      xfs        20G   33M   20G   1% /data/sdc1
/dev/sdd1      xfs        20G   33M   20G   1% /data/sdd1
/dev/sde1      xfs        20G   33M   20G   1% /data/sde1

添加地址映射
echo "192.168.118.200 node1" >> /etc/hosts
echo "192.168.118.55 node2" >> /etc/hosts
echo "192.168.118.100 node3" >> /etc/hosts
echo "192.168.118.50 node4" >> /etc/hosts
echo "192.168.118.88 client" >> /etc/hosts


##安装部署GlusterFS,设置本地源安装
unzip gfsrepo.zip 
cd /etc/yum.repos.d/
mkdir bak
mv CentOS-* bak

vim gfs.repo
[glfs]
name=glfs
baseurl=file:///opt/gfsrepo
gpgcheck=0
enabled=1

yum clean all				#刷新本地仓库
yum makecache
rpm -e --nodeps glusterfs-api glusterfs-libs glusterfs-fuse glusterfs-cli  glusterfs glusterfs-client-xlators
yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma		#下载依赖包

##开启服务

systemctl start glusterd.service 
systemctl enable glusterd.service
systemctl status glusterd.service

加入存储信息池

[root@node1 opt]# gluster peer probe node1  //加入存储信任池,只需要在一台节点上操作即可
peer probe: success. Probe on localhost not needed
[root@node1 opt]# gluster peer probe node2
peer probe: success. 
[root@node1 opt]# gluster peer probe node3
peer probe: success. 
[root@node1 opt]# gluster peer probe node4
peer probe: success. 


[root@node1 opt]# gluster peer status 
Number of Peers: 3

Hostname: node2
Uuid: a02106dc-7fed-4bf8-9968-efa2a5bc4ec7
State: Peer in Cluster (Connected)

Hostname: node3
Uuid: 038c0761-f1f6-42c3-914e-40aedbdbf720
State: Peer in Cluster (Connected)

Hostname: node4
Uuid: 6840d481-bf60-43b8-ae71-97395a0d9bcb
State: Peer in Cluster (Connected)



创建卷

卷名称 				卷类型				Brick
dis-volume			分布式卷				node1(/data/sdb1)、node2(/data/sdb1)
stripe-volume		条带卷			    node1(/data/sdc1)、node2(/data/sdc1)
rep-volume			复制卷			    node3(/data/sdb1)、node4(/data/sdb1)
dis-stripe			分布式条带卷			node1(/data/sdd1)、node2(/data/sdd1)、node3(/data/sdd1)、node4(/data/sdd1)
dis-rep				分布式复制卷			node1(/data/sde1)、node2(/data/sde1)、node3(/data/sde1)、node4(/data/sde1)
[root@node1 gfsrepo]# gluster volume create dis-volume node1:/data/sdb1 node2:/data/sdb1 force
volume create: dis-volume: success: please start the volume to access data
[root@node1 gfsrepo]# gluster volume list				#查看卷列表
dis-volume
[root@node1 gfsrepo]# gluster volume start dis volume	#启动新建分布式卷
Usage: volume start <VOLNAME> [force]
[root@node1 gfsrepo]# gluster volume info dis-volume	#查看分布式卷信息
 
Volume Name: dis-volume
Type: Distribute
Volume ID: c542f24d-b18f-432f-acdd-6f7bb9ee6e1b
Status: Created
Snapshot Count: 0
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdb1
Brick2: node2:/data/sdb1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on

创建复制卷

[root@node1 gfsrepo]# gluster volume create rep-volume replica 2 node3:/data/sdb1 node4:/data/sdb1 force
volume create: rep-volume: success: please start the volume to access data
[root@node1 gfsrepo]# gluster volume start rep-volume
volume start: rep-volume: success
[root@node1 gfsrepo]# gluster volume info rep-volume
 
Volume Name: rep-volume
Type: Replicate
Volume ID: fbac45bc-a688-4228-a96b-d9407bd40f08
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node3:/data/sdb1
Brick2: node4:/data/sdb1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on

创建条带卷

[root@node1 opt]# gluster volume create stripe-volume stripe 2 node1:/data/sdc1 node2:/data/sdc1 force  //指定类型为 stripe,数值为 2,且后面跟了 2 个 Brick Server,所以创建的是条带卷
volume create: stripe-volume: success: please start the volume to access data
[root@node1 opt]# gluster volume start stripe-volume   //启动新建条带卷
volume start: stripe-volume: success
[root@node1 opt]# gluster volume info stripe-volume   //查看新建条带卷信息
 
Volume Name: stripe-volume
Type: Stripe
Volume ID: 478b8497-4c3d-4db4-b958-2abf5798aac2
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdc1
Brick2: node2:/data/sdc1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
[root@node1 opt]# 

创建分布式复制卷

[root@node1 opt]# gluster volume create dis-rep replica 2 node1:/data/sde1 node2:/data/sde1 node3:/data/sde1 node4:/data/sde1 force  //指定类型为 replica,数值为 2,而且后面跟了 4 个 Brick Server,是 2 的两倍,所以创建的是分布式复制卷
volume create: dis-rep: success: please start the volume to access data
[root@node1 opt]# gluster volume start dis-rep  //启动新建分布式复制卷
volume start: dis-rep: success
[root@node1 opt]# gluster volume info dis-rep    //查看新建分布式复制卷信息
 
Volume Name: dis-rep
Type: Distributed-Replicate
Volume ID: 39a8d0e8-79e9-431f-aeca-b69254d687c5
Status: Started
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: node1:/data/sde1
Brick2: node2:/data/sde1
Brick3: node3:/data/sde1
Brick4: node4:/data/sde1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on

创建分布式条带卷

[root@node1 opt]# gluster volume create dis-stripe stripe 2 node1:/data/sdd1 node2:/data/sdd1 node3:/data/sdd1 node4:/data/sdd1 force  //指定类型为 stripe,数值为 2,而且后面跟了 4 个 Brick Server,是 2 的两倍,所以创建的是分布式条带卷
volume create: dis-stripe: success: please start the volume to access data
[root@node1 opt]# gluster volume start dis-stripe   //启动新建分布式条带卷
volume start: dis-stripe: success
[root@node1 opt]# gluster volume info dis-stripe   //查看分布式条带卷信息
 
Volume Name: dis-stripe
Type: Distributed-Stripe
Volume ID: 54bcbe8e-f30a-4bbb-a36a-13d7cfaaab2b
Status: Started
Snapshot Count: 0
Number of Bricks: 2 x 2 = 4
Transport-type: tcp
Bricks:
Brick1: node1:/data/sdd1
Brick2: node2:/data/sdd1
Brick3: node3:/data/sdd1
Brick4: node4:/data/sdd1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on

部署

[root@client ~]# echo "192.168.30.6 node1" >> /etc/hosts
[root@client ~]# echo "192.168.30.7 node2" >> /etc/hosts
[root@client ~]# echo "192.168.30.8 node3" >> /etc/hosts
[root@client ~]# echo "192.168.30.9 node4" >> /etc/hosts
[root@client ~]# echo "192.168.30.5 client" >> /etc/hosts
[root@client ~]# 

** 创建挂载点**

[root@client opt]# mkdir -p /test/{dis,stripe,rep,dis_stripe,dis_rep}
[root@client opt]# ls /test
dis  dis_rep  dis_stripe  rep  stripe
[root@client opt]# mount.glusterfs node1:dis-volume /test/dis
[root@client opt]# mount.glusterfs node1:stripe-volume /test/stripe
[root@client opt]# mount.glusterfs node1:rep-volume /test/rep
[root@client opt]# mount.glusterfs node1:dis-stripe /test/dis_stripe
[root@client opt]# mount.glusterfs node1:dis-rep /test/dis_rep
[root@client opt]# df -hT
文件系统            类型            容量  已用  可用 已用% 挂载点
/dev/sda3           xfs             197G  4.5G  193G    3% /
devtmpfs            devtmpfs        895M     0  895M    0% /dev
tmpfs               tmpfs           910M     0  910M    0% /dev/shm
tmpfs               tmpfs           910M   11M  900M    2% /run
tmpfs               tmpfs           910M     0  910M    0% /sys/fs/cgroup
/dev/sda1           xfs            1014M  174M  841M   18% /boot
tmpfs               tmpfs           182M   12K  182M    1% /run/user/42
tmpfs               tmpfs           182M     0  182M    0% /run/user/0
node1:dis-volume    fuse.glusterfs  8.0G   65M  8.0G    1% /test/dis
node1:stripe-volume fuse.glusterfs  8.0G   65M  8.0G    1% /test/stripe
node1:rep-volume    fuse.glusterfs  4.0G   33M  4.0G    1% /test/rep
node1:dis-stripe    fuse.glusterfs   16G  130M   16G    1% /test/dis_stripe
node1:dis-rep       fuse.glusterfs  8.0G   65M  8.0G    1% /test/dis_rep
[root@client opt]# 

数据写入

[root@client opt]# ls -lh /opt
总用量 150M
-rw-r--r--  1 root root  20M 811 19:55 demo1.log
-rw-r--r--  1 root root  20M 811 19:55 demo2.log
-rw-r--r--  1 root root  20M 811 19:55 demo3.log
-rw-r--r--  1 root root  20M 811 19:55 demo4.log
-rw-r--r--  1 root root  20M 811 19:55 demo5.log
drwxr-xr-x  3 root root 8.0K 1120 2020 gfsrepo
-rw-r--r--  1 root root  50M 811 09:33 gfsrepo.zip
drwxr-xr-x. 2 root root    6 1031 2018 rh
[root@client opt]# 
[root@client opt]# cp demo* /test/dis
[root@client opt]# cp demo* /test/stripe/
[root@client opt]# cp demo* /test/rep/
[root@client opt]# cp demo* /test/dis_stripe/
[root@client opt]# cp demo* /test/dis_rep/

查看文件

[root@client test]# ls -lh dis/ stripe/ rep dis_stripe/ dis_rep/
dis/:
总用量 80M
-rw-r--r-- 1 root root 20M 811 19:55 demo1.log
-rw-r--r-- 1 root root 20M 811 19:55 demo2.log
-rw-r--r-- 1 root root 20M 811 19:55 demo3.log
-rw-r--r-- 1 root root 20M 811 19:55 demo4.log

dis_rep/:
总用量 100M
-rw-r--r-- 1 root root 20M 811 19:55 demo1.log
-rw-r--r-- 1 root root 20M 811 19:55 demo2.log
-rw-r--r-- 1 root root 20M 811 19:55 demo3.log
-rw-r--r-- 1 root root 20M 811 19:55 demo4.log
-rw-r--r-- 1 root root 20M 811 19:55 demo5.log

dis_stripe/:
总用量 20M
-rw-r--r-- 1 root root 20M 811 19:55 demo5.log

rep:
总用量 100M
-rw-r--r-- 1 root root 20M 811 19:55 demo1.log
-rw-r--r-- 1 root root 20M 811 19:55 demo2.log
-rw-r--r-- 1 root root 20M 811 19:55 demo3.log
-rw-r--r-- 1 root root 20M 811 19:55 demo4.log
-rw-r--r-- 1 root root 20M 811 19:55 demo5.log

stripe/:
ls: 正在读取目录stripe/: 传输端点尚未连接
总用量 0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值