confd 模板自動生成配置,安裝使用介紹

2021-08-25 08:30:11 字數 4683 閱讀 1206

mkdir -p /usr/local/confd/

wget

/confd/releases

/download/v

0.14.0/confd-0.14.0-linux-amd64

建立模板資料夾(templates) 和 配置資料夾(conf.d) confd預設使用的是這兩個目錄檔名

mkdir -p /usr/local/confd/
2.etcd建立儲存
/usr/local/etcd//etcdctl put /nginx/user  www

/usr/local/etcd//etcdctl put /nginx/group www

/usr/local/etcd//etcdctl put /nginx/worker_processes auto

/usr/local/etcd//etcdctl put /nginx/error_log /home/wwwlogs/nginx_error.log

/usr/local/etcd//etcdctl put /nginx/pid_path /usr/local/nginx/logs/nginx.pid

/usr/local/etcd//etcdctl put /nginx/log_level crit

3.建立模板配置
vi  /usr/local/confd/conf.d/nginx.toml

[template]

src = "nginx.conf.tmpl"

## templates中模板檔名

dest = "/usr/local/nginx/conf/nginx.conf"

## 配置檔案生成路徑

keys = [

"/nginx/group",

"/nginx/user",

"/nginx/worker_processes",

"/nginx/error_log",

"/nginx/log_level",

"/nginx/pid_path"

]check_cmd = "/usr/sbin/nginx -t -c }"

##nginx檢測配置檔案

reload_cmd = "/usr/sbin/service nginx reload"

##nginx服務重啟

4.建立nginx配置模板(只更改部分引數用於演示)

}} 5. 測試

命令返回我們看到nginx的配置檔案已經更新,nginx配置檔案reload載入成功

```shell

./confd -confdir /usr/local/confd/ -onetime -backend etcdv3 -node

.0.1:2379 -log-level debug

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: info backend set to etcdv3

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: info starting confd

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: info backend source(s) set to

.0.1:2379

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug loading template resources from confdir /usr/local/confd/

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug found template: /usr/local/confd/conf.d/nginx.toml

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug loading template resource from /usr/local/confd/conf.d/nginx.toml

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug retrieving keys from store

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug key prefix set to /

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug got the following map from store: map[/nginx/user:www /nginx/worker_processes:auto /nginx/error_log:/home/wwwlogs/nginx_error.log /nginx/log_level:crit /nginx/pid_path:/usr/local/nginx/logs/nginx.pid /nginx/group:www]

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug using source template /usr/local/confd/templates/nginx.conf

.tmpl

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug compiling source template /usr/local/confd/templates/nginx.conf

.tmpl

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug comparing candidate config to /usr/local/nginx/conf/nginx.conf

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: info target config /usr/local/nginx/conf/nginx.conf

out of sync

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug running /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/.nginx

.conf050458651

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug "nginx: the configuration file /usr/local/nginx/conf/.nginx.conf050458651 syntax is ok\nnginx: configuration file /usr/local/nginx/conf/.nginx.conf050458651 test is successful\n"

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug overwriting target config /usr/local/nginx/conf/nginx.conf

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug running /usr/sbin/service nginx reload

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: debug "reload service nginx... done\n"

2017-11-10t11:05:26+08:00 localhost.localdomain ./confd[52470]: info target config /usr/local/nginx/conf/nginx.conf has been updated

6.常用引數

confd預設配置路徑/etc/confd/ -confdir引數更改路徑為 /usr/local/confd/

-onetime 執行一次

-backend 後端資料服務節點

-log-level 置頂日誌級別

-interval 輪詢週期 預設10分鐘

confd模板配置說明(變數 函式和語法)

以confd和etcd為例 1 confd通過配置檔案,確定監聽的key,需要更新的檔案,例,myconfig.toml template src nginx.tmpl confd更新的模板檔案 dest home root nginx conf nginx.conf 模板檔案更新完畢後,替換的目標...

Solr自動生成ID配置

solr基於lucene的索引,而索引中的最基本的單元式document,在solr中,管理每乙個document 更新 刪除 查詢 基本都會用到對應的id,類似關係資料表中的主鍵。但是,如果我希望solr能夠自動生成這個唯一的id,有時候也省去了不少的工作,而只需要在solr中進行配置即可。下面,...

Solr自動生成ID配置

solr基於lucene的索引,而索引中的最基本的單元式document,在solr中,管理每乙個document 更新 刪除 查詢 基本都會用到對應的id,類似關係資料表中的主鍵。但是,如果我希望solr能夠自動生成這個唯一的id,有時候也省去了不少的工作,而只需要在solr中進行配置即可。下面,...