Setup Grafana for high availability

This tutorial is setup Grafana cluster with Stateless sessions as a recommended session by official docs. We have 3 servers:

  • 10.201.201.10 – Grafana1
  • 10.201.201.20 – Grafana2
  • 10.201.201.40 – MySQL

Install MySQL

sudo apt install mysql-server
sudo mysql_secure_installation

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
bind address = 10.201.201.40

Create Database

mysql -u root -p
CREATE DATABASE grafana;
CREATE DATABASE grafana_user;
GRANT ALL ON grafana.* TO 'grafana_user'@'%' IDENTIFIED BY 'UnholyConfessions';
GRANT ALL ON grafana_user.* TO 'grafana_user'@'%' IDENTIFIED BY 'UnholyConfessions';
FLUSH PRIVILEGES;

show grants for grafana_user@'%';
EXIT;

okay, let’s configure all the Grafana nodes

Download Grafana

cd /opt
sudo wget https://dl.grafana.com/oss/release/grafana-6.1.3.linux-amd64.tar.gz
sudo tar -zxvf grafana-6.1.3.linux-amd64.tar.gz

Create user and group for Grafana

sudo groupadd -f grafana
sudo useradd -c "grafana user" -d /opt/grafana-6.1.3 -s /bin/false -g grafana grafana
sudo chown -R grafana:grafana /opt/grafana-6.1.3

Edit Grafana configuration

cd /opt/grafana-6.1.3
sudo -u grafana nano conf/defaults.ini

Delete all configuration in section [database] and [session] and add this configuration:

[database]
url = mysql://grafana_user:UnholyConfessions@10.201.201.40:3306/grafana
type = mysql
host = 10.201.201.40:3306
name = grafana
user = grafana_user
password = UnholyConfessions

[session]
provider = mysql
provider_config = grafana_user:UnholyConfessions@tcp(10.201.201.40:3306)/grafana_user

Create service files

sudo nano /etc/systemd/system/grafana.service

[Unit]
Description=Grafana

[Service]
User=grafana
ExecStart=/opt/grafana-6.1.3/bin/grafana-server -homepath /opt/grafana-6.1.3/

[Install]
WantedBy=default.target

Start Grafana

sudo systemctl daemon-reload
sudo systemctl enable grafana.service
sudo systemctl start grafana.service
sudo systemctl status grafana.service

Comments are closed.