<?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>Distributed | Easton Man's Blog</title>
	<atom:link href="https://blog.eastonman.com/blog/tag/distributed/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.eastonman.com</link>
	<description>临渊羡鱼，不如退而结网</description>
	<lastBuildDate>Tue, 03 Aug 2021 03:06:06 +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>Distributed | 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>
		<item>
		<title>去中心化通讯协议 Matrix</title>
		<link>https://blog.eastonman.com/blog/2020/10/matrix/</link>
					<comments>https://blog.eastonman.com/blog/2020/10/matrix/#comments</comments>
		
		<dc:creator><![CDATA[Easton Man]]></dc:creator>
		<pubDate>Wed, 07 Oct 2020 01:39:42 +0000</pubDate>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[Distributed]]></category>
		<category><![CDATA[Matrix]]></category>
		<category><![CDATA[Synapse]]></category>
		<category><![CDATA[去中心化]]></category>
		<guid isPermaLink="false">https://blog.eastonman.com/?p=206</guid>

					<description><![CDATA[<p>在现在这个时代，所有的聊天软件不可避免地会遭到审查，那么如何能够将个人隐私牢牢地掌握在自己手中呢？Matrix就是一个新兴的去中心化通讯协议</p>
The post <a href="https://blog.eastonman.com/blog/2020/10/matrix/">去中心化通讯协议 Matrix</a> first appeared on <a href="https://blog.eastonman.com">Easton Man's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p class="wpwc-reading-time">预计阅读时间： 5 分钟</p>
<h2 class="wp-block-heading">写在前面</h2>



<p>在现在这个时代，所有的聊天软件不可避免地会遭到审查，那么如何能够将个人隐私牢牢地掌握在自己手中呢？有不少人使用较为安全的支持e2e加密的软件Telegram，但是国内无法正常访问，本文教你如何搭建类似的e2e加密的国内可以正常使用的聊天软件——Matrix。</p>



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



<p><a href="https://matrix.org/">Matrix</a>是一个去中心化的通讯协议，功能丰富，架构健壮。与客户端直接通讯的服务端可以自行部署，无需担心在国内无法访问。</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="875" height="674" src="https://blog.eastonman.com/wp-content/uploads/2020/09/image.png" alt="" class="wp-image-208" srcset="https://blog.eastonman.com/wp-content/uploads/2020/09/image.png 875w, https://blog.eastonman.com/wp-content/uploads/2020/09/image-300x231.png 300w, https://blog.eastonman.com/wp-content/uploads/2020/09/image-768x592.png 768w" sizes="(max-width: 875px) 100vw, 875px" /></figure>



<p>由于使用的是http api，所以部署非常方便，第三方客户端的开发也十分便捷。目前matrix生态十分丰富，还有不少bot、bridge等增加它的功能。</p>



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



<p>Synapse是一个最常用的matrix服务端软件，使用Python编写，由matrix官方维护，是我们部署matrix服务端的最佳选择。</p>



<p>Matrix官方还有开发一个Golang的版本，但是仍在Beta阶段，短期内不建议部署。</p>



<p>因为Python版本多环境复杂，我们首先考虑使用Docker进行部署，官方的docker 镜像位于<a href="https://hub.docker.com/r/matrixdotorg/synapse">Docker Hub</a></p>



<p>，直接使用问题也不大，有一点小问题我们很快就会讲到。</p>



<p>因为环境变量较多，我们自然是选择docker-compose 来部署和管理，docker-compose的安装教程位于<a href="https://docs.docker.com/compose/install/">https://docs.docker.com/compose/install/</a>，没有安装的可以按照官网提示安装。</p>



<p>synapse官方有example位于<a href="https://github.com/matrix-org/synapse/blob/master/contrib/docker/docker-compose.yml">https://github.com/matrix-org/synapse/blob/master/contrib/docker/docker-compose.yml</a>，使用了traefic作为反向代理，不太符合我的需求，在此提供一份我使用的compose file</p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">version: '2.4'

volumes:
  db:
    name: synapse_db

networks:
  synapse:
    name: synapse
    ipam:
      config:
        - subnet: 172.23.1.0/24

services:

  synapse:
    #image: reg.techminer.org/library/synapse:latest
    image: matrixdotorg/synapse:latest
    container_name: synapse
    # Since synapse does not retry to connect to the database, restart upon
    # failure
    restart: unless-stopped
    # See the readme for a full documentation of the environment settings
    environment:
      - SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
    networks:
      synapse:
        ipv4_address: 172.23.1.2
    volumes:
      - ./files:/data
    depends_on:
      - db

  db:
    image: postgres:12-alpine
    container_name: synapse_db
    restart: unless-stopped
    # Change that password, of course!
    environment:
      - POSTGRES_USER=synapse
      - POSTGRES_PASSWORD=MammalMatrixPretty
      # ensure the database gets created correctly
      # https://github.com/matrix-org/synapse/blob/master/docs/postgres.md#set-up-database
      - POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C
    volumes:
      - db:/var/lib/postgresql/data
    networks:
      synapse:</pre>



<p>然后我们<code>docker-compose up -d</code>就可以开始运行了。</p>



<p>方便起见我把tls放在反向代理上，就不在synapse中配置cert了，印象中Matrix要求使用tls也就是https用于通信，所以一个有效的证书是避不开的了。对于证书我推荐使用<a href="https://github.com/acmesh-official/acme.sh">Acme.sh</a>，文档见链接。TLS的配置我就不赘述了。</p>



<p>此处需要注意的是反向代理需要一些额外的配置，官方已经有<a href="https://github.com/matrix-org/synapse/blob/develop/docs/reverse_proxy.md">建议</a>，此处列举一个我使用的HAProxy配置。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">frontend https
  bind :::443 v4v6 ssl crt /etc/ssl/haproxy/ strict-sni alpn h2,http/1.1

  # Matrix client traffic
  acl matrix-host hdr(host) -i matrix.example.com
  acl matrix-path path_beg /_matrix
  acl matrix-path path_beg /_synapse/client

  use_backend matrix if matrix-host matrix-path

frontend matrix-federation
  bind :::8448 v4v6 ssl crt /etc/ssl/haproxy/synapse.pem alpn h2,http/1.1
  default_backend matrix

backend matrix
  server matrix 127.0.0.1:8008</pre>



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



<p>由于Matrix是一个开放的协议，任何人都可以为它编写客户端。</p>



<p>所有的客户端见<a href="https://matrix.org/clients/">官方页面</a>。</p>



<p>目前开发得比较完善的客户端是<a href="https://element.io/">Element</a>，原名Riot.im。</p>



<p></p>



<p>至此，我们已经安装好服务端和客户端了，可以按照指示创建一个新用户并愉快地开始聊天了。</p>



<h2 class="wp-block-heading">Known Bugs</h2>



<p><s>Python的Twisted库Bug导致发注册邮件等无法使用TLSv1.2，所以如果使用的邮件服务商不支持旧的TLS版本，那么还需要更改Dockerfile使用nightly的Twisted。</s> 2021-08-03 Update: Twisted库已经修复了这个Bug。</p>



<p>目前其实就算是Element开发得也不是很完善，然后发布版本缺乏测试，经常引入新bug。</p>



<p>还有就是synapse这个服务端是用Python写的，性能非常抱歉，尤其是相当消耗硬盘I/O，3000iops的ssd都能给占满活动时间。</p>



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



<p>其实主要还是感受一下这样的去中心化即时聊天形式，matrix协议使用的去中心化方式带来的federation查询时主要消耗性能的地方，尤其是对于曾经存在过的HomeServer，Synapse没有做区分，导致不停地重复查询已经不可能查询到的federation API。</p>



<p>如果是真正想要体验良好的聊天体验的话还是建议使用<a href="https://telegram.org/">Telegram</a>。</p>The post <a href="https://blog.eastonman.com/blog/2020/10/matrix/">去中心化通讯协议 Matrix</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/10/matrix/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
