How to Install and Use InfluxDB on Ubuntu
How to Install and Use InfluxDB on Ubuntu
InfluxDB is a powerful time-series database designed for handling high-write loads and large data volumes, making it an ideal choice for applications such as monitoring systems, IoT data storage, and real-time analytics. In this guide, we will walk through the installation process of InfluxDB on Ubuntu and provide basic usage instructions to get you started.
Prerequisites
Before you begin, ensure that you have the following:
- Ubuntu Server or Desktop: This guide is based on Ubuntu 20.04 and later.
- Sudo Privileges: You will need administrative privileges to install software packages.
- Internet Connection: Ensure your server is connected to the internet to download necessary packages.
Step 1: Update Your System
First, update your system’s package index to ensure you have the latest information on available packages. Open your terminal and run:( ctrl+ T )
sudo apt update
sudo apt upgrade -y
Step 2: Install InfluxDB
InfluxDB provides a repository for easy installation on Ubuntu. Follow these steps to add the repository and install InfluxDB:
Import the GPG key:
wget -qO – https://repos.influxdata.com/influxdb.key | sudo apt-key add –
Add the InfluxDB repository:
For Ubuntu 20.04, run:
echo “deb https://repos.influxdata.com/ubuntu focal stable main” | sudo tee /etc/apt/sources.list.d/influxdb.list
For other Ubuntu versions, replace focal with your respective release name (e.g., jammy for 22.04).
Update the package index again:
sudo apt update
Install InfluxDB:
Now you can install InfluxDB with the following command:
sudo apt install influxdb -y
Step 3: Start and Enable the InfluxDB Service
After installation, you need to start the InfluxDB service and enable it to launch on boot:
sudo systemctl start influxdb
sudo systemctl enable influxdb
You can check the status of the InfluxDB service using:
sudo systemctl status influxdb
This command should indicate that the service is active and running.
Step 4: Configure InfluxDB
InfluxDB has a default configuration file located at /etc/influxdb/influxdb.conf. You can edit this file to customize your InfluxDB installation, such as enabling authentication, configuring the HTTP service, and more. To edit the file, use a text editor like nano:
sudo nano /etc/influxdb/influxdb.conf
Make any necessary changes, then save and exit the editor (in nano, you can do this by pressing CTRL + X, then Y, and ENTER).
Step 5: Create a Database
Now that InfluxDB is running, you can create a database for your time-series data. Access the InfluxDB shell by typing:
influx
In the InfluxDB shell, run the following command to create a new database:
CREATE DATABASE mydb
You can verify that your database has been created by running:
SHOW DATABASES
You should see mydb listed among other databases.
Step 6: Writing Data
InfluxDB uses a line protocol to write data points to the database. Here’s an example of how to insert data into your newly created database. First, switch to your database:
USE mydb
Next, write some data points. For instance, let’s log temperature readings:
INSERT temperature,location=room1 value=23.5
INSERT temperature,location=room2 value=22.3
To confirm the data has been written, you can query the data:
SELECT * FROM temperature
Step 7: Querying Data
InfluxDB supports a powerful query language, allowing you to analyze your time-series data effectively. For example, you can retrieve the last 10 temperature readings with the following command:
SELECT * FROM temperature ORDER BY time DESC LIMIT 10
Step 8: Using Telegraf
Telegraf is the data collection agent for InfluxDB and can be used to gather metrics from various sources. To install Telegraf, run:
sudo apt install telegraf -y
Once installed, you can configure it by editing the configuration file at /etc/telegraf/telegraf.conf. Make sure to set the output to point to your InfluxDB instance:
[[outputs.influxdb]]
urls = [“http://localhost:8086”]
database = “mydb”
After editing, start and enable Telegraf:
sudo systemctl start telegraf
sudo systemctl enable telegraf
official InfluxDB documentation here.
Thank you for visiting our page! If you’d like to read more articles about Linux systems and Telegraf, feel free to check out the links below.
How to Install and Use Telegraf for Monitoring on Ubuntu
Moreover, by renting a server from our site, you can conduct your tests in a reliable and effective environment, helping you to enhance your skills more rapidly. Great job! 🙂