当前位置:网站首页>如何使用 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 “混合云/多云存储架构的实践和展望”,欢迎点此报名。
边栏推荐
- 【flask入门系列】Cookie与Session
- [observation] where is the consulting going in the digital age? Thoughts and actions of softcom consulting
- 独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
- VMware virtual machine failed during startup: VMware Workstation is incompatible with hyper-v
- [pyg] document summary and project experience (continuously updated
- [nodemon] app crashed - waiting for file changes before starting...解决方法
- 模板引擎Velocity 基础
- 判断二叉树是否为二叉搜索树
- Virtual serial port simulator and serial port debugging assistant tutorial "suggestions collection"
- 免费抽奖 | 《阿巴豆》探索未来系列盲盒数字版权作品全网首发!
猜你喜欢
String类
巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...
Principes et applications du système de base de données (006) - - compilation et installation de MySQL 5.7 (environnement Linux)
Tutorial on the principle and application of database system (001) -- MySQL installation and configuration: installation of MySQL software (Windows Environment)
Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!
[pyg] document summary and project experience (continuously updated
阿里云、追一科技抢滩对话式AI
PostgreSQL 存储结构浅析
C language input / output stream and file operation
Germany if was crowned with many awards. How strong is this pair of headphones? In depth evaluation of yinpo GTW 270 hybrid
随机推荐
Concatenate strings to get the result with the smallest dictionary order
Template engine velocity Foundation
How to optimize repeated if err in go language= Nil template code?
Template Engine Velocity Foundation
[live broadcast appointment] database obcp certification comprehensive upgrade open class
Tutorial on principles and applications of database system (004) -- MySQL installation and configuration: resetting MySQL login password (Windows Environment)
P2592 [zjoi2008] birthday party (DP)
Rhcsa Road
广东用电量大跌,说明高新技术产业替代高能耗产业已取得初步成果
SQL question brushing 586 Customers with the most orders
Comprehensively view the value of enterprise digital transformation
Redis6.0 新功能
How to restore the system with one click on Lenovo laptop
Go 语言源码级调试器 Delve
想做软件测试的女孩子看这里
数据库系统原理与应用教程(003)—— MySQL 安装与配置:手工配置 MySQL(windows 环境)
sql刷题586. 订单最多的客户
Installation and use of sqoop
[observation] where is the consulting going in the digital age? Thoughts and actions of softcom consulting
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?