Run podman/docker InfluxDB 1.8 container to collect statistics from collectd

Yet another article on the topic of the InfluxDB 1.8 and collectd gathering statistics, in continuation of the articles Monitor and analyze with Grafana, influxdb 1.8 and collectd under Ubuntu 22.04 LTS and Monitor and analyze with Grafana, influxdb 1.8 and collectd under CentOS Stream 9. This time, the InfluxDB runs in a container created with podman or docker software.

main menu
podman run and show databases

Here are the important points to mind when running InfluxDB 1.8 in a docker/podman container:

  1. Mount the InfluxDB configuration directory into the container not only the /etc/influxdb/influxdb.conf file. Most howtos and even the official docker hub examples do not include the influxdb.conf. Download the official example influxdb.conf from the source code and put it in a separate directory, which will be mounted in the container.
  2. Mount the InfluxDB data directory /var/lib/influxdb into the docker/podman container. The data should be out of the container to preserve it over containers’ upgrades and deletes. The same logic is for the InfluxDB configuration.
  3. Redirect the ports needed for the current setup. Because this howto tends to pair with a collectd daemon and should redirect the 25826 UDP port out of the container. Use IP only if one IP should expose the ports.
  4. Start the docker container on every docker/machine restart (–restart=always).
  5. Use the daemon (-d), i.e. background, option to run the container without blocking the terminal, i.e. as a background process.
  6. Prepare a directory for the container, something like /srv/[container-name]. This article will use /srv/influxdb folder. This folder will host the two sub-folders conf for configuration files and the data for InfluxDB data files, which will be mounted into the container.

To start the container under CentOS Stream 9 execute with podman.

STEP 1) Install podman and prepare the configuration.

First, install the podman software.

dnf install -y podman

Second, prepare the configuration.
Download the InfluxDB 1.8.10 sources and extract the sample configuration and copy it under /srv/influxdb/conf, which will be mounted into the container. Download the collectd sources and extract only the types.db, because the InfluxDB configuration needs the collectd types. The last step is only needed if InfluxDB is going to be used to gather data from the collectd daemon. Skip it, if collectd is not needed.

[root@srv files]# mkdir -p /srv/influxdb/files
[root@srv files]# mkdir /srv/influxdb/conf
[root@srv files]# mkdir /srv/influxdb/data
[root@srv files]# cd /srv/influxdb/files
[root@srv files]# wget https://github.com/influxdata/influxdb/archive/refs/tags/v1.8.10.tar.gz
--2023-07-25 13:02:56--  https://github.com/influxdata/influxdb/archive/refs/tags/v1.8.10.tar.gz
Resolving github.com (github.com)... 140.82.121.3
Connecting to github.com (github.com)|140.82.121.3|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/influxdata/influxdb/tar.gz/refs/tags/v1.8.10 [following]
--2023-07-25 13:02:57--  https://codeload.github.com/influxdata/influxdb/tar.gz/refs/tags/v1.8.10
Resolving codeload.github.com (codeload.github.com)... 140.82.121.10
Connecting to codeload.github.com (codeload.github.com)|140.82.121.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘v1.8.10.tar.gz’

v1.8.10.tar.gz                     [                               <=>                ]  11.52M   136KB/s    in 83s     

2023-07-25 13:04:26 (141 KB/s) - ‘v1.8.10.tar.gz’ saved [12082933]

[root@srv files]# tar xvf v1.8.10.tar.gz influxdb-1.8.10/etc/config.sample.toml
influxdb-1.8.10/etc/config.sample.toml
[root@srv files]# mv influxdb-1.8.10/etc/config.sample.toml ../conf/influxdb.conf
[root@srv files]# wget https://storage.googleapis.com/collectd-tarballs/collectd-5.12.0.tar.bz2
--2023-07-25 13:06:49--  https://storage.googleapis.com/collectd-tarballs/collectd-5.12.0.tar.bz2
Resolving storage.googleapis.com (storage.googleapis.com)... 172.217.169.176, 172.217.17.112, 142.251.140.16, ...
Connecting to storage.googleapis.com (storage.googleapis.com)|172.217.169.176|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1902756 (1.8M) [application/x-bzip]
Saving to: ‘collectd-5.12.0.tar.bz2’

collectd-5.12.0.tar.bz2        100%[=================================================>]   1.81M  1.57MB/s    in 1.2s    

2023-07-25 13:06:51 (1.57 MB/s) - ‘collectd-5.12.0.tar.bz2’ saved [1902756/1902756]

[root@srv files]# tar xvf collectd-5.12.0.tar.bz2 collectd-5.12.0/src/types.db
collectd-5.12.0/src/types.db
[root@srv files]# mv collectd-5.12.0/src/types.db ../conf/
[root@srv files]# ls -altr ../conf/
total 44
-rw-r--r--. 1 myuser myuser 17183 Sep  3  2020 types.db
-rw-rw-r--. 1 root   root   21607 Oct 11  2021 influxdb.conf
drwxr-xr-x. 5 root   root      43 Jul 25 12:56 ..
drwxr-xr-x. 2 root   root      43 Jul 25 13:08 .

Uncomment the following lines under section [[collectd]] in /srv/influxdb/conf:

[[collectd]]
  enabled = true 
  bind-address = ":25826"
  database = "collectd"
  # retention-policy = ""
  #
  # The collectd service supports either scanning a directory for multiple types
  # db files, or specifying a single db file.
  typesdb = "/etc/influxdb/types.db"

Note, the enabled line is changed from false to true.

STEP 2) Start the InfluxDB container and configure the firewall.

Run the container with:

[root@srv influxdb]# podman run -d --restart=always --name influxdb-1.8 -p 192.168.1.200:8086:8086 -p 192.168.1.200:25826:25826/udp -v /srv/influxdb/data:/var/lib/influxdb:Z -v /srv/influxdb/conf:/etc/influxdb:Z influxdb:1.8
✔ docker.io/library/influxdb:1.8
Trying to pull docker.io/library/influxdb:1.8...
Getting image source signatures
Copying blob d397ee47fe79 done  
Copying blob 34df401c391c done  
Copying blob 85a776f9a01b done  
Copying blob 6fdd0e5b72cc done  
Copying blob 36d067b9c792 done  
Copying blob 14969aabedba done  
Copying blob 7f932fab495f done  
Copying config 4a287b6e62 done  
Writing manifest to image destination
6cffc7e449575862eb654eef9f7aa96749d087b07be210dd3212b353135d4ceb
[root@srv influxdb]# podman ps
CONTAINER ID  IMAGE                           COMMAND     CREATED        STATUS        PORTS                                                         NAMES
6cffc7e44957  docker.io/library/influxdb:1.8  influxd     6 seconds ago  Up 6 seconds  192.168.1.200:8086->8086/tcp, 192.168.1.200:25826->25826/udp  influxdb-1.8

While the podman container is running it is possible to attach to it and use the InfluxDB command utility:

[root@srv influxdb]# podman exec -it influxdb-1.8 bash
root@6cffc7e44957:/# influx 
Connected to http://localhost:8086 version 1.8.10
InfluxDB shell version: 1.8.10
> help
Usage:
        connect <host:port>   connects to another node specified by host:port
        auth                  prompts for username and password
        pretty                toggles pretty print for the json format
        chunked               turns on chunked responses from server
        chunk size <size>     sets the size of the chunked responses.  Set to 0 to reset to the default chunked size
        use <db_name>         sets current database
        format <format>       specifies the format of the server responses: json, csv, or column
        precision <format>    specifies the format of the timestamp: rfc3339, h, m, s, ms, u or ns
        consistency <level>   sets write consistency level: any, one, quorum, or all
        history               displays command history
        settings              outputs the current settings for the shell
        clear                 clears settings such as database or retention policy.  run 'clear' for help
        exit/quit/ctrl+d      quits the influx shell

        show databases        show database names
        show series           show series information
        show measurements     show measurement information
        show tag keys         show tag key information
        show field keys       show field key information

        A full list of influxql commands can be found at:
        https://docs.influxdata.com/influxdb/latest/query_language/spec/
> show databases
name: databases
name
----
_internal

Only the _internal database is shown, because the firewall (firewalld) blocks the incoming connections to the UDP 25826 port of InfluxDB 1.8 daemon.

Do not forget to configure the firewall (firewalld in CentOS Stream 9):

[root@srv influxdb]# firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.1.0/24" port protocol="udp" port="25826" accept"
success
[root@srv influxdb]# firewall-cmd --reload
success
[root@srv influxdb]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        rule family="ipv4" source address="192.168.1.0/24" port port="25826" protocol="udp" accept

And after allowing the IPs from the 192.168.1.0/24 network to access the InfluxDB server, check the databases, again:

[root@srv influxdb]# podman exec -it influxdb-1.8 bash
root@4859826111ca:/# influx
Connected to http://localhost:8086 version 1.8.10
InfluxDB shell version: 1.8.10
> show databases
name: databases
name
----
_internal
collectd

On first write the collectd database is created.

STEP 3) Enable the container to autoboot on restart of the system.

The last step is to make a systemd service, which will start the podman container on boot (unfortunately, the –restart option will not work for podman, only for docker!).

[root@srv ~]# podman generate systemd --new --name influxdb-1.8 > /etc/systemd/system/influxdb-1.8.service
[root@srv ~]# systemctl daemon-reload
[root@srv ~]# systemctl start influxdb-1.8
[root@srv ~]# systemctl enable influxdb-1.8
Created symlink /etc/systemd/system/default.target.wants/influxdb-1.8.service → /etc/systemd/system/influxdb-1.8.service.
[root@srv ~]# systemctl status influxdb-1.8
● influxdb-1.8.service - Podman container-influxdb-1.8.service
     Loaded: loaded (/etc/systemd/system/influxdb-1.8.service; disabled; vendor preset: disabled)
     Active: active (running) since Tue 2023-07-25 14:17:15 UTC; 9s ago
       Docs: man:podman-generate-systemd(1)
   Main PID: 1904 (conmon)
      Tasks: 1 (limit: 23020)
     Memory: 772.0K
        CPU: 494ms
     CGroup: /system.slice/influxdb-1.8.service
             └─1904 /usr/bin/conmon --api-version 1 -c bb88ca43df993b0826dc7211b347f6f92b8872ede10626991abcf39fdcf508a6 >

Jul 25 14:17:15 srv influxdb-1.8[1904]: ts=2023-07-25T14:17:15.593523Z lvl=info msg="Starting HTTP service" log_id=0jFMQ>
Jul 25 14:17:15 srv influxdb-1.8[1904]: ts=2023-07-25T14:17:15.593529Z lvl=info msg="opened HTTP access log" log_id=0jFM>
Jul 25 14:17:15 srv influxdb-1.8[1904]: ts=2023-07-25T14:17:15.593832Z lvl=info msg="Storing statistics" log_id=0jFMQka0>
Jul 25 14:17:15 srv influxdb-1.8[1904]: ts=2023-07-25T14:17:15.594094Z lvl=info msg="Listening on HTTP" log_id=0jFMQka00>
Jul 25 14:17:15 srv influxdb-1.8[1904]: ts=2023-07-25T14:17:15.594116Z lvl=info msg="Starting retention policy enforceme>
Jul 25 14:17:15 srv influxdb-1.8[1904]: ts=2023-07-25T14:17:15.594125Z lvl=info msg="Starting collectd service" log_id=0>
Jul 25 14:17:15 srv influxdb-1.8[1904]: ts=2023-07-25T14:17:15.594143Z lvl=info msg="Loading types from file" log_id=0jF>
Jul 25 14:17:15 srv influxdb-1.8[1904]: ts=2023-07-25T14:17:15.599093Z lvl=info msg="Listening on UDP" log_id=0jFMQka000>
Jul 25 14:17:15 srv influxdb-1.8[1904]: ts=2023-07-25T14:17:15.600058Z lvl=info msg="Listening for signals" log_id=0jFMQ>
Jul 25 14:17:15 srv influxdb-1.8[1904]: ts=2023-07-25T14:17:15.600467Z lvl=info msg="Sending usage statistics to usage.i>

This is how to generate a root service, which will be controlled by the systemd. Because podman may execute unprivileged containers, podman generate systemd could be used to set a user systemd service, but this is beyond the scope of this article.

The podman logs command will show all the InfluxDB daemon output:

[root@srv influxdb]# podman logs influxdb-1.8
ts=2023-07-25T13:31:20.528331Z lvl=info msg="InfluxDB starting" log_id=0jFJnbK0000 version=1.8.10 branch=1.8 commit=688e697c51fd
ts=2023-07-25T13:31:20.529220Z lvl=info msg="Go runtime" log_id=0jFJnbK0000 version=go1.13.8 maxprocs=2
ts=2023-07-25T13:31:20.638751Z lvl=info msg="Using data dir" log_id=0jFJnbK0000 service=store path=/var/lib/influxdb/data
ts=2023-07-25T13:31:20.638983Z lvl=info msg="Compaction settings" log_id=0jFJnbK0000 service=store max_concurrent_compactions=1 throughput_bytes_per_second=50331648 throughput_bytes_per_second_burst=50331648
ts=2023-07-25T13:31:20.639074Z lvl=info msg="Open store (start)" log_id=0jFJnbK0000 service=store trace_id=0jFJnbkl000 op_name=tsdb_open op_event=start
ts=2023-07-25T13:31:20.639265Z lvl=info msg="Open store (end)" log_id=0jFJnbK0000 service=store trace_id=0jFJnbkl000 op_name=tsdb_open op_event=end op_elapsed=0.193ms
ts=2023-07-25T13:31:20.639349Z lvl=info msg="Opened service" log_id=0jFJnbK0000 service=subscriber
ts=2023-07-25T13:31:20.639400Z lvl=info msg="Starting monitor service" log_id=0jFJnbK0000 service=monitor
ts=2023-07-25T13:31:20.639444Z lvl=info msg="Registered diagnostics client" log_id=0jFJnbK0000 service=monitor name=build
ts=2023-07-25T13:31:20.639491Z lvl=info msg="Registered diagnostics client" log_id=0jFJnbK0000 service=monitor name=runtime
ts=2023-07-25T13:31:20.639538Z lvl=info msg="Registered diagnostics client" log_id=0jFJnbK0000 service=monitor name=network
ts=2023-07-25T13:31:20.639584Z lvl=info msg="Registered diagnostics client" log_id=0jFJnbK0000 service=monitor name=system
ts=2023-07-25T13:31:20.639635Z lvl=info msg="Starting precreation service" log_id=0jFJnbK0000 service=shard-precreation check_interval=10m advance_period=30m
ts=2023-07-25T13:31:20.639707Z lvl=info msg="Starting snapshot service" log_id=0jFJnbK0000 service=snapshot
ts=2023-07-25T13:31:20.639773Z lvl=info msg="Starting continuous query service" log_id=0jFJnbK0000 service=continuous_querier
ts=2023-07-25T13:31:20.639829Z lvl=info msg="Starting HTTP service" log_id=0jFJnbK0000 service=httpd authentication=false
ts=2023-07-25T13:31:20.639875Z lvl=info msg="opened HTTP access log" log_id=0jFJnbK0000 service=httpd path=stderr
ts=2023-07-25T13:31:20.640040Z lvl=info msg="Listening on HTTP" log_id=0jFJnbK0000 service=httpd addr=[::]:8086 https=false
ts=2023-07-25T13:31:20.640104Z lvl=info msg="Starting retention policy enforcement service" log_id=0jFJnbK0000 service=retention check_interval=30m
ts=2023-07-25T13:31:20.640215Z lvl=info msg="Starting collectd service" log_id=0jFJnbK0000 service=collectd
ts=2023-07-25T13:31:20.640296Z lvl=info msg="Loading types from file" log_id=0jFJnbK0000 service=collectd path=/etc/influxdb/types.db
ts=2023-07-25T13:31:20.641349Z lvl=info msg="Storing statistics" log_id=0jFJnbK0000 service=monitor db_instance=_internal db_rp=monitor interval=10s
ts=2023-07-25T13:31:20.645753Z lvl=info msg="Listening on UDP" log_id=0jFJnbK0000 service=collectd addr=[::]:25826
ts=2023-07-25T13:31:20.646255Z lvl=info msg="Listening for signals" log_id=0jFJnbK0000
ts=2023-07-25T13:31:20.646395Z lvl=info msg="Sending usage statistics to usage.influxdata.com" log_id=0jFJnbK0000

Under Ubuntu world

main menu
docker run and show databases

Under Ubuntu, use docker command instead of the podman in all of the above commands. Of course, podman is also available under Ubuntu Server 22.04, so podman should be good, too.

docker run -d --restart=always --name influxdb-1.8 -p 192.168.1.200:8086:8086 -p 192.168.1.200:25826:25826/udp -v /srv/influxdb/data:/var/lib/influxdb:Z -v /srv/influxdb/conf:/etc/influxdb:Z influxdb:1.8

Note, under Ubuntu server 22.04.1 to install docker is:

apt update
apt install docker.io
systemctl enable docker
#or install podman with
apt install podman-docker

After following the above configuration with /srv/influxdb directory, execute the docker command.

root@srv:/srv/influxdb/files# docker run -d --restart=always --name influxdb-1.8 -p 192.168.1.200:8086:8086 -p 192.168.1.200:25826:25826/udp -v /srv/influxdb/data:/var/lib/influxdb:Z -v /srv/influxdb/conf:/etc/influxdb:Z influxdb:1.8
Unable to find image 'influxdb:1.8' locally
1.8: Pulling from library/influxdb
34df401c391c: Pull complete 
6fdd0e5b72cc: Pull complete 
85a776f9a01b: Pull complete 
36d067b9c792: Pull complete 
14969aabedba: Pull complete 
d397ee47fe79: Pull complete 
7f932fab495f: Pull complete 
Digest: sha256:27673d794041b91ed66d813160f0447ac63d1240bc188d79a3eef2097bf87a3b
Status: Downloaded newer image for influxdb:1.8
53988a54206bcf85b3dfd0bfe2edd16d8cc1fb1b7f00b52f3e4d7ef0423777db
root@srv:/srv/influxdb/files# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS         PORTS                                                          NAMES
53988a54206b   influxdb:1.8   "/entrypoint.sh infl…"   10 seconds ago   Up 6 seconds   192.168.1.200:8086->8086/tcp, 192.168.1.200:25826->25826/udp   influxdb-1.8
root@srv:/srv/influxdb/files# docker exec -it influxdb-1.8 bash
root@53988a54206b:/# influx
Connected to http://localhost:8086 version 1.8.10
InfluxDB shell version: 1.8.10
> show databases
name: databases
name
----
_internal
collectd
> root@53988a54206b:/# 
exit

Leave a Reply

Your email address will not be published. Required fields are marked *