gpt4 book ai didi

debian - 更改 Prometheus 节点导出器在 systemd 插入单元中监听的地址

转载 作者:行者123 更新时间:2023-12-03 21:22:50 24 4
gpt4 key购买 nike

我有一个这样的插入单元:

# /etc/systemd/system/prometheus-node-exporter.service.d/override.conf
[Service]
Environment=ARGS=--web.listen-address=localhost:9101

它与 Debian 软件包中的这个单元有关 prometheus-node-exporter ( stretch-backports 版本):
# /lib/systemd/system/prometheus-node-exporter.service
[Unit]
Description=Prometheus exporter for machine metrics
Documentation=https://github.com/prometheus/node_exporter

[Service]
Restart=always
User=prometheus
EnvironmentFile=/etc/default/prometheus-node-exporter
ExecStart=/usr/bin/prometheus-node-exporter $ARGS
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
SendSIGKILL=no

[Install]
WantedBy=multi-user.target
/etc/default/prometheus-node-exporterARGS="" ,即节点导出器的默认端口 9100 适用。插入旨在将其更改为 9101 并让服务仅监听 localhost .

systemctl start prometheus-node-exporter服务监听 :::9100 ( tcp6 )。但是,如果我注释掉 EnvironmentFile在它监听的单元文件中 127.0.0.1:9101 ( tcp ),如我所愿。所以看起来好像 EnvironmentFile从单位优先于 Environment在插入单元中。

为什么 drop-in 在选择 ARGS 的值时不覆盖单位?我缺少什么,我可以使用自定义插入单元更改默认监听地址吗?

最佳答案

来自 man systemd.exec :

EnvironmentFile= ... Settings from these files override settings made with Environment=. If the same variable is set twice from these files, the files will be read in the order they are specified and the later setting will override the earlier setting.



所以你需要指定一个 EnvironmentFile覆盖单元文件中的设置:

# /etc/systemd/system/prometheus-node-exporter.service.d/override.conf
[Service]
EnvironmentFile=/etc/prometheus.conf

和实际配置:

# cat /etc/prometheus.conf
ARGS=--web.listen-address=localhost:9101

关于debian - 更改 Prometheus 节点导出器在 systemd 插入单元中监听的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51569408/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com