目录
1 准备工作
1.1 每台机器添加一块磁盘
1.2 分区
# 分区(三台都要执行)
[root@wyl01 opt]# fdisk /dev/sdb
1.3 格式化磁盘
# 初始化磁盘(三台都要执行)
[root@wyl01 ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655296 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2621184, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@wyl01 opt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 17G 9.2G 7.9G 55% /
devtmpfs 473M 0 473M 0% /dev
tmpfs 489M 84K 489M 1% /dev/shm
tmpfs 489M 14M 476M 3% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 173M 842M 18% /boot
tmpfs 98M 16K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 9.8G 37M 9.2G 1% /data # 已经成功挂载
1.4 挂载磁盘
# 挂载,三台都要执行
[root@wyl01 opt]# mount /dev/sdb1 /data/
# 查看挂载情况
[root@wyl01 opt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 17G 9.2G 7.9G 55% /
devtmpfs 473M 0 473M 0% /dev
tmpfs 489M 84K 489M 1% /dev/shm
tmpfs 489M 14M 476M 3% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 173M 842M 18% /boot
tmpfs 98M 16K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 9.8G 37M 9.2G 1% /data # 已经成功挂载
开机自动挂载
vim /ey/fstab
/dev/sdb1 /data xfs defaults 0 0
2 安装GlusterFS
2.1 安装依赖
# 所有机器都要安装
yum install -y flex bison openssl openssl-devel acl libacl libacl-devel sqlite-devel libxml2-devel python-devel make cmake gcc gcc-c++ autoconf automake libtool unzip zip
2.2 安装glusterfs
安装三台机器都要安装
[root@wyl01 opt]# tar -zxvf /usr/local/src/glusterfs-3.6.9.tar.gz -C /usr/local/
[root@wyl01 glusterfs-3.6.9]# cd /usr/local/glusterfs-3.6.9/
[root@wyl01 glusterfs-3.6.9]# ./configure --prefix=/usr/local/glusterfs
[root@wyl01 glusterfs-3.6.9]# make && make install
添加环境变量
[root@wyl01 glusterfs-3.6.9]# vim /etc/profile #在文件最底部添加如下内容
export GLUSTERFS_HOME=/usr/local/glusterfs
export PATH=$PATH:$GLUSTERFS_HOME/sbin
#环境变量生效
[root@wyl01 glusterfs-3.6.9]# source /etc/profile
2.3 启动服务
#启动服务三台均执行
[root@wyl01 opt]# /usr/local/glusterfs/sbin/glusterd
2.4 存储主机加入信任存储池
在wyl01机器上执行(在其它机器上执行,则不需要执行自己probe)
[root@wyl01 init.d]# gluster peer probe wyl02
peer probe: success.
[root@wyl01 init.d]# gluster peer probe wyl03
peer probe: success.
查看状态,我们换到wyl03机器上执行查看
2.5 创建Volume及其他操作
创建volume的有下面4种方式
- 分布式卷
- 条带卷
- 分布式条带卷
- 分布式复制卷
我们这里讲的是分布式卷和分布式复制卷:
分布式卷:文件通过has算法随机的分不到由bricks组成的卷上。
分布式复制复制卷:volume中brick所包含的存储服务器数必须是relica的倍数(>= 2倍),兼顾分布式和复制式的功能。
创建卷
[root@wyl01 data]# gluster volume create gv1 wyl01:/data wyl02:/data wyl03:/data force
volume create: gv1: success: please start the volume to access data
启动卷
[root@wyl01 data]# gluster volume start gv1
volume start: gv1: success
任意一台查看
[root@wyl02 data]# gluster volume info
Volume Name: gv1
Type: Distribute
Volume ID: 2df7baaa-1759-4975-8fe5-bb25dac9ea2b
Status: Started
Number of Bricks: 3
Transport-type: tcp
Bricks:
Brick1: wyl01:/data
Brick2: wyl02:/data
Brick3: wyl03:/data
挂载卷到目录
[root@wyl01 data]# mount -t glusterfs 192.168.32.132:gv1 /mnt
查看挂载情况,之前是3个10G的磁盘,现在合并成了30G,上述指令可以在其他机器执行,这样其他机器在/mnt目录下也是有相同的文件。
至此,分布式卷已经创建成功。