GlusterFS环境搭建

来源:互联网 发布:python try 出错不退出 编辑:程序博客网 时间:2024/05/03 13:39
环境:CentOS7.0 开发模式安装
1、tar -zxvf glusterfs-3.6.0.tar.gz
2、./configure
默认的模块如下如所示

3、make && make install
4、sudo vim /etc/glusterfs/glusterfsd.vol
<span style="font-family:Microsoft YaHei;font-size:14px;">volume bricktype storage/posix # POSIX FS translatoroption directory /home/dir1 # Export this directoryend-volumevolume servertype protocol/serveroption transport-type tcp/serveroption transport.socket.bind-address 172.10.2.222 # Default is to listen on all interfacessubvolumes brickoption auth.addr.brick.allow * # Allow access to "brick" volumeend-volume</span>

5、开启glusterfsd
glusterfsd -f /etc/glusterfs/glusterfsd.vol -l /var/log/glusterfs/glusterfsd.log

这里讲一下glusterfs包里几个重要的组件,gluster,glusterfsd,glusterd,glusterfs

gluster:服务器端的CLI,运行添加节点,删除节点之类都是它发命令给glusterd
glusterd:运行于服务器端的守护进程,它打开了gluster才能用,它把gluster的命令传递给glusterfsd
glusterfsd:服务器端主要干活的,它接受服务器端的管理指令和客户端的数据请求,配合底层VFS和文件系统完成工作
glusterfs:运行于客户端,接收fuse的指令,因为客户端的APP都是通过FUSE和glusterfs通信的,它接收到请求后传给glusterfs,再通过RPC传给服务器端的gluserfsd

6、检验glusterfsd进程是否存在
ps -ef|grep -v grep |grep gluster
这里我没有查到进程,有问题,可以查看日志
/var/log/glusterfs/glusterfsd.log


我的port没有设置,使用的默认的port可能被占用了,另外设置了一个6996
<pre name="code" class="plain"><span style="font-family:Microsoft YaHei;font-size:14px;">option transport.socket.bind-addressoption transport.socket.listen-port 6996</span>
设置监听端口前先查一下这个端口有没有被使用
netstat -ln | grep 6996
显示如下则说明6996端口处在监听状态
tcp 0 0 124.127.117.28:6996 0.0.0.0:* LISTEN

卷的路径:option directory /home/dir没有创建,mkdir了一个,这个简单
再次查看
ps -ef|grep -v grep |grep gluster


7、开启glusterd
[root@localhost glusterfs]# service glusterd start 
Redirecting to /bin/systemctl start glusterd.service

8、为磁盘分区,挂载

格式化成XFS文件系统

[root@localhost glusterfs]# mount /dev/sdb /brick1 
[root@localhost glusterfs]# mount /dev/sdc /brick2

9、clone,将clone的机器开启(虚机环境嘛)

10、开启glusterd服务:service glusterd start,开启了它gluster才能用

chkconfig glusterd on可设置开机时自动开启

11、建立存储池
[root@localhost ~]# gluster peer statusNumber of Peers: 0[root@localhost ~]# gluster peer probe 172.10.2.171peer probe: failed: Probe returned with unknown errno 107
这里遇到了错误,查看日志
/var/log/glusterfs/usr-local-etc-glusterfs-glusterd.vol.log"

好像是网络的问题,节点的IP都是dhcp的,试着改成了static,并添加网关,添加网关后还是出错,日志信息如下,因为之前关闭防火墙只关了iptables,查了查CentOS7.0还有个防火墙,可能是它的问题

关闭防火墙 

sudo systemctl stop firewalld.servicesudo systemctl disable firewalld.servicesudo systemctl stop iptables.servicesudo systemctl disable iptables.servicesudo vim /etc/selinux/config注释下面两行:#SELINUX=enforcing#SELINUXTYPE=targetedsudo setenforce 0
这回就成功了


查询存储池状态:



一共两个节点,本节点只能查询另外的节点的信息,这是分别在两个节点上查询到的信息
试验一下删除的操作
删除节点:gluster peer detach node2

12、创建卷
# gluster volume create NEW-VOLNAME [stripe COUNT | replica COUNT]
[transport [tcp | rdma | tcp,rdma]] NEW-BRICK1 NEW-BRICK2 NEW-BRICK3...

gluster vol create testvol replica 2 node1:/brick1 node2:/brick1 
[root@localhost ~]# gluster vol create testvol replica 2 node1:/brick1 node2:/brick1volume create: testvol: failed: The brick node2:/brick1 is a mount point. Please create a sub-directory under the mount point and use that as the brick directory. Or use 'force' at the end of the command if you want to override this behavior.
成功了
[root@localhost ~]# gluster vol create testvol replica 2 node1:/brick1 node2:/brick1 force volume create: testvol: success: please start the volume to access data
查看卷的信息:gluster vol info

13、开启卷:gluster vol start testvol

失败的一种情况:

由于机器重启,brick挂载失败了,在/etc/fstab里设置会在开机时自动挂载,这里就重新挂载一次就行了

试验一下停止卷:gluster vol stop testvol


14、利用原生客户端挂载
[root@localhost ~]# mkdir /mnt/gls [root@localhost ~]# mount -t glusterfs node1:testvol /mnt/gls[root@localhost ~]# mkdir /mnt/gls [root@localhost ~]# mount -t glusterfs node1:testvol /mnt/gls [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 8.5G 7.0G 1.6G 82% / devtmpfs 489M 0 489M 0% /dev tmpfs 498M 92K 498M 1% /dev/shm tmpfs 498M 7.2M 491M 2% /run tmpfs 498M 0 498M 0% /sys/fs/cgroup /dev/sda1 497M 120M 377M 25% /boot node1:testvol 2.0G 33M 2.0G 2% /mnt/gls

15、扩展卷: volume add-brick <VOLNAME> <NEW-BRICK> ...


扩展了两个节点,就从复制卷变成了分布式复制卷

16、负载均衡
        volume rebalance <VOLNAME> start
              Start rebalancing the specified volume.

        volume rebalance <VOLNAME> stop
              Stop rebalancing the specified volume.

        volume rebalance <VOLNAME> status
              Display the rebalance status of the specified volume.
这是没有开始负载均衡时查询到的状态:

这是负载均衡后查询到的状态:


原始
[root@localhost ~]# ll /brick* /brick1: total 8 -rw-r--r--. 2 root root 14 11?.18 13:14 file1 -rw-r--r--. 2 root root 11 11?.18 13:14 file2 /brick2: total 0 
过程1
[root@localhost ~]# ll /brick* /brick1: total 8 ---------T. 2 root root 14 11?.18 13:14 file1 -rw-r--r--. 2 root root 11 11?.18 13:14 file2 /brick2: total 4 -rw-r--r--. 2 root root 14 11?.18 13:14 file1
结果 
[root@localhost ~]# ll /brick* /brick1: total 4 -rw-r--r--. 2 root root 11 11?.18 13:14 file2 /brick2: total 4 -rw-r--r--. 2 root root 14 11?.18 13:14 file1 ---------T. 2 root root 11 11?.18 13:42 file2 
这是写file2,T文件变成真实的文件,又新写了几个文件

17、设置卷的参数
gluster volume set VOLNAME OPTION PARAMETER
e.g.
gluster volume set testvol performance.cache-size 256MB






0 0