Confd 配置指导
Quick Start Guide
Before we begin be sure to download and install confd.
Select a backend
confd supports the following backends:
- etcd
- consul
- vault
- environment variables
- redis
- zookeeper
- dynamodb
- rancher
- ssm (AWS Simple Systems Manager Parameter Store)
Add keys
This guide assumes you have a working etcd, or consul server up and running and the ability to add new keys.
etcd
etcdctl set /myapp/database/url db.example.com
etcdctl set /myapp/database/user rob
consul
curl -X PUT -d 'db.example.com' http://localhost:8500/v1/kv/myapp/database/url
curl -X PUT -d 'rob' http://localhost:8500/v1/kv/myapp/database/user
vault
vault mount -path myapp generic
vault write myapp/database url=db.example.com user=rob
environment variables
export MYAPP_DATABASE_URL=db.example.com
export MYAPP_DATABASE_USER=rob
redis
redis-cli set /myapp/database/url db.example.com
redis-cli set /myapp/database/user rob
zookeeper
[zk: localhost:2181(CONNECTED) 1] create /myapp ""
[zk: localhost:2181(CONNECTED) 2] create /myapp/database ""
[zk: localhost:2181(CONNECTED) 3] create /myapp/database/url "db.example.com"
[zk: localhost:2181(CONNECTED) 4] create /myapp/database/user "rob"
dynamodb
First create a table with the following schema:
aws dynamodb create-table \
--region <YOUR_REGION> --table-name <YOUR_TABLE> \
--attribute-definitions AttributeName=key,AttributeType=S \
--key-schema AttributeName=key,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
Now create the items. The attribute value value
must be of type string:
aws dynamodb put-item --table-name <YOUR_TABLE> --region <YOUR_REGION> \
--item '{ "key": { "S": "/myapp/database/url" }, "value": {"S": "db.example.com"}}'
aws dynamodb put-item --table-name <YOUR_TABLE> --region <YOUR_REGION> \
--item '{ "key": { "S": "/myapp/database/user" }, "value": {"S": "rob"}}'
Rancher
This backend consumes the Rancher metadata service. For available keys, see the Rancher Metadata Service docs.
ssm
aws ssm put-parameter --name "/myapp/database/url" --type "String" --value "db.example.com"
aws ssm put-parameter --name "/myapp/database/user" --type "SecureString" --value "rob"
Create the confdir
The confdir is where template resource configs and source templates are stored.
sudo mkdir -p /etc/confd/{conf.d,templates}
Create a template resource config
Template resources are defined in TOML config files under the confdir
.
/etc/confd/conf.d/myconfig.toml
[template]
src = "myconfig.conf.tmpl"
dest = "/tmp/myconfig.conf"
keys = [
"/myapp/database/url",
"/myapp/database/user",
]
Create the source template
Source templates are Golang text templates.
/etc/confd/templates/myconfig.conf.tmpl
[myconfig]
database_url = {{getv "/myapp/database/url"}}
database_user = {{getv "/myapp/database/user"}}
Process the template
confd supports two modes of operation daemon and onetime. In daemon mode confd polls a backend for changes and updates destination configuration files if necessary.
etcd
confd -onetime -backend etcd -node http://127.0.0.1:2379
consul
confd -onetime -backend consul -node 127.0.0.1:8500
vault
ROOT_TOKEN=$(vault read -field id auth/token/lookup-self)
confd -onetime -backend vault -node http://127.0.0.1:8200 \
-auth-type token -auth-token $ROOT_TOKEN
dynamodb
confd -onetime -backend dynamodb -table <YOUR_TABLE>
env
confd -onetime -backend env
redis
confd -onetime -backend redis -node 192.168.255.210:6379
or if you want to connect to a specific redis database (4 in this example):
confd -onetime -backend redis -node 192.168.255.210:6379/4
rancher
confd -onetime -backend rancher -prefix /2015-07-25
Note: The metadata api prefix can be defined on the cli, or as part of your keys in the template toml file.
Output:
2014-07-08T20:38:36-07:00 confd[16252]: INFO Target config /tmp/myconfig.conf out of sync
2014-07-08T20:38:36-07:00 confd[16252]: INFO Target config /tmp/myconfig.conf has been updated
The dest
configuration file should now be in sync.
cat /tmp/myconfig.conf
Output:
# This a comment
[myconfig]
database_url = db.example.com
database_user = rob
ssm
confd -onetime -backend ssm
Advanced Example
In this example we will use confd to manage two nginx config files using a single template.
Add keys
etcd
etcdctl set /myapp/subdomain myapp
etcdctl set /myapp/upstream/app2 "10.0.1.100:80"
etcdctl set /myapp/upstream/app1 "10.0.1.101:80"
etcdctl set /yourapp/subdomain yourapp
etcdctl set /yourapp/upstream/app2 "10.0.1.102:80"
etcdctl set /yourapp/upstream/app1 "10.0.1.103:80"
consul
curl -X PUT -d 'myapp' http://localhost:8500/v1/kv/myapp/subdomain
curl -X PUT -d '10.0.1.100:80' http://localhost:8500/v1/kv/myapp/upstream/app1
curl -X PUT -d '10.0.1.101:80' http://localhost:8500/v1/kv/myapp/upstream/app2
curl -X PUT -d 'yourapp' http://localhost:8500/v1/kv/yourapp/subdomain
curl -X PUT -d '10.0.1.102:80' http://localhost:8500/v1/kv/yourapp/upstream/app1
curl -X PUT -d '10.0.1.103:80' http://localhost:8500/v1/kv/yourapp/upstream/app2
Create template resources
/etc/confd/conf.d/myapp-nginx.toml
[template]
prefix = "/myapp"
src = "nginx.tmpl"
dest = "/tmp/myapp.conf"
owner = "nginx"
mode = "0644"
keys = [
"/subdomain",
"/upstream",
]
check_cmd = "/usr/sbin/nginx -t -c {{.src}}"
reload_cmd = "/usr/sbin/service nginx reload"
/etc/confd/conf.d/yourapp-nginx.toml
[template]
prefix = "/yourapp"
src = "nginx.tmpl"
dest = "/tmp/yourapp.conf"
owner = "nginx"
mode = "0644"
keys = [
"/subdomain",
"/upstream",
]
check_cmd = "/usr/sbin/nginx -t -c {{.src}}"
reload_cmd = "/usr/sbin/service nginx reload"
Create the source template
/etc/confd/templates/nginx.tmpl
upstream {{getv "/subdomain"}} {
{{range getvs "/upstream/*"}}
server {{.}};
{{end}}
}
server {
server_name {{getv "/subdomain"}}.example.com;
location / {
proxy_pass http://{{getv "/subdomain"}};
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Confd 配置指导的更多相关文章
- Anaconda多环境多版本python配置指导
Anaconda多环境多版本python配置指导 字数3696 阅读644 评论0 喜欢0 最近学python,读完了语法后在GitHub找了一些练习来做,由 于学的是python3.x语法,而Git ...
- MySql 双主多从配置指导
MySql 双主多从配置指导 一.背景 互联网项目为了数据的可靠性和架构的可拓展性经常会用到双主多从的数据库,来实现数据的备份.负载均衡和突发状况时数据库切换. 二.思路 配置两台数据库A.B互为主从 ...
- F5负载均衡-配置指导手册(含IPv6)
F5负载均衡-配置手册 设备概况 图形化界面 通过网络形式访问F5任一接口地址,打开浏览器输入https://网络接口地址:或pc机直连F5的MGMT带外管理口,打开浏览器,输入https://192 ...
- 【转】【linux系统】nacos + confd配置nginx
为什么要支持confd,老的应用配置管理模式是启动时读取配置文件,然后重新读取配置文件需要应用重启.一般的配置管理系统都是代码侵入性的,应用接入配置管理系统都需要使用对应的SDK来查询和监听数据的变更 ...
- Nginx实现七层负载均衡配置指导
本文描述了如何使用Nginx实现在应用层实现7层负载均衡功能,Nginx支持虚拟主机,可以按照轮询,IP哈希,URL哈希,权重方式对后端服务器做负载均衡,还支持后端服务器健康检查功能.废话不多说,详细 ...
- Archlinux 安装配置指导 2015-05-24
因为用的Linode VPS的系统是Archlinux的,想在本地弄个系统做测试用,这样比较方便.然后发现自己在6年前做的一个Archlinux 安装配置Flash,好怀念的赶脚. 时过进迁,没想到A ...
- 基于端口的VLAN典型配置指导
本文为转发,简单明了,我喜欢 VLAN典型配置全过程如下: 组网图 图1-1 基于端口的VLAN组网示意图 应用要求 如图1-1所示,Switch A和Switch B分别连接了不同部门使用的Host ...
- (转)Zabbix Agent-Windows平台配置指导
原地址:http://blog.itpub.net/26739940/viewspace-1169538/ zabbix是一个CS结构的监控系统,支持ping,snmp等很多的监控,但是大部分 ...
- Console 口配置 Telnet 登录方式典型配置指导
1.进入系统视图,启动 Telnet 服务 system-view [Sysname] telnet server enable 2.配置从 VTY 用户界面登录后可以访问的命令级别为 2 级 [Sy ...
随机推荐
- Fakeapp2.2安装,使用简记--------------转载自iJessie
原文:https://www.cnblogs.com/iJessie/p/8568377.html 1,硬件和操作系统,支持cuda的Nvidia显卡,8G及以上的内存,Windows10 x64(推 ...
- grunt前端打包——css篇
[导读] 前端打包的工具有很多,我用的习惯的就是这个grunt,无论是你要在github上做开源,还是让自己的项目变得更易于维护,grunt都是首选. 前端打包的工具有很多,我用的习惯的就是这个gru ...
- snmp默认团体名/弱口令漏洞及安全加固
0x00基础知识 简单网络管理协议(SNMP)被广泛用于计算机操作系统设备.网络设备等领域监测连接到网络上的设备是否有任何引起管理上关注的情况.在运行SNMP服务的设备上,若管理员配置不当运行默认团体 ...
- OpenCV 中的三大数据类型:IplImage 类型
前言 本文将介绍 OpenCV 中的图像结构 IplImage 并提供一些很实用的技巧. 更多的矩阵处理函数还请参阅相关资料. IplImage 的类型定义 typedef struct _IplIm ...
- Android setTag()与getTag(),与set多个setTag()
首先我们要知道setTag方法是干什么的,SDK解释为 Tags Unlike IDs, tags are not used to identify views. Tags are essential ...
- Emgu安装配置及使用
前言:项目需要,需使用图像处理来完成机械臂从运动的皮带上抓取物体的功能,所以又重拾视觉与图像处理内容. 内容:Emgu是OpenCV的一个跨平台的.NET封装,结构如下图所示: 下载地址:http:/ ...
- iOS 应用发布
本文转载至 http://blog.csdn.net/ysy441088327/article/details/7833579 苹果为广大的开发者提供了一个很好的应用生态环境 参考资料: 1:如何向 ...
- Java 8 default 函数
我们知道在java8之前 ,一个类实现一个接口需要实现接口所有的方法, 但是这样会导致一个问题,当一个接口有很多的实现类的时候,修改这个接口就变成了一个非常麻烦的事,需要修改这个接口的所有实现类 不过 ...
- Ubuntu下如何配置使终端透明
今天学习了一招如何将Ubuntu下的终端背景颜色变得透明,感觉透明之后有好处,比如网上有些命令,可以直接覆盖原来的网页察看,然后敲击命令. 下面就来看看终端背景变透明前后的对比效果. 完全不透明,最大 ...
- Codeforces Round #243 (Div. 1)——Sereja and Two Sequences
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012476429/article/details/24798219 题目链接 题意:给两个长度分别 ...