cd /opt
mkdir prometheus
cd prometheus
//下载
wget https://github.com/prometheus/prometheus/releases/download/v2.45.1/prometheus-2.45.1.linux-amd64.tar.gz
//解压
tar -zxvf prometheus-2.45.1.linux-amd64.tar.gz
//创建数据存放目录
mkdir prometheus/data
//rometheus官方只提供了二进制文件tar包,为了方便管理,我们可以创建prometheus系统服务启动文件
vim /etc/systemd/system/prometheus.service
输入:
[Unit]
Description=Prometheus service
After=network.target
[Service]
User=root
Type=simple
ExecReload=/bin/sh -c "/bin/kill -1 `/usr/bin/pgrep prometheus`"
ExecStop=/bin/sh -c "/bin/kill -9 `/usr/bin/pgrep prometheus`"
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data --storage.tsdb.retention.time=30d --storage.tsdb.retention.size=30GB
[Install]
WantedBy=multi-user.target
- 说明:当使用其他目录部署时,注意ExecStart命令中的目录需要同步修改一致。此外,在启动参数中我们还配置了Prometheus中数据存储的过期条件为“30天”或“大于30GB”,可以按需修改
//启动服务:
systemctl daemon-reload
systemctl start prometheus.service
//prometheus默认使用的端口为9090,也可以使用netstat命令查看9090端口的状态
netstat -nltp | grep 9090
//设置开机启动
systemctl enable prometheus.service
其他相关命令:
-
停止服务:systemctl stop prometheus.service
-
重启服务:systemctl restart prometheus.service
-
热加载配置:systemctl reload prometheus.service
-
禁用开机启动:systemctl disable prometheus.service
登录
- http://IP:9090/