上下文:我在一个空的centos VM中添加了一些脚本来安装一些监控工具,包括prometheus 2.0。
问题:一旦安装在非根 sudo 用户的主目录中,我将写入的 prometheus.service 复制到“/etc/systemd/system”,运行 sudo systemctl daemon -reload, sudo systemctl enable prometheus.service, sudo systemctl start prometheus.service
但服务失败。
注意:我可以直接使用相同的命令在终端中运行 prometheus 二进制文件而不会出现任何问题,但我无法将其作为服务运行。
这是我的 .service 文件:
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
User=centos
ExecStart=/home/centos/prometheus/prometheus --config.file="/home/centos/prometheus/prometheus.yml" --storage.tsdb.path="/home/centos/prometheus/data"
[Install]
WantedBy=multi-user.target
这是一些日志:
...
Nov 21 12:41:55 localhost.localdomain prometheus[1554]: level=info ts=2017-11-21T17:41:55.114757834Z caller=main.go:314 msg="Starting TSDB"
Nov 21 12:41:55 localhost.localdomain prometheus[1554]: level=error ts=2017-11-21T17:41:55.114819195Z caller=main.go:323 msg="Opening storage failed" err="mkdir \": permission denied"
Nov 21 12:41:55 localhost.localdomain systemd[1]: prometheus.service: control process exited, code=exited status=1
Nov 21 12:41:55 localhost.localdomain systemd[1]: Failed to start Prometheus Server.
...
我是 linux 服务管理的新手,我花了很多时间在线阅读,但我不确定服务的权限是如何工作的,以及为什么它不能创建它需要创建的目录。
我试过:
将“SELINUX=enforcing”更改为“SELINUX=permissive”
修改prometheus目录权限为777
...
最佳答案
您还必须设置 --web.console.templates
和 --web.console.libraries
。您可以从提取的存档中复制这些目录。例如:
sudo cp -R ~/prometheus-2.0.0.linux-amd64/consoles /etc/prometheus
sudo cp -R ~/prometheus-2.0.0.linux-amd64/console_libraries /etc/prometheus
工作服务示例(为您更改路径):
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
附言灵感来自建议here .
关于linux - Prometheus 2.0 centos 服务无法启动,因为 "Opening storage failed", "permission denied",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47419765/