Prometheus安装(采用 influxdb)
一、安装Prometheus
# 获取软件 $ wget https://github.com/prometheus/prometheus/releases/download/v2.20.1/prometheus-2.20.1.linux-amd64.tar.gz $ groupadd prometheus $ useradd -g prometheus -m -d /usr/local/prometheus -s /sbin/nologin prometheus $ tar zxf prometheus-2.24.1.linux-amd64.tar.gz $ mv prometheus-2.24.1.linux-amd64/* /usr/local/prometheus $ sed -i 's/localhost/10.4.7.100/g' /usr/local/prometheus/prometheus.yml # 创建systemd服务 $ cat <<EOF > /usr/lib/systemd/system/prometheus.service [Unit] Description=prometheus After=network.target [Service] Type=simple User=prometheus WorkingDirectory=/usr/local/prometheus # 如果添加这一行,可以不指定配置文件(--config.file=/usr/local/prometheus/prometheus.yml) ExecStart=/usr/local/prometheus/prometheus --web.enable-lifecycle Restart=on-failure [Install] WantedBy=multi-user.target EOF # --web.enable-lifecycle: 支持通过http请求重载配置 # 启动服务 $ systemctl daemon-reload $ systemctl start prometheus $ systemctl status prometheus && systemctl enable prometheus # 确认端口已经被监听 $ ss -lnput | grep 9090 tcp LISTEN 0 1024 :::9090 :::* users:(("prometheus",pid=8257,fd=7))
二、后端存储配置
默认情况下prometheus会将采集的数据防止到本机的data目录的, 存储数据的大小受限和扩展不便,这是使用influxdb作为后端的数据库来存储数据。
三、 influxdb安装配置
influxdb的官方文档地址为: https://docs.influxdata.com/influxdb/v1.7/introduction/downloading/ 根据不同系统进行下载,这里使用官方提供的rpm进行安装。
# 获取软件包 $ wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.8.x86_64.rpm # 本地安装 $ yum localinstall influxdb-1.7.8.x86_64.rpm # 备份默认的默认的配置文件,这里可以对influxdb的数据存放位置做些设置 $ cp /etc/influxdb/influxdb.conf /etc/influxdb/influxdb.conf.default # 启动 $ systemctl start influxdb && systemctl enable influxdb # 查看状态 $ systemctl status influxdb # 查看端口是否监听 $ ss -lnput | grep 8086 tcp LISTEN 0 1024 :::8086 :::* users:(("influxd",pid=9405,fd=5))
创建一个Prometheus数据库
$ influx # 登录influxdb数据库 > create database prometheus; # 创建prometheus数据库 > show databases; # 查看数据库 name: databases name ---- _internal prometheus > exit # 退出
四、 配置prometheus集成infludb
官方的帮助文档在这里: https://docs.influxdata.com/influxdb/v1.7/supported_protocols/prometheus/
$ vim /usr/local/prometheus/prometheus.yml # 添加如下几行 remote_write: - url: "http://10.4.7.100:8086/api/v1/prom/write?db=prometheus" remote_read: - url: "http://10.4.7.100:8086/api/v1/prom/read?db=prometheus" $ systemctl restart prometheus $ systemctl status prometheus
注意: 如果influxdb配置有密码, 请参考上面的官方文档地址进行配置。
五、测试数据是否存储到influxdb中
$ influx > show databases; name: databases name ---- _internal prometheus > use prometheus Using database prometheus > show measures; ERR: error parsing query: found measures, expected CONTINUOUS, DATABASES, DIAGNOSTICS, FIELD, GRANTS, MEASUREMENT, MEASUREMENTS, QUERIES, RETENTION, SERIES, SHARD, SHARDS, STATS, SUBSCRIPTIONS, TAG, USERS at line 1, char 6 > show MEASUREMENTS; name: measurements name ---- go_gc_duration_seconds go_gc_duration_seconds_count go_gc_duration_seconds_sum go_goroutines go_info go_memstats_alloc_bytes # 后面还是有很多,这里不粘贴了。 # 做个简单查询 > select * from prometheus_http_requests_total limit 10 ; name: prometheus_http_requests_total time __name__ code handler instance job value ---- -------- ---- ------- -------- --- ----- 1568975686217000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 1 1568975701216000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 2 1568975716218000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 3 1568975731217000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 4 1568975746216000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 5 1568975761217000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 6 1568975776217000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 7 1568975791217000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 8 1568975806217000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 9 1568975821216000000 prometheus_http_requests_total 200 /metrics localhost:9090 prometheus 10
*************** 当你发现自己的才华撑不起野心时,就请安静下来学习吧!***************
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律