步骤 1. 安装 MariaDB/MySQL 并创建 Grafana 数据库

首先,我们需要安装 MariaDB/MySQL

[jack@onitroad ~]# yum install mariadb-server

使用以下命令在系统启动时启用和启动 MariaDB/MySQL

[jack@onitroad ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[jack@onitroad ~]# systemctl start mariadb

不要忘记使用 mysql_secure_installtion 为 root 设置密码

连接到 MariaDB/MySQL 并创建一个 Grafana 数据库和

[jack@onitroad ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 25
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database grafana;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on grafana.* to grafana@localhost identified by "Password";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye

步骤 3. 访问 Grafana 前端

Grafana安装成功后,打开网页浏览器,输入grafana服务器IP地址(3000端口)http://grafana_ip_address:3000/。
使用默认用户“admin”和密码“admin”登录 Grafana 仪表板。

我们将看到 Grafana 仪表板

准备工作

  • RHEL7 或者 CentOS 7.
  • root权限。
如何在 CentOS 7/RHEL 7 上使用 MySQL/MariaDB 数据库安装 Grafana

Grafana 是一个开源数据可视化和监控套件。
它提供对 Graphite 、 Elasticsearch 、 Prometheus 、 Zabbix 和更多数据库的支持。
Grafana 允许我们查询、可视化、警报和了解指标,并能够为应用程序或者基础设施性能监控管理和创建我们自己的仪表板。

Grafana 需要一个数据库来存储用户、仪表板和会话(以及其他东西)。
默认情况下,它被配置为使用嵌入式数据库 sqlite3.
在本教程中,我们将介绍如何在 CentOS 7 或者 RHEL 7 上使用 MySQL /MariaDB 数据库安装和设置 Grafana。

步骤 2. 安装 Grafana

Grafana 提供了两种安装方式,使用 rpm 包和使用 yum 仓库。
在本教程中,我们将使用 rpm 包安装进行安装。
那么让我们开始吧

# sudo yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.6.3-1.x86_64.rpm

在开始使用以下命令之前备份 grafana.ini 配置文件:

[jack@onitroad ~]# cp /etc/grafana/grafana.ini{,.org}

编辑 grafana.ini 配置文件如下:

[jack@onitroad ~]# vi /etc/grafana/grafana.ini
#################################### Database ####################################
[database]
# You can configure the database connection by specifying type, host, name, user and password
# as seperate properties or as on string using the url propertie.
# Either "mysql", "postgres" or "sqlite3", it's your choice
type = mysql
host = 127.0.0.1:3306
name = grafana
user = grafana
# If the password contains # or ; you have to wrap it with trippel quotes. Ex """#password;"""
;password =
password = Password
#################################### Session ####################################
[session]
# Either "memory", "file", "redis", "mysql", "postgres", default is "file"
provider = mysql
# Provider config options
# memory: not have any config yet
# file: session dir path, is relative to grafana data_path
# redis: config like redis server e.g. `addr=127.0.0.1:6379,pool_size=100,db=grafana`
# mysql: go-sql-driver/mysql dsn config string, e.g. `user:jack@onitroad(127.0.0.1:3306)/database_name`
# postgres: user=a password=b host=localhost port=5432 dbname=c sslmode=disable
provider_config = `grafana:jack@onitroad(127.0.0.1:3306)/grafana`
# Session cookie name
;cookie_name = grafana_sess
# If you use session in https only, default is false
;cookie_secure = false
# Session life time, default is 86400
;session_life_time = 86400

安装后,我们需要使用以下命令在引导系统中启用并启动 Grafana:

[jack@onitroad ~]# systemctl enable grafana-server
Created symlink from /etc/systemd/system/multi-user.target.wants/grafana-server.service to /usr/lib/systemd/system/grafana-server.service.
[jack@onitroad ~]# systemctl daemon-reload
[jack@onitroad ~]# systemctl start grafana-server

默认情况下,Grafana 在端口 3000 上运行。
如果我们使用的是防火墙,请使用 firewall-cmd 命令打开端口,如下所示。

[jack@onitroad ~]# firewall-cmd --permanent --add-port=3000/tcp
success
[jack@onitroad ~]# firewall-cmd --reload
success
日期:2020-06-02 22:18:15 来源:oir作者:oir