文章目录
- openEuler2403安装部署Prometheus和Grafana
- 一、前言
- 1.简介
- 2.环境
- 二、正文
- 1.环境准备
- 1)JDK 安装部署(可选)
- 2)关闭防火墙
- 2.安装 Prometheus
- 1)下载和安装
- 2)启动
- 3)systemd服务管理
- 3.安装 Grafana
- 1)添加YUM仓库
- 2)安装Grafana
- 3)systemd服务管理
- 4)配置监控面板
- (1)配置数据源
- (2)导入面板
openEuler2403安装部署Prometheus和Grafana
一、前言
1.简介
-
Prometheus 是一个开源系统监控和警报工具包;使用领先的开源监控解决方案,全面监控应用程序、系统及服务。通过指标埋点、采集、存储和查询,实现告警、仪表盘展示等多样化应用场景。
-
Grafana 是一款多平台开源分析和交互式可视化网络应用程序;通过Grafana轻松实现数据采集、关联分析与可视化仪表盘。
2.环境
- Linux 发行版:openEuler-24.03-LTS-SP2-x86_64-dvd.iso
- JDK 版本:Alibaba Dragonwell Extended Edition-11.0.27.24+6-GA
- prometheus 版本:3.5.0
- Grafana 版本:12.1.1-1
Prometheus 官网:https://prometheus.io/
Prometheus 文档:https://prometheus.io/docs/introduction/overview/
Grafana 官网:https://grafana.com/oss/grafana/
Grafana 文档:https://grafana.com/docs/grafana/latest/?pg=oss-graf&plcmt=hero-btn-2
openEuler常用操作指令:https://blog.csdn.net/u011424614/article/details/150942929
openEuler中LVM调整实现home与root分区空间平衡:https://blog.csdn.net/u011424614/article/details/150961763
openEuler安装部署JDK11:https://blog.csdn.net/u011424614/article/details/150961633
openEuler2403安装部署MySQL8:https://blog.csdn.net/u011424614/article/details/150966094
VirtualBox安装openEuler24.03:https://blog.csdn.net/u011424614/article/details/150725588
VMware安装openEuler24.03:https://blog.csdn.net/u011424614/article/details/150723134
二、正文
1.环境准备
1)JDK 安装部署(可选)
- 安装参考:《openEuler安装部署JDK11》
- JDK 版本:Alibaba Dragonwell Extended Edition-11.0.27.24+6-GA
- 安装目录:
/opt/java/dragonwell-11.0.27.24+6-GA
2)关闭防火墙
- 可禁用防火墙,或配置开放的端口,后者比较安全
# 关闭防火墙
systemctl stop firewalld.service
# 开机禁用防火墙
systemctl disable firewalld.service
# 防火墙状态
systemctl status firewalld.service
2.安装 Prometheus
1)下载和安装
# 安装目录
mkdir /opt/prometheus && cd /opt/prometheus# 下载软件包,如果 wget 无法下载,可使用浏览器或迅雷下载
# 查看历史版本:https://github.com/prometheus/prometheus/releases
wget https://github.com/prometheus/prometheus/releases/download/v3.5.0/prometheus-3.5.0.linux-amd64.tar.gz --no-check-certificate# 解压
tar xvfz prometheus-*.tar.gz# 修改文件夹名称
mv /opt/prometheus/prometheus-3.5.0.linux-amd64 /opt/prometheus/prometheus-3.5.0# 进入安装目录
cd /opt/prometheus/prometheus-3.5.0
2)启动
./prometheus --config.file=prometheus.yml
- 浏览器访问:
-
http://192.168.249.144:9090/status
-
http://192.168.249.144:9090/targets
3)systemd服务管理
- 创建 prometheus.service
cat > /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target[Service]
User=root
ExecStart=/opt/prometheus/prometheus-3.5.0/prometheus \--config.file=/opt/prometheus/prometheus-3.5.0/prometheus.yml \--storage.tsdb.path=/opt/prometheus/prometheus-3.5.0/data[Install]
WantedBy=default.target
EOF
- 启动服务,并设置开机自启动
systemctl daemon-reload
systemctl start prometheus.service
systemctl enable prometheus.service
- 查询进程状态
systemctl status prometheus.service
3.安装 Grafana
1)添加YUM仓库
- 阿里云镜像源
tee /etc/yum.repos.d/grafana.repo <<EOF
[grafana]
name=grafana
baseurl=https://mirrors.aliyun.com/grafana/yum/rpm
repo_gpgcheck=0
enabled=1
gpgcheck=0
EOF
- 生成或更新 YUM/DNF 的元数据缓存
yum makecache
2)安装Grafana
dnf install grafana
3)systemd服务管理
- 启动服务,并设置开机自启动
systemctl start grafana-server
systemctl enable grafana-server.service
- 查询进程状态
systemctl status grafana-server
- 浏览器访问:
http://192.168.249.144:3000
- 首次登录:
admin
/admin
- 登录后,自动跳转至修改密码页面
4)配置监控面板
(1)配置数据源
- 左侧菜单:Connections - Data Source - Add Data Source
- 选择 Prometheus
- 填写 Connection:http://<服务器IP>:9090
- 最下方点击【Save & test】按钮
(2)导入面板
- 导入面板有2种方式:
- 下载面板的 json 文件
- 通过面板ID在线导入
-
示例:prometheus-2-0-overview:https://grafana.com/grafana/dashboards/3662-prometheus-2-0-overview/
-
进入面板页面,查看右下角,可【下载JSON文件】和【复制面板ID】
- 头部菜单:加号 - 导入面板
- 上传面板 JSON 文件 或者 输入面板ID【3662】- 点击【Load】按钮
- 点击【Import】按钮
- 导入完成