Install InfluxDB on Linux | 3 Easy steps

Introduction

InfluxDB is a time-series database licensed under open source. It helps to collect metric data from devices such as servers, switches, virtual servers, ups and plot graphs in realtime. It is written in Go language and optimized for fast and high availability.

Enabling Repository

InfluxDB can be installed on most of all distributions. Below are few

Ubuntu Linux Repository

Install InfluxDB by importing the key and enable the required repository.

$ wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
$ source /etc/lsb-release
$ echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

Debian Linux Repository

$ wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
$ source /etc/os-release
$ echo "deb https://repos.influxdata.com/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

CentOS Repository

cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF

OpenSUSE & SLES

# zypper ar -f obs://devel:languages:go/ go

Install InfluxDB

Right after enabling the repository, Install Influxdb packages by running package manager for the respective operating system.

Use apt for installing on Ubuntu and Debian Linux distributions

Installing on Ubuntu and Debian

To install the influxdb on Ubuntu and Debian use the apt.

$ sudo apt-get update
$ sudo apt-get install influxdb

Installing on CentOS

The same package name in CentOS can be installed suing yum command.

$ sudo yum install influxdb
$ sudo systemctl start influxdb

Installing on SELS & OpenSUSE

Zypper manage can be used on SELS and OpenSUSE

# zypper in influxdb

Enable the Service

Right after installing the package enable the service to start persistently, however don’t start it.

$ sudo systemctl enable influxdb

Firewall Exclusion

Allowing port 8086 for inbound traffics is required.

Adding firewall on a Ubuntu Linux

$ sudo ufw allow 8086/tcp

Adding firewall on a CentOS Linux

$ firewall-cmd --add-port=8086/tcp --permanent
$ firewall-cmd -reload
$ firewall-cmd --list-all

Configuring InfluxDB

By default most of options are enabled. To enable the user authentication over HTTP/HTTPS make the below changes.

$ sudo vim /etc/influxdb/influxdb.conf

The reason for enabling this, will show how to create a DB using POST method.

[http]
  auth-enabled = true

Starting the InfluxDB

Start the InfluxDB service after configuration.

$ sudo systemctl restart influxdb
$ sudo systemctl status influxdb
sysadmin@monitor:~$ sudo systemctl status influxdb
● influxdb.service - InfluxDB is an open-source, distributed, time series database
     Loaded: loaded (/lib/systemd/system/influxdb.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-01-01 20:13:42 UTC; 13s ago
       Docs: https://docs.influxdata.com/influxdb/
   Main PID: 3333 (influxd)
      Tasks: 8 (limit: 1075)
     Memory: 8.6M
     CGroup: /system.slice/influxdb.service
             └─3333 /usr/bin/influxd -config /etc/influxdb/influxdb.conf

Jan 01 20:13:42 monitor.linuxsysadmins.local influxd[3333]: ts=2021-01-01T20:13:42.937417Z lvl=info msg="Starting precreation service" log_id=0RRuC48W000 service=shard-precreation check_interval=10m advance_period=30m
Jan 01 20:13:42 monitor.linuxsysadmins.local influxd[3333]: ts=2021-01-01T20:13:42.937426Z lvl=info msg="Starting snapshot service" log_id=0RRuC48W000 service=snapshot
Jan 01 20:13:42 monitor.linuxsysadmins.local influxd[3333]: ts=2021-01-01T20:13:42.937432Z lvl=info msg="Starting continuous query service" log_id=0RRuC48W000 service=continuous_querier
Jan 01 20:13:42 monitor.linuxsysadmins.local influxd[3333]: ts=2021-01-01T20:13:42.937445Z lvl=info msg="Starting HTTP service" log_id=0RRuC48W000 service=httpd authentication=false
Jan 01 20:13:42 monitor.linuxsysadmins.local influxd[3333]: ts=2021-01-01T20:13:42.937450Z lvl=info msg="opened HTTP access log" log_id=0RRuC48W000 service=httpd path=stderr
Jan 01 20:13:42 monitor.linuxsysadmins.local influxd[3333]: ts=2021-01-01T20:13:42.937527Z lvl=info msg="Listening on HTTP" log_id=0RRuC48W000 service=httpd addr=[::]:8086 https=false
Jan 01 20:13:42 monitor.linuxsysadmins.local influxd[3333]: ts=2021-01-01T20:13:42.937538Z lvl=info msg="Starting retention policy enforcement service" log_id=0RRuC48W000 service=retention check_interval=30m
Jan 01 20:13:42 monitor.linuxsysadmins.local influxd[3333]: ts=2021-01-01T20:13:42.937602Z lvl=info msg="Listening for signals" log_id=0RRuC48W000
Jan 01 20:13:42 monitor.linuxsysadmins.local influxd[3333]: ts=2021-01-01T20:13:42.937694Z lvl=info msg="Storing statistics" log_id=0RRuC48W000 service=monitor db_instance=_internal db_rp=monitor interval=10s
Jan 01 20:13:42 monitor.linuxsysadmins.local influxd[3333]: ts=2021-01-01T20:13:42.938979Z lvl=info msg="Sending usage statistics to usage.influxdata.com" log_id=0RRuC48W000
sysadmin@monitor:~$ 

Accessing InfluxDB

To access the influx cli use command

$ influx

List the databases by running show databases

sysadmin@monitor:~$ influx 
Connected to http://localhost:8086 version 1.8.3
InfluxDB shell version: 1.8.3
> show databases
name: databases
name
----
_internal
> 

Creating Database

Let’s start to create a admin use and unprivileged account by following create a database.

root@monitor:~# influx
Connected to http://localhost:8086 version 1.8.3
InfluxDB shell version: 1.8.3
> CREATE USER admin WITH PASSWORD 'Redhat@123' WITH ALL PRIVILEGES
> CREATE DATABASE testdb
> CREATE USER testuser WITH PASSWORD 'Redhat@123'
> GRANT ALL ON testdb TO testuser
> 

Verify the Created User

Check the privilege for testuser, list the available databases.

> SHOW GRANTS FOR testuser
database privilege
-------- ---------
testdb   ALL PRIVILEGES
> 
> SHOW DATABASES
name: databases
name
----
_internal
mondb
testdb
> 
> exit
root@monitor:~#

Login to InfluxDB

Right after creating the admin account we can login to admin account using a single command with options and arguments.

$ influx -username admin -password Redhat@123 -host localhost

Login was success, List the all users

root@monitor:~# influx -username admin -password Redhat@123 -host localhost
Connected to http://localhost:8086 version 1.8.3
InfluxDB shell version: 1.8.3
> 
> show users
user    admin
----    -----
admin   true
monuser false
> 

We can see there are two users, admin user with admin privilege and monuser as a normal user without privilege.

Using the Post Method

To create the users, database and query the information we can use the post method as follows.

Create a user and list the user

$ curl -XPOST "http://localhost:8086/query" --data-urlencode "q=CREATE USER testuser WITH PASSWORD 'Redhat@123' WITH ALL PRIVILEGES"

$ curl -G http://localhost:8086/query -u admin:Redhat@123 --data-urlencode "q=SHOW USERS"

Output for reference

root@monitor:~# curl -XPOST "http://localhost:8086/query" --data-urlencode "q=CREATE USER testuser WITH PASSWORD 'Redhat@123' WITH ALL PRIVILEGES"
{"results":[{"statement_id":0}]}
root@monitor:~# 
root@monitor:~# curl -G http://localhost:8086/query -u admin:Redhat@123 --data-urlencode "q=SHOW USERS"
{"results":[{"statement_id":0,"series":[{"columns":["user","admin"],"values":[["admin",true],["monuser",false],["testuser",true]]}]}]}
root@monitor:~#

Creating Database

Create a database using post method

$ curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE linuxsys_db"

For reference

root@monitor:~# curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE linuxsys_db"
HTTP/1.1 200 OK
Content-Type: application/json
Request-Id: 4f378acd-4ce5-11eb-8911-1c697bca3972
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.8.3
X-Request-Id: 4f378acd-4ce5-11eb-8911-1c697bca3972
Date: Sat, 02 Jan 2021 10:28:52 GMT
Transfer-Encoding: chunked

{"results":[{"statement_id":0}]}
root@monitor:~#

List the database

$ curl -G http://localhost:8086/query -u testuser:Redhat@123 --data-urlencode "q=SHOW DATABASES"

Output for reference

root@monitor:~# curl -G http://localhost:8086/query -u testuser:Redhat@123 --data-urlencode "q=SHOW DATABASES"
{"results":[{"statement_id":0,"series":[{"name":"databases","columns":["name"],"values":[["_internal"],["mondb"],["linuxsys_db"]]}]}]}
root@monitor:~# 

That’s it for now, we have completed with setting up influxDB.

Conclusion

InfluxDB store the time series database in production environment, an Open-Source tool provide an enterprise-level visualization from the collected metrics. In future guide will see how to get generate a graph from collected metric data. subscribe to our newsletter for more guides, your feedbacks are welcome through below comment section.

One thought on “Install InfluxDB on Linux | 3 Easy steps

Comments are closed.