Rootop 服务器运维与web架构

GlusterFS分布式文件系统-安装配置

GlusterFS是一个开源的分布式文件系统,用户可以使用多台服务器,并通过以太网或者Infiniband RDMA互联从而组成一个GlusterFS的集群。
GlusterFS集群对外提供NFS,CIFS和Gluster Native(通过FUSE进行挂载)的接口以便用户访问GlusterFS的存储池。
GlusterFS使用了弹性哈希算法来定位文件存储的位置。 由于使用了弹性哈希算法,GlusterFS不需要专门的Meta-Data Server来保存元数据,因此可以避免因为元数据服务器宕机导致的整个集群不可用。
也正是因为不需要元数据服务器,所以GlusterFS在多个挂载点同时进行数据读写的时候,其整体性能很突出。

官方网站:http://www.gluster.org/

下载:
fuse-2.9.3.tar.gz         #依赖于fuse
glusterfs-3.6.0.tar.gz #本文用的版本

准备2台机器,系统为centos6.5 64位。
IP地址               主机名
192.168.0.107   g1
192.168.0.136   g2

首先关闭iptables和selinux。
修改主机名,并添加hosts映射:
g1:
[root@localhost ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=g1
[root@localhost ~]# hostname
g1
[root@localhost ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.107 g1
192.168.0.136 g2
g2:
[root@localhost ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=g2
[root@localhost ~]# hostname
g2
[root@localhost ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.107 g1
192.168.0.136 g2

安装预编译环境:
[root@localhost ~]# yum install -y gcc gcc-c++ flex flex-devel bison bison-devel openssl openssl-devel libxml2 libxml2-devel
安装fuse:
[root@localhost ~]# cd fuse-2.9.3
[root@localhost fuse-2.9.3]# ./configure && make && make install
[root@localhost fuse-2.9.3]# cd

安装gluster:
[root@localhost ~]# cd glusterfs-3.6.0

[root@localhost glusterfs-3.6.0]# ./configure --prefix=/usr/local/glusterfs && make && make install

g1和g2均执行上面操作。

g1和g2启动gluster:
[root@localhost ~]# service glusterd start

添加集群:
[root@localhost ~]# ln -s /usr/local/glusterfs/sbin/gluster /usr/bin/gluster #做一个软链接方便执行命令
[root@localhost ~]# gluster peer probe g2 #在g1中将g2加入到gluster集群中,本机(g1)不需要加入。
peer probe: success. Probe on localhost not needed
查看集群信息:
[root@localhost ~]# gluster peer status
Number of Peers: 1

Hostname: g2
Uuid: c7aa664a-3161-4716-9f81-2dc4b4718fa1
State: Peer in Cluster (Connected) #已连接

剔除机器:
[root@localhost ~]# gluster peer detach g2
peer detach: success

创建卷:
[root@localhost ~]# gluster volume create test-volume replica 2 transport tcp g1:/data g2:/data force
volume create: test-volume: success: please start the volume to access data
test-volume 卷名 replica 副本数 transport 传输协议 g1:/data 服务器名及存储路径

启动卷:
[root@localhost ~]# gluster volume start test-volume
volume start: test-volume: success

查看卷:
[root@localhost ~]# gluster volume info
Volume Name: test-volume
Type: Replicate
Volume ID: 104d73c5-17f5-4150-a40d-b97cd78dd6bb
Status: Started
Number of Bricks: 1 x 2 = 2
Transport-type: tcp
Bricks:
Brick1: g1:/data
Brick2: g2:/data

客户端1挂载(同样安装fuse和glusterfs才能支持glusterfs文件系统):
[root@localhost ~]# mkdir /mnt/gfs
[root@localhost ~]# mount -t glusterfs g1:test-volume /mnt/gfs/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 77G 3.7G 70G 6% /
tmpfs 499M 0 499M 0% /dev/shm
g1:test-volume 77G 3.8G 70G 6% /mnt/gfs

客户端2挂载:
[root@localhost ~]# mkdir /mnt/gfs
[root@localhost ~]# mount -t glusterfs g2:test-volume /mnt/gfs
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 77G 3.8G 70G 6% /
tmpfs 499M 0 499M 0% /dev/shm
g2:test-volume 77G 3.8G 70G 6% /mnt/gfs

可以看到g1和g2都支持挂载。

gluster支持的参数:
[root@localhost ~]# gluster help #查看参数

安装配置完成。

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/3101.html

作者:Venus

服务器运维与性能优化

评论已关闭。