系统环境

标题 版本 备注
系统版本 ubuntu 22.04.3 LTS (Jammy Jellyfish) -
内核版本 5.15.0-91-generic #98-Ubuntu SMP Mon Oct 2 15:18:56 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux -
Grafana v10.4.2 -

Grafana 简介

Grafana 官方网址: https://grafana.com/

Grafana 官网文档: https://grafana.com/docs/grafana/latest/setup-grafana/start-restart-grafana/

Grafana 安装

1.创建运行 grafana 的用户 grafana

1
useradd -s /sbin/nologin grafana

2.创建 grafana 数据、日志以及插件存放目录:

1
mkdir -p /data/grafana/{data,log,plugins,provisioning}

3.将上面创建的 grafana 目录所属主和组都修改为 grafana:

1
chown -R grafana:grafana /data/grafana

4.点击这里下载 Grafana 到服务器的 /usr/local/src/ 目录下:

1
wget -O /usr/local/src/grafana-enterprise-10.4.2.linux-amd64.tar.gz https://dl.grafana.com/enterprise/release/grafana-enterprise-10.4.2.linux-amd64.tar.gz

5.将下载好的打包文件解压到下载目录:

1
tar -zxf /usr/local/src/grafana-enterprise-10.4.2.linux-amd64.tar.gz -C /usr/local/src/

6.将解压移动到 /usr/local/ 目录下并重命名为 grafana:

1
mv /usr/local/src/grafana-v10.4.2 /usr/local/grafana

7.编辑 grafana 安装目录 /usr/local/grafana/conf/ 目录下的 defaults.ini 文件,找到 [paths] 配置段,将其修改为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[paths]
# Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used)
data = /data/grafana/data

# Temporary files in `data` directory older than given duration will be removed
temp_data_lifetime = 24h

# Directory where grafana can store logs
logs = /data/grafana/log

# Directory where grafana will automatically scan and look for plugins
plugins = /data/grafana/plugins

# folder that contains provisioning config files that grafana will apply on startup and while running.
provisioning = /data/grafana/provisioning

8.在 /lib/systemd/system/ 目录下创建 grafana 启动脚本文件 grafana.service, 内容为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Grafana - a data visualization tool
After=network.target
User=grafana
Group=grafana

[Service]
Type=simple
WorkingDirectory=/usr/local/grafana
ExecStart=/usr/local/grafana/bin/grafana-server -config /usr/local/grafana/conf/defaults.ini
TimeoutSec=60
Restart=on-failure

[Install]
WantedBy=multi-user.target

9.执行命令,加载 grafana 启动脚本:

1
systemctl daemon-reload

10.执行命令启动 grafana 并将其设置为开机启动:

1
systemctl enable --now grafana.service

11.启动完成,查看系统是否有监听 3000端口:

1
2
root@instance-2UkeKOzr:/usr/local/grafana# ss -lnpt |egrep grafana
LISTEN 0 4096 *:3000 *:* users:(("grafana",pid=623047,fd=12))

12.打开浏览器,输入服务器IP:3000 ,访问 grafana web 端,如下图:

13.输入 grafana 默认账号(admin)密码(admin)进行登陆,由于是第一次登陆,系统会强制要求修改密码。如图:

修改密码后,会自动登陆到 grafana: