InfluxDB is a popular open source time series database with APIs for querying and storing data and processing the data in the background for visualization, monitoring and alerting purposes and user dashboards. InfluxDB is designed to handle high write and query loads and provides a SQL-like query language called InfluxQL for interacting with data. The time series database is part of the TICK (Telegraf, InfluxDB, Chronograf, Kapacitor) stack.
In this article we will be performing an installation of InfluxDB on Amazon Linux 2. The server can be running in the Cloud or as a VM in your home or company’s Infrastructure. The edition of InfluxDB that we’ll be installing is the open source (OSS). With this installation you’ll get the influx command line interface (CLI), which is included in all InfluxDB packages and is a lightweight and simple way to interact with the database.
Install InfluxDB on Amazon Linux 2
As of this article update the latest release of InfluxDB time series database is version 2.0 but is available in Beta and not fit for production use. As we can cannot dictate the use, we’ll be doing the installation of InfluxDB 1.x on Amazon Linux 2 server.
The first step is addition of YUM repository. This is done by executing the commands below in the terminal.
cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL 7
baseurl = https://repos.influxdata.com/rhel/7/x86_64/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF
Run the yum repolist command to confirm we’ve the repository added to our Amazon Linux 2 server.
$ sudo yum repolist
Loaded plugins: dkms-build-requires, langpacks, priorities, update-motd
amzn2-core | 3.7 kB 00:00:00
amzn2extra-docker | 3.0 kB 00:00:00
grafana/signature | 488 B 00:00:00
grafana/signature | 2.9 kB 00:00:00 !!!
influxdb | 2.5 kB 00:00:00
prometheus/signature | 833 B 00:00:00
prometheus/signature | 1.0 kB 00:00:00 !!!
(1/4): amzn2extra-docker/2/x86_64/updateinfo | 76 B 00:00:00
(2/4): amzn2extra-docker/2/x86_64/primary_db | 68 kB 00:00:00
(3/4): influxdb/primary_db | 49 kB 00:00:00
(4/4): grafana/primary_db | 78 kB 00:00:01
repo id repo name status
amzn2-core/2/x86_64 Amazon Linux 2 core repository 21,106
amzn2extra-docker/2/x86_64 Amazon Extras repo for docker 28
grafana grafana 115+152
influxdb InfluxDB Repository - RHEL 7 204
prometheus prometheus 336
repolist: 21,789
If all is good proceed with the installation of InfluxDB on Amazon Linux 2 server.
sudo yum install influxdb
All that is required to complete the installation is hitting a y key.
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
influxdb x86_64 1.8.3-1 influxdb 61 M
Transaction Summary
==================================================================================================================================================================
Install 1 Package
Total download size: 61 M
Installed size: 166 M
Is this ok [y/d/N]: y
Do the same for GPG key importation.
Retrieving key from https://repos.influxdata.com/influxdb.key
Importing GPG key 0x2582E0C5:
Userid : "InfluxDB Packaging Service <[email protected]>"
Fingerprint: 05ce 1508 5fc0 9d18 e99e fb22 684a 14cf 2582 e0c5
From : https://repos.influxdata.com/influxdb.key
Is this ok [y/N]: y
Then make sure the service is started:
sudo systemctl start influxdb
Set the service to be started every time the server is restarted.
sudo systemctl enable influxdb
Check service status.
$ systemctl status influxd
● influxdb.service - InfluxDB is an open-source, distributed, time series database
Loaded: loaded (/usr/lib/systemd/system/influxdb.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2020-10-07 18:09:59 UTC; 11s ago
Docs: https://docs.influxdata.com/influxdb/
Main PID: 3570 (influxd)
CGroup: /system.slice/influxdb.service
└─3570 /usr/bin/influxd -config /etc/influxdb/influxdb.conf
Oct 07 18:09:59 amazon-linux influxd[3570]: ts=2020-10-07T18:09:59.527670Z lvl=info msg="Starting precreation service" log_id=0Pi3wMVl000 service=shar...eriod=30m
Oct 07 18:09:59 amazon-linux influxd[3570]: ts=2020-10-07T18:09:59.527682Z lvl=info msg="Starting snapshot service" log_id=0Pi3wMVl000 service=snapshot
Oct 07 18:09:59 amazon-linux influxd[3570]: ts=2020-10-07T18:09:59.527686Z lvl=info msg="Starting continuous query service" log_id=0Pi3wMVl000 service...s_querier
Oct 07 18:09:59 amazon-linux influxd[3570]: ts=2020-10-07T18:09:59.527695Z lvl=info msg="Starting HTTP service" log_id=0Pi3wMVl000 service=httpd authe...ion=false
Oct 07 18:09:59 amazon-linux influxd[3570]: ts=2020-10-07T18:09:59.527699Z lvl=info msg="opened HTTP access log" log_id=0Pi3wMVl000 service=httpd path=stderr
Oct 07 18:09:59 amazon-linux influxd[3570]: ts=2020-10-07T18:09:59.527758Z lvl=info msg="Listening on HTTP" log_id=0Pi3wMVl000 service=httpd addr=[::]...tps=false
Oct 07 18:09:59 amazon-linux influxd[3570]: ts=2020-10-07T18:09:59.527768Z lvl=info msg="Starting retention policy enforcement service" log_id=0Pi3wMV...erval=30m
Oct 07 18:09:59 amazon-linux influxd[3570]: ts=2020-10-07T18:09:59.530852Z lvl=info msg="Listening for signals" log_id=0Pi3wMVl000
Oct 07 18:09:59 amazon-linux influxd[3570]: ts=2020-10-07T18:09:59.531129Z lvl=info msg="Storing statistics" log_id=0Pi3wMVl000 service=monitor db_ins...erval=10s
Oct 07 18:09:59 amazon-linux influxd[3570]: ts=2020-10-07T18:09:59.531484Z lvl=info msg="Sending usage statistics to usage.influxdata.com" log_id=0Pi3wMVl000
Hint: Some lines were ellipsized, use -l to show in full.
The network ports used by InfluxDB are:
- TCP port 8086 is used for client-server communication over InfluxDB’s HTTP API
- TCP port 8088 is used for the RPC service for backup and restore.
If you have an active firewalld service add these ports to the allowed list.
sudo firewall-cmd --add-port=8086/tcp --permanent
sudo firewall-cmd --add-port=8088/tcp --permanent
sudo firewall-cmd --reload
Let’s test InfluxDB by sending curl request to show databases.
curl -G http://localhost:8086/query --data-urlencode "q=SHOW DATABASES"
Output:
{"results":[{"statement_id":0,"series":[{"name":"databases","columns":["name"],"values":[["_internal"]]}]}]}
Enable Authentication (optional)
The InfluxDB API and the command line interface (CLI), which connects to the database using the API, include simple, built-in authentication based on user credentials.
To enable authentication edit InfluxDB configuration file and turn auth-enabled to true.
sudo vim /etc/influxdb/influxdb.conf
Look for the [http] section in the configuration file – Around line 245
[http]
enabled = true
bind-address = ":8086"
auth-enabled = true # Set to true
log-enabled = true
When you enable HTTP authentication, InfluxDB requires you to create at least one admin user before you can interact with the system.
$ influx
Connected to http://localhost:8086 version 1.8.3
InfluxDB shell version: 1.8.3
>
Create Admin user.
CREATE USER admin WITH PASSWORD '[email protected]' WITH ALL PRIVILEGES
To create an additional admin user the same syntax is used.
CREATE USER <username> WITH PASSWORD '<password>' WITH ALL PRIVILEGES
Example:
CREATE USER techviewleo WITH PASSWORD 'Str9ngPassw0rd' WITH ALL PRIVILEGES
To grant Admin privileges to existing user run:
GRANT ALL PRIVILEGES TO <username>
When done exit the InfluxDB shell.
> exit
Restart influxdb service.
sudo systemctl restart influxdb
This is how you’ll use the influx command line tool to connect to InfluxDB with authentication.
$ influx -username admin -password '[email protected]'
Connected to http://localhost:8086 version 1.8.3
InfluxDB shell version: 1.8.3
> SHOW DATABASES;
name: databases
name
----
_internal
>
For curl use:
$ curl -G "http://localhost:8086/query?u=admin&[email protected]" --data-urlencode "q=SHOW DATABASES"
{"results":[{"statement_id":0,"series":[{"name":"databases","columns":["name"],"values":[["_internal"]]}]}]}
Or
curl -G http://localhost:8086/query -u admin:[email protected] --data-urlencode "q=SHOW DATABASES"
If you try without providing the username and password you should get authentication error message.
curl -G http://localhost:8086/query --data-urlencode "q=SHOW DATABASES"
{"error":"unable to parse authentication credentials"}
Enjoy using InfluxDB to store time series data and build and end-to-end monitoring platform for both Applications and Infrastructure.