1 您需要了解
- 注意:提供了两个地方下载二进制包,第一个链接(G-i-t-H-u-b)如被河蟹,用第二个官方链接,包的存储地址都一样。
- Prometheus 二进制包下载(GitHub): https://github.com/prometheus/prometheus/releases
- Prometheus 二进制包下载(官网): https://prometheus.io/download/
- Prometheus 二进制包具体版本名称: prometheus-3.4.2.linux-amd64.tar.gz(当前最新版)
- 操作系统:目前手头刚好有
CentOS Linux release 8.4.2105
2 下载预览
2.1 G-i-t-H-u-b 预览
2.2 官网预览
3 二进制搭建
3.1 关墙
3.2 创建目录并解压
手工下载已在最上方提供链接,我这里就直接
wget
了。
[root@henry ~]# mkdir -p /opt/app/prometheus /soft
[root@henry ~]# wget -P /soft/ https://github.com/prometheus/prometheus/releases/download/v3.4.2/prometheus-3.4.2.linux-amd64.tar.gz
[root@henry ~]# ls /soft/
prometheus-3.4.2.linux-amd64.tar.gz
[root@henry ~]# tar --strip-components=1 -zxvf /soft/prometheus-3.4.2.linux-amd64.tar.gz -C /opt/app/prometheus/
prometheus-3.4.2.linux-amd64/prometheus.yml
prometheus-3.4.2.linux-amd64/NOTICE
prometheus-3.4.2.linux-amd64/prometheus
prometheus-3.4.2.linux-amd64/promtool
prometheus-3.4.2.linux-amd64/LICENSE
[root@henry ~]# ls /opt/app/prometheus/
LICENSE NOTICE prometheus prometheus.yml promtool
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
3.3 配置systemd
注意配置文件中的路径。
cat << "EOF" > /etc/systemd/system/prometheus.service
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
ExecStart=/opt/app/prometheus/prometheus --config.file="/opt/app/prometheus/prometheus.yml"
LimitNOFILE=65536
PrivateTmp=true
RestartSec=2
StartLimitInterval=0
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# 重启服务
systemctl daemon-reload
systemctl restart prometheus.service
systemctl status prometheus.service
# 状态节选
● prometheus.service - prometheus
Loaded: loaded (/etc/systemd/system/prometheus.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2025-07-09 16:06:54 CST; 938ms ago
Main PID: 10162 (prometheus)
Tasks: 7 (limit: 50540)
Memory: 18.3M
CGroup: /system.slice/prometheus.service
└─10162 /opt/app/prometheus/prometheus --config.file=/opt/app/prometheus/prometheus.yml
Jul 09 16:06:54 henry prometheus[10162]: time=2025-07-09T08:06:54.427Z level=INFO source=head.go:752 msg="Replaying WAL, this may take a while" component=tsdb
Jul 09 16:06:54 henry prometheus[10162]: time=2025-07-09T08:06:54.427Z level=INFO source=head.go:825 msg="WAL segment loaded" component=tsdb segment=0 maxSegment>
Jul 09 16:06:54 henry prometheus[10162]: time=2025-07-09T08:06:54.427Z level=INFO source=head.go:862 msg="WAL replay completed" component=tsdb checkpoint_replay_>
Jul 09 16:06:54 henry prometheus[10162]: time=2025-07-09T08:06:54.436Z level=INFO source=main.go:1287 msg="filesystem information" fs_type=XFS_SUPER_MAGIC
Jul 09 16:06:54 henry prometheus[10162]: time=2025-07-09T08:06:54.436Z level=INFO source=main.go:1290 msg="TSDB started"
Jul 09 16:06:54 henry prometheus[10162]: time=2025-07-09T08:06:54.436Z level=INFO source=main.go:1475 msg="Loading configuration file" filename=/opt/app/promethe>
Jul 09 16:06:54 henry prometheus[10162]: time=2025-07-09T08:06:54.485Z level=INFO source=main.go:1514 msg="updated GOGC" old=100 new=75
Jul 09 16:06:54 henry prometheus[10162]: time=2025-07-09T08:06:54.485Z level=INFO source=main.go:1524 msg="Completed loading of configuration file" db_storage=89>
Jul 09 16:06:54 henry prometheus[10162]: time=2025-07-09T08:06:54.485Z level=INFO source=main.go:1251 msg="Server is ready to receive web requests."
Jul 09 16:06:54 henry prometheus[10162]: time=2025-07-09T08:06:54.485Z level=INFO source=manager.go:175 msg="Starting rule manager..." component="rule manager"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
3.4 查版本查端口
# 查版本
[root@henry ~]# /opt/app/prometheus/prometheus --version
prometheus, version 3.4.2 (branch: HEAD, revision: b392caf256d7ed36980992496c8a6274e5557d36)
build user: root@f841ca3a6e68
build date: 20250626-20:51:48
go version: go1.24.4
platform: linux/amd64
tags: netgo,builtinassets,stringlabels
# 查端口
[root@henry ~]# ss -ntlp |grep 90
LISTEN 0 128 *:9090 *:* users:(("prometheus",pid=10162,fd=6))
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
3.5 修改配置文件
目的是为了可以看到本机的
Metrics
数据
[root@henry ~]# vim /opt/app/prometheus/prometheus.yml
# 将 targets 的 localhost 修改为本机 ip 地址
static_configs:
- targets: ["192.168.226.148:9090"]
# The label name is added as a label `label_name=<label_value>` to any timeseries scraped from this config.
labels:
app: "prometheus"
[root@henry ~]# systemctl restart prometheus.service
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
3.6 登录测试
4 容器搭建
注意关闭当前节点的Prometheus服务,避免9090端口冲突。
4.1 配置在线yum源
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/
cat <<EOF > /etc/yum.repos.d/henry.repo
[appstream]
name=CentOS Stream $releasever - AppStream
#mirrorlist=http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo=AppStream&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$stream/AppStream/$basearch/os/
baseurl = https://mirrors.aliyun.com/centos-vault/8.4.2105/AppStream/x86_64/os/
gpgcheck=0
enabled=1
[baseos]
name=CentOS Stream $releasever - BaseOS
#mirrorlist=http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo=BaseOS&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$stream/BaseOS/$basearch/os/
baseurl = https://mirrors.aliyun.com/centos-vault/8.4.2105/BaseOS/x86_64/os/
gpgcheck=0
enabled=1
EOF
yum clean all
yum repolist all
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
4.2 配置主机IP映射
[root@henry ~]# echo '192.168.226.148 henry' >> /etc/hosts
[root@henry ~]# ping -c 3 henry
PING henry (192.168.226.148) 56(84) bytes of data.
64 bytes from henry (192.168.226.148): icmp_seq=1 ttl=64 time=0.022 ms
64 bytes from henry (192.168.226.148): icmp_seq=2 ttl=64 time=0.032 ms
64 bytes from henry (192.168.226.148): icmp_seq=3 ttl=64 time=0.027 ms
--- henry ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2040ms
rtt min/avg/max/mdev = 0.022/0.027/0.032/0.004 ms
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
4.3 安装Docker
yuminstall -y yum-utils vim bash-completion net-tools wget
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum install -y docker-ce
cat <<EOF > /etc/docker/daemon.json
{
"registry-mirrors": ["https://05e525e1985345b8b95f9e048a8eebab.mirror.swr.myhuaweicloud.com"]
}
EOF
systemctl daemon-reload
systemctl enable docker
systemctl restart docker
docker --version
# Docker 版本记录
[root@henry ~]# docker --version
Docker version 26.1.3, build b72abbb
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
4.4 拉取镜像并创建容器
兄弟们,你们不要问我镜像拉取不了该怎么办这种问题呀,这种小问题不匹配你们这些大佬的气质和气场。
4.5 编辑配置文件
[root@henry ~]# find / -name prometheus.yml
/var/lib/docker/overlay2/edb00033b4da642b017106a00f8f6caca371ee701a67f5ff8d4d423235c45f6d/diff/etc/prometheus/prometheus.yml
/var/lib/docker/overlay2/bc34ef9d9c7ecc5ff909a59117bdcc344017a1cc03dbc10a656d8e06d8264ec2/diff/etc/prometheus/prometheus.yml
[root@henry ~]# mkdir /etc/prometheus
[root@henry ~]# cp /var/lib/docker/overlay2/edb00033b4da642b017106a00f8f6caca371ee701a67f5ff8d4d423235c45f6d/diff/etc/prometheus/prometheus.yml /etc/prometheus/
[root@henry ~]# vim /etc/prometheus/prometheus.yml
# 将配置文件 targets 中的 localhost 改为宿主机主机名
static_configs:
- targets: ["henry:9090"]
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
4.6 创建容器
docker run -tid --name prometheus \
-p 9090:9090 \
--restart always \
-v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
-v /etc/hosts:/etc/hosts \
prom/prometheus:v3.4.2
[root@henry ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6cfb01a834c3 prom/prometheus:v3.4.2 "/bin/prometheus --c…" 2 seconds ago Up 1 second 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp prometheus
[root@henry ~]# ss -ntlp |grep 90
LISTEN 0 128 0.0.0.0:9090 0.0.0.0:* users:(("docker-proxy",pid=13523,fd=4))
LISTEN 0 128 [::]:9090 [::]:* users:(("docker-proxy",pid=13530,fd=4))
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
4.7 登录测试
最后:当你通过浏览器点击 Endpoint 的链接 http://henry:9090/metrics会发现,无法加载出指标数据。请注意,这个是正常现象,因为你的请求是从当前浏览器发出的,浏览器(当前windows)并不知道henry这个主机名是谁,所以无法显示,这并不是配置问题或Prometheus的问题。如果真要去查看当前节点的指标,请更换成ip地址即可。如:http://192.168.226.148:9090/metrics
- [End]