判官007 发表于 2019-2-1 10:13:01

在Centos上安装使用GlusterFS

  最近接触了下GlusterFS,所以就想着在自己的笔记本上的虚拟机里安装个测试环境。起初想要从https://github.com/gluster/glusterfs/ 上下载一个build然后编译安装, 但是试了很多次,在make时总是失败,折腾了两天后,彻底死心了...
  

  1. 先介绍下我的实验环境,由于笔记本配置不是很高,所以我就只开了两个CentOS7的虚拟机,网络选择NAT,以确保能够连接到外网,都做server,其中一台还要兼做client,没有单独的client端。还有两个server要能够相互解析hostname,而我这里又没有DNS服务器,所以要把下面的两行信息加入到/etc/hosts文件里。
  192.168.133.145      node01.lab.example.com
  192.168.133.135      node02.lab.exampe.com
  

  2. 下载安装yum源头,非特殊说明,以下操作步骤在两台server上均要执行,贴出的命令以node01为例
  # wget -P /etc/yum.repos.d/ http://download.gluster.org/pub/gluster/glusterfs/LATEST/CentOS/glusterfs-epel.repo
  

  3. 安装glusterfs的主要组件:
  # yum install -y glusterfs glusterfs-server glusterfs-fuse
  # rpm -qa | grep gluster
glusterfs-fuse-3.11.1-1.el7.x86_64
glusterfs-3.11.1-1.el7.x86_64
glusterfs-cli-3.11.1-1.el7.x86_64
glusterfs-server-3.11.1-1.el7.x86_64
glusterfs-client-xlators-3.11.1-1.el7.x86_64
glusterfs-api-3.11.1-1.el7.x86_64
glusterfs-libs-3.11.1-1.el7.x86_64
  

  4. 启动glusterfs service,并设置为开机自启动
  # systemctl start glusterd
# systemctl enable glusterd
Created symlink from /etc/systemd/system/multi-user.target.wants/glusterd.service to /usr/lib/systemd/system/glusterd.service.
  至此,glusterfs已经成功安装到两台server上了,接下来做一些简单使用测试
  

  5. 创建trust storage pool(信任存储池?不知道这个翻译准不准确,暂且这样用吧)
  1)如果开启了firewall或者iptables服务,我们需要先放开相应的服务,以firewall为例:
  # firewall-cmd --add-service=glusterfs
  # firewall-cmd --runtime-to-permanent
  2)在node01上创建信任池,也可以在node02上执行,总之只需在一台服务器上执行以下命令即可:
  # gluster peer probe node02.lab.example.com
  # gluster peer status
Number of Peers: 1
  Hostname: node02.lab.example.com
Uuid: 707099ff-5c39-467e-950c-9fef9ca7f701
State: Peer in Cluster (Connected)
# gluster pool list
UUID                                    Hostname                State
707099ff-5c39-467e-950c-9fef9ca7f701    node02.lab.example.comConnected
2be7bf8f-fba4-4b3f-a510-31d99c7c9ccf    localhost               Connected
#
  

  6. 创建Volume以便进行挂载测试,glusterfs上可以创建多种类型的volume,例如简单点的distributed volume, replicated volume,复杂点的dispersed volume,当然也可以创建复合volume,如distributed-replicated volume.今次我们先来个简单的,创建一个2副本的replicated volume.
  ---我这里使用的是瘦逻辑卷做的底层存储,所以开始前先把瘦逻辑卷做出来:
  # pvs
PV         VG      FmtAttr PSizePFree
/dev/sdb   vg_bricks lvm2 a--20.00g 17.99g
# vgs
VG      #PV #LV #SN Attr   VSizeVFree
vg_bricks   1   2   0 wz--n- 20.00g 17.99g
# lvs
LV       VG      Attr       LSizePoolOrigin Data%Meta%Move Log Cpy%Sync Convert
pool1    vg_bricks twi-aotz--2.00g            0.55   1.17                           
thinvol1 vg_bricks Vwi-a-tz--2.00g pool1      0.55                                 
#
  

  ---格式化逻辑卷并进行挂载,在格式化时注意要加参数-i size=512,这个是glusterfs需要的
  # mkfs -t xfs -i size=512 /dev/mapper/vg_bricks-thinvol1
  # mkdir /bricks/thinvol1/
  # mount /dev/mapper/vg_bricks-thinvol1 /bricks/thinvol1/
  建议将挂载步骤写入到/etc/fstab里,以确保实现开机自动挂载
  

  glusterfs是基于brick的,而且我们的brick不能是mount point,所以还要创建一个brick目录在挂载目录下
  # mkdir /bricks/thinvol1/brick/
  如果开启了selinux,还需要配置安全上下文
  # chcon -R -t glusterd_brick_t /bricks/thinvol1/
  

  7. Create and start volume
  准备工作到此可以告一段落了,现在我们可以创建volume了
  # gluster volume create RepVol replica 2 \
> node01.lab.example.com:/bricks/thinvol1/brick \
> node02.lab.example.com:/bricks/thinvol1/brick
  创建完后,volume还不能立即使用,我们还需要start volume
  # gluster volume start RepVol
  # gluster volume info RepVol

Volume Name: RepVol
Type: Replicate
Volume ID: 2ae04508-a5ec-47f6-a436-e3a87ee39ced
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: node01.lab.example.com:/bricks/thinvol1/brick
Brick2: node02.lab.example.com:/bricks/thinvol1/brick
  ...
  

  8. 在Client端使用Volume,这里我们假设我们的node02是一个Client节点
  Glusterfs支持的挂载类型根据挂载方式不同可以分为以下三类:
  1)Native mount,需要安装glusterfs-fuse,本身支持高可用
  2)NFS 方便简单,在创建完 volume后,glusterfs会自动启动一个nfs共享进程,server端只需在firewall中打开nfs相关的access即可,无需其他配置
  firewall-cmd --add-service=nfs
  firewall-cmd --add-service=rpc-bind
  3)Samba 配置较上面两种类型稍显复杂,但也有优点,就是可以支持Windows挂载,这里我们不做详细介绍了
  ---使用Native mount挂载gluster volume 到node02节点的/test目录下
  # mount -t glusterfs node02.lab.example.com:RepVol /test/
# df -h | grep test
node02.lab.example.com:RepVol   2.0G   33M2.0G   2% /test
  

  # cd /test
# touch file{1..100}.txt
  # ls -l /test/ | grep -v total | wc -l
100
  

  分别在node01 和node02 上验证下,发现在两个节点的brick里面都存在100个测试文件:
  # ls -l /bricks/thinvol1/brick/ | grep -v total | wc -l
100
  # ls -l /bricks/thinvol1/brick/ | grep -v total | wc -l
100



页: [1]
查看完整版本: 在Centos上安装使用GlusterFS