context : 我在一个空的 centos VM 中添加了一些脚本来安装一些监控工具,包括 prometheus 2.0。
问题:安装在非root 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
...