当前位置:网站首页>Confid+etcd to realize automatic discovery of high availability
Confid+etcd to realize automatic discovery of high availability
2022-07-26 20:40:00 【Brother Xing plays with the clouds】
Confd What is it?
Confd Is a lightweight configuration management tool . By querying backend storage , Combined with the configuration template engine , Keep local configuration up to date , At the same time, it has regular detection mechanism , Configuration changes automatically reload. The corresponding back-end storage can be etcd,redis、zookeeper wait We use etcd Demonstrate for the back end confd Use , Teach you how to generate configuration dynamically in the simplest and rudimentary way
One . Get ready confd Dependent storage etcd
etcd -listen-client-urls="http://0.0.0.0:2379" --advertise-client-urls="http://0.0.0.0:2379" &etcd Build if you can't see the previous article 《 Build from scratch etcd Distributed The storage system +web Management interface 》
Two . install confd
# download
wget https://github.com/kelseyhightower/confd/releases/download/v0.16.0/confd-0.16.0-linux-amd64
# install
mv confd-0.16.0-linux-amd64 /usr/local/bin/confd
chmod +x /usr/local/bin/confd
# Check if the installation is successful
[email protected]:/home/chenqionghe/test/confd# confd --version
confd 0.16.0 (Git SHA: 7217b0ca, Go Version: go1.10.2)- confd The default configuration file is /etc/confd in , You can use the parameter -confdir Appoint . The directory contains two subdirectories , Namely :conf.d templates.
- confd Read first conf.d The configuration file in the directory (toml Format ), Then render the template according to the template path specified by the file , Re execution <RELOAD_CMD>.
Let's create
mkdir -p /etc/confd/{conf.d,templates}confd Configuration file for , It mainly includes the generation logic of configuration , For example, template source , Back end storage corresponds to keys, Order execution, etc . templates: The configuration template Template, That is, configuration based on different components , It is amended as follows go Language template file .
3、 ... and . Configuration and use confd
1. create profile /etc/confd/conf.d/chenqionghe.toml
[template]
# Template file path
src = "https://www.linuxidc.com/Linux/2019-03/chenqionghe.tmpl"
# Generate final file path
dest = "/home/chenqionghe/test/confd/gym-data.txt"
keys = [
"/chenqionghe/deap_squat",
"/chenqionghe/bench_press",
"/chenqionghe/dead_lift",
]
# Command executed after generating file
reload_cmd = "echo 'light weight baby' >> /home/chenqionghe/test/confd/reaload.txt"2. Create template file /etc/confd/templates/chenqionghe.tmpl
[ Chen qionghe ]
Squat down = {{getv "/chenqionghe/deap_squat"}}
Oh my god = {{getv "/chenqionghe/bench_press"}}
Hard drawn = {{getv "/chenqionghe/dead_lift"}}3. initialization etcd Data in
endpoints=http://127.0.0.1:2379
etcdctl --endpoints=$endpoints set /chenqionghe/deap_squat '130kg'
etcdctl --endpoints=$endpoints set /chenqionghe/bench_press '100kg'
etcdctl --endpoints=$endpoints set /chenqionghe/dead_lift '160kg'4. start-up confd Service for
confd Support with daemon perhaps onetime Two modes of operation onetime Pattern : The configuration will only be generated once , after key No matter the change will not generate again
confd -onetime -backend etcd -node http://127.0.0.1:2379- daemon Pattern :confd It will monitor the configuration changes of back-end storage , Generate the target configuration file dynamically according to the configuration template .
confd Support with daemon perhaps onetime Two modes of operation
- daemon Pattern :confd It will monitor the configuration changes of back-end storage , And dynamically generate the target configuration file according to the configuration template .
confd -watch -backend etcd -node http://127.0.0.1:2379 &We use daemon mode , Then change key Value , Observe file changes , You can see reload.txt Documents are being added continuously light weight baby
gym-data.txt Follow 3 individual key The changes are constantly updated
Four . About - Template syntax
confd The template used is go Linguistic template, Yes go Students who are familiar with the language should find it very simple confd A lot of template functions have been integrated , Reference link
5、 ... and . Think about expanding -confd What can be done
We probably know confd Principle 1. Read configuration file -> 2. Use the template to generate the specified file -> 3. Run overload command ( Optional )
So basically using configuration and reload The command can be used everywhere confd, Such as the demand below
- nginx Dynamic generation upstream Implementing service discovery
- prometheus Dynamic generation prometheus.yml Realize automatic alarm
- php-fpm Dynamic generation php.ini File to achieve dynamic performance tuning
- Dynamically generate report files and send notifications
Only unexpected , No, I can't , I thought about writing a nginx Dynamic generation of upstream, I didn't expect someone to write it out , It's really powerful , Guys, hurry up high Get up
边栏推荐
- 数据块的存储系统中缓存的作用是什么?
- 【刷题记录】22. 括号生成
- 实验5 OSPF综合实验
- 一文读懂 Kubernetes的四种服务类型!
- Leetcode-300 最长递增子序列
- Nmap installation and use
- Single core A7 plays with face recognition, and NXP "crossover processor" plays a new trick!
- Gbase learning - install gbase 8A MPP cluster v95
- Small scenes bring great improvement! Baidu PaddlePaddle easydl helps AI upgrade of manufacturing assembly line
- 从零开始搭建Prometheus自动监控报警系统
猜你喜欢

Read the four service types of kubernetes!

解决IBGP的水平分割和BGP选路原则

MPLS 多协议标签交换技术

81. (cesium home) cesium modifies the gray background (default blue)

执行上下文与词法环境

BUU刷题记4

Arpspoof installation and use

gospel! Wechat personal official account can be renamed!

Solve the horizontal segmentation of iBGP and BGP routing principles

Game partner topic: breederdao and ultiverse have established a new metauniverse
随机推荐
20220726
[pyqt5 basic control usage analysis]
After being fined "paid leave" for one month, Google fired him from AI on "love"
The Sandbox 和艺术家 Alec Monopoly 达成合作
BUU刷题记-网鼎杯专栏2
李彦宏遭“泼冷水”热情不减!百度结盟华为麒麟,发布“鸿鹄”芯片
一文读懂 Kubernetes的四种服务类型!
美司法部律师团队要求法官拒绝受理华为诉讼
Quick start to connection pooling
7岁男童因下棋太快?机器人竟夹断其手指
如何优雅地赞美他人?不妨尝试下这几种方式
游戏合作伙伴专题:BreederDAO 与 Ultiverse 建立了一个新的元宇宙
7.25 simulation summary
When there are many query fields, you can add ordinary query and advanced query
深度可分离卷积(DepthwiseSeparableConvolution):Depthwise卷积与Pointwise卷积
实验6 BGP联邦综合实验
Group convolution
传惠普/戴尔/微软/亚马逊考虑将部分硬件生产线转到大陆以外
数字化工厂有哪些关键技术
数据块的存储系统中缓存的作用是什么?