prometheus集群搭建
时间: 2023-10-17 12:26:26 浏览: 118
要搭建Prometheus集群,可以按照以下步骤进行操作:
1. 在三个Prometheus节点上分别部署Prometheus主服务器和Prometheus联邦。在各个节点上执行以下命令:
- 创建Prometheus连接:`ln -sv /opt/prometheus/prometheus-2.36.2.linux-amd64 /opt/prometheus/prometheus`
- 添加Prometheus启动脚本:编辑`/etc/systemd/system/prometheus.service`文件,并添加以下内容:
```
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target
[Service]
Restart=on-failure
WorkingDirectory=/opt/prometheus/prometheus/
ExecStart=/opt/prometheus/prometheus/prometheus --config.file=/opt/prometheus/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target
```
- 启动Prometheus:`systemctl restart prometheus`
- 设置开机启动:`systemctl enable prometheus`
2. 配置联邦节点到node节点抓取数据。在Prometheus服务器上编辑`prometheus.yml`配置文件,添加以下内容:
```
- job_name: 'prometheus-federate-2.61'
scrape_interval: 10s
honor_labels: true
metrics_path: '/federate'
params:
'match[]':
- '{job="prometheus"}'
- '{__name__=~"job:.*"}'
- '{__name__=~"node.*"}'
static_configs:
- targets: ["10.19.2.61:9090"]
- job_name: 'prometheus-federate-2.62'
scrape_interval: 10s
honor_labels: true
metrics_path: '/federate'
params:
'match[]':
- '{job="prometheus"}'
- '{__name__=~"job:.*"}'
- '{__name__=~"node.*"}'
static_configs:
- targets: ["10.19.2.62:9090"]
```
3. 检查配置文件语法:执行命令`./promtool check config ./prometheus.yml`来验证配置文件的语法是否正确。
4. 重启Prometheus:执行命令`systemctl restart prometheus`来使配置生效。
通过以上步骤,你可以搭建一个Prometheus集群。 <span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [prometheus联邦集群](https://blog.csdn.net/m0_64417032/article/details/125508828)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [从零搭建Prometheus监控报警系统](https://download.csdn.net/download/weixin_38688380/15448172)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文