当前位置:网站首页>如何使用 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 “混合云/多云存储架构的实践和展望”,欢迎点此报名。
边栏推荐
- 模板引擎Velocity 基础
- 毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
- Tutorial on the principle and application of database system (005) -- Yum offline installation of MySQL 5.7 (Linux Environment)
- Is the programmer's career really short?
- [nodemon] app crashed - waiting for file changes before starting... resolvent
- Golang爬虫框架初探
- [kotlin] Introduction to higher-order functions
- Advantages, values and risks of chain games compared with traditional games
- P2893 [USACO08FEB] Making the Grade G(dp&优先队列)
- SQL question brushing 586 Customers with the most orders
猜你喜欢

What is the digital transformation of manufacturing industry
![[JetsonNano] [教程] [入门系列] [三] 搭建TensorFlow环境](/img/0e/52e37527bc717c7a55741725087bad.png)
[JetsonNano] [教程] [入门系列] [三] 搭建TensorFlow环境

Template engine velocity Foundation

Tutorial on principles and applications of database system (004) -- MySQL installation and configuration: resetting MySQL login password (Windows Environment)

免费抽奖 | 《阿巴豆》探索未来系列盲盒数字版权作品全网首发!
![[live broadcast appointment] database obcp certification comprehensive upgrade open class](/img/50/83a533f4e8a60f90e03b991385c08d.jpg)
[live broadcast appointment] database obcp certification comprehensive upgrade open class

数据库系统原理与应用教程(003)—— MySQL 安装与配置:手工配置 MySQL(windows 环境)
![[flask introduction series] cookies and session](/img/2e/d50e0a032c4ec48935cb5df206a29b.png)
[flask introduction series] cookies and session

广东用电量大跌,说明高新技术产业替代高能耗产业已取得初步成果

Redis 分布式鎖
随机推荐
China carbon disulfide industry research and investment strategy report (2022 Edition)
广东用电量大跌,说明高新技术产业替代高能耗产业已取得初步成果
Research and investment strategy report of China's sodium sulfate industry (2022 Edition)
Principle of SSM framework
模板引擎Velocity 基礎
数据库系统原理与应用教程(005)—— yum 离线安装 MySQL5.7(Linux 环境)
How does go use symmetric encryption?
数据库系统原理与应用教程(004)—— MySQL 安装与配置:重置 MySQL 登录密码(windows 环境)
數據庫系統原理與應用教程(006)—— 編譯安裝 MySQL5.7(Linux 環境)
How to solve the keyboard key failure of notebook computer
Redis 分布式锁
What is the digital transformation of manufacturing industry
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
模板引擎Velocity 基础
数据库系统原理与应用教程(006)—— 编译安装 MySQL5.7(Linux 环境)
Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
Bugku's file contains
C language input / output stream and file operation
Hi Fun Summer, play SQL planner with starrocks!
vim用户自动命令示例