目录
下载
1、下载地址:https://prometheus.io/download/
2、根据实际版本进行下载,当前下载
部署
1、将安装包上传到服务器/data目录
2、解压
tar -zxvf prometheus-2.28.1.linux-amd64.tar.gz
3、修改目录
mv prometheus-2.28.1.linux-amd64 prometheus
检查配置文件
该步骤非必须,但修改prometheus.yml文件后都建议执行该操作进行检查
1、进入prometheus安装目录
2、检查./promtool check config prometheus.yml
启动
安装目录下启动./prometheus --config.file=prometheus.yml
访问prometheus
地址:http://ip:port/graph,其中默认端口9090
设置prometheus系统服务,并配置开机启动
创建prometheus.service文件
输入如下命令:
touch /usr/lib/systemd/system/prometheus.service
vim /usr/lib/systemd/system/prometheus.service
将以下配置内容写入prometheus.service
[Unit]
Description=Prometheus
After=network.target
[Service]
Type=simple
ExecStart=/data/prometheus/prometheus --config.file=/data/prometheus/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/data/prometheus/data --storage.tsdb.retention=60d
Restart=on-failure
[Install]
WantedBy=multi-user.target
参数说明:
–config.file – 指明prometheus的配置文件路径
–web.enable-lifecycle – 指明prometheus配置更改后可以进行热加载
–storage.tsdb.path – 指明监控数据存储路径
–storage.tsdb.retention --指明数据保留时间
设置开机启动
—重新加载服务配置文件
systemctl daemon-reload
—设置开机自启
systemctl enable prometheus.service
— 启动prometheus
systemctl start prometheus.service
—查看 prometheus状态
systemctl status prometheus.service
说明: prometheus在2.0之后默认的热加载配置没有开启, 配置修改后,需要重启prometheus server才能生效, 这对于生产环境的监控是不可容忍的,所以我们需要开启prometheus server的配置热加载功能。在启动prometheus时加上参数 web.enable-lifecycle , 可以启用配置的热加载, 配置修改后, 热加载配置。
重载prometheus配置
curl -X POST http://ip:9090/-/reload
比如,添加target后验证重载配置是否生效,则访问prometheus查看targets