Compute Engine Google Cloud

Install Grafana on Ubuntu 18.04 with Nginx – Google Cloud

Install Grafana on Ubuntu 18.04 with Nginx – Google Cloud Platform and connect it to Cloud SQL.

Grafana is a open-source platform for data-visualization and monitoring any kind of database with over 150,000 active installations. Grafana is widely used in DevOps, IIoT and AdTech.

In this guide you are going to learn how to install and setup Grafana on Google Cloud and add Cloud SQL as data source.

Prerequisites

  1. Your Compute Engine Instance running.
  2. For setting up Compute Engine, see the Setting up Compute Engine Instance.
  3. Initial Server Setup on Google Cloud.
  4. Set up Cloud DNS, see the Setting up Google Cloud DNS for your domain.
  5. Google Cloud SQL Setup, see Setup Cloud SQL and connect with Compute Engine.

This setup can also be done on other Cloud hosting or any other VPS or Dedicated servers. Below are some lists to checkout.

Step 1: Update Server

Make sure your server is upto date.

sudo apt update
sudo apt upgrade

Step 2: Install Grafana

Add Grafana gpg key to install signed packages and add the repository.

curl https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"

Update the repository and install Grafana.

sudo apt update
sudo apt -y install grafana

Start Grafana.

sudo systemctl start grafana-server
sudo systemctl enable grafana-server

You can check the status of Grafana using this command

sudo systemctl status grafana-server

You will receive an output similar to this.

● grafana-server.service - Grafana instance
    Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; enabled; vendor preset: enabled)
    Active: active (running) since Tue 2019-07-30 09:36:47 UTC; 15s ago
      Docs: http://docs.grafana.org
  Main PID: 4399 (grafana-server)
     Tasks: 10 (limit: 667)
    CGroup: /system.slice/grafana-server.service
            └─4399 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini 

Enable it to startup on boot.

sudo systemctl enable grafana-server

Step 3: Install Nginx

Once Grafana is installed you can install Nginx and configure it.

sudo apt install nginx

Step 4: Configure Nginx

Remove the default Nginx configuration.

sudo rm -rf /etc/nginx/sites-available/default
sudo rm -rf /etc/nginx/sites-enabled/default

Create a new configuration with the reverse proxy setup for Grafana

sudo nano /etc/nginx/sites-available/grafana.conf

Paste the following in the file.

server {
     listen 80;

     server_name yourdomainname.com;

     location / {
         proxy_pass http://localhost:3000;
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection 'upgrade';
         proxy_set_header Host $host;
         proxy_cache_bypass $http_upgrade;
     }
}

Hit Ctrl + X followed by Y and Enter to save and exit the file.

Enable the configuration by creating a symbolic link to sites-enabled directory.

sudo ln -s /etc/nginx/sites-available/grafana.conf /etc/nginx/sites-enabled/grafana.conf

Restart Nginx

sudo nginx -t
sudo service nginx restart

Step 5: Check the Installation

Now check your domain name on your browser.

You will see the login page of Grafana.

Grafana Login

The default username is admin and the password is admin

In the next screen you can setup a new password.

Once you setup a new password you will land at the Grafana dashboard.

Grafana Dashboard

Next you can add the Cloud SQL as the source.

Click Add Data Source and select MySQL.

Here you can add the details of Cloud SQL.

Specify the name, Enter Cloud SQL IP address as the Host, Enter database name, Enter username and password and click Save and Test.

Cloud SQL in Grafana

Once the connection is successful you can visualize the database in Grafana.

Cloud SQL data in Grafana

Conclusion

Now you have learned how to install Grafana on Google Cloud and configure it with Nginx and access Clloud SQL database.

Cloudbooklet builds a large collection of Linux based guides and tutorials on Cloud platforms like Google Cloud, AWS, Azure, DigitalOcean and more

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.