码迷,mamicode.com
首页 > 其他好文 > 详细

在Centos上安装使用GlusterFS

时间:2017-07-21 21:52:29      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:glusterfs   centos7   

        最近接触了下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为例

[root@node01 ~]# wget -P /etc/yum.repos.d/ http://download.gluster.org/pub/gluster/glusterfs/LATEST/CentOS/glusterfs-epel.repo


3. 安装glusterfs的主要组件:

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

[root@node01 ~]# 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,并设置为开机自启动

[root@node01 ~]# systemctl start glusterd
[root@node01 ~]# 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为例:

[root@node01 ~]# firewall-cmd --add-service=glusterfs

[root@node01 ~]# firewall-cmd --runtime-to-permanent   

2)在node01上创建信任池,也可以在node02上执行,总之只需在一台服务器上执行以下命令即可:

[root@node01 ~]# gluster peer probe node02.lab.example.com

[root@node01 ~]# gluster peer status
Number of Peers: 1

Hostname: node02.lab.example.com
Uuid: 707099ff-5c39-467e-950c-9fef9ca7f701
State: Peer in Cluster (Connected)
[root@node01 ~]# gluster pool list
UUID                                    Hostname                State
707099ff-5c39-467e-950c-9fef9ca7f701    node02.lab.example.com  Connected
2be7bf8f-fba4-4b3f-a510-31d99c7c9ccf    localhost               Connected
[root@node01 ~]#


6. 创建Volume以便进行挂载测试,glusterfs上可以创建多种类型的volume,例如简单点的distributed volume, replicated volume,复杂点的dispersed volume,当然也可以创建复合volume,如distributed-replicated volume.今次我们先来个简单的,创建一个2副本的replicated volume.

---我这里使用的是瘦逻辑卷做的底层存储,所以开始前先把瘦逻辑卷做出来:

[root@node01 ~]# pvs
  PV         VG        Fmt  Attr PSize  PFree
  /dev/sdb   vg_bricks lvm2 a--  20.00g 17.99g
[root@node01 ~]# vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vg_bricks   1   2   0 wz--n- 20.00g 17.99g
[root@node01 ~]# lvs
  LV       VG        Attr       LSize  Pool  Origin 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                                  
[root@node01 ~]#


---格式化逻辑卷并进行挂载,在格式化时注意要加参数-i size=512,这个是glusterfs需要的

[root@node01 ~]# mkfs -t xfs -i size=512 /dev/mapper/vg_bricks-thinvol1

[root@node01 ~]# mkdir /bricks/thinvol1/

[root@node01 ~]# mount /dev/mapper/vg_bricks-thinvol1 /bricks/thinvol1/

建议将挂载步骤写入到/etc/fstab里,以确保实现开机自动挂载


glusterfs是基于brick的,而且我们的brick不能是mount point,所以还要创建一个brick目录在挂载目录下

[root@node01 ~]# mkdir /bricks/thinvol1/brick/

如果开启了selinux,还需要配置安全上下文

[root@node01 ~]# chcon -R -t glusterd_brick_t /bricks/thinvol1/


7. Create and start volume

准备工作到此可以告一段落了,现在我们可以创建volume了

[root@node01 ~]# gluster volume create RepVol replica 2 \
> node01.lab.example.com:/bricks/thinvol1/brick \
> node02.lab.example.com:/bricks/thinvol1/brick

创建完后,volume还不能立即使用,我们还需要start volume

[root@node01 ~]# gluster volume start RepVol

[root@node01 ~]# 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目录下

[root@node02 glusterfs]# mount -t glusterfs node02.lab.example.com:RepVol /test/
[root@node02 glusterfs]# df -h | grep test
node02.lab.example.com:RepVol   2.0G   33M  2.0G   2% /test


[root@node02 ~]# cd /test
[root@node02 test]# touch file{1..100}.txt

[root@node02 test]# ls -l /test/ | grep -v total | wc -l
100


分别在node01 和node02 上验证下,发现在两个节点的brick里面都存在100个测试文件:

[root@node01 ~]# ls -l /bricks/thinvol1/brick/ | grep -v total | wc -l
100

[root@node02 test]# ls -l /bricks/thinvol1/brick/ | grep -v total | wc -l
100

本文出自 “不积跬步,无以至千里” 博客,请务必保留此出处http://jiaxiaolei.blog.51cto.com/3117381/1949855

在Centos上安装使用GlusterFS

标签:glusterfs   centos7   

原文地址:http://jiaxiaolei.blog.51cto.com/3117381/1949855

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!