下载,已在nas中准备好,

解压到/opt/prometheus中。

添加一个没有家目录,不能登录的用户

useradd -M -s /usr/sbin/nologin prometheus

将目录所有者更改

chown prometheus:prometheus -R /opt/prometheus/

查看用户命令

id prometheus

创建systemd服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cat > /etc/systemd/system/prometheus.service << "EOF"
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prj/prometheus/prometheus \
--config.file=/opt/prj/prometheus/prometheus.yml \
--storage.tsdb.path=/opt/prj/prometheus/data \
--storage.tsdb.retention.time=60d \
--web.enable-lifecycle

[Install]
WantedBy=multi-user.target
EOF

检查一下

http://192.168.66.103:9090/

http://192.168.66.103:9090/metrics