当前位置:网站首页>如何使用 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 “混合云/多云存储架构的实践和展望”,欢迎点此报名。
边栏推荐
- 毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
- 用手机在同花顺上开户靠谱吗?这样有没有什么安全隐患
- 拼接字符串,得到字典序最小的结果
- Flux d'entrées / sorties et opérations de fichiers en langage C
- Tutorial on the principle and application of database system (003) -- MySQL installation and configuration: manually configure MySQL (Windows Environment)
- Golang爬虫框架初探
- SystemVerilog-结构体(二)
- vim用户自动命令示例
- 红队第10篇:coldfusion反序列化过waf改exp拿靶标的艰难过程
- String类
猜你喜欢

Installation and use of sqoop

苹果自研基带芯片再次失败,说明了华为海思的技术领先性

机器学习11-聚类,孤立点判别

Internet News: "20220222" get together to get licenses; Many products of Jimi have been affirmed by consumers; Starbucks was fined for using expired ingredients in two stores

OJ questions related to complexity (leetcode, C language, complexity, vanishing numbers, rotating array)

Rhcsa Road

数据库系统原理与应用教程(006)—— 编译安装 MySQL5.7(Linux 环境)

Activity的生命周期和启动模式详解

Are you still using charged document management tools? I have a better choice! Completely free

String类
随机推荐
How to maintain the laptop battery
Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!
Tutorial on the principle and application of database system (003) -- MySQL installation and configuration: manually configure MySQL (Windows Environment)
AI college entrance examination volunteer filling: the gods of Dachang fight, and candidates pay to watch
What is the effect of choosing game shield safely in the game industry?
C语言输入/输出流和文件操作
Rhcsa Road
Go 语言源码级调试器 Delve
Is the programmer's career really short?
How to restore the system with one click on Lenovo laptop
FPN network details
红队第8篇:盲猜包体对上传漏洞的艰难利用过程
UML旅游管理系统「建议收藏」
Judge whether the binary tree is a binary search tree
Concatenate strings to get the result with the smallest dictionary order
Zabbix2.2监控之系统及应用日志监控报警
Determine whether the linked list is a palindrome linked list
China nylon 11 industry research and future forecast report (2022 Edition)
The supply of chips has turned to excess, and the daily output of Chinese chips has increased to 1billion, which will make it more difficult for foreign chips
[jetsonnano] [tutorial] [introductory series] [III] build tensorflow environment