Hostinger Grafana VPS 模板快速入门指南
用 Hostinger VPS 一键模板,几分钟内搭建一套专业级服务器监控可视化面板。
一、什么是 Hostinger Grafana VPS 模板?
1.1 Hostinger VPS 模板机制
Hostinger 的 VPS 主机提供**应用模板(Application Template)**功能,允许用户在购买 VPS 或重装系统时,一键部署预配置好的软件环境。无需手动安装依赖、编辑配置文件,选择模板后系统自动完成全部部署。
常见的 VPS 模板包括:WordPress、Drupal、Docker、CyberPanel 等,Grafana 是其中面向运维监控场景的模板。
1.2 Grafana 是什么?
Grafana 是一款开源的数据可视化和监控平台,支持将来自 Prometheus、InfluxDB、Zabbix、Elasticsearch 等多种数据源的指标以图表、仪表盘的形式展示。
核心能力:
- 多数据源支持(Prometheus、Graphite、InfluxDB、MySQL、PostgreSQL 等)
- 丰富的图表类型(折线图、热力图、仪表盘、表格、状态面板)
- 仪表盘模板市场(Grafana.com 提供数千个预制 Dashboard)
- 告警规则配置与多渠道通知(Email、Slack、Webhook 等)
- 用户权限管理(组织、团队、文件夹级别的访问控制)
1.3 模板通常包含什么?
Hostinger 的 Grafana VPS 模板通常预装以下组件:
| 组件 | 作用 |
|---|---|
| Grafana Server | 可视化面板前端 + 后端服务,默认端口 3000 |
| Prometheus(可选) | 时序数据库,采集和存储监控指标 |
| node_exporter(可选) | 服务器系统指标采集器(CPU、内存、磁盘、网络) |
| Nginx(可选) | 反向代理,用于配置域名和 HTTPS |
具体预装组件以 Hostinger 模板实际配置为准。部分模板可能仅包含 Grafana 本体,需要手动添加数据源。
二、准备工作
2.1 选择 VPS 套餐
Hostinger VPS 采用 AMD EPYC 处理器 + NVMe SSD 存储,提供多个套餐:
| 套餐 | vCPU | 内存 | 磁盘 | 带宽 | 适合场景 |
|---|---|---|---|---|---|
| KVM 1 | 1 核 | 4 GB | 50 GB | 4 TB | 个人监控、小型项目 |
| KVM 2 | 2 核 | 8 GB | 100 GB | 8 TB | 中小型团队监控 |
| KVM 4 | 4 核 | 16 GB | 200 GB | 16 TB | 多服务器集中监控 |
| KVM 8 | 8 核 | 32 GB | 400 GB | 32 TB | 大规模监控集群 |
建议:Grafana 本身资源消耗较低,若同时运行 Prometheus 并监控多台服务器,建议选择 KVM 2 及以上配置。
2.2 购买时选择模板
- 进入 Hostinger VPS 购买页面
- 选择合适的套餐
- 在操作系统/模板选择区域,找到 Grafana 模板
- 完成购买,系统自动部署
2.3 已有 VPS 切换模板
如果已经有一台 Hostinger VPS,可以通过重装系统切换到 Grafana 模板:
- 登录 hPanel(Hostinger 管理面板)
- 进入 VPS 管理页面
- 找到 Reinstall / 重装系统 选项
- 在模板列表中选择 Grafana
- 确认重装(注意:会清除服务器上的所有数据)
重装前务必备份重要数据。
三、首次登录与基础配置
3.1 获取访问信息
部署完成后,在 hPanel 的 VPS 管理页面可以找到:
- 服务器 IP 地址
- SSH 登录凭据(root 密码或 SSH 密钥)
- Grafana 访问地址(通常为
http://<服务器IP>:3000) - Grafana 默认管理员密码(模板预配置或通过 SSH 查看)
3.2 登录 Grafana
- 在浏览器中打开
http://<你的服务器IP>:3000 - 使用默认凭据登录:
- 用户名:
admin - 密码:模板预设密码(在 hPanel 或服务器上的说明文件中查找)
- 用户名:
- 首次登录后,系统会提示修改密码——务必立即修改为强密码
3.3 查看预装服务
通过 SSH 登录服务器,检查各组件状态:
# 查看 Grafana 服务状态
systemctl status grafana-server
# 查看 Prometheus 服务状态(如果预装)
systemctl status prometheus
# 查看 node_exporter 状态(如果预装)
systemctl status node_exporter
# 查看监听端口
ss -tlnp | grep -E '3000|9090|9100'
预期端口:
| 端口 | 服务 |
|---|---|
| 3000 | Grafana Web UI |
| 9090 | Prometheus(如预装) |
| 9100 | node_exporter(如预装) |
四、配置数据源
4.1 如果模板已预装 Prometheus
Grafana 模板通常已将 Prometheus 配置为默认数据源。验证方法:
- 进入 Grafana 左侧菜单 Connections → Data sources
- 查看是否已有
Prometheus数据源 - 点击进入,确认 URL 为
http://localhost:9090 - 点击 Save & test,确认连接成功
4.2 手动添加 Prometheus 数据源
如果模板未预装或需要重新配置:
- Connections → Data sources → Add data source
- 选择 Prometheus
- 填写配置:
- Name:
Prometheus(或自定义名称) - Prometheus server URL:
http://localhost:9090 - 其余保持默认
- Name:
- 点击 Save & test
4.3 添加其他数据源
Grafana 支持多种数据源,常见配置:
InfluxDB:
URL: http://localhost:8086
Database: 你的数据库名
User / Password: 凭据
MySQL / PostgreSQL:
Host: localhost:3306 (或 5432)
Database: 数据库名
User / Password: 凭据
五、导入监控仪表盘
5.1 导入 Node Exporter 全量监控面板
这是最常用的服务器系统监控仪表盘,覆盖 CPU、内存、磁盘、网络、进程等所有维度。
- 左侧菜单 Dashboards → New → Import
- 在 Import via grafana.com 输入框中填入模板 ID:
1860 - 点击 Load
- 选择 Prometheus 数据源
- 点击 Import
仪表盘 ID 1860(Node Exporter Full)包含以下监控面板:
- CPU 使用率(按核心、按模式)
- 内存使用率与交换分区
- 磁盘 I/O 与磁盘空间
- 网络流量(收发包、错误包、丢包)
- TCP 连接状态
- 系统负载(Load Average)
- 进程数量与运行时间
- 温度传感器(如硬件支持)
5.2 其他常用仪表盘模板
| 监控对象 | Dashboard ID | 说明 |
|---|---|---|
| 服务器系统 | 1860 | Node Exporter Full,最全面的系统监控 |
| Docker 容器 | 893 | Docker monitoring with node-exporter |
| Nginx | 12708 | Nginx Plus / VTS 监控 |
| MySQL | 7362 | MySQL 性能监控 |
| Redis | 763 | Redis 监控面板 |
| PostgreSQL | 9628 | PostgreSQL 监控 |
| 黑盒探测 | 7587 | Blackbox Exporter(HTTP/TCP/ICMP 探测) |
在 grafana.com/grafana/das… 搜索更多模板。
5.3 自定义仪表盘
- Dashboards → New → New dashboard
- 点击 Add visualization
- 选择数据源
- 在 Query 编辑器中编写 PromQL 查询(Prometheus)或 SQL 查询
- 选择图表类型(Time series、Bar chart、Gauge、Stat、Table 等)
- 设置面板标题、单位、阈值颜色
- 点击 Apply 保存面板
- 点击右上角 Save 保存整个仪表盘
六、监控多台服务器
6.1 在目标服务器安装 node_exporter
要监控其他服务器,需要在每台目标机器上安装 node_exporter:
# 下载最新版 node_exporter(以 1.8.2 为例,请到 GitHub 查看最新版本)
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
# 解压
tar xzf node_exporter-1.8.2.linux-amd64.tar.gz
cd node_exporter-1.8.2.linux-amd64
# 安装到系统路径
sudo cp node_exporter /usr/local/bin/
# 创建 systemd 服务
sudo tee /etc/systemd/system/node_exporter.service << 'EOF'
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=nobody
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
EOF
# 启动并设置开机自启
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter
# 验证
curl http://localhost:9100/metrics
6.2 在 Prometheus 中添加目标
编辑 Prometheus 配置文件(通常在 /etc/prometheus/prometheus.yml):
scrape_configs:
- job_name: 'node'
static_configs:
- targets:
- 'localhost:9100' # 本机
- '192.168.1.101:9100' # 服务器 A
- '192.168.1.102:9100' # 服务器 B
- '10.0.0.5:9100' # 服务器 C
重启 Prometheus:
sudo systemctl restart prometheus
在 Grafana 的 Node Exporter 仪表盘中,通过顶部的 host 变量切换查看不同服务器。
6.3 防火墙配置
确保目标服务器的 9100 端口对 Prometheus 服务器开放:
# 使用 ufw(Ubuntu/Debian)
sudo ufw allow from <Prometheus服务器IP> to any port 9100
# 使用 firewalld(CentOS/RHEL)
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="<Prometheus服务器IP>" port protocol="tcp" port="9100" accept'
sudo firewall-cmd --reload
在 Hostinger hPanel 的 Firewall management 中也可以配置端口规则。
七、配置告警
7.1 创建告警规则
- 左侧菜单 Alerts & IRM → Alert rules → New alert rule
- 选择数据源(Prometheus)
- 编写查询条件,例如:
# CPU 使用率超过 90% 持续 5 分钟
100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 90
- 设置评估周期:
5m - 设置条件:
IS ABOVE 90 - 配置告警标签和注释(用于通知模板)
- 保存规则
7.2 配置通知渠道
- Alerts & IRM → Contact points → New contact point
- 选择通知类型:
- Email:填写收件人地址
- Slack:配置 Webhook URL
- Webhook:自定义 HTTP 回调
- Telegram:配置 Bot Token 和 Chat ID
- 保存后,在 Notification policies 中将默认策略绑定到该联系点
7.3 常用告警规则示例
# 内存使用率 > 85%
(1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100 > 85
# 磁盘使用率 > 90%
(1 - node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"} / node_filesystem_size_bytes) * 100 > 90
# 服务器宕机(up == 0 持续 2 分钟)
up{job="node"} == 0
# 网络入站流量异常(> 100MB/s)
rate(node_network_receive_bytes_total[5m]) > 100 * 1024 * 1024
八、安全加固
8.1 配置反向代理与 HTTPS
直接暴露 3000 端口不安全,建议用 Nginx 反向代理并配置 SSL:
server {
listen 80;
server_name grafana.yourdomain.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
使用 Certbot 申请免费 SSL 证书:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d grafana.yourdomain.com
8.2 Grafana 安全配置
编辑 /etc/grafana/grafana.ini:
[server]
domain = grafana.yourdomain.com
root_url = https://grafana.yourdomain.com/
[security]
# 禁用匿名访问
disable_gravatar = true
[auth.anonymous]
enabled = false
[users]
# 禁止用户自行注册
allow_sign_up = false
[auth.basic]
enabled = true
重启 Grafana:
sudo systemctl restart grafana-server
8.3 防火墙策略
在 Hostinger hPanel 或服务器层面配置:
- 仅开放 80/443(HTTP/HTTPS)给公网
- 3000 端口仅允许本地访问(
127.0.0.1) - 9090(Prometheus)不对外暴露
- 9100(node_exporter)仅允许 Prometheus 服务器 IP 访问
# 示例:限制 3000 端口仅本地访问
sudo ufw deny 3000
sudo ufw allow from 127.0.0.1 to any port 3000
九、日常运维
9.1 常用命令
# Grafana 服务管理
sudo systemctl start grafana-server
sudo systemctl stop grafana-server
sudo systemctl restart grafana-server
sudo systemctl status grafana-server
# 查看 Grafana 日志
sudo journalctl -u grafana-server -f --tail 50
# 查看 Prometheus 日志
sudo journalctl -u prometheus -f --tail 50
# 备份 Grafana 配置和仪表盘
sudo tar czf grafana-backup-$(date +%Y%m%d).tar.gz \
/etc/grafana/ \
/var/lib/grafana/
9.2 升级 Grafana
# Debian/Ubuntu
sudo apt update
sudo apt upgrade grafana
# 或手动安装最新版
wget https://dl.grafana.com/oss/release/grafana_<version>_amd64.deb
sudo dpkg -i grafana_<version>_amd64.deb
9.3 数据持久化与备份
Hostinger VPS 提供免费每周备份,建议同时手动备份关键数据:
- Grafana 配置:
/etc/grafana/ - Grafana 数据库(SQLite):
/var/lib/grafana/grafana.db - Prometheus 数据:
/var/lib/prometheus/ - Prometheus 配置:
/etc/prometheus/
十、常见问题
Q: 打开 http://IP:3000 无法访问?
A: 检查以下几点:
- Grafana 服务是否运行:
systemctl status grafana-server - 防火墙是否放行 3000 端口
- Hostinger hPanel 的防火墙管理中是否添加了 3000 端口规则
- 查看日志:
journalctl -u grafana-server -n 50
Q: 忘记 Grafana 管理员密码怎么办?
A: 通过 SSH 执行密码重置:
sudo grafana-cli admin reset-admin-password 新密码
sudo systemctl restart grafana-server
Q: Prometheus 目标显示 DOWN?
A:
- 检查目标服务器 node_exporter 是否运行:
systemctl status node_exporter - 检查目标服务器 9100 端口是否可访问:
curl http://目标IP:9100/metrics - 检查防火墙是否允许 Prometheus 服务器访问 9100 端口
- 在 Prometheus UI(
http://IP:9090/targets)查看具体错误信息
Q: 仪表盘没有数据显示?
A:
- 确认数据源连接正常(Data sources → Save & test)
- 确认 Prometheus 正在采集目标(Targets 页面状态为 UP)
- 检查仪表盘的时间范围选择器是否合理(默认 Last 6 hours)
- 确认 Dashboard 变量(如
job、instance)有可选项
Q: 如何监控 Windows 服务器?
A: 使用 windows_exporter(原 wmi_exporter),在 Windows 服务器上安装后,在 Prometheus 配置中添加目标,导入 Dashboard ID 12518(Windows Exporter)。
Q: Hostinger VPS 模板重装会丢失数据吗?
A: 会。重装系统会清除服务器上的所有数据。操作前务必备份 Grafana 配置、仪表盘和 Prometheus 数据。
参考资源
- Hostinger VPS 官方页面:www.hostinger.com/vps-hosting
- Grafana 官方文档:grafana.com/docs/
- Prometheus 官方文档:prometheus.io/docs/
- Grafana 仪表盘市场:grafana.com/grafana/das…
- node_exporter GitHub:github.com/prometheus/…
- PromQL 查询教程:prometheus.io/docs/promet…
本文基于 Hostinger VPS 平台和 Grafana 开源版本的通用部署流程整理。具体模板预装组件和配置以 Hostinger 实际提供的为准。建议部署后通过 SSH 检查实际安装的服务和版本。