更改 Prometheus 节点导出器在 systemd 插入单元中侦听的地址
Change address where Prometheus node exporter listens in systemd drop-in unit
我有一个这个临时单位:
# /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-exporter
设置ARGS=""
,即应用节点导出器的默认端口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
我有一个这个临时单位:
# /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-exporter
设置ARGS=""
,即应用节点导出器的默认端口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