[转帖]Quick Start Guide

quick,start,guide · 浏览次数 : 0

小编点评

Sure, here's a summary of the content you provided: **Auth Configuration:** * Use auth-type token to authenticate with DynamoDB. * Define the root token configuration in `$ROOT_TOKENdynamodbconfd`. * Use `onetime` flag with specific backend configurations for DynamoDB, Environment File, File, Redis, and Consul. **Template Configuration:** * Define multiple server blocks within a single template. * Each server block defines the server name, location, proxy settings, and a `server_name` variable referencing the subdomain. * The `template` prefix is used to create the server block template. * The `getv` and `range` functions are used to retrieve values from the input data. **Output:** * The generated configuration file will be named `myconfig.conf` and placed in the `/tmp` directory. * The file will be in sync with the actual configuration in the `/tmp` directory. * The output message indicates that the configuration file is now in sync with the actual settings.

正文

 

Before we begin be sure to download and install confd.

Select a backend

confd supports the following backends:

  • etcd
  • consul
  • vault
  • environment variables
  • file
  • 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

file

myapp.yaml

myapp:
  database:
    url: db.example.com
    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

file

confd -onetime -backend file -file myapp.yaml

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;
   }
}

与[转帖]Quick Start Guide相似的内容:

[转帖]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

[转帖]程序员的平行宇宙 —— eBPF 系统级跟踪技术简单入门

https://blog.mygraphql.com/zh/posts/low-tec/trace/trace-quick-start/ 程序员的平行宇宙 程序员有两个世界: 一个是编码世界,我们很容易认为,我们考虑了一切,也完成了一切的代码。 然后是运行世界,我们发现,无论我们多么的严谨和考虑一切

[转帖]使用Prometheus和Grafana监控RabbitMQ集群 (使用RabbitMQ自带插件)

https://www.cnblogs.com/hahaha111122222/p/15683696.html 配置RabbitMQ集群 官方文档:https://www.rabbitmq.com/prometheus.html#quick-start 官方github地址:https://gith

[转帖]QUIC协议简史

QUIC简史 QUIC(Quick UDP Internet Connection)是谷歌推出的一套基于UDP的传输协议,它实现了TCP + HTTPS + HTTP/2的功能,目的是保证可靠性的同时降低网络延迟。因为UDP是一个简单传输协议,基于UDP可以摆脱TCP传输确认、重传慢启动等因素,建立

【转帖】QUIC协议简史

QUIC简史 QUIC(Quick UDP Internet Connection)是谷歌推出的一套基于UDP的传输协议,它实现了TCP + HTTPS + HTTP/2的功能,目的是保证可靠性的同时降低网络延迟。因为UDP是一个简单传输协议,基于UDP可以摆脱TCP传输确认、重传慢启动等因素,建立

[转帖]QUIC & HTTP/3 Support:主流浏览器和服务端对 HTTP/3 的支持情况(2021年12月更新)

https://sysin.org/blog/quic-http3-support/ 1. 相关概念 1.1 TLSv1.3 TLS 1.3 由 IETF 于 2018 年 8 月正式发布。 SSL 即 Secure Sockets Layer 安全套接字层。TLS 即 Transport Laye

[转帖]Web技术(六):QUIC 是如何解决TCP 性能瓶颈的?

文章目录 一、QUIC 如何解决TCP的队头阻塞问题?1.1 TCP 为何会有队头阻塞问题1.2 QUIC 如何解决队头阻塞问题1.3 QUIC 没有队头阻塞的多路复用 二、QUIC 如何优化TCP 的连接管理机制?2.1 TCP连接的本质是什么2.2 QUIC 如何减少TCP 建立连接的开销2.3

【转帖】让互联网更快:新一代QUIC协议在腾讯的技术实践分享

https://www.cnblogs.com/jb2011/p/8458549.html 本文来自腾讯资深研发工程师罗成在InfoQ的技术分享。 1、前言 如果:你的 App,在不需要任何修改的情况下就能提升 15% 以上的访问速度,特别是弱网络的时候能够提升 20% 以上的访问速度。 如果:你的

[转帖]TLSv1.3 Support:主流 Web 客户端和服务端对 TLSv1.3 的支持情况(2021版)

TLSv1.3 Support:主流 Web 客户端和服务端对 TLSv1.3 的支持情况(2021版) https://sysin.org/blog/tlsv1-3-support/ 2021 年 8 月发布的 Windows Server 2022 正式支持 QUIC 和 TLS 1.3 相关特

[转帖]

Linux ubuntu20.04 网络配置(图文教程) 因为我是刚装好的最小系统,所以很多东西都没有,在开始配置之前需要做下准备 环境准备 系统:ubuntu20.04网卡:双网卡 网卡一:供连接互联网使用网卡二:供连接内网使用(看情况,如果一张网卡足够,没必要做第二张网卡) 工具: net-to