consul-template 使用教程

2020-08-31

# 获取当前节点下的服务信息
{{ with node "agent-two" }}
hello {{.Node.Address}}
{{.Node}}
{{range .Services}}
{{.Service}} {{.Port}} {{.Tags | join ","}} {{.ID}} {{end}}
{{end}}
#### nginx config file
user  www www;

{{with key "node/name/agent-one/assets" | parseJSON }}
worker_processes  {{.cpu}};
{{ if eq .cpu "2" }}
worker_cpu_affinity 01 10;
{{ else if eq .cpu "4" }}
worker_cpu_affinity 1000 0100 0010 0001;
{{ else if ge .cpu "8" }}
worker_cpu_affinity 0000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
{{ end }}
{{end}}
worker_rlimit_nofile 65535;

error_log {{ key_or_default "nginx/config/error_log" "logs/error.log notice" }};

pid {{ key_or_default "nginx/config/pid" "logs/nginx.pid" }};

events {
    use epoll;
    worker_connections  65535;
    accept_mutex off;
}

{{$log := (printf "nginx/config/%s/error_log" $node_name)}}
{{$log}}
error_log {{ if keyExists $log }} {{key $log}} {{else}} {{keyOrDefault "nginx/config/error_log" "logs/error.log notice"}}{{end}};

echo -n {"mem": "64G", "cpu": "8", "disk": "500G"} | consul kv put node/name/agent-one/assets -

consul 使用教程

dns缓存