当前位置:网站首页>如何使用 etcd 实现分布式 /etc 目录
如何使用 etcd 实现分布式 /etc 目录
2022-07-01 16:27:00 【Juicedata】
etcd 是 Kubernetes 中首选的数据存储系统,这个名字来自于 “/etc” 和 ”distributed“,“/etc” 是Linux 存储配置文件的目录,但 etcd 是一个 Key-Value 键值数据库,不能存储文件。
背景
etcd 是一款兼具一致性和高可用性的键值数据库,简单、安全、快速、可信,目前是 Kubernetes 的首要数据存储。我们先来看一段 etcd 官方对于名字的解释。
The name “etcd” originated from two ideas, the unix “/etc” folder and “d"istributed systems. The “/etc” folder is a place to store configuration data for a single system whereas etcd stores configuration information for large scale distributed systems. Hence, a “d"istributed “/etc” is “etcd”.
上面一段话来源于 etcd 官网,etcd 富有想象力地把etc (Linux 系统通常用来存储配置文件的地方) 与 distributed (分布式) 两个概念结合在了一起,然而,由于 etcd 通过 HTTP API 提供服务,因此”遗憾”地没能实现一个真正的分布式 /etc 目录。下面我们将介绍,如何通过 JuiceFS,帮助 etcd 实现一个真正的分布式 /etc 目录。
那么可以用 etcd 实现真正的分布式 /etc 么?下面的方法亲测可以。
我们使用开源的分布式文件系统 JuiceFS 来为 /etc 提供 POSIX 文件接口的访问能力,而 JuiceFS 可以使用 etcd 作为 Metadata 引擎,存储文件系统中目录树、文件名等元数据,配合 JuiceFS CSI Driver,可以作为 Persistent Volume,在 Kubernetes 平台中实现多个应用实例共享配置文件,这就是不折不扣的分布式 /etc 了。
下文将从什么是 JuiceFS、为什么 JuiceFS 可以实现分布式 /etc 以及如何实现分布式 /etc 等方面展开介绍,讲述 etcd 如何借助 JuiceFS 实现在多个应用实例中共享配置文件。
什么是 JuiceFS

JuiceFS 是一个开源的云原生分布式文件系统,为云环境设计,提供完备的 POSIX、HDFS 和 S3 API 兼容性。JuiceFS 的架构采用了分层插件式的设计,元数据引擎陆续开放了对 Redis、MySQL、PostgreSQL、TiKV 等数据库的支持,并且在 v1.0-beta3 版本中正式支持 etcd 作为元数据引擎。数据存储引擎对接任意对象存储存储系统,在 v1.0-rc1 中也支持了 etcd 作为数据存储引擎,正适合存储容量不大的配置文件。
为什么 JuiceFS 可以实现分布式 /etc
根据上面所述的分层架构设计可以看到,JuiceFS 将文件的元数据存储在数据库中,而文件数据存储在对象存储中,从而使得用户可以在不同节点上都可以访问到相同的树形文件系统结构,并达到共享文件的目的。有了 JuiceFS 分布式文件系统的加持,我们就可以将配置文件放在文件系统中,然后在每个应用中将 JuiceFS 挂载进其 /etc 目录,进而实现真正的分布式 "/etc"。整个过程如下图所示。

如何实现分布式 /etc
接下来以 nginx 应用为例,讲述 etcd 如何借助 JuiceFS,使得多个 nginx 实例间共享同一份配置,实现分布式 /etc。
部署 etcd
在 Kubernetes 环境中,建议搭建独立的 etcd 服务供 JuiceFS 使用,而不是使用集群中默认的 etcd 服务,避免当文件系统访问压力高时影响 Kubernetes 集群的稳定性。
安装 etcd 的方式可以参考官方文档,搭建多节点的 etcd 集群;也可以使用 Bitnami 提供的 etcd 的 chart 安装包。
在数据敏感的情况下,可以开启 etcd 的加密通信功能,进行数据的加密传输。参考 etcd 项目提供的示例脚本。
在 JuiceFS 中准备配置文件
安装好 etcd 集群后,两行命令初始化一个 JuiceFS 文件系统。
$ juicefs format etcd://$IP1:2379,$IP2:2379,$IP3:2379/jfs --storage etcd --bucket etcd://$IP1:2379,$IP2:2379,$IP3:2379/data pics$ juicefs mount etcd://$IP1:2379,$IP2:2379,$IP3:2379/jfs /mnt/jfs将 JuiceFS volume 挂载到 /mnt/jfs 目录后,就可以直接在该目录放置 nginx.conf 文件。
在 Kubernetes 中使用 JuiceFS
首先创建一个 Secret,在其中配置 etcd 的连接信息:
apiVersion: v1kind: Secretmetadata: name: juicefs-secret namespace: kube-systemtype: OpaquestringData: name: test metaurl: etcd://$IP1:2379,$IP2:2379,$IP3:2379/jfs storage: etcd bucket: etcd://$IP1:2379,$IP2:2379,$IP3:2379/data元数据引擎和对象存储都使用 etcd,其中 $IP1、$IP2、$IP3 为 etcd 的客户端 IP。接着创建 PV 和 PVC(可以参考文档)。然后就可以在 Nginx 应用中,将 PVC 挂载到 /etc,如下:
apiVersion: apps/v1kind: Deploymentmetadata: name: nginx-appspec: … volumes: - name: config persistentVolumeClaim: claimName: etcd containers: - image: nginx volumeMounts: - mountPath: /etc/nginx name: config …Nginx 应用在启动时会读取 /etc/nginx 下的 nginx.conf 配置文件,即读取我们放置在 JuiceFS 中的 nginx.conf 配置文件即可,而 nginx.conf 文件就是通过 JuiceFS volume 共享的。
总结
etcd 作为一款云原生键值数据库,用于存储 Kubernetes 平台中的服务配置信息,已经成为事实标准。但是很多上层应用的配置文件管理仍然不方便,本文分享 JuiceFS 如何把 etcd 变成分布式 "/etc" 的方法,帮助 etcd 完成了最初的梦想 。
活动预告
本周六将举办 Meetup “混合云/多云存储架构的实践和展望”,欢迎点此报名。
边栏推荐
- Tutorial on the principle and application of database system (001) -- MySQL installation and configuration: installation of MySQL software (Windows Environment)
- Flux d'entrées / sorties et opérations de fichiers en langage C
- 数据库系统原理与应用教程(004)—— MySQL 安装与配置:重置 MySQL 登录密码(windows 环境)
- P2893 [usaco08feb] making the grade g (DP & priority queue)
- How to restore the system of Sony laptop
- Virtual serial port simulator and serial port debugging assistant tutorial "suggestions collection"
- 数据库系统原理与应用教程(006)—— 编译安装 MySQL5.7(Linux 环境)
- Red team Chapter 8: blind guess the difficult utilization process of the package to upload vulnerabilities
- 游戏行业安全选择游戏盾,效果怎么样?
- The difference between the lazy mode of singleton mode and the evil mode
猜你喜欢

How to solve the problem that the battery icon of notebook computer does not display

Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022

软件工程导论——第六章——详细设计
![[flask introduction series] cookies and session](/img/2e/d50e0a032c4ec48935cb5df206a29b.png)
[flask introduction series] cookies and session

Apple's self-developed baseband chip failed again, which shows Huawei Hisilicon's technological leadership

Redis Distributed Lock

程序员职业生涯真的很短吗?

Redis6.0 新功能

游戏行业安全选择游戏盾,效果怎么样?

PR basic clip operation / video export operation
随机推荐
How to repair the laptop that cannot connect to the wireless network
Research and investment strategy report of China's sodium sulfate industry (2022 Edition)
模板引擎Velocity 基础
How to cancel automatic search and install device drivers for laptops
China benzene hydrogenation Market Research and investment forecast report (2022 Edition)
瑞典公布决定排除华为5G设备,但是华为已成功找到新出路
Hi Fun Summer, play SQL planner with starrocks!
[pyg] document summary and project experience (continuously updated
Stegano in the world of attack and defense
sql刷题627. 变更性别
数据库系统原理与应用教程(005)—— yum 离线安装 MySQL5.7(Linux 环境)
Leetcode 77 combination -- backtracking method
想做软件测试的女孩子看这里
数据库系统原理与应用教程(001)—— MySQL 安装与配置:MySQL 软件的安装(windows 环境)
Rhcsa Road
VMware 虛擬機啟動時出現故障:VMware Workstation 與 Hyper-v 不兼容...
苹果自研基带芯片再次失败,说明了华为海思的技术领先性
Research and investment strategy report of neutral protease industry in China (2022 Edition)
SQL question brushing 627 Change gender
Is the programmer's career really short?