如何更改prometheus监控系统启动的默认端口号

本文介绍如何将Prometheus的默认监听端口9090更改为自定义端口,适用于容器和虚机两种安装方式。通过修改启动命令或服务配置文件中的--web.listen-address参数,实现端口自定义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装好prometheus以后,访问的默认端口号是9090,通常不需要修改。但有时候情况特殊,需要把默认端口号改为自定义端口,例如改为8091,该如何操作?

一般情况,prometheus有两种安装运行方式:容器方式和虚机(服务器)方式,更改方法不同,简述如下:

一、容器方式

prometheus在容器中安装运行,启动方式通常是:


docker run -d -p 9090:9090 \
            -v $PWD/prometheus.yml:/etc/prometheus/prometheus.yml \
            -v $PWD/alert.rules:/etc/prometheus/alert.rules \
            --name prometheus \
            prom/prometheus \
            -config.file=/etc/prometheus/prometheus.yml \
            -alertmanager.url=http://10.0.2.15:9093


因此,要自定义端口号,启动时直接更改 -p 后面的端口参数就可以了,简单直接。

二、虚机(服务器)方式

prometheus在虚机(服务器)中安装运行。

命令行启动

在安装完成以后,可以直接在命令行启动。启动方式通常是:

./prometheus --config.file=prometheus.yml &

或者
nohup /opt/prometheus/prometheus &

如果要使用不同于9090的端口号,可以在命令行参数 --web.listen-address中指定,如:

./prometheus --config.file=prometheus.yml --web.listen-address=:8091 &

启动以后,访问http://xxx.xxx.xxx.xxx:8091,可以看到,端口确实更改了。

顺便说一下,要看prometheus的所有命令行参数,可以执行如下命令:

./prometheus -h

服务方式启动

安装完成以后,也可以把prometheus配置成自启动的服务,在其中的配置文件中也可以自定义prometheus的启动端口。步骤如下:

1. 在 /etc/systemd/system目录下创建新文件 prometheus.service,其中ExecStart字段指定启动参数时,设置自定义端口,内容如下:

 --web.listen-address=:8091

[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System

[Service]
ExecStart=/opt/proe/prometheus-2.3.1.linux-amd64/prometheus \
  --config.file=/opt/proe/prometheus-2.3.1.linux-amd64/prometheus.yml --web.enable-admin-api \
  --web.listen-address=:8091

[Install]
WantedBy=multi-user.target

2.执行命令:

systemctl start prometheus.service

如果prometheus在运行,有时候要执行如下命令:

systemctl daemon-reload

3.验证prometheus是否在新端口正常启动:

输入如下命令:

netstat -lntp | grep prometheus

[root@k8s-node-3 system]# netstat -lntp |grep prometheus
tcp6       0      0 :::8091                 :::*                    LISTEN      11758/prometheus    

可见端口已经是自定义的端口了。

访问:http://localhost:8091

看看页面是否出来了,一切正常:

<think>嗯,用户想在Linux上配置Prometheus来监控Windows系统。首先,我需要回忆Prometheus的基本架构。Prometheus服务器通常运行在一个系统上,然后通过exporter来收集目标系统的数据。对于Windows来说,应该需要安装一个Windows Exporter,这样Prometheus才能抓取数据。 首先,用户需要在Windows上下载并安装Windows Exporter。我记得这个exporter会暴露一些指标,比如CPU、内存、磁盘等。然后,Prometheus服务器在Linux上需要配置一个job来指向Windows机器的IP和端口。用户可能需要开启Windows的防火墙端口,确保Linux的Prometheus能访问到。 接下来,配置Prometheus的配置文件prometheus.yml,添加一个针对Windows的job。这里要注意格式是否正确,缩进和语法不能出错,否则Prometheus可能无法启动。然后重启Prometheus服务使配置生效。 验证部分,可以通过PrometheusWeb界面或者使用curl命令检查是否成功采集到数据。之后,用户可能还想用Grafana来可视化这些数据,需要导入对应的Windows仪表盘模板,比如3119号仪表盘。 另外,用户提供的引用中有提到Grafana和Prometheus的安装步骤,可能需要引用相关的安装步骤,比如引用[2]和[3]提到的解压Prometheus,引用[4]关于配置数据源的部分。不过用户的问题是关于Windows监控的,所以重点在Windows Exporter的配置和Prometheus的job设置。 还要考虑用户可能遇到的常见问题,比如防火墙设置、exporter服务是否正常运行,Prometheus配置文件的正确性。可能需要提醒用户检查这些点。 最后,生成的相关问题可能涉及如何优化监控、报警设置,或者与其他监控系统的对比。比如如何配置Alertmanager来接收警报,或者Exporter的高级配置选项。</think>### 在 Linux 上使用 Prometheus 监控 Windows 系统的配置方法 #### 1. **Windows 系统端配置** **步骤 1:安装 Windows Exporter** - 下载 Windows Exporter 最新版本(例如 `windows_exporter-0.24.0-amd64.msi`)[^1] - 运行安装程序,默认启用基础指标(CPU、内存、磁盘、网络等) - 验证服务是否运行: ```bash curl http://<Windows_IP>:9182/metrics # 默认端口9182 ``` **步骤 2:配置防火墙** - 开放 Windows 防火墙的 `9182` 端口,允许 Linux 服务器的 IP 访问 --- #### 2. **Linux 服务器端配置** **步骤 1:确保 Prometheus 已安装** - 参考安装命令(以 v2.45.0 为例): ```bash wget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz tar -xf prometheus-2.45.0.linux-amd64.tar.gz # 解压步骤见引用[2] ``` **步骤 2:修改 Prometheus 配置文件** - 编辑 `prometheus.yml`,添加 Windows 监控任务: ```yaml scrape_configs: - job_name: 'windows' static_configs: - targets: ['<Windows_IP>:9182'] labels: group: 'windows-servers' ``` - 校验配置文件: ```bash ./promtool check config prometheus.yml ``` **步骤 3:重启 Prometheus 服务** ```bash systemctl restart prometheus # 或通过二进制文件重新启动 ``` --- #### 3. **验证数据采集** - 访问 Prometheus Web 界面(默认端口 `9090`) - 执行查询 `up{job="windows"}`,若返回 `1` 表示连接成功 - 检查指标是否存在(如 `windows_cpu_time_total`) --- #### 4. **可视化配置(Grafana 可选)** - 在 Grafana 中添加 Prometheus 数据源(引用[4]方法) - 导入 Windows 仪表盘模板(例如 ID `3119`) ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值