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

Gluster分布式存储--使用

时间:2017-07-16 00:08:40      阅读:409      评论:0      收藏:0      [点我收藏+]

标签:解析   mil   disk   html   out   https   wordpress   cat   figure   

实现功能:

w1w2上的/ application/nginx-1.10.2/html/blog/wp-content/uploadswordpress图片目录)目录挂载到n1n2/data目录下

1.1.1 准备阶段

IP规划

w1  172.16.1.121

w2  172.16.1.122

n1  172.16.1.123

n2  172.16.1.124

查看阻碍

[root@web02 ~]# getenforce

Disabled

[root@web02 ~]# /etc/init.d/iptables status

iptables: Firewall is not running.

 

所有服务器都要解析,查看hosts解析情况

[root@web02 ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

172.16.1.121 w1

172.16.1.122 w2

172.16.1.123 n1

172.16.1.124 n2

 

yum下载服务(需要特殊的gluster)

wget -P /etc/yum.repos.d/  http://download.gluster.org/pub/gluster/glusterfs/3.7/LATEST/RHEL/glusterfs-epel.repo

yum install glusterfs-server -y

这里就统一都下载服务端用yum安装即可

一般是有服务端和客户端区分的,想要下载建议去官网下载https://www.gluster.org/ 需要编译安装

1.2 安装部署

开启服务(以下内容在n1n2上操作即可,客户端不用操作/启动

[root@n1 ~]# /etc/init.d/glusterd start

Starting glusterd:                                         [  OK  ]

n2加入池(只在n1上操作)

[root@nfs01 ~]# gluster peer probe n2

peer probe: success. Host 10.0.0.61 port 24007 already in peer list

查看池子

[root@n1 ~]# gluster peer status

Number of Peers: 1                                                            #显示除自己外的池子里还有几台服务器

 

Hostname: n2                                                                     #服务器的名字

Uuid: e530336c-d1f0-46b6-b431-d932679764d9       #如果磁盘或服务器挂了可以使用UUID恢复数据

State: Peer in Cluster (Connected)

最好用新的磁盘来做卷

插入一块磁盘sdb并创建分区

[root@n1 ~]# fdisk /dev/sdb

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-130, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):

Using default value 130

 

Command (m for help): wq

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

创建完了磁盘分区然后格式化

[root@n1 ~]# mkfs.ext4 /dev/sdb1

挂载到要创建卷的目录/data

[root@n1 ~]# mount -t ext4 /dev/sdb1 /data/

[root@n1 ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3       6.9G  3.2G  3.4G  49% /

tmpfs           491M     0  491M   0% /dev/shm

/dev/sda1       190M   33M  147M  19% /boot

/dev/sdb1       988M  1.3M  936M   1% /data

1.2.1 创建复制卷(以下内容只在n1上操作即可,n2不用操作)

[root@n1 ~]# gluster volume create pick replica 2 n1:/data/ n2:/data/ force

volume create: pick: success: please start the volume to access data

 

查看卷的信息

[root@n1 ~]# gluster volume info

Volume Name: pick                                                                          #卷的名字

Type: Replicate                                                                                #卷的类别(属于什么卷)

Volume ID: b4623968-3268-4bb9-b631-409355ebfe10                 #卷的ID

Status: Created                                                                                #卷的状态

Number of Bricks: 1 x 2 = 2                                                            #一共有几个brick

Transport-type: tcp                                                                           #什么协议(TCP/UDP/TCP+UDP

Bricks:

Brick1: n1:/data                                                                               #第一个brick目录

Brick2: n2:/data                                                                               #第二个brick目录

Options Reconfigured:

performance.readdir-ahead: on

状态Status: Created是关闭的,所以要开启卷

[root@n1 ~]# gluster volume start pick

volume start: pick: success

 

检查是否开启

[root@n1 ~]# gluster volume info

 

Volume Name: pick

Type: Replicate

Volume ID: b4623968-3268-4bb9-b631-409355ebfe10

Status: Started

Number of Bricks: 1 x 2 = 2

Transport-type: tcp

Bricks:

Brick1: n1:/data

Brick2: n2:/data

Options Reconfigured:

performance.readdir-ahead: on

1.2.2 挂载卷

w1w2上,把wordpress图片目录挂载上即可(不用开启glusterd

[root@w1 ~]# mount -t glusterfs n1:/pick /application/nginx/html/blog/wp-content/uploads/

[root@w1 ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3       6.9G  3.7G  2.8G  58% /

tmpfs           491M     0  491M   0% /dev/shm

/dev/sda1       190M   33M  147M  19% /boot

n1:/pick        988M  1.4M  936M   1% /application/nginx-1.10.2/html/blog/wp-content/uploads

1.2.3 取消挂载

[root@w1 ~]# umount /application/nginx-1.10.2/html/blog/wp-content/uploads

[root@w1 ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3       6.9G  3.7G  2.8G  58% /

tmpfs           491M     0  491M   0% /dev/shm

/dev/sda1       190M   33M  147M  19% /boot

1.2.4 停止卷

[root@n1 ~]# gluster volume stop pick

Stopping volume will make its data inaccessible. Do you want to continue? (y/n) y

volume stop: pick: success

1.2.5 移除brick(必须移除再删除卷)

[root@n1 ~]# gluster volume remove-brick pick replica 1 n1:/data/  force

Removing brick(s) can result in data loss. Do you want to Continue? (y/n) y

volume remove-brick commit force: success

移除一个即可

1.2.6 删除卷

[root@n1 ~]# gluster volume delete pick

Deleting volume will erase all information about the volume. Do you want to continue? (y/n) y

volume delete: pick: success

1.2.7 移除池

[root@n1 ~]# gluster peer detach n2

peer detach: success

1.2.8 磁盘平衡

磁盘平衡时很有必要的(平衡布局:rebalance),因为布局结构是静态的,当新的bricks加入先有卷,新创建的文件会分布到旧的Bricks中,只有平衡布局(rebalance),新加入的磁盘才会生效。

Gluster分布式存储--使用

标签:解析   mil   disk   html   out   https   wordpress   cat   figure   

原文地址:http://www.cnblogs.com/tsboy/p/7187804.html

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