GlusterFS用法

一、glusterfs简介
Glusterfs是一个开源的分布式文件系统,是Scale存储的核心,能够处理千数量级的客户端。是整合了许多存储块(server)通过Infiniband RDMA或者 Tcp/Ip方式互联的一个并行的网络文件系统。
特征:

  • 容量可以按比例的扩展,且性能却不会因此而降低。
  • 廉价且使用简单,完全抽象在已有的文件系统之上。
  • 扩展和容错设计的比较合理,复杂度较低
  • 适应性强,部署方便,对环境依赖低,使用,调试和维护便利
    二、glusterfs安装部署
    一般在企业中,采用的是分布式复制卷,因为有数据备份,数据相对安全。
    网络要求全部千兆环境,gluster服务器至少有2 块网卡,1块网卡绑定供gluster 使用,剩余一块分配管理网络 IP,用于系统管理。如果有条件购买万兆交换机,服务器配置万兆网卡,存储性能会更好。网络方面如果安全性要求较高,可以多网卡绑定。
    跨地区机房配置 Gluster,在中国网络格局下不适用。
  • 注意:GlusterFS将其动态生成的配置文件存储在/var/lib/glusterd中。如果在任何时候GlusterFS无法写入这些文件(例如,当后备文件系统已满),它至少会导致您的系统不稳定的行为; 或者更糟糕的是,让您的系统完全脱机。建议为/var/log等目录创建单独的分区,以确保不会发生这种情况。
    1、安装glusterfs前的环境准备 
    1.1、服务规划:
td {white-space:nowrap;border:1px solid #dee0e3;font-size:10pt;font-style:normal;font-weight:normal;vertical-align:middle;word-break:normal;word-wrap:normal;}操作系统IP主机名centos 7.410.0.0.101node01centos 7.410.0.0.102node02centos 7.410.0.0.103node03

1.2、首先关闭iptables和selinux,配置hosts文件如下(全部glusterfs主机)
注:node01~node04所有的主机hosts文件均为此内容;同时全部修改为对应的主机名,centos7修改主机名方式:#hostnamectl set-hostname 主机名 (即为临时和永久生效)
可以使用#hostnamectl status 查看系统基本信息
[root@node01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.101 node01
10.0.0.102 node02
10.0.0.103 node03
[root@node01 ~]# systemctl stop firewalld.service #停止firewalld
[root@node01 ~]# systemctl disable firewalld.service #禁止firewalld开机自启
[root@node01 ~]# sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g’ /etc/selinux/config #关闭SELinux
[root@node01 ~]# setenforce 0
[root@node01 ~]# getenforce
Permissive
[root@node01 ~]# yum install -y ntp #安装ntp命令
[root@node01 ~]# ntpdate time.windows.com #同步时间

1.3、安装gluterfs源(全部glusterfs主机)
[root@node01 ~]#yum search centos-release-gluster #查看有哪些版本的glusterfs源
================================================ N/S matched: centos-release-gluster =================================================
centos-release-gluster-legacy.noarch : Disable unmaintained Gluster
…: repositories from the CentOS Storage SIG
centos-release-gluster40.x86_64 : Gluster 4.0 (Short Term Stable) packages
: from the CentOS Storage SIG repository
centos-release-gluster41.noarch : Gluster 4.1 (Long Term Stable) packages from
: the CentOS Storage SIG repository
centos-release-gluster5.noarch : Gluster 5 packages from the CentOS Storage
: SIG repository
centos-release-gluster6.noarch : Gluster 6 packages from the CentOS Storage
: SIG repository
centos-release-gluster7.noarch : Gluster 7 packages from the CentOS Storage
: SIG repository
centos-release-gluster8.noarch : Gluster 8 packages from the CentOS Storage
: SIG repository
centos-release-gluster9.noarch : Gluster 9 packages from the CentOS Storage
: SIG repository

使用版本6的源
[root@node01 ~]#yum -y install centos-release-gluster6.noarch

1.4、安装glusterfs(全部glusterfs主机)
[root@node01 ~]# yum -y --enablerepo=centos-gluster*-test install glusterfs-server glusterfs-cli glusterfs-geo-replication

1.5、查看glusterfs版本并启动glusterfs服务(全部glusterfs主机)
[root@node01 ~]# glusterfs -V #查看版本
glusterfs 6.10
[root@node01 ~]# systemctl start glusterd.service
[root@node01 ~]# systemctl enable glusterd.service
[root@node01 ~]# systemctl status glusterd.service
[root@node01 ~]# yum install net-tools #安装net工具
[root@node01 ~]# netstat -lntup

2、创建复制卷
2.1、将分布式存储主机加入到信任主机池并查看加入的主机状态
随便在一个开启glusterfs服务的主机上将其他主机加入到一个信任的主机池里,这里选择node01
[root@node01 ~]# gluster peer probe node02
peer probe: success.
[root@node01 ~]# gluster peer probe node03
peer probe: success.

查看主机池中主机的状态
[root@node01 ~]# gluster peer status
Number of Peers: 2 #除本机外,还有三台主机主机池中

Hostname: node02
Uuid: 6020709d-1b46-4e2c-9cdd-c4b3bba47b4b
State: Peer in Cluster (Connected)

Hostname: node03
Uuid: 147ee557-51f1-43fe-a27f-3dae2880b5d4
State: Peer in Cluster (Connected)
注意:一旦建立了这个池,只有受信任的成员可能会将新的服务器探测到池中。新服务器无法探测池,必须从池中探测。

2.2、创建glusterfs卷
GlusterFS 五种卷

  • Distributed:分布式卷,文件通过 hash 算法随机分布到由 bricks 组成的卷上。
  • Replicated: 复制式卷,类似 RAID 1,replica 数必须等于 volume 中 brick 所包含的存储服务器数,可用性高。
  • Striped: 条带式卷,类似 RAID 0,stripe 数必须等于 volume 中 brick 所包含的存储服务器数,文件被分成数据块,以 Round Robin 的方式存储在 bricks 中,并发粒度是数据块,大文件性能好。
  • Distributed Striped: 分布式的条带卷,volume中 brick 所包含的存储服务器数必须是 stripe 的倍数(>=2倍),兼顾分布式和条带式的功能。
  • Distributed Replicated: 分布式的复制卷,volume 中 brick 所包含的存储服务器数必须是 replica 的倍数(>=2倍),兼顾分布式和复制式的功能。
     分布式复制卷的brick顺序决定了文件分布的位置,一般来说,先是两个brick形成一个复制关系,然后两个复制关系形成分布。
     企业一般用后两种,大部分会用分布式复制(可用容量为 总容量/复制份数),通过网络传输的话最好用万兆交换机,万兆网卡来做。这样就会优化一部分性能。它们的数据都是通过网络来传输的。
    配置复制卷
    注:复制模式,既AFR, 创建volume 时带 replica x 数量: 将文件复制到 replica x 个节点中。
    这条命令的意思是使用Replicated的方式,建立一个名为gv2的卷(Volume),存储块(Brick)为2个,分别为node01:/data/brick2和node02:/data/brick2;
    fore为强制创建:因为复制卷在双方主机通信有故障再恢复通信时容易发生脑裂。本次为实验环境,生产环境不建议使用。

[root@node01 ~]# gluster volume create gv1 replica 3 node01:/data/brick1 node02:/data/brick1 node03:/data/brick1 force
volume create: gv1: success: please start the volume to access data
[root@node01 ~]# gluster volume start gv1 #启动gv1卷
volume start: gv1: success
[root@node01 ~]# gluster volume info gv1 #查看gv1信息
Volume Name: gv1
Type: Replicate #复制卷
Volume ID: 1155e5f5-f0c0-42bb-b023-1e6de3b50053
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 3 = 3pee
Transport-type: tcp
Bricks:
Brick1: new1:/data/brick1
Brick2: new2:/data/brick1
Brick3: new3:/data/brick1
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off
[root@node01 ~]# mount -t glusterfs 127.0.0.1:/gv1 /mnt #文件夹/mnt挂载到gv1下
[root@node01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
127.0.0.1:/gv1 5.0G 33M 5.0G 1% /mnt
[root@node01 ~]# cd /mnt/
[root@node01 mnt]# touch {1…6}
[root@node01 mnt]# ll /data/brick1
总用量 0
-rw-r–r–. 2 root root 0 2月 3 01:06 1
-rw-r–r–. 2 root root 0 2月 3 01:06 2
-rw-r–r–. 2 root root 0 2月 3 01:06 3
-rw-r–r–. 2 root root 0 2月 3 01:06 4
-rw-r–r–. 2 root root 0 2月 3 01:06 5
-rw-r–r–. 2 root root 0 2月 3 01:06 6
[root@node02 ~]# ll /data/brick1
总用量 0
-rw-r–r–. 2 root root 0 2月 3 01:06 1
-rw-r–r–. 2 root root 0 2月 3 01:06 2
-rw-r–r–. 2 root root 0 2月 3 01:06 3
-rw-r–r–. 2 root root 0 2月 3 01:06 4
-rw-r–r–. 2 root root 0 2月 3 01:06 5
-rw-r–r–. 2 root root 0 2月 3 01:06 6
#创建文件的实际存在位置为node01、node02和node03上的/data/brick1目录下,因为是复制卷,这两个目录下的内容是完全一致的。
#在文件夹/mnt下创建的文件同样会同步

参考文档:https://www.cnblogs.com/huangyanqi/p/8406534.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值