我正在尝试为 Prometheus 和 Node Exporter 创建服务。
两个 .service 文件的内容几乎相同。
#!/bin/sh -
# /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
[Service]
User=prometheus
RemainAfterExit=true
ExecStart=/usr/bin/node_exporter
我的问题是我无法启动该服务。我收到以下错误
● node_exporter.service - Node Exporter
Loaded: loaded (/etc/systemd/system/node_exporter.service; enabled; vendor preset: enabled)
Active: active (exited) (Result: exit-code) since Mon 2017-01-30 16:00:31 MST; 7min ago
Process: 18693 ExecStart=/usr/bin/node_exporter (code=exited, status=203/EXEC)
Main PID: 18693 (code=exited, status=203/EXEC)
我尝试过更改用户、验证路径是否正确以及许多其他迭代。经过几个小时的调整、谷歌和回溯之后,我一生都无法让它发挥作用。有 Upstart 的指南,但我需要它在 16.04 上工作,而不需要 Upstart 作为依赖项。
答案1
我这样解决了这个问题...
节点导出器:
ExecStart=/bin/sh -c '/usr/local/bin/node_exporter'
Mysql_导出器:
=/bin/sh -c '/usr/local/bin/mysqld_exporter \
--config.my-cnf /etc/.mysqld_exporter.cnf \
--collect.global_status \
--collect.info_schema.innodb_metrics \
--collect.auto_increment.columns \
--collect.info_schema.processlist \
--collect.binlog_size \
--collect.info_schema.tablestats \
--collect.global_variables \
--collect.info_schema.query_response_time \
--collect.info_schema.userstats \
--collect.info_schema.tables \
--collect.perf_schema.tablelocks \
--collect.perf_schema.file_events \
--collect.perf_schema.eventswaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tableiowaits \
--collect.slave_status \
--web.listen-address=0.0.0.0:9104'
这是完整的命令:
sudo vim /etc/systemd/system/mysql_exporter.service
内容mysql_exporter.service
:
[Unit]
Description=Prometheus MySQL Exporter
After=network.target
[Service]
Type=simple
Restart=always
ExecStart=/bin/sh -c '/usr/local/bin/mysqld_exporter \
--config.my-cnf /etc/.mysqld_exporter.cnf \
--collect.global_status \
--collect.info_schema.innodb_metrics \
--collect.auto_increment.columns \
--collect.info_schema.processlist \
--collect.binlog_size \
--collect.info_schema.tablestats \
--collect.global_variables \
--collect.info_schema.query_response_time \
--collect.info_schema.userstats \
--collect.info_schema.tables \
--collect.perf_schema.tablelocks \
--collect.perf_schema.file_events \
--collect.perf_schema.eventswaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tableiowaits \
--collect.slave_status \
--web.listen-address=0.0.0.0:9104'
[Install]
WantedBy=multi-user.target
节点导出器:
sudo vim /etc/systemd/system/node_exporter.service
内容node_exporter
:
[Unit]
Description=Prometheus Node Exporter
After=network.target
User=prometheus
Group=prometheus
[Service]
Type=simple
Restart=always
ExecStart=/bin/sh -c '/usr/local/bin/node_exporter'
[Install]
WantedBy=multi-user.target
答案2
看来node_exporter的路径不正确。
ExecStart=/usr/bin/node_exporter
我在 Ubuntu 16.04 上有另一条路径
~# cat /etc/issue
Ubuntu 16.04.3 LTS \n \l
~# which node_exporter
/usr/sbin/node_exporter
如果这不是问题的根源,请检查您的/var/log/syslog
.它必须显示失败的原因,类似于:
Oct 20 12:30:30 prom systemd[8848]: node_exporter.service: Failed at step EXEC spawning /usr/bin/node_exporter: No such file or directory
Oct 20 12:30:30 prom systemd[1]: node_exporter.service: Main process exited, code=exited, status=203/EXEC
Oct 20 12:30:30 prom systemd[1]: node_exporter.service: Unit entered failed state.
Oct 20 12:30:30 prom systemd[1]: node_exporter.service: Failed with result 'exit-code'.
Oct 20 12:30:30 prom systemd[1]: node_exporter.service: Service hold-off time over, scheduling restart.
Oct 20 12:30:30 prom systemd[1]: Stopped Prometheus exporter for machine metrics, written in Go with pluggable metric collectors..
Oct 20 12:30:30 prom systemd[1]: Started Prometheus exporter for machine metrics, written in Go with pluggable metric collectors..
答案3
尝试手动启动您传递给的命令ExecStart
以验证它是否运行。
我也收到了 203 错误,显然这是由于下载/使用了错误平台的二进制文件所致。我使用“Darwin”而不是“Linux”。
Process: 20340 ExecStart=/usr/local/bin/node_exporter (code=exited, status=203/EXEC)
$ ls -lah /usr/local/bin/node_exporter
-rwxr-xr-x 1 node_exporter node_exporter 12M Jan 16 16:36 /usr/local/bin/node_exporter
$ /usr/local/bin/node_exporter
-bash: /usr/local/bin/node_exporter: cannot execute binary file: Exec format error
答案4
我收到这个错误。解决为@Saex。
出现此错误的原因是我下载了错误的软件包node_exporter-1.2.2.darwin-amd64.tar.gz
而不是node_exporter-1.2.2.linux-amd64.tar.gz
node_exporter.service - Node Exporter
Loaded: loaded (/etc/systemd/system/node_exporter.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-08-18 11:22:44 UTC; 17s ago
Main PID: 3830 (code=exited, status=203/EXEC)
Aug 18 11:22:44 ip-10-0-101-80 systemd[1]: Started Node Exporter.
Aug 18 11:22:44 ip-10-0-101-80 systemd[3830]: node_exporter.service: Failed to execute command: Exec format error
Aug 18 11:22:44 ip-10-0-101-80 systemd[3830]: node_exporter.service: Failed at step EXEC spawning /opt/node_exporter/node_exporter: Exec>
Aug 18 11:22:44 ip-10-0-101-80 systemd[1]: node_exporter.service: Main process exited, code=exited, status=203/EXEC
Aug 18 11:22:44 ip-10-0-101-80 systemd[1]: node_exporter.service: Failed with result 'exit-code'.