How to Setup InfluxDB instance on Cloud VM [Ubuntu/Debian]

InfluxDB is a Time Series Database system which is a perfect fit for Internet Of Things Applications. It supports high read/write load and also has retention policies that describes for how long and how much data is kept by InfluxDB over a period of time.

Here in this article we will learn how to setup InfluxDB instance on a Linux Virtual Machine with necessary security.

InfluxDB on Ubuntu Virtual Machine

Step 1 : First you need to add the InfluxDB repository with the following three commands.
wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -

export DISTRIB_ID=$(lsb_release -si); export DISTRIB_CODENAME=$(lsb_release -sc)


echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
Step 2 : Run the command below in the terminal to install InfluxDB.
sudo apt update
sudo apt install influxdb
Step 3 : After the installation, it is still necessary that you start InfluxDB
sudo systemctl unmask influxdb
sudo systemctl start influxdb

Here are some general commands to Create Database and Enter Measurements Values

# Setup of Influx DB
influx
CREATE DATABASE database_name
SHOW DATABASES
USE database_name

> INSERT temperature,location=indoor value=23
> INSERT temperature,location=outdoor value=19
> INSERT temperature,location=indoor value=22
> INSERT temperature,location=outdoor value=18

SELECT * FROM temperature
SELECT value FROM temperature WHERE location='indoor''

SHOW measurements
SHOW field keys
SHOW tag keys
SHOW users

DROP DATABASE database_name

Securing your InfluxDB and Modify Config File

It’s important to secure your InfluxDB Database to protect from unauthorized access. Use the Below commands to implement Username/Password Authentication.

CREATE USER samarth WITH PASSWORD '*******' WITH ALL PRIVILEGES

# Modify config file to implement authentication 
sudo nano /etc/influxdb/influxdb.conf

[HTTP]
auth-enabled = true
pprof-enabled = true
pprof-auth-enabled = true
ping-auth-enabled = true
flux-enabled = true

# Restart to implement changes
sudo systemctl restart influxdb

# Login with below command 
influx -username samarth -password *******

You will be able to login without the username and password but you won’t be able to Use any database.

Important: If you want to access InfluxDB from the cloud you need to open port 8086 in your VM settings. No need to open the port if your cloud application is using the database.

Leave a Reply

Your email address will not be published.