prometheus部署教程(一)

1、prometheus 安装

(1)下载文件:

# wget https://github.com/prometheus/prometheus/releases/tag/v3.2.1/prometheus-3.2.1.linux-amd64.tar.gz

(2)解压安装包:

[root@localhost ~]#tar xvf prometheus-3.2.1.linux-amd64.tar.gz -C /usr/local/

[root@localhost ~]#mv /usr/local/ prometheus-3.2.1.linux-amd64 /usr/local/prometheus

(3)创建数据启动和数据目录

[root@localhost ~]#mkdir -p /etc/prometheus /var/lib/prometheus

[root@localhost ~]#cp /usr/local/prometheus/prometheus.yml /etc/prometheus/

(4)创建service文件:

[root@localhost ~]#vim /etc/systemd/system/prometheus.service

[Unit]

Description=Prometheus Monitoring System

After=network.target

[Service]

ExecStart=/usr/local/prometheus/prometheus \

--config.file=/etc/prometheus/prometheus.yml \

--storage.tsdb.path=/var/lib/prometheus \

--web.listen-address=:9090 \

--web.enable-lifecycle

Restart=on-failure

[Install]

WantedBy=multi-user.target

(5)重载配置并启动服务

systemctl daemon-reload

systemctl start prometheus

systemctl enable prometheus   

systemctl status prometheus

(6)关闭防火墙    

(7)页面上访问

2、监控主机(node_exporter)安装

(1)下载安装包

下载并解压:

wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz

[root@localhost ~]# tar -zxvf node_exporter-1.6.1.linux-amd64.tar.gz -C /usr/local/

[root@localhost ~]# mv /usr/local/node_exporter-1.6.1.linux-amd64 /usr/local/node_exporter

(2)创建service文件:

[root@localhost ~]# vi /etc/systemd/system/node_exporter.service

[Unit]

Description=node_exporter

After=network.target

[Service]

User=root

ExecStart=/usr/local/node_exporter/node_exporter

Restart=on-failure

[Install]

WantedBy=multi-user.target

(3)重载配置并启动服务

[root@localhost ~]# systemctl daemon-reload

[root@localhost ~]# systemctl start node_exporter

(4)关闭防火墙

(5)在promethues的配置文件上添加主机信息

[root@localhost ~]# vim /etc/prometheus/prometheus.yml

(6)重启promethues

(7)登录prometheus页面查看主机已经被监控到了

到此prometheus监控主机的配置已完成。

3、验证cpu,内存,存储

(1)cpu信息

(2)内存信息

(3)存储信息

页面上还可以查看网络,io,端口等主机信息都可以监控,这里不一一展示。

接下来分享mysql_exporter,redis_exporter和grafana等,请各位大佬指教。

### 关于 Prometheus 部署的详细教程 #### 准备工作 在开始部署 Prometheus 之前,确保环境已经准备好必要的依赖项。对于大多数情况而言,这通常意味着安装 Docker 或者 Kubernetes 平台来运行容器化应用[^4]。 #### 下载并启动 Prometheus 可以通过多种方式获取 Prometheus种简单的方法是从官方网站下载二进制文件或使用 Helm Chart 在 Kubernetes 上快速部署。如果是在本地测试,则可以直接通过命令行解压 tarball 文件后执行 prometheus 可执行程序即可启动服务[^1]。 #### 编写配置文件 Prometheus 使用 YAML 格式的配置文件来进行目标抓取设置和其他参数定义。个典型的 `prometheus.yml` 文件会指定 scrape_configs 来告知 Prometheus 应该监控哪些端点以及它们的位置。例如: ```yaml scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] ``` 此段代码告诉 Prometheus 定期从 localhost 的 9090 端口拉取数据,这是默认情况下 Prometheus 自身暴露的个 HTTP API 接口地址用于自我监测[^2]。 #### 启动 Prometheus 实例 当所有准备工作完成后,在终端输入如下指令可以启动 Prometheus: ```bash ./prometheus --config.file=prometheus.yml ``` 上述命令将会读取当前目录下的 `prometheus.yml` 文件作为配置源,并按照其中设定的内容初始化个新的 Prometheus Server 进程。 #### 测试与验证 旦成功启动之后,打开浏览器访问 http://localhost:9090 即可进入 Web UI 页面查看已收集到的时间序列数据库中的各项性能指标图表展示。此时还可以尝试编写 PromQL 查询语句进步探索所获得的数据价值所在。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值