当前位置:首页 > 系统教程 > 正文

Ubuntu系统安装Prometheus+Grafana(基于Shell脚本的自动化一键部署教程)

Ubuntu系统安装Prometheus+Grafana(基于Shell脚本的自动化一键部署教程)

在现代IT运维中,监控系统是保障业务稳定运行的核心。Ubuntu Prometheus安装教程是许多开发者入门监控领域的首选。本文将手把手带你完成Prometheus与Grafana的搭建,通过Prometheus一键部署脚本,即便是技术小白也能轻松上手,构建高效的Linux系统监控方案

Ubuntu系统安装Prometheus+Grafana(基于Shell脚本的自动化一键部署教程) Ubuntu Prometheus安装教程  Grafana可视化面板配置 Prometheus一键部署脚本 Linux系统监控方案 第1张

一、准备工作

在开始之前,请确保你拥有一台安装了Ubuntu系统的服务器(推荐20.04或22.04 LTS版本),并拥有root权限或sudo权限。我们将通过Grafana可视化面板配置来展示最终的监控效果。

二、一键部署脚本

为了提高效率,我们将安装过程封装为Shell脚本。请在终端执行以下操作:

# 创建部署脚本

cat << 'EOF' > deploy_monitor.sh

#!/bin/bash

# 更新软件源

sudo apt-get update

# 安装Prometheus

wget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz

tar -xvf prometheus-2.45.0.linux-amd64.tar.gz

cd prometheus-2.45.0.linux-amd64

nohup ./prometheus --config.file=prometheus.yml > prometheus.log 2>&1 &

# 安装Grafana

sudo apt-get install -y apt-transport-https software-properties-common

wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -

echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list

sudo apt-get update && sudo apt-get install grafana -y

sudo systemctl start grafana-server

sudo systemctl enable grafana-server

echo "部署成功!Prometheus端口:9090, Grafana端口:3000"

EOF

# 运行脚本

bash deploy_monitor.sh

三、验证与配置

1. Prometheus验证:打开浏览器访问 http://IP:9090,看到指标查询界面说明安装成功。
2. Grafana登录:访问 http://IP:3000,默认用户名和密码均为 admin
3. 添加数据源:在Grafana中点击"Data Sources",选择Prometheus,URL填写 http://localhost:9090 即可完成对接。

四、SEO关键词总结

  • 1. Ubuntu Prometheus安装教程:本文提供了基于Ubuntu系统的详细安装路径。
  • 2. Grafana可视化面板配置:介绍了如何将监控数据导入Grafana进行图形化展示。
  • 3. Prometheus一键部署脚本:使用自动化Shell脚本降低了搭建难度。
  • 4. Linux系统监控方案:这是一套适用于企业级Linux环境的标准监控组合。

© 2023 监控系统实战指南 - 运维技术分享