InfluxDB is a powerful open-source time series database built to collect, store, process, and visualize time series data. It is widely used for various purposes such as operation monitoring, application and server performance metrics, IoT sensor data, and real-time analytics. In this tutorial, we will guide you through the process of installing InfluxDB and Telegraf on a Rocky Linux 9 server, securing the deployment with authentication and TLS certificates, configuring the InfluxDB CLI, collecting metrics via the Telegraf agent, and visualizing the data on the InfluxDB dashboard.
Prerequisites
Before getting started, make sure you have the following requirements:
- A Rocky Linux 9 server.
- A non-root user with sudo/root administrator privileges.
- SELinux set to ‘permissive’ mode.
Setting up the Repository
To install InfluxDB on Linux, you have the option to either manually install it via a binary package or use the InfluxDB repository. In this tutorial, we will install InfluxDB using the official InfluxDB repository.
First, add the InfluxDB repository to your Rocky Linux system by running the following command:
sudo tee /etc/yum.repos.d/influxdb.repo <<EOF [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
Verify that the InfluxDB repository has been successfully added by running the following command:
sudo dnf repolist
You should see the InfluxDB repository listed.
Installing InfluxDB
Now that the repository is set up, we can proceed with installing InfluxDB. Run the following command to install the InfluxDB package:
sudo dnf install influxdb2
When prompted, enter ‘y’ to confirm and press ENTER to proceed. You will also be asked to confirm the installation of the InfluxDB GPG key.
After the installation is complete, start the InfluxDB service and enable it to start automatically on boot:
sudo systemctl start influxdb sudo systemctl enable influxdb
Verify that the InfluxDB service is running by running the following command:
sudo systemctl status influxdb
By default, InfluxDB runs on TCP port ‘8086’. To allow incoming connections to InfluxDB, add port ‘8086’ to the firewall:
sudo firewall-cmd --add-port=8086/tcp --permanent sudo firewall-cmd --reload
Installing the InfluxDB CLI
After installing the InfluxDB time series database, we will now install the InfluxDB CLI (Command Line Interface) or command-line tool. The InfluxDB CLI provides a convenient way to manage InfluxDB administration tasks such as managing buckets, organizations, users, and tasks.
To install the InfluxDB CLI, run the following command:
sudo dnf install influxdb2-cli
When prompted, enter ‘y’ to confirm and press ENTER to proceed.
After the installation is complete, you can check the version of the InfluxDB CLI by running the following command:
influx version
You should see the version of the InfluxDB CLI installed on your system.
To enable command completion for the InfluxDB CLI in the bash shell, run the following command:
sudo influx completion bash > /etc/bash_completion.d/influx.sh sudo chmod +x /etc/bash_completion.d/influx.sh
Now, when you type the ‘influx’ command and press TAB, you will see the available options for the ‘influx’ command.
Configuring InfluxDB via the InfluxDB CLI
In this step, we will configure the InfluxDB installation using the InfluxDB CLI. We will set up the InfluxDB administrator user and password, define the organization name, set up the default bucket or database, and verify the list of users and authentication on InfluxDB. We will also learn how to connect to the InfluxDB shell and access the InfluxDB web administration dashboard.
To start configuring the InfluxDB deployment, run the following command:
sudo influx setup
You will be prompted to configure the following:
- Setup admin user: Enter a new username for your InfluxDB server. For example, ‘Jhon’ can be used as the admin user.
- Setup admin password: Enter a new admin password for your InfluxDB deployment and repeat the password.
- Define the organization name: Enter your organization name. For this example, we will use ‘ex.IO’ as the organization name.
- Set up the primary bucket name: Enter the bucket name for the default installation. For this example, we will use ‘test-bucket’ as the bucket name.
- Setup the retention period for InfluxDB: Enter ‘0’ for infinite retention.
After providing the necessary information, enter ‘Yes’ to confirm the InfluxDB basic configurations.
Now, let’s verify the list of users and authentication on InfluxDB using the following commands:
sudo influx user list sudo influx auth list
You should see the InfluxDB admin user ‘Jhon’ and the corresponding authentication details, including the auth ID, token, and permissions.
To log in to the InfluxDB shell, you need to create an environment variable ‘INFLUX_TOKEN’ by running the following command:
export INFLUX_TOKEN=FlIq521ZVxEA40Iz7rVVKK25sDmuEWUHm_Mbly-4mYxt-rWrYOOytVnmE5yL5bpNB_gNHBWlYXKDED9PEbk-0g==
Now, you can log in to the InfluxDB shell using the following command:
sudo influx v1 shell $INFLUX_TOKEN
After logging in, you will see a message indicating that you are connected to InfluxDB OSS (Open Source Software) with the version number.
To verify that the default bucket ‘test-bucket’ is available on the InfluxDB server, run the following query:
show DATABASES
You should see the ‘test-bucket’ database listed.
To exit from the interactive mode, press ‘q’, and then type ‘exit’ to log out from the InfluxDB shell.
You can also access the InfluxDB web administration dashboard using your web browser. Open your web browser and enter the InfluxDB server IP address followed by port ‘8086’. For example, http://192.168.5.100:8086.
Enter the InfluxDB user and password that you created during the InfluxDB setup process, and click ‘SIGN IN’. In this example, the admin user is ‘Jhon’.
After logging in, you will see the InfluxDB web-based administration dashboard.
To view the ‘test-bucket’ and its data, click on the ‘Load Data’ menu and select the ‘Buckets’ tab. You should see the ‘test-bucket’ listed.
With the basic configuration of InfluxDB complete, let’s move on to securing the InfluxDB deployment by enabling a secure connection using TLS certificates.
Securing InfluxDB with TLS
After completing the basic configuration of the InfluxDB server, we will now secure the InfluxDB deployment using SSL/TLS certificates. We will update the InfluxDB default configuration/profile with the new secured InfluxDB server details.
Before we begin, make sure you have generated SSL/TLS certificates. You can use self-signed SSL/TLS certificates or certificates generated by a trusted third-party provider like Let’s Encrypt.
First, create a new directory to store the SSL/TLS certificates by running the following command:
sudo mkdir -p /etc/influxdb/ssl
Next, copy the SSL/TLS certificates to the ‘/etc/influxdb/ssl’ directory and change the ownership of the directory to the user ‘influx’. Replace ‘/etc/letsencrypt/live/influxdb.example.io/{fullchain.pem,privkey.pem}’ with the path to your SSL/TLS certificates.
sudo cp /etc/letsencrypt/live/influxdb.example.io/{fullchain.pem,privkey.pem} /etc/influxdb/ssl/ sudo chown -R influx: /etc/influxdb/ssl
After copying the certificates, open the InfluxDB configuration file ‘/etc/influxdb/config.toml’ using the nano editor:
sudo nano /etc/influxdb/config.toml
Add the following lines to the file:
tls-cert = "/etc/influxdb/ssl/fullchain.pem" tls-key = "/etc/influxdb/ssl/privkey.pem"
Save the file and exit the editor.
Restart the InfluxDB service to apply the new changes:
sudo systemctl restart influxdb
With TLS enabled, you will not be able to query and manage the InfluxDB server using the ‘influx’ command line. To resolve this, we need to update the default Influx profile on your system.
Run the following command to update the ‘default’ configuration/profile:
sudo influx config set -a -n default -u https://influxdb.example.io:8086 -t $INFLUX_TOKEN -o ex.IO
Verify the list of Influx configurations/profiles:
sudo influx config ls
You should see that the URL is changed to ‘https://influxdb.example.io:8086’, indicating that SSL/TLS is enabled on the InfluxDB server.
To verify that the updated Influx configuration/profile is working, run the following commands:
sudo influx user list sudo influx auth list
If the Influx configuration/profile is updated correctly, you should see the list of users and authentication details on the InfluxDB server, indicating that you have connected to the InfluxDB server using a secure SSL/TLS connection.
At this point, we have completed the installation and configuration of the InfluxDB server on Rocky Linux 9 and secured the InfluxDB deployment using SSL/TLS certificates. Next, we will start collecting data and metrics using Telegraf and visualize the data on the InfluxDB dashboard.
Collecting Data via Telegraf
Telegraf is an open-source server-based agent built by InfluxData for collecting and sending metrics and events from various environments such as IoT sensors, database systems, system telemetry, and DevOps tools. It is a powerful tool that allows you to gather data from different sources and send it to the InfluxDB server.
To install Telegraf on Rocky Linux, make sure you have added the InfluxDB repository. Then, run the following command to install Telegraf:
sudo dnf install telegraf
After the installation is complete, start the Telegraf service and enable it to start automatically on boot:
sudo systemctl start telegraf sudo systemctl enable telegraf
To verify that the Telegraf service is running and enabled, run the following commands:
sudo systemctl is-enabled telegraf
sudo systemctl status telegraf
You should see that the Telegraf service is enabled and running.
Next, open the Telegraf configuration file ‘/etc/telegraf/telegraf.conf’ using the nano editor:
sudo nano /etc/telegraf/telegraf.conf
In the configuration file, locate the ‘[[outputs.influxdb_v2]]’ section and add the InfluxDB server details, including the URL, token, organization, and bucket name:
[[outputs.influxdb_v2]] urls = ["https://influxdb.example.io:8086"] token = "$INFLUX_TOKEN" organization = "ex.IO" bucket = "test-bucket"
Save the file and exit the editor.
Restart the Telegraf service to apply the configuration changes:
sudo systemctl restart telegraf
Now, Telegraf will collect metrics from your system and send them to the InfluxDB server.
To verify that Telegraf is sending metrics to the InfluxDB server, you can check the InfluxDB web administration dashboard. Click on the ‘Data Explorer’ menu and select the ‘test-bucket’. You should see system telemetry metrics collected by Telegraf, such as CPU, disk, diskio, kernel, memory, swap, and system.
You can also verify Telegraf metrics using the InfluxDB shell. Connect to the InfluxDB shell using the following command:
sudo influx v1 shell
Run the following query to switch to the ‘test-bucket’ and show available measurements:
use test-bucket SHOW MEASUREMENTS
You should see the metrics collected by the Telegraf service available on the InfluxDB server.
Visualizing Data and Creating a Dashboard
In this step, we will create a new dashboard to monitor system telemetry using the InfluxDB server and Telegraf. We will create InfluxDB dashboards and cells to visualize metrics collected by the Telegraf service.
To begin, select the ‘Dashboard’ menu on the InfluxDB web administration dashboard and click ‘CREATE DASHBOARD’.
Enter the name of your dashboard and click ‘ADD CELL’. For this example, let’s create a dashboard named ‘Test Dashboard’.
Now, you can start adding cells to monitor your system. Here are some examples of graphs for system monitoring using Telegraf:
- Memory Available and Memory Usage: Monitor the available memory and memory usage on your system.
- Process Monitoring: Monitor the processes running on your system.
- System Load: Monitor the system load average.
- Uptime: Monitor the system uptime.
- Active Users: Monitor the number of active users on the system.
- CPU Usage: Monitor the CPU usage on your system.
With these cells for system monitoring, your ‘Test Dashboard’ should resemble the following screenshot.
Congratulations! You have successfully set up system monitoring using the InfluxDB server and Telegraf. You have learned how to set up the InfluxDB dashboard and create cells to visualize metrics collected by Telegraf.
Conclusion
In this guide, we have covered the installation and configuration of the InfluxDB time series database and the InfluxDB CLI on a Rocky Linux 9 server. We have also secured the InfluxDB deployment using SSL/TLS certificates and configured the InfluxDB server using the InfluxDB CLI.
Additionally, we installed and configured Telegraf to collect and send metrics to the InfluxDB server using a secure SSL/TLS connection. Finally, we created a dashboard to monitor system telemetry using the InfluxDB server and Telegraf.
With the powerful combination of InfluxDB and Telegraf, you can effectively collect, store, process, and visualize time series data for various monitoring and analytics purposes.
If you are looking for reliable cloud hosting solutions, consider Shape.host’s Linux SSD VPS services. Shape.host offers scalable and secure cloud hosting solutions designed to meet the needs of businesses. Visit Shape.host for more information.