Skip to content

antony@notes:~/misc$ cat "How-to-install-Influxdb-on-RedHat-Enterprise-Linux-9.md"

How to install Influxdb on RedHat Enterprise Linux 9

2025-11-03· misc

How to install Influxdb on RedHat Enterprise Linux 9

1. 先決條件

  1. 已安裝好可連線到 Public 網路的 RHEL 9

2. InfluxDB 檔案結構

Engine path

storage engine 的目錄路徑,InfluxDB 在此儲存時間序列資料 (time series data)。它包含以下目錄:

  • data:儲存時間結構合併樹 (TSM) 檔案。有關 data 目錄結構的更多資訊,請參閱 TSM 目錄和檔案佈局。
  • replicationq:儲存 InfluxDB replication service 的複製佇列 (replication queue)。
  • wal:儲存預寫日誌 (WAL) 檔案。有關 wal 目錄結構的更多資訊,請參閱 WAL 目錄和檔案佈局。

若要自訂此路徑,請使用 engine-path 設定選項。

Bolt path

Boltdb 資料庫的檔案路徑。這是一個 file-based key-value store,用於儲存非時間序列資料,例如 InfluxDB 的使用者、儀表板 (dashboards) 和任務 (tasks)。

若要自訂此路徑,請使用 bolt-path 設定選項。

SQLite path

SQLite 資料庫的檔案路徑。這是一個 SQL 資料庫,用於儲存非時間序列資料,例如 InfluxDB 的筆記本 (notebooks) 和註解 (annotations)。

若要自訂此路徑,請使用 sqlite-path 設定選項。

Configs path

influx CLI 連線設定 (configs) 的檔案路徑。

若要使用自訂路徑,請在使用 influx CLI 命令時傳遞 --configs-path 旗標。

Linux default paths (package)

PathDefault
Engine path/var/lib/influxdb/engine/
Bolt path/var/lib/influxdb/influxd.bolt
SQLite path/var/lib/influxdb/influxd.sqlite
Configs path/var/lib/influxdb/configs
Default config file path/etc/influxdb/config.toml

Linux file system overview (package)

/var/lib/influxdb/
├── engine
│   ├── data             #--> TSM directories and files
│   └── replicationq     #--> WAL directories and files
├── influxd.bolt
├── influxd.pid
└── influxd.sqlite
/etc/influxdb/
└── config.toml          #--> (influxd configuration file)

3. 規劃一顆硬碟給 Influxdb 用

# 1. 在 VM 新增一顆硬碟專門給 Influxdb 使用

# 2. 檢查新的硬碟名稱
$ lsblk
...
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sdb               8:16   0  100G  0 disk

# 3. 將硬碟名稱設為變數
$ D="/dev/sdb"

# 4. 使用 parted 建立 GPT 分割區,從 1 MiB 到磁碟尾,並標記為 LVM 用途
$ sudo parted -s ${D} mklabel gpt
$ sudo parted -s ${D} unit MiB mkpart primary 1 100%

# 5. 將剛建立的分割區初始化為 LVM PV
$ sudo pvcreate ${D}1

# 6. 建立名為 vg-Influxdb 的 VG
$ sudo vgcreate vg-Influxdb ${D}1

# 7. 從 VG 中建立一 LV,利用全部剩餘空間並命名為 lv-Influxdb
$ sudo lvcreate -l +100%FREE -n lv-Influxdb /dev/vg-Influxdb

# 8. 格式化 LV 為 XFS 檔案系統,以提供穩健且高效的儲存
$ sudo mkfs.xfs /dev/vg-Influxdb/lv-Influxdb

# 9. 將目錄設為開機自動掛載 lv 裝置上
$ echo '/dev/vg-Influxdb/lv-Influxdb      /var/lib/influxdb               xfs     defaults        0 0' | sudo tee -a /etc/fstab

# 10. 建立目錄
$ sudo mkdir -p /var/lib/influxdb

# 11. 將目錄掛載到 lv 裝置上
$ sudo mount -a && sudo systemctl daemon-reload

4. Install InfluxDB as a service with systemd

  1. Add the InfluxData key to verify downloads

    curl --silent --location -O https://repos.influxdata.com/influxdata-archive.key
    gpg --show-keys --with-fingerprint --with-colons ./influxdata-archive.key 2>&1 \
    | grep -q '^fpr:\+9D539D90D3328DC7D6C8D3B9D8FF8E1F7DF8B07E:$' \
    && cat influxdata-archive.key \
    | gpg --dearmor \
    | sudo tee /etc/pki/rpm-gpg/RPM-GPG-KEY-influxdata > /dev/null
  2. Add the InfluxData repository to the repository list.

    cat <<EOF | sudo tee /etc/yum.repos.d/influxdata.repo
    [influxdata]
    name = InfluxData Repository - Stable
    baseurl = https://repos.influxdata.com/stable/\${basearch}/main
    enabled = 1
    gpgcheck = 1
    gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-influxdata
    EOF
  3. 安裝 influxdb

    sudo yum install influxdb2

    執行結果:

    Updating Subscription Management repositories.
    InfluxData Repository - Stable                                                        374 kB/s | 631 kB     00:01
    Dependencies resolved.
    ======================================================================================================================
     Package                     Architecture             Version                      Repository                    Size
    ======================================================================================================================
    Installing:
     influxdb2                   x86_64                   2.7.12-1                     influxdata                    47 M
    
    Transaction Summary
    ======================================================================================================================
    Install  1 Package
    
    Total download size: 47 M
    Installed size: 115 M
    Is this ok [y/N]: y
    Downloading Packages:
    influxdb2-2.7.12-1.x86_64.rpm                                                         5.9 MB/s |  47 MB     00:08
    ----------------------------------------------------------------------------------------------------------------------
    Total                                                                                 5.9 MB/s |  47 MB     00:08
    InfluxData Repository - Stable                                                        2.7 MB/s | 2.8 kB     00:00
    Importing GPG key 0x9FC2F927:
     Userid     : "InfluxData Package Signing Key <support@influxdata.com>"
     Fingerprint: 24C9 75CB A61A 024E E1B6 3178 7C3D 5715 9FC2 F927
     From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-influxdata
    Is this ok [y/N]: y
    Key imported successfully
    Running transaction check
    Transaction check succeeded.
    Running transaction test
    Transaction test succeeded.
    Running transaction
      Preparing        :                                                                                              1/1
      Running scriptlet: influxdb2-2.7.12-1.x86_64                                                                    1/1
      Installing       : influxdb2-2.7.12-1.x86_64                                                                    1/1
      Running scriptlet: influxdb2-2.7.12-1.x86_64                                                                    1/1
    Created symlink /etc/systemd/system/influxd.service → /usr/lib/systemd/system/influxdb.service.
    Created symlink /etc/systemd/system/multi-user.target.wants/influxdb.service → /usr/lib/systemd/system/influxdb.service.
    
      Verifying        : influxdb2-2.7.12-1.x86_64                                                                    1/1
    Installed products updated.
    
    Installed:
      influxdb2-2.7.12-1.x86_64
    
    Complete!

5. 啟動並初始化 Influxdb

  1. 啟動 Influxdb 服務並設為開機自動啟動

    sudo systemctl enable --now influxdb
  2. 檢視 Influxdb 服務啟動狀態

    sudo systemctl status influxdb.service

    執行結果:

    ● influxdb.service - InfluxDB is an open-source, distributed, time series database
         Loaded: loaded (/usr/lib/systemd/system/influxdb.service; enabled; preset: disabled)
         Active: active (running) since Mon 2025-11-03 11:36:43 CST; 5min ago
           Docs: https://docs.influxdata.com/influxdb/
        Process: 5474 ExecStart=/usr/lib/influxdb/scripts/influxd-systemd-start.sh (code=exited, status=0/SUCCESS)
       Main PID: 5475 (influxd)
          Tasks: 9 (limit: 48880)
         Memory: 59.2M
            CPU: 253ms
         CGroup: /system.slice/influxdb.service
                 └─5475 /usr/bin/influxd
    
    Nov 03 11:36:43 influxdb.kubeantony.com influxd-systemd-start.sh[5475]: ts=2025-11-03T03:36:43.499145Z lvl=info msg="Starting retention policy enforcement service" log_id=0zyxT2tl000 service=retention check_interval=30m
    Nov 03 11:36:43 influxdb.kubeantony.com influxd-systemd-start.sh[5475]: ts=2025-11-03T03:36:43.499149Z lvl=info msg="Starting precreation service" log_id=0zyxT2tl000 service=shard-precreation check_interval=10m advance_period=30m
    Nov 03 11:36:43 influxdb.kubeantony.com influxd-systemd-start.sh[5475]: ts=2025-11-03T03:36:43.499456Z lvl=info msg="Starting query controller" log_id=0zyxT2tl000 service=storage-reads concurrency_quota=1024 initial_memory_bytes_quota_per_query=9223372036854775807 memory_bytes_quota_per_query=9223372036854775807 max_memory_bytes=0 queue_size=1024
    Nov 03 11:36:43 influxdb.kubeantony.com influxd-systemd-start.sh[5475]: ts=2025-11-03T03:36:43.500102Z lvl=info msg="Configuring InfluxQL statement executor (zeros indicate unlimited)." log_id=0zyxT2tl000 max_select_point=0 max_select_series=0 max_select_buckets=0
    Nov 03 11:36:43 influxdb.kubeantony.com influxd-systemd-start.sh[5494]: Command "print-config" is deprecated, use theinflux-cli command server-config to display the configuration values from the running server
    Nov 03 11:36:43 influxdb.kubeantony.com influxd-systemd-start.sh[5475]: ts=2025-11-03T03:36:43.506157Z lvl=info msg=Starting log_id=0zyxT2tl000 service=telemetry interval=8h
    Nov 03 11:36:43 influxdb.kubeantony.com influxd-systemd-start.sh[5475]: ts=2025-11-03T03:36:43.506184Z lvl=info msg=Listening log_id=0zyxT2tl000 service=tcp-listener transport=http addr=:8086 port=8086
    Nov 03 11:36:43 influxdb.kubeantony.com influxd-systemd-start.sh[5507]: Command "print-config" is deprecated, use theinflux-cli command server-config to display the configuration values from the running server
    Nov 03 11:36:43 influxdb.kubeantony.com influxd-systemd-start.sh[5474]: InfluxDB started
    Nov 03 11:36:43 influxdb.kubeantony.com systemd[1]: Started InfluxDB is an open-source, distributed, time series database.
  3. 下載 Influx CLI 套件,並解壓縮執行檔至 /usr/local/bin 底下

    wget https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.5-linux-amd64.tar.gz
    sudo tar -xzf influxdb2-client-2.7.5-linux-amd64.tar.gz \
      -C /usr/local/bin \
      --strip-components=1 \
      ./influx
    rm influxdb2-client-2.7.5-linux-amd64.tar.gz
  4. 透過 Influx CLI 初始化 InfluxDB

    influx setup \
      --host http://influxdb.kubeantony.com:8086 \
      --username bigred \
      --password bigred123 \
      --org taroko \
      --bucket default \
      --force

    執行結果:

    User    Organization    Bucket
    bigred  taroko          default
  5. 透過 influx auth create 命令來建立一個擁有所也權限的 token

    influx auth create \
      --all-access \
      --host http://influxdb.kubeantony.com:8086 \
      --org taroko \
      --token=$(influx auth list --json | jq -r '.[].token')

    執行結果:

    ID                      Description     Token                                                          User Name        User ID                 Permissions
    0fbe12e7d9695000                        hZgKmE_GBl9Kw0I0dSzQGGdC7Eub1JVq0peNCwanoAk_dYcCwZvh_Kb1Vte0e4-G2rJGO9k4eEtAEOQJaq4SuQ==        bigred          0fbe12de55e95000        [read:orgs/3013331d26241ede/authorizations write:orgs/3013331d26241ede/authorizations read:orgs/3013331d26241ede/buckets write:orgs/3013331d26241ede/buckets read:orgs/3013331d26241ede/dashboards write:orgs/3013331d26241ede/dashboards read:/orgs/3013331d26241ede read:orgs/3013331d26241ede/sources write:orgs/3013331d26241ede/sources read:orgs/3013331d26241ede/tasks write:orgs/3013331d26241ede/tasks read:orgs/3013331d26241ede/telegrafs write:orgs/3013331d26241ede/telegrafs read:/users/0fbe12de55e95000 write:/users/0fbe12de55e95000 read:orgs/3013331d26241ede/variables write:orgs/3013331d26241ede/variables read:orgs/3013331d26241ede/scrapers write:orgs/3013331d26241ede/scrapers read:orgs/3013331d26241ede/secrets write:orgs/3013331d26241ede/secrets read:orgs/3013331d26241ede/labels write:orgs/3013331d26241ede/labels read:orgs/3013331d26241ede/views write:orgs/3013331d26241ede/views read:orgs/3013331d26241ede/documents write:orgs/3013331d26241ede/documents read:orgs/3013331d26241ede/notificationRules write:orgs/3013331d26241ede/notificationRules read:orgs/3013331d26241ede/notificationEndpoints write:orgs/3013331d26241ede/notificationEndpoints read:orgs/3013331d26241ede/checks write:orgs/3013331d26241ede/checks read:orgs/3013331d26241ede/dbrp write:orgs/3013331d26241ede/dbrp read:orgs/3013331d26241ede/notebooks write:orgs/3013331d26241ede/notebooks read:orgs/3013331d26241ede/annotations write:orgs/3013331d26241ede/annotations read:orgs/3013331d26241ede/remotes write:orgs/3013331d26241ede/remotes read:orgs/3013331d26241ede/replications write:orgs/3013331d26241ede/replications]
  6. 設定 CLI 連線設定

    influx config create \
      --config-name myinfluxdb \
      --host-url http://influxdb.kubeantony.com:8086  \
      --org taroko \
      --token=$(influx auth list --json | jq -r '.[1].token')
  7. 分別建立多個 bucket

    influx bucket create --name linux
    influx bucket create --name windows
    influx bucket create --name solaris
    influx bucket create --name aix
  8. 幫以上這些 buckets 建立擁有可寫權限的 token

    influx auth create \
      --description "Write token for linux, windows, aix AND solaris buckets" \
      --write-bucket $(influx bucket list --name linux --json | jq -r '.[0].id') \
      --write-bucket $(influx bucket list --name windows --json | jq -r '.[0].id') \
      --write-bucket $(influx bucket list --name aix --json | jq -r '.[0].id') \
      --write-bucket $(influx bucket list --name solaris --json | jq -r '.[0].id')

    執行結果:

    ID                      Description                                             Token                  User Name        User ID                 Permissions
    0fbe16da13a95000        Write token for linux, windows, aix AND solaris buckets YNaFEzTRGd5MnzDerSDRvThgB854WtcmzVTF0x4fzzkYmTpQWtpQYmz3jrMkuEYhLM-oRjrsYev3fHCLpma6Xw==        bigred          0fbe12de55e95000[write:orgs/3013331d26241ede/buckets/65e7b5deacab7d4d write:orgs/3013331d26241ede/buckets/229921a56017d92d write:orgs/3013331d26241ede/buckets/ed048508752dc904 write:orgs/3013331d26241ede/buckets/92ddb41e878a8bec]
  9. 使用以上 token 透過 curl 指令往 buckets 寫入資料做測試

    curl --request POST \
    "http://influxdb.kubeantony.com:8086/api/v2/write?org=taroko&bucket=windows&precision=ns" \
      --header "Authorization: Token $(influx auth list --id 0fbe16da13a95000 --json | jq -r '.token')" \
      --header "Content-Type: text/plain; charset=utf-8" \
      --header "Accept: application/json" \
      --data-binary '
        airSensors,sensor_id=TLM0201 temperature=73.97038159354763,humidity=35.23103248356096,co=0.48445310567793615
        airSensors,sensor_id=TLM0202 temperature=75.30007505999716,humidity=35.651929918691714,co=0.5141876544505826
        '
  10. 確認有成功寫入

    influx query 'from(bucket: "windows")
      |> range(start: -1m)
      |> filter(fn: (r) => r._measurement == "airSensors")'

    執行結果:

    Result: _result
    Table: keys: [_start, _stop, _field, _measurement, sensor_id]
                       _start:time                      _stop:time           _field:string     _measurement:string        sensor_id:string                      _time:time                  _value:float
    ------------------------------  ------------------------------  ----------------------  ----------------------  ----------------------  ------------------------------  ----------------------------
    2025-11-03T06:37:18.367026238Z  2025-11-03T06:38:18.367026238Z                      co              airSensors                 TLM0201  2025-11-03T06:38:10.405809063Z           0.48445310567793615
    Table: keys: [_start, _stop, _field, _measurement, sensor_id]
                       _start:time                      _stop:time           _field:string     _measurement:string        sensor_id:string                      _time:time                  _value:float
    ------------------------------  ------------------------------  ----------------------  ----------------------  ----------------------  ------------------------------  ----------------------------
    2025-11-03T06:37:18.367026238Z  2025-11-03T06:38:18.367026238Z                humidity              airSensors                 TLM0201  2025-11-03T06:38:10.405809063Z             35.23103248356096
    Table: keys: [_start, _stop, _field, _measurement, sensor_id]
                       _start:time                      _stop:time           _field:string     _measurement:string        sensor_id:string                      _time:time                  _value:float
    ------------------------------  ------------------------------  ----------------------  ----------------------  ----------------------  ------------------------------  ----------------------------
    2025-11-03T06:37:18.367026238Z  2025-11-03T06:38:18.367026238Z             temperature              airSensors                 TLM0201  2025-11-03T06:38:10.405809063Z             73.97038159354763
    Table: keys: [_start, _stop, _field, _measurement, sensor_id]
                       _start:time                      _stop:time           _field:string     _measurement:string        sensor_id:string                      _time:time                  _value:float
    ------------------------------  ------------------------------  ----------------------  ----------------------  ----------------------  ------------------------------  ----------------------------
    2025-11-03T06:37:18.367026238Z  2025-11-03T06:38:18.367026238Z                      co              airSensors                 TLM0202  2025-11-03T06:38:10.405809063Z            0.5141876544505826
    Table: keys: [_start, _stop, _field, _measurement, sensor_id]
                       _start:time                      _stop:time           _field:string     _measurement:string        sensor_id:string                      _time:time                  _value:float
    ------------------------------  ------------------------------  ----------------------  ----------------------  ----------------------  ------------------------------  ----------------------------
    2025-11-03T06:37:18.367026238Z  2025-11-03T06:38:18.367026238Z                humidity              airSensors                 TLM0202  2025-11-03T06:38:10.405809063Z            35.651929918691714
    Table: keys: [_start, _stop, _field, _measurement, sensor_id]
                       _start:time                      _stop:time           _field:string     _measurement:string        sensor_id:string                      _time:time                  _value:float
    ------------------------------  ------------------------------  ----------------------  ----------------------  ----------------------  ------------------------------  ----------------------------
    2025-11-03T06:37:18.367026238Z  2025-11-03T06:38:18.367026238Z             temperature              airSensors                 TLM0202  2025-11-03T06:38:10.405809063Z             75.30007505999716
  11. 清除測試資料

    influx delete \
      --org taroko \
      --bucket windows \
      --start 1970-01-01T00:00:00Z \
      --stop 2030-01-01T00:00:00Z \
      --predicate '_measurement="airSensors"'
  12. 確認是否清除成功

    influx query 'from(bucket: "windows")
      |> range(start: -1m)
      |> filter(fn: (r) => r._measurement == "airSensors")'

    執行結果:

    應該要看到沒有任何螢幕輸出

6. 參考文件