<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GlusterFS | Easton Man's Blog</title>
	<atom:link href="https://blog.eastonman.com/blog/tag/glusterfs/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.eastonman.com</link>
	<description>临渊羡鱼，不如退而结网</description>
	<lastBuildDate>Mon, 25 Jan 2021 02:18:49 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.5</generator>

<image>
	<url>https://blog.eastonman.com/wp-content/uploads/2021/02/cropped-Logo-e1613298891313-32x32.png</url>
	<title>GlusterFS | Easton Man's Blog</title>
	<link>https://blog.eastonman.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>GlusterFS 部署简记</title>
		<link>https://blog.eastonman.com/blog/2020/12/glusterfs/</link>
					<comments>https://blog.eastonman.com/blog/2020/12/glusterfs/#comments</comments>
		
		<dc:creator><![CDATA[Easton Man]]></dc:creator>
		<pubDate>Wed, 02 Dec 2020 14:35:09 +0000</pubDate>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Distributed]]></category>
		<category><![CDATA[GlusterFS]]></category>
		<guid isPermaLink="false">https://blog.eastonman.com/?p=286</guid>

					<description><![CDATA[<p>本文从实验性的角度阐述在Debian 10 (Buster) 上部署Gluster FS的过程，力求步骤简便，能够由一个人很快地完成。为了达到这个目的，本文尽量使用Debian官方repo中的包，避免编译，并使用ansible统一执行命令。</p>
The post <a href="https://blog.eastonman.com/blog/2020/12/glusterfs/">GlusterFS 部署简记</a> first appeared on <a href="https://blog.eastonman.com">Easton Man's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p class="wpwc-reading-time">预计阅读时间： 9 分钟</p>
<p>本文从实验性的角度阐述在Debian 10 (Buster) 上部署Gluster FS的过程，力求步骤简便，能够由一个人很快地完成。为了达到这个目的，本文尽量使用Debian官方repo中的包，避免编译，并使用ansible统一执行命令。</p>



<h2 class="wp-block-heading">开始之前</h2>



<h3 class="wp-block-heading">什么是Gluster FS</h3>



<p>摘录一段GlusterFS官网的介绍。</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p><strong>Gluster is a free and open-source scalable network filesystem</strong></p><p>Gluster is a scalable network filesystem. Using common off-the-shelf hardware, you can create large, distributed storage solutions for media streaming, data analysis, and other data- and bandwidth-intensive tasks. Gluster is free.</p><cite><a href="https://www.gluster.org/" title="https://www.gluster.org/">Gluster | Storage for your cloud</a></cite></blockquote>



<p>这段介绍的大意是：GlusterFS是一个分布式的文件系统，是一个网络文件系统，适合在数据和带宽密集型应用中使用。</p>



<p>我认为GlusterFS除了以上描述中的场景，还适用于HPC集群的场景下。相较于HPC领域传统的Lustre和BeeGFS之类的文件系统，GlusterFS具有以下优势：</p>



<ul class="wp-block-list"><li><strong>持续的维护更新</strong>（我认为这一点最为重要）。像Lustre这样应用广泛的HPC基础设施，竟然维护者几经转换，社区十分混乱，虽然仍有持续的更新，但是这样的项目状态实在难以称之为优秀的项目。</li><li><strong>优秀的生态。</strong>开源社区对GlusterFS的大量关注使得它拥有数量众多的资料、文章，各大Linux发行版也都有官方的预编译包。</li><li><strong>相对优秀的性能。</strong>虽然没有做过对比测试，但是GlusterFS在其他应用场景下表现出的性能十分的不俗，相信在HPC这样的计算密集型应用场景下也应当有不错的表现。</li><li><strong>使用FUSE挂载。</strong>另一个我觉得相对优势巨大的特性是GlusterFS的挂载方式是基于FUSE的，也就是在用户空间挂载，相较于Lustre需要重新编译内核或者使用dkms，GlusterFS的挂载方式无疑提供了更高的解耦合，更加利于故障恢复之类的情况。</li></ul>



<h3 class="wp-block-heading">基本概念</h3>



<ul class="wp-block-list"><li>Brick: 存储的基本单元，类似于Linux上块设备（block device）的概念</li><li>Volume: 卷是bricks的逻辑集合，类似于LVM中的Volume</li><li>GFID: 每个GlusterFS中的文件或者目录都有一个128bit的数字标识称为GFID</li><li>glusterd: Gluster的管理守护进程，需要运行在所有的提供Volume的服务器上</li><li>glusterfsd: 用于挂载GlusterFS Volume的守护进程</li><li>Namespace: 名称空间是被创建的一个抽象容器或环境用来保存唯一标识符号</li><li>Quorum: 设置一个可信的存储池中最多失效的主机节点数量</li><li>Quota: 允许通过目录或者卷设置对磁盘空间使用的限制</li><li>Distributed: 分布卷</li><li>Replicated: 副本卷</li><li>Distributed Replicated: 分布式复制卷</li><li>Geo-Replication: 异地备份为站点通过局域网、广域网、互联网提供一个连续的异步的和增量复制服务</li><li>Metedata: 元数据定义为关于数据的数据描述信息，GlusterFS没有专门区分元数据的存储</li><li>Extended Attributes: 扩展属性是文件系统的一个特性</li><li>FUSE: 用户空间的文件系统是一个用于类Unix操作系统的可加载内核模块，以允许非特权用户在使用内核代码的情况下创建自己的文件系统。实现了在用户空间下运行文件系统代码</li></ul>



<h3 class="wp-block-heading">Ansible</h3>



<p>本次安装会使用到Ansible，Ansible是一个强大的工具，有关信息参见<a href="https://docs.ansible.com/ansible/latest/index.html" title="https://docs.ansible.com/ansible/latest/index.html" target="_blank" rel="noreferrer noopener">Ansible官网</a>，此处就不赘述了。</p>



<h2 class="wp-block-heading">安装GlusterFS</h2>



<p>按照官方的<a href="https://docs.gluster.org/en/latest/Install-Guide/Install/" title="https://docs.gluster.org/en/latest/Install-Guide/Install/" target="_blank" rel="noreferrer noopener">教程</a>，第一步是添加APT源的公钥</p>



<pre class="wp-block-code"><code>wget -O - https://download.gluster.org/pub/gluster/glusterfs/LATEST/rsa.pub | apt-key add -</code></pre>



<p>但是实际操作时这个LATEST需要被替换为实际上的最新大版本号，比如撰写事最新的版本是8，于是实际执行的命令是：</p>



<pre class="wp-block-code"><code>ansible all -m shell -a "wget -O - https://download.gluster.org/pub/gluster/glusterfs/LATEST/rsa.pub | apt-key add -" --become</code></pre>



<p>接下来是添加APT源</p>



<pre class="wp-block-code"><code>ansible -m shell -a "echo deb https://download.gluster.org/pub/gluster/glusterfs/LATEST/Debian/10/amd64/apt buster main &gt; /etc/apt/sources.list.d/gluster.list" --become</code></pre>



<p>然后就可以安装了。由于我的情况是在四台机器都同时作为服务端和客户端，于是直接全部都安装。</p>



<pre class="wp-block-code"><code>ansible -m shell -a "apt update; apt-get install -y glusterfs-server glusterfs-cli" --become</code></pre>



<p>在我的环境中安装完成后会自动运行glusterd并加入systemd开机自启，至此我们已经安装完全部的软件了。接下来就是配置。</p>



<h2 class="wp-block-heading">构建集群</h2>



<p>在任意节点上运行</p>



<pre class="wp-block-code"><code>sudo gluster peer probe &lt;another node hostname&gt;</code></pre>



<p>就可以将两个节点构成集群，这个<code>peer probe</code>理论上是双向的，也就是无需在另一台节点上再执行一遍。但是有一点需要注意，这些节点需要提前配置好hostname和hosts文件，使得它们之间均可以使用hostname互访。当然配置一个dns也是可以的，不过就不在本文的讨论范围内了。</p>



<p>使用<code>gluster peer status</code>可以查看此时的集群情况。以下是我的环境中执行的情况。注意，此时的Connected仅代表单向的联通，如果没有提前配置好hostname的话需要注意其它机器的可访问情况。否则创建Volume的时候将会出错。</p>



<pre class="wp-block-code"><code>easton@main:~$ sudo gluster peer status
Number of Peers: 3

Hostname: node3
Uuid: 24460b94-03a2-48ea-ab29-ec2cbdd2a008
State: Peer in Cluster (Connected)

Hostname: node1
Uuid: e079d8e3-5972-4801-9525-04f8050b9b6f
State: Peer in Cluster (Connected)

Hostname: node2
Uuid: 84074def-a277-469b-942c-19963113b0c4
State: Peer in Cluster (Connected)</code></pre>



<h2 class="wp-block-heading">创建Volume</h2>



<p>GlusterFS中Volume支持许多Brick的组合方式，类似于RAID中的RAID0、RAID1、RAID10等概念，但是不支持RAID5或者ZFS中RAIDZ之类的方式。</p>



<p>此处我们直接创建一个4个副本的镜像卷</p>



<pre class="wp-block-code"><code>sudo gluster volume create &lt;volume name&gt; replica 4 main{1..3}:/data/gluster main:/data/gluster</code></pre>



<p>Gluster CLI 支持展开{n..m}这样的写法。如果之前创建过同样名字的Volume但是错误了，此时将无法重新创建，添加force参数可以解决此问题。</p>



<p>创建完的Volume需要Start才能够被挂载</p>



<pre class="wp-block-code"><code>sudo gluster volume &lt;volume name&gt; start</code></pre>



<p>使用gluster volume info可以查看Volume的信息。</p>



<pre class="wp-block-code"><code>easton@main:~$ sudo gluster volume info

Volume Name: home
Type: Replicate
Volume ID: 73fa38da-a3f9-4a97-838b-352fd7b7ff9a
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 4 = 4
Transport-type: tcp
Bricks:
Brick1: node1:/data/gluster
Brick2: node2:/data/gluster
Brick3: node3:/data/gluster
Brick4: main:/data/gluster
Options Reconfigured:
storage.fips-mode-rchecksum: on
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off</code></pre>



<h2 class="wp-block-heading">挂载GlusterFS</h2>



<p>挂载GlusterFS十分的简单</p>



<pre class="wp-block-code"><code>sudo mount -t glusterfs &lt;server hostname&gt;:/&lt;volume name&gt; &lt;mount point&gt;</code></pre>



<p>对于我来说是这样的</p>



<pre class="wp-block-code"><code>sudo mount -t glusterfs main:/home /mnt/home</code></pre>



<p>GlusterFS还提供NFS挂载的支持。但是由于NFS不支持InfiniBand之类的RDMA技术，在HPC领域很少使用，于是不推荐使用NFS挂载。</p>



<p>此时我们可以制造一些故障检验GlusterFS的可靠性，比如我们把main服务器关闭以后，在node3节点依然可以正常访问文件，对文件的修改也在main服务器上线后同步到了main的目录下。</p>



<p>有一点值得注意的是，在main服务器关闭后三个node花费了相当长的一段时间（5-10秒）才确认main服务器下线并选举出新的主服务器，这在某些即时性要求较高的商业应用场景下是比较大的问题，但是在HPC场景下我认为这不是一个特别大的问题。</p>



<h2 class="wp-block-heading">后记</h2>



<p>此次安装GlusterFS起因是需要因陋就简地在实验室搭建一个集群供测试使用，搭建前也进行了分布式文件系统的调研，最终选择了GlusterFS，原因见以上GlusterFS的优势部分。</p>



<p>GlusterFS的安装可以说是相当方便了，加上前期的调研和安装操作系统，总共花去了我4-5个小时的时间，如果采用传统的Lustre方案，只能使用CentOS作为宿主操作系统，因为在别的发行版中Lustre都从内核中移除了，从4.xx开始就被Kernel移除了，理由是“糟糕的代码“，这也是我抛弃Lustre的原因之一。</p>



<h2 class="wp-block-heading">后记2</h2>



<p>在使用中发现GlusterFS并未区分元数据的设计导致执行各种目录操作极为耗时，小文件操作性能也很差，如果在GlusterFS上执行./configure可能永远也执行不完<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f602.png" alt="😂" class="wp-smiley" style="height: 1em; max-height: 1em;" />。后来我把集群上家目录的文件系统更换成了BeeGFS，解决了这个架构问题。</p>



<h2 class="wp-block-heading">Reference</h2>



<ul class="wp-block-list"><li><a href="https://www.jianshu.com/p/7435ff434136" target="_blank" rel="noreferrer noopener">分布式存储glusterfs 安装和使用(一)</a></li><li><a href="https://docs.ansible.com/ansible/latest/user_guide/intro_adhoc.html" target="_blank" rel="noreferrer noopener">Introduction to ad-hoc commands</a></li><li><a href="https://docs.gluster.org/en/latest/Administrator-Guide/Brick-Naming-Conventions/" target="_blank" rel="noreferrer noopener" title="https://docs.gluster.org/en/latest/Administrator-Guide/Brick-Naming-Conventions/">Brick Naming Conventions</a></li></ul>



<p></p>The post <a href="https://blog.eastonman.com/blog/2020/12/glusterfs/">GlusterFS 部署简记</a> first appeared on <a href="https://blog.eastonman.com">Easton Man's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://blog.eastonman.com/blog/2020/12/glusterfs/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
