GlusterFS最佳实践

标签(linux): glusterfs

笔者Q:972581034 交流群:605799367。有任何疑问可与笔者或加群交流

今天我们来从实战中学习glusterfs


环境准备:

gluster-server两台,各添加一块10G硬盘:
db02 db03

实现目标:

将文件系统挂载到web服务器的www站点用户上传目录

提示:提前就搭建好web服务器nginx,www站点。

=================================环境准备==================================

关闭防火墙:
systemctl disable firewalld
systemctl stop firewalld
selinux:
[root@db02 ~]# getenforce 
Disabled
系统版本
[root@db03 ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)
[root@db03 ~]# uname -r
3.10.0-327.el7.x86_64 

hosts解析

[root@db02 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.52  db02
172.16.1.53  db03
172.16.1.250 docker 

将添加的磁盘写入文件系统

mkfs.xfs -i size=512 /dev/sdb

创建挂载目录

mkdir -p /bricks/brick1

加入fstab开机自动挂载

echo "/dev/sdb                                  /bricks/brick1          xfs     defaults        1 2" >> /etc/fstab
[root@db03 ~]# tail -1 /etc/fstab 
/dev/sdb                                  /bricks/brick1          xfs     defaults        1 2
#挂载/etc/fstab里面的所有条目
mount -a

以下如无特殊说明均在两台节点操作

安装:

所有服务器

yum install centos-release-gluster -y
yum  install glusterfs-server -y

查看glusterfs版本

[root@db03 ~]# gluster --version
glusterfs 3.10.1
Repository revision: git://git.gluster.org/glusterfs.git
Copyright (c) 2006-2016 Red Hat, Inc. <https://www.gluster.org/>
GlusterFS comes with ABSOLUTELY NO WARRANTY.
It is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3
or later), or the GNU General Public License, version 2 (GPLv2),
in all cases as published by the Free Software Foundation.

启动服务

systemctl start gluster
systemctl enable glusterd

在任意一台节点上添加信任池

[root@db02 ~]# gluster peer probe db03
peer probe: success. 

查看状态,如果从一个节点能看到其它节点说明OK

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

Hostname: db03
Uuid: 6465d902-4ec6-4e21-a5dc-f196b499a07e
State: Peer in Cluster (Connected)

设置GlusterFS卷

[root@db02 ~]# mkdir /bricks/brick1/{www,bbs,blog,jpress}
[root@db02 ~]# tree /bricks/
/bricks/
└── brick1
    ├── bbs
    ├── blog
    ├── jpress
    └── www

在任意一台机器上创建复制卷(可用性高,写性能不佳.读取速度快,可类比RAID 1)

[root@db02 ~]# gluster volume create www replica 2 db02:/bricks/brick1/www db03:/bricks/brick1/www
volume create: www: success: please start the volume to access data
[root@db02 ~]# for i in bbs blog jpress;do gluster volume create $i replica 2 db02:/bricks/brick1/$i db03:/bricks/brick1/$i;done
volume create: bbs: success: please start the volume to access data
volume create: blog: success: please start the volume to access data
volume create: jpress: success: please start the volume to access data

启动卷

[root@db02 ~]# for i in www bbs blog jpress;do gluster volume start $i;done
volume start: www: success
volume start: bbs: success
volume start: blog: success
volume start: jpress: success

确认卷显示“已启动”:

[root@db02 ~]# gluster volume info
 
Volume Name: bbs
Type: Replicate
Volume ID: d1776666-d035-4855-8758-fe199b6c1198
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: db02:/bricks/brick1/bbs
Brick2: db03:/bricks/brick1/bbs
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
 
Volume Name: blog
Type: Replicate
Volume ID: d21a6a25-9da0-4940-a831-045257dc4550
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: db02:/bricks/brick1/blog
Brick2: db03:/bricks/brick1/blog
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
 
Volume Name: jpress
Type: Replicate
Volume ID: b9835dcc-da68-4858-9009-2821e31b1cb3
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: db02:/bricks/brick1/jpress
Brick2: db03:/bricks/brick1/jpress
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
 
Volume Name: www
Type: Replicate
Volume ID: 3c541856-f55b-4c03-82e9-d0fe58e6b2f2
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: db02:/bricks/brick1/www
Brick2: db03:/bricks/brick1/www
Options Reconfigured:
transport.address-family: inet
nfs.disable: on

创建www用户,由于

[root@db02 brick1]# useradd -s /sbin/nologin -M -u 1000 www

web服务器挂载卷

mount -t glusterfs db02:/www /application/nginx/html/www/uploads
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值