Sunday, December 29, 2024
Google search engine
HomeGuest BlogsInstall Grafana and InfluxDB on CentOS 7 / RHEL 7

Install Grafana and InfluxDB on CentOS 7 / RHEL 7

This will be our first series on how to do smart monitoring and visualization of your entire Infrastructure. The entire series will concentrate on tools like Grafana, Prometheus, InfluxDB, Telegraf and maybe others to come. This guide will discuss how to install Grafana / InfluxDB on CentOS 7 / RHEL 7 Linux system.

Since this is the first article in the series, I’ll make an introductory definition of tools that we’ll be working with:

InfluxDB is an open-source time series database developed written in Go by InfluxData. InfluxDB is optimized for fast, high-availability storage and retrieval of time series data for metrics analysis. This can be installed on a single server or a clustered.

Telegraf is an agent written in Go for collecting, processing, aggregating, and writing metrics. Design goals are to have a minimal memory footprint with a plugin system so that developers in the community can easily add support for collecting metrics from local or remote services. It is installed on all devices that need to be monitored, and all metrics collected by Telegraf are pushed stored on InfluxDB.

Grafana is an open source, feature rich metrics dashboard and graph editor for Graphite, Elasticsearch, OpenTSDB, Prometheus, and InfluxDB. Data stored on InfluxDB will be visualized using Grafana.

Prometheus is a tool used for systems and service monitoring. It collects metrics from configured targets at given intervals, evaluates rule expressions, displays the results, and can trigger alerts if some condition is observed to be true. Metrics stored on Prometheus can be visualized using Grafana.

For Ubuntu / Debian, check:

Installing InfluxDB on CentOS 7 / RHEL 7

Influxdata provides the repository for installing InfluxDB and telegraf on CentOS 7 / RHEL 7. To add the repository to your system, use the commands:

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 = 0
gpgkey = https://repos.influxdata.com/influxdb.key
EOF

Update cache to confirm that the repository is working fine:

sudo yum makecache

Then install influxDB:

sudo yum -y install influxdb vim curl

Start and enable the service:

sudo systemctl start influxdb && sudo systemctl enable influxdb

Configure InfluxDB firewall

By default, InfluxDB uses the following network ports:

  • 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.

To open it on the firewall, use the command:

sudo firewall-cmd --add-port=8086/tcp --permanent
sudo firewall-cmd --reload

Port mappings can be modified by changing the file /etc/influxdb/influxdb.conf. Since all is configured now, we can start the service now.

sudo systemctl start influxdb
sudo systemctl enable influxdb

Confirm 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  Fri 2023-08-18 22:32:28 UTC; 7s ago
     Docs: https://docs.influxdata.com/influxdb/
  Process: 13870 ExecStart=/usr/lib/influxdb/scripts/influxd-systemd-start.sh (code=exited, status=0/SUCCESS)
 Main PID: 13871 (influxd)
    Tasks: 13 (limit: 49496)
   Memory: 11.9M
   CGroup: /system.slice/influxdb.service
           └─13871 /usr/bin/influxd -config /etc/influxdb/influxdb.conf

InfluxDB http Authentication (Optional)

If you need http authentication, modify influxdb http section to contain the following.

$ sudo vim /etc/influxdb/influxdb.conf
[http]
# Determines whether HTTP endpoint is enabled.
  enabled = true
# Determines whether user authentication is enabled over HTTP/HTTPS.
  auth-enabled = true

Then create a user with an authentication password:

curl -XPOST "http://localhost:8086/query" --data-urlencode \
"q=CREATE USER admin WITH PASSWORD 'StrongPassw0rd' WITH ALL PRIVILEGES"

Replace:

  • admin with your own username
  • StrongPassw0rd with your own password (note that the password requires single quotes)

Restart influxd service:

sudo systemctl restart influxd

Now whenever you need to run any influxdb commands on the terminal, you need to specify username using -username and password using -password options.

$ influx -username 'admin' -password 'StrongPassw0rd'
Connected to http://localhost:8086 version 1.8.10
InfluxDB shell version: 1.8.10
> quit

For curl, use -u to specify username and password separated by a colon.

$ curl -G http://localhost:8086/query -u admin:StrongPassw0rd --data-urlencode "q=SHOW DATABASES"
{"results":[{"statement_id":0,"series":[{"name":"databases","columns":["name"],"values":[["_internal"]]}]}]}

By default, influxdb service is listening on all interfaces on port 8086.

Installing Grafana on CentOS 7 / RHEL 7

There are two ways to install Grafana on CentOS 7 / RHEL 7, one is using official Grafana yum repository, and the other method involves manually downloading rpm package and installing it locally on the server.

The preferred method is using repo since it is easy to update to latest release. So add the following to a new file at /etc/yum.repos.d/grafana.repo

cat <<EOF | sudo tee /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
EOF

Then run:

sudo yum -y install grafana

You’ll be prompted to accept gpg key, press Yes to continue. To start grafana service and enable it to start on boot, run:

sudo systemctl start grafana-server
sudo systemctl enable grafana-server

This will start the grafana-server process as the grafana user, which is created during package installation. The default HTTP port is 3000, and default user and group is admin.  By default Grafana will log to /var/log/grafana.

Checking service status:

$ systemctl status grafana-server
 grafana-server.service - Grafana instance
   Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; enabled; vendor preset: disabled)
   Active: active (running) since since Wed 2022-04-20 10:13:09 UTC; 36s ago
     Docs: http://docs.grafana.org
 Main PID: 14526 (grafana-server)
    Tasks: 10 (limit: 49496)
   Memory: 27.9M
   CGroup: /system.slice/grafana-server.service
           └─14526 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid --packaging=rpm cfg:default.paths.log>

The default configuration  file is /etc/grafana/grafana.in with sqlite3 database store  located at /var/lib/grafana/grafana.db

Open firewall port for Grafana

If you have a running firewalld service, consider opening port 3000 of you’re going to access the dashboard over the network.

sudo firewall-cmd --add-port=3000/tcp --permanent
sudo firewall-cmd --reload

You can access the dashboard on the web using port 3000 and IP address or hostname and start creating Dashboards.

grafana dashboard

On our next article, we’ll look at how to install telegraf client agent for InfluxDB and collect server metrics for visualization on Grafana: Monitor Linux System with Grafana and Telegraf

Other Grafana Monitoring guides:

RELATED ARTICLES

Most Popular

Recent Comments