GlusterFS源码解析 —— GlusterFS 配置

来源:互联网 发布:淘宝主视频制作软件 编辑:程序博客网 时间:2024/05/18 15:08
原文地址:http://blog.csdn.net/wangyuling1234567890/article/details/25747679

GlusterFS 源码安装方式:http://blog.csdn.net/wangyuling1234567890/article/details/25519261

1、GlusterFS的典型架构图


2、GlusterFS常用translators(中继)


2.1.1.    storage/posix

type storage/posix
storage/posix的作用是指定一个本地目录给GlusterFS内的一个卷使用。
配置例子:
volume posix-example
    type storage/posix
    option directory /sda4
end-volume

2.1.2.    protocol/server (服务器)

type protocol/server
服务器中继(protocol/server)表示本节点在GlusterFS中为服务器模式。
配置例子:
volume server-example
     type protocol/server
    option transport-type tcp
    subvolumes brick                #定义好的卷
    option auth.addr.brick.allow *  #指定可访问本卷的访问者,*为所有,可对访问者做限制,如192.168.1.*
end-volume

2.1.3.    protocol/client (客户端)

type protocol/client
客户端中继(protocol/server)用于客户端连接服务器时使用。
配置例子:
volume client-example
    type protocol/client
    option transport-type tcp
    option remote-host 192.168.1.13    #连接的服务器
    option remote-subvolume brick      #连接的服务器卷名
end-volume

2.1.4.    cluster/replicate(复制)

type cluster/replicate
复制中继(cluster/replicate,前身是AFR)为GlusterFS提供了类似RAID-1的功能。
Replicate会复制文件或者文件夹到各个subvolumes里。如一个卷(volume)内有两个子卷(subvolume),那就会有两份文件或文件夹的复本。
Replicate只时还有高可用的功能,如果两个子卷中有一个子卷挂了,卷依然可以正常工作。当这个子卷重新启用时,会自动更新丢失的文件或文件夹,不过更新是通过客户端进行的。
配置例子:
volume replicate-example
    type cluster/replicate
    subvolumes brick3 brick4
end-volume

2.1.5.    cluster/distribute (分布式)

type cluster/distribute
分布式中继(cluster/distribute,前身是unify)为GlusterFS提供了类似RAID-0的功能。
Distribute可把两个卷或子卷组成一个大卷,实现多存储空间的聚合
配置例子:
volume distribute-example
    type cluster/distribute
    subvolumes repl1 repl2
end-volume

2.1.6.    features/locks (锁)

type features/locks
锁中继(features/locks)只能用于服务器端的posix中继之上,表示给这个卷提供加锁(fcntl locking)的功能。
配置例子:
volume locks-example
    type features/locks
    subvolumes posix-example
end-volume

2.1.7.    performance/read-ahead (预读)

type performance/read-ahead
预读中继(performance/read-ahead)属于性能调整中继的一种,用预读的方式提高读取的性能。
读取操作前就预先抓取数据。这个有利于应用频繁持续性的访问文件,当应用完成当前数据块读取的时候,下一个数据块就已经准备好了。
额外的,预读中继也可以扮演读聚合器,许多小的读操作被绑定起来,当成一个大的读请求发送给服务器。
预读处理有page-size和page-count来定义,page-size定义了,一次预读取的数据块大小,page-count定义的是被预读取的块的数量
不过官方网站上说这个中继在以太网上没有必要,一般都能跑满带宽。主要是在IB-verbs或10G的以太网上用。
配置例子:
volume readahead-example
    type performance/read-ahead
    option page-size  256         # 每次预读取的数据块大小
    option page-count 4           # 每次预读取数据块的数量
    option force-atime-update off #是否强制在每次读操作时更新文件的访问时间,不设置这个,访问时间将有些不精确,这个将影响预读转换器读取数据时的那一时刻而不是应用真实读到数据的那一时刻。
    subvolumes <x>
end-volume

2.1.8.    performance/write-behind (回写)

type performance/write-behind
回写中继(performance/read-ahead)属于性能调整中继的一种,作用是在写数据时,先写入缓存内,再写入硬盘。以提高写入的性能。
回写中继改善了了写操作的延时。它会先把写操作发送到后端存储,同时返回给应用写操作完毕,而实际上写的操作还正在执行。使用后写转换器就可以像流水线一样把写请求持续发送。这个后写操作模块更适合使用在client端,以期减少应用的写延迟。
回写中继同样可以聚合写请求。如果aggregate-size选项设置了的话,当连续的写入大小累积起来达到了设定的值,就通过一个写操作写入到存储上。这个操作模式适合应用在服务器端,以为这个可以在多个文件并行被写入磁盘时降低磁头动作。
配置例子:
volume write-behind-example
    type performance/write-behind
    option cache-size 3MB    # 缓存大小,当累积达到这个值才进行实际的写操作
    option flush-behind on   # 这个参数调整close()/flush()太多的情况,适用于大量小文件的情况
    subvolumes <x>
end-volume

2.1.9.    performance/io-threads (IO线程)

type performance/io-threads
IO线程中继(performance/io-threads)属于性能调整中继的一种,作用是增加IO的并发线程,以提高IO性能。
IO线程中继试图增加服务器后台进程对文件元数据读写I/O的处理能力。由于GlusterFS服务是单线程的,使用IO线程转换器可以较大的提高性能。这个转换器最好是被用于服务器端,而且是在服务器协议转换器后面被加载。
IO线程操作会将读和写操作分成不同的线程。同一时刻存在的总线程是恒定的并且是可以配置的。
配置例子:
volume iothreads
    type performance/io-threads
    option thread-count 32 # 线程使用的数量
    subvolumes <x>
end-volume

2.1.10.    performance/io-cache (IO缓存)

type performance/io-cache
IO缓存中继(performance/io-threads)属于性能调整中继的一种,作用是缓存住已经被读过的数据,以提高IO性能。
IO缓存中继可以缓存住已经被读过的数据。这个对于多个应用对同一个数据多次访问,并且如果读的操作远远大于写的操作的话是很有用的(比如,IO缓存很适合用于提供web服务的环境,大量的客户端只会进行简单的读取文件的操作,只有很少一部分会去写文件)。
当IO缓存中继检测到有写操作的时候,它就会把相应的文件从缓存中删除。
IO缓存中继会定期的根据文件的修改时间来验证缓存中相应文件的一致性。验证超时时间是可以配置的。
配置例子:
volume iothreads
    type performance/ io-cache
    option cache-size 32MB  #可以缓存的最大数据量
    option cache-timeout 1  #验证超时时间,单位秒
    option priority   *:0   #文件匹配列表及其设置的优先级
    subvolumes <x>
end-volume

2.1.11.    其它中继

其它中继还有
cluster/nufa(非均匀文件存取)
cluster/stripe(条带,用于大文件,分块存储在不用服务器)
cluster/ha(集群)
features/filter(过滤)
features/trash(回收站)
path-converter
quota
老的还有:
cluster/unify(和distribute,可定义不同的调度器,以不同方式写入数据)



3.    GlusterFS配置


3.1.    服务器端配置

先建立需要share的文件夹
make -p /home/dir1
chmod 1777 /home/dir1
然后建立配置文件
vi /etc/glusterfs/server.vol

### file: server-volume.vol.sample######################################## GlusterFS Server Volume File ########################################### CONFIG FILE RULES:### "#" is comment character.### - Config file is case sensitive### - Options within a volume block can be in any order.### - Spaces or tabs are used as delimitter within a line.### - Multiple values to options will be : delimitted.### - Each option should end within a line.### - Missing or commented fields will assume default values.### - Blank/commented lines are allowed.### - Sub-volumes should already be defined above before referring.### Export volume "brick" with the contents of "/home/export" directory.volume brick    type storage/posix # POSIX FS translator    option directory /home/dir1 # Export this directoryend-volume### Add network serving capability to above brick.volume server    type protocol/server    option transport-type tcp/server    option bind-address 192.168.211.128 # Default is to listen on all interfaces    option listen-port 6996 # Default is 6996    subvolumes brick    option auth.addr.brick.allow * # Allow access to "brick" volumeend-volume

启动服务:

gulsterfsd -f /etc/glusterfs/server.vol

[root@contos5-1-1 etc]# ps ax|grep -v grep |grep gluster
2028 ? Ssl 0:00 glusterfsd -f ./server.vol

看到这个证明服务器端就启动了


3.2.    客户端配置

modprobe -i fuse
vi /etc/glusterfs/client.vol

### file: client-volume.vol.sample######################################## GlusterFS Client Volume File ########################################### CONFIG FILE RULES:### "#" is comment character.### - Config file is case sensitive### - Options within a volume block can be in any order.### - Spaces or tabs are used as delimitter within a line.### - Each option should end within a line.### - Missing or commented fields will assume default values.### - Blank/commented lines are allowed.### - Sub-volumes should already be defined above before referring.### Add client feature and attach to remote subvolumevolume client0    type protocol/client    option transport-type tcp/client    option remote-host 192.168.211.128 # IP address of the remote brick    option remote-port 6996 # default server port is 6996    option remote-subvolume brick # name of the remote volumeend-volume

启动服务:

glusterfs -l /tmp/glustfs.log -f /etc/glusterfs/client.vol /mnt/

[root@contos5-1-4 glusterfs]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 7.1G 2.5G 4.3G 37% /
/dev/sda1 190M 11M 170M 7% /boot
tmpfs 125M 0 125M 0% /dev/shm
glusterfs 7.1G 2.9G 3.9G 43% /mnt

看到这个了,就说明client端mount正常,如果没有请查看/tmp/glusterfs.log文件


3.3.    GlusterFS挂载

GlusterFS挂载为在客户端上执行:
# glusterfs -f /etc/glusterfs/glusterfs.vol /gmnt/ -l /var/log/glusterfs/glusterfs.log
-f /etc/glusterfs/glusterfs.vol为指定GlusterFS的配置文件
/gmnt是挂载点
-l /var/log/glusterfs/glusterfs.log为日志

另外,GlusterFS也可以结果fstab或autofs方式开机挂载。挂载后就可以在/gmnt内读写文件了,用法与读写本地硬盘一样。


                                                                                            —— —— 以上内容整理自互联网

0 0
原创粉丝点击