您好,登錄后才能下訂單哦!
consul_template:?https://www.hi-linux.com/posts/36431.html
1、下載安裝包 并解壓consul 得到consul二進制文件
https://releases.hashicorp.com/consul/1.3.1/consul_1.3.1_linux_amd64.zip?
mkdir /application &&? mv consul /application
2、啟動腳本啟動consul_server?
#!/bin/bash bin_path=/application/ data_path="$bin_path"/data nodename=`hostname` idc=dc1 bindip=`/sbin/ifconfig?eth0?|grep?'\binet?\b'?|sed?-nr?'s#[^0-9]*([0-9.]*).*#\1#gp'` bootstrap_expect=1 $bin_path/consul?agent??-server?\ ????????????????????????-bind=$bindip?\ ????????????????????????-ui?\ ???-client=0.0.0.0?\ ????????????????????????-bootstrap-expect=$bootstrap_expect?\ ????????????????????????-data-dir?$data_path?\ ????????????????????????-node?$nodename?\ ????????????????????????-datacenter=$idc?\ ????????????????????????-log-level=warn?\ ????????????????????????-pid-file=$bin_path/consul.pid
3、consul配合consul_template自動修改prometheus配置
參考博客:https://www.hi-linux.com/posts/36431.html
1、consul指定添加單個key
./consul?kv?put?prometheus/kubernetes-apiserver/address?10.0.0.31
2、consul指定獲取單個key
./consul?kv?get?prometheus/kubernetes-apiserver/address
3、consul指定刪除單個key
./consul?kv?delete?prometheus/kubernetes-apiserver/address
4、consul_template安裝
$?wget?https://releases.hashicorp.com/consul-template/0.18.3/consul-template_0.18.3_linux_amd64.zip $?unzip?consul-template_0.18.3_linux_amd64.zip $?mv?consul-template?/usr/local/bin/
5、prometheus配置文件來設置tcp端口檢測機制:
-?job_name:?"tcp_port_discorvery" ??scrape_interval:?5s ??metrics_path:?/probe ??params: ????module:?[tcp_connect] ??file_sd_configs: ????-?files: ??-?/home/work/software/prometheus/tcp_port.json ??relabel_configs: ????-?source_labels:?[__address__] ??target_label:?__param_target -?source_labels:?[__param_target] ??target_label:?instance -?target_label:?__address__ ??replacement:?xxx.xx.xx.xx:31659
配置consul_template模板來進行配置渲染
vim?/prometheus/template.json [{{?range?tree?"prometheus/linux"?}} { "targets":?["{{?.Value?}}"], "labels":?{ "process_name":?"{{?.Key?}}" } }, {{?end?}} { "targets":?["xxx.xx.xx.xx:80"], "labels":?{ "process_name":?"tengine" } } ]
vim?/application/prometheus.ops consul?{ address?=?"xxx.xx.xx.xx:8500" } template?{ source?=?"/prometheus/template.json" destination?=?"/home/work/software/prometheus/tcp_port.json" command?=?"curl?-X?POST?http://127.0.0.1:9090/-/reload" }
測試模板生成文件 看到文件內容為空
consul-template??-consul-addr?xxx.xxx.xx.xx:8500?-template="complate.json:result"?-once?-dry
將要獲取的key推到consul中注冊
./consul?kv?put?prometheus/tcp_port/k8smaster-apiserver?1xx.xx.xx.xx:6443
測試無誤后啟動consul-template
consul-template?-config?"/application/prometheus.ops"?&
也可以添加到systemctl服務管理程序設置開機自啟動
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。