文章目录
- 一、基础
- 二、安装consul
- 下载地址
- 启动consul
- 访问consul
- 三、编写服务发现文件nodes.json
- 四、prometheus配置consul发现
- 修改prometheus.yml
- 重启Prometheus
- 参考
一、基础
二、安装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:8500tags:- "nodes"refresh_interval: 2m
重启Prometheus
systemctl restart prometheus
可以发现现在获取的Targets里面有consul的字段
参考
https://www.bilibili.com/video/BV1PT4y1P7bX/?from=search&seid=851756632097160928