一、基础
二、安装consul
下载地址
https://developer.hashicorp.com/consul/install
启动consul
mkdir -p /app/consul/{data,etc,bin}
unzip /home/devops/consul_1.17.2_linux_amd64.zip -d /app/consul/bin/
ln -sv /app/consul/bin/consul /usr/local/bin/consul
consul -v
cd /app/consul/
nohup consul agent -dev -ui -data-dir=/app/consul/data/ -config-dir=/app/consul/etc/ -client=0.0.0.0 &
访问consul
http://IP:8500/ui/
三、编写服务发现文件nodes.json
vim /app/consul/etc/nodes.json
{
"services":[
{
"id":"node exporter-node01",
"name": "node01",
"address":"192.168.1.31",
"port": 10050,
"tags": ["nodes"] ,
"checks": [{
"http":"http://192.168.1.31:10050/metrics",
"interval":"5s"
}]
},
{
"id":"node exporter-node02",
"name": "node02",
"address":"192.168.1.34",
"port": 10050,
"tags": ["nodes"] ,
"checks": [{
"http":"http://192.168.1.34:10050/metrics",
"interval":"5s"
}]
},
{
"id":"node exporter-node03",
"name": "node03",
"address":"192.168.1.36",
"port": 10050,
"tags": ["nodes"] ,
"checks": [{
"http":"http://192.168.1.36:10050/metrics",
"interval":"5s"
}]
}
]
}
consul reload #加载配置文件
四、prometheus配置consul发现
修改prometheus.yml
增加如下配置
- job_name: "nodes"
consul_sd_configs:
- server: 192.168.1.34:8500
tags:
- "nodes"
refresh_interval: 2m
重启Prometheus
systemctl restart prometheus
可以发现现在获取的Targets里面有consul的字段
文章来源:https://www.toymoban.com/news/detail-828234.html
参考
https://www.bilibili.com/video/BV1PT4y1P7bX/?from=search&seid=851756632097160928文章来源地址https://www.toymoban.com/news/detail-828234.html
到了这里,关于prometheus基于consul的服务发现的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!