Prometheus部署

本文档详细介绍了在Linux环境下如何部署Prometheus监控系统,包括node_exporter探针的安装、Prometheus的配置与启动、Grafana的安装与端口修改。在部署过程中,提到了如何使用Linux命令开启端口、同步时间,并提供了各组件的默认访问地址。

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

一、使用的Linux命令

Linux查看某进程使用的网络带宽情况

lsof -i:端口号                          查看端口占用
netstat -tunlp |grep 端口号,用于查看指定的端口号的进程情况
							-t (tcp) 仅显示tcp相关选项

                                 -u (udp)仅显示udp相关选项

                                 -n 拒绝显示别名,能显示数字的全部转化为数字

                                 -l 仅列出在Listen(监听)的服务状态

                                 -p 显示建立相关链接的程序名

可能会涉及到开端口,比如
#开放8000端口

firewall-cmd --add-port=8000/tcp --permanent

#重启防火墙

firewall-cmd --reload

二、部署

grafana国内下载地址:
华为源(https://mirrors.huaweicloud.com/grafana/)
清华源(https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/)
prometheus官方下载
一篇文章搞定Prometheus普罗米修斯监控系统的部署
Prometheus+Grafana+node_exporter实现Centos服务器性能监控:实现服务后台启动
Prometheus+Grafana+node_exporter端口修改

1. node_exporter探针安装

默认端口9100.

  1. 设置时间同步
    yum install ntpdate -y
  2. 进行时间同步
ntpdate cn.ntp.org.cn
date
#解压

tar -zxvf node_exporter-1.3.1.linux-amd64.tar.gz
# 更改一个简单的名字

mv node_exporter-1.3.1.linux-amd64 node_exporter
#习惯性移动到/usr/local文件夹下

mv node_exporter /usr/local/
# 运行探针 默认端口是 9100,
## 通过ip:9090访问

cd node_exporter/
./node_exporter

也可以使用此命令启动,指定监听端口为8080

cd node_exporter/
./node_exporter --web.listen-address 127.0.0.1:8080

上面是前台启动,如果ctrl+c后,服务就会停掉,下面配置后台启动

编辑文件:vim /usr/lib/systemd/system/node-exporter.service

[Unit]
Description=This is prometheus node exporter
After=node_exporter.service

[Service]
Type=simple

#修改端口
ExecStart=/usr/local/node_exporter-1.3.1.linux-amd64/node_exporter --web.listen-address=:23111
ExecReload=/bin/kill -HUP
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target

执行Linux命令

#刷新

systemctl daemon-reload

#重启

systemctl stop node-exporter.service

systemctl start node-exporter.service

2.prometheus安装

# 对软件包进行解压

tar -zxvf prometheus-2.36.1.linux-amd64.tar.gz
#更改一个简单的名字

mv prometheus-2.34.0.linux-amd64  prometheus
#习惯性移动到/usr/local文件夹下

mv prometheus /usr/local/
#启动prometheus,默认端口9090,可查看netstat -tulpn | grep 9090端口是否启用

./prometheus
通过ip:9090访问

上面是前台启动,如果ctrl+c后,服务就会停掉,下面配置后台启动

#编辑prometheusd.service

vim /usr/lib/systemd/system/prometheusd.service
#内容如下

[Unit]Description=Prometheus
​
[Service]# 修改端口
ExecStart=/usr/local/prometheus/prometheus  --web.enable-lifecycle  --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:8001
​
Restart=on-failure
​
[Install]WantedBy=multi-user.target

启动prometheus服务

systemctl daemon-reload
systemctl start prometheusd        

3. prometheus配置文件

node-exporter启动后,需要在scrape_configs下添加ip端口监听。

在生产环境中,prometheus经常会存在修改配置的情况,那么就需要在不停止服务的前提下进行重新加载配置,有如下两种解决方式:

  • 添加–web.enable-lifecycle参数,启动服务
  • kill -1 PID # 重载配置 或者访问 /-/reload 接口

重启后在grafana要1-2分钟才能显示
prometheus.yml

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
# 采集node exporter监控数据
  - job_name: '203 job'
    static_configs:
      - targets: ['localhost:9100']

4.grafana安装

默认端口修改
#修改grafana配置文件

vim /etc/grafana/grafana.ini

#重启

systemctl stop grafana-server.service

systemctl start grafana-server.service

#开启服务

systemctl start grafana-server.service
#查看端口验证(grafana默认监听3000端口)

netstat -nlpt|grep 3000
#ip:3000访问,访问成功之后输入默认的用户名和密码登录,默认的用户名和密码均为:admin,首次登录要重置密码

官网dashboard

5.默认访问地址

1. node_exporter

http://ip:9100/metrics : node_exporter监控指标
在这里插入图片描述

2. Prometheus默认端口

http://ip:9090/
搜索框输入 up 显示 目前监听的ip

3. grafana 默认端口

http://ip:3000/
默认用户名和密码都是Admin,初次登陆需要修改密码
官网dashboard
import: 8919

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值