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.pid3、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.312、consul指定获取单个key
./consul kv get prometheus/kubernetes-apiserver/address3、consul指定删除单个key
./consul kv delete prometheus/kubernetes-apiserver/address4、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服务管理程序设置开机自启动
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。