Prometheus部署
1、二进制部署
官网二进制安装包:https://prometheus.io/download/
Github安装包地址: https://github.com/prometheus/prometheus/releases
示例:
## 1、下载安装包
wget https://github.com/prometheus/prometheus/releases/download/v3.5.0/prometheus-3.5.0.linux-amd64.tar.gz
## 2、解压到指定目录并创建软连接
tar xvf prometheus-3.5.0.linux-amd64.tar.gz -C /usr/local
ln -s prometheus-3.5.0.linux-amd64 prometheus
## 3、创建相关目录,data目录是默认的存放数据目录,可以不创建,系统会自动创建,可以通过选项--storage.tsdb.path="data/"修改
# 规划目录,创建prometheus用户,方便后续管理以及使用service方式启动
mkdir bin conf data
mv prometheus promtool bin/
mv prometheus.yml conf/
useradd -r -s /sbin/nologin prometheus
chown -R prometheus.prometheus /usr/local/prometheus/
## 4、修改环境变量
vim /etc/profile
export PROMETHEUS_HOME=/usr/local/prometheus
export PATH=${PROMETHEUS_HOME}/bin:$PATH
source /etc/profile
# 检查配置文件是否正确的命令
promtool check config /usr/local/prometheus/conf/prometheus.yml
## 5、创建service文件,方便后续使用systemctl 方式启动
cat > /lib/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target
[Service]
Restart=on-failure
User=prometheus
Group=prometheus
WorkingDirectory=/usr/local/prometheus/
ExecStart=/usr/local/prometheus/bin/prometheus --config.file=/usr/local/prometheus/conf/prometheus.yml --web.enable-lifecycle
ExecReload=/bin/kill -HUP \$MAINPID
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
## 加载service配置并启动prometheus
systemctl daemon-reload
systemctl enable --now prometheus.service
ss -tnlp |grep prometheus
#选项--web.enable-lifecycle支持reload加载修改过的配置
curl -X POST http://localhost:9090/-/reload #选项--web.enable-lifecycle支持远程关闭prometheus服务,安全风险
2、Docker容器方式部署
官网: https://prometheus.io/docs/prometheus/latest/installation/
Github网站 https://github.com/prometheus/prometheus/blob/main/Dockerfile
示例:
#默认容器的配置文件路径/etc/prometheus/prometheus.yml。数据存储路径默认为/prometheus
docker run -d --name prometheus -p 9090:9090 prom/prometheus
#定制配置,持久化
docker run -d --name prometheus -p 9090:9090 -v ./prometheus.yml:/etc/prometheus/prometheus.yml -v prometheus_data:/prometheus prom/prometheus:v2.53.0
#定制配置文件启动
docker run -d --add-host "prometheus.linux.org:10.0.0.201" --name=prometheus -p 9090:9090 -v ./prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --web.enable-lifecycle
作者:于浩 创建时间:2025-12-05 17:04
最后编辑:于浩 更新时间:2025-12-05 17:25
最后编辑:于浩 更新时间:2025-12-05 17:25