InfluxDB 最新版本是 v2.x . 官方最新开源版本不支持集群,如果是单机部署则考虑最新的开源版本。

安装 InfluxDB

然后,安装并启动 InfluxDB 服务:

yum update
yum install -y wget curl tar gettext iptables
Red Hat && CentOS 使用 “yum” 安装

Red Hat 和 CentOS 用户可以使用yum包管理器安装最新稳定版本的 InfluxDB

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

将存储库添加到yum配置后,通过运行以下命令安装并启动 InfluxDB 服务:

sudo yum install influxdb
sudo service influxdb start

或者,如果您的操作系统使用的是 systemd(CentOS 7+、RHEL 7+):

sudo yum install influxdb
sudo systemctl start influxdb
SLES & openSUSE 使用 “zypper” 安装

openSUSE Build Service 为 SUSE Linux 用户提供了 RPM 包:

# add go repository
zypper ar -f obs://devel:languages:go/ go
# install latest influxdb
zypper in influxdb
FreeBSD/PC-BSD 使用 “pkg” 安装

InfluxDB 是 FreeBSD 包系统的一部分。它可以通过运行来安装:

sudo pkg install influxdb

配置文件位于 /usr/local/etc/influxd.conf 中, 可参考 /usr/local/etc/influxd.conf.sample

通过执行以下命令启动后端:

sudo service influxd onestart

要让 InfluxDB 在系统启动时启动,请添加influxd_enable="YES"/etc/rc.conf.

使用 Linux Binaries 方式安装
1、选择与你linux系统架构匹配的版本:

从浏览器 或 命令行 下载 InfluxDB 二进制文件。

注意:可先网页下载到本地,上传到 /usr/local/src 目录下,也可以使用 wget 下载;

从您的浏览器下载

从命令行下载

# amd64
cd /usr/local/src && wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.6.1-linux-amd64.tar.gz

# arm
cd /usr/local/src && wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.6.1-linux-arm64.tar.gz
2、解压并安装
amd64
$ cd /usr/local/src && tar xvzf influxdb2-2.6.1-linux-amd64.tar.gz -C /usr/local
$ cd .. && mv influxdb2_linux_amd64 influxdb
$ echo 'export INFLUXDB_HOME=/usr/local/influxdb/' >>/etc/profile
$ echo 'export PATH="$PATH:$INFLUXDB_HOME/bin"' >>/etc/profile
$ source /etc/profile
# (可选)将提取的influxd可执行二进制文件放入您的系统中$PATH
$ ln -s /usr/local/influxdb/influxd /usr/bin/influxd;
arm
# 本地安装包
$ cd /usr/local/src && tar xvzf influxdb2-2.6.1-linux-arm64.tar.gz -C /usr/local
$ cd .. && mv influxdb2_linux_amd64 influxdb
$ echo 'export INFLUXDB_HOME=/usr/local/influxdb/' >>/etc/profile
$ echo 'export PATH="$PATH:$INFLUXDB_HOME/bin"' >>/etc/profile
$ source /etc/profile
# (可选)将提取的influxd可执行二进制文件放入您的系统中$PATH
$ ln -s /usr/local/influxdb/influxd /usr/bin/influxd;

2、配置 InfluxDB

InfluxDB 配置选项

influxd 通过使用配置标志、设置环境变量或在配置文件中定义配置选项来自定义您的 InfluxDB 配置。

查看您的运行时服务器配置

使用influxCLI 或 InfluxDB API 获取 InfluxDB 实例的运行时服务器配置。

服务器配置命令需要操作员令牌。

使用 CLI 查看服务器配置

使用influx server-config命令 检索您的运行时服务器配置。

influx server-config
使用 API 查看您的服务器配置

使用/api/v2/configInfluxDB API 端点检索您的运行时服务器配置。

获取 http://localhost:8086/api/v2/config
配置优先级

InfluxDB 使用以下优先级遵循配置设置:

  1. influxd flag
  2. 环境变量
  3. 配置文件设置
InfluxDB 配置文件

启动时 influxd,它会检查在当前工作目录中以 config.* 命名的文件。文件扩展名取决于配置文件的语法。InfluxDB 配置文件支持以下语法:

  • YAML (.yaml, .yml)
  • TOML (.toml)
  • JSON (.json)

要自定义配置文件的目录路径,请将INFLUXD_CONFIG_PATH 环境变量设置为您的自定义路径。

$ echo 'export INFLUXD_CONFIG_PATH=/usr/local/influxdb' >>/etc/profile
$ source /etc/profile
示例配置文件

YAML

vi /usr/local/influxdb/config.yaml
query-concurrency: 20
query-queue-size: 15
secret-store: vault
session-length: 120
tls-cert: /path/to/influxdb.crt
tls-key: /path/to/influxdb.key

TOML

query-concurrency = 20
query-queue-size = 15
secret-store = "vault"
session-length = 120
tls-cert = "/path/to/influxdb.crt"
tls-key = "/path/to/influxdb.key"

JSON

{
  "query-concurrency": 20,
  "query-queue-size": 15,
  "secret-store": "vault",
  "session-length": 120,
  "tls-cert": "/path/to/influxdb.crt",
  "tls-key": "/path/to/influxdb.key"
}
3、启动 InfluxDB

如果 InfluxDB 作为 systemd 服务安装,则 systemd 管理influxd守护进程,不需要进一步的操作。如果二进制文件是手动下载并添加到系统中的,请使用以下命令$PATH启动守护进程:influxd

[root@localhost local]# influxd
2023-02-08T08:40:26.285251Z     info    Welcome to InfluxDB     {"log_id": "0ft2mDg0000", "version": "v2.6.1", "commit": "9dcf880fe0", "build_date": "2022-12-29T15:53:07Z", "log_level": "info"}
2023-02-08T08:40:26.326574Z     info    Resources opened        {"log_id": "0ft2mDg0000", "service": "bolt", "path": "/root/.influxdbv2/influxd.bolt"}
2023-02-08T08:40:26.326708Z     info    Resources opened        {"log_id": "0ft2mDg0000", "service": "sqlite", "path": "/root/.influxdbv2/influxd.sqlite"}
2023-02-08T08:40:26.338018Z     info    Bringing up metadata migrations {"log_id": "0ft2mDg0000", "service": "KV migrations", "migration_count": 20}
2023-02-08T08:40:27.847882Z     info    Bringing up metadata migrations {"log_id": "0ft2mDg0000", "service": "SQL migrations", "migration_count": 8}
2023-02-08T08:40:28.143999Z     info    Using data dir  {"log_id": "0ft2mDg0000", "service": "storage-engine", "service": "store", "path": "/root/.influxdbv2/engine/data"}
2023-02-08T08:40:28.144207Z     info    Compaction settings     {"log_id": "0ft2mDg0000", "service": "storage-engine", "service": "store", "max_concurrent_compactions": 4, "throughput_bytes_per_second": 50331648, "throughput_bytes_per_second_burst": 50331648}
2023-02-08T08:40:28.144291Z     info    Open store (start)      {"log_id": "0ft2mDg0000", "service": "storage-engine", "service": "store", "op_name": "tsdb_open", "op_event": "start"}
2023-02-08T08:40:28.144402Z     info    Open store (end)        {"log_id": "0ft2mDg0000", "service": "storage-engine", "service": "store", "op_name": "tsdb_open", "op_event": "end", "op_elapsed": "0.127ms"}
2023-02-08T08:40:28.144468Z     info    Starting retention policy enforcement service   {"log_id": "0ft2mDg0000", "service": "retention", "check_interval": "30m"}
2023-02-08T08:40:28.144499Z     info    Starting precreation service    {"log_id": "0ft2mDg0000", "service": "shard-precreation", "check_interval": "10m", "advance_period": "30m"}
2023-02-08T08:40:28.146053Z     info    Starting query controller       {"log_id": "0ft2mDg0000", "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}
2023-02-08T08:40:28.150441Z     info    Configuring InfluxQL statement executor (zeros indicate unlimited).     {"log_id": "0ft2mDg0000", "max_select_point": 0, "max_select_series": 0, "max_select_buckets": 0}
2023-02-08T08:40:28.191576Z     info    Starting        {"log_id": "0ft2mDg0000", "service": "telemetry", "interval": "8h"}
2023-02-08T08:40:28.194039Z     info    Listening       {"log_id": "0ft2mDg0000", "service": "tcp-listener", "transport": "http", "addr": ":8086", "port": 8086}
4、开机自启动

创建专用的数据存储目录

mkdir -p /data/influxdb/data;
mkdir -p /data/influxdb/meta;
mkdir -p /data/influxdb/wal;
mkdir -p /data/influxdb/logs;
mkdir -p /usr/lib/influxdb/scripts;

创建 influxdb:influxdb 用户组和用户(安装程序自动安装的,默认创建了 influxdb 用户组和 influxdb 用户),并进行授权:

groupadd influxdb;
useradd -g influxdb -M -s /sbin/nologin influxdb;
chown -R influxdb. /data/influxdb;

创建开机启动脚本(来自官方程序安装后的文件):

influxdb.service

vi /lib/systemd/system/influxdb.service

脚本内容:

[Unit]
Description=InfluxDB is an open-source, distributed, time series database
Documentation=https://docs.influxdata.com/influxdb/
After=network.target remote-fs.target nss-lookup.target

[Service]
PIDFile=/var/lib/influxdb/influxd.pid
ExecStart=/usr/local/influxdb/influxd > /data/influxdb/logs/influxdb.log 2>&1 &
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
LimitNOFILE=65536
Restart=0

[Install]
WantedBy=multi-user.target
Alias=influxd.service

设置随机启动:

[root@local ~]# systemctl daemon-reload
[root@local ~]# systemctl disable influxdb.service
[root@local ~]# systemctl enable influxdb.service
[root@local ~]# systemctl start influxdb.service
[root@local ~]# systemctl status influxdb.service
[root@local ~]# systemctl stop influxdb.service
[root@local ~]# systemctl restart influxdb.service

端口: InfluxDB 通过端口 808880898091 进行通信。

一定要确保端口放开,或者直接关闭防火墙,否则后续一定会出现错误。

# CentOS
firewall-cmd --zone=public --add-port=8086/tcp --permanent;
firewall-cmd --zone=public --add-port=8088/tcp --permanent;
firewall-cmd --zone=public --add-port=8089/tcp --permanent;
firewall-cmd --zone=public --add-port=8091/tcp --permanent;

iptables -I INPUT -m tcp -p tcp --dport 8086 -j ACCEPT;
iptables -I INPUT -m tcp -p tcp --dport 8088 -j ACCEPT;
iptables -I INPUT -m tcp -p tcp --dport 8089 -j ACCEPT;
iptables -I INPUT -m tcp -p tcp --dport 8091 -j ACCEPT;

浏览器访问数据库管理平台:

http://[IP]:8086/

安装 influx CLI(可选)

使用influxCLI 与 InfluxDB 实例交互并对其进行管理。编写和查询数据、生成 InfluxDB 模板、导出数据等。

1、下载 influx CLI 包。

从 浏览器 或命令行下载influxCLI 包。

注意:可先网页下载到本地,上传到 /usr/local/src 目录下,也可以使用 wget 下载;

从您的浏览器下载

从命令行下载

# amd64
wget https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.6.1-linux-amd64.tar.gz

# arm
wget https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.6.1-linux-arm64.tar.gz
2、解压并安装
amd64
$ cd /usr/local/src && tar xvzf influxdb2-client-2.6.1-linux-amd64.tar.gz -C /usr/local
$ cd .. && mv influxdb2-client-2.6.1-linux-amd64 influxdb2-client
$ echo 'export INFLUXDB_HOME=/usr/local/influxdb2-client/' >>/etc/profile
$ echo 'export PATH="$PATH:$INFLUXDB_HOME/bin"' >>/etc/profile
$ source /etc/profile
# (可选)将提取的influxd可执行二进制文件放入您的系统中$PATH
$ sudo cp influxdb2-client/influx /usr/local/bin/
arm
$ cd /usr/local/src && tar xvzf influxdb2-client-2.6.1-linux-arm64.tar.gz -C /usr/local
$ cd .. && mv influxdb2-client-2.6.1-linux-arm64 influxdb2-client
$ echo 'export INFLUXDB_HOME=/usr/local/influxdb2-client/' >>/etc/profile
$ echo 'export PATH="$PATH:$INFLUXDB_HOME/bin"' >>/etc/profile
$ source /etc/profile
# (可选)将提取的influxd可执行二进制文件放入您的系统中$PATH
$ sudo cp influxdb2-client/influx /usr/local/bin/

配置完成后命令行执行 influx 查看命令情况

[root@localhost local]# influx
NAME:
   influx - Influx Client

USAGE:
   influx [command]

HINT: If you are looking for the InfluxQL shell from 1.x, run "influx v1 shell"

COMMANDS:
   version              Print the influx CLI version
   write                Write points to InfluxDB
   bucket               Bucket management commands
   completion           Generates completion scripts
   query                Execute a Flux query
   config               Config management commands
   org, organization    Organization management commands
   delete               Delete points from InfluxDB
   user                 User management commands
   task                 Task management commands
   telegrafs            List Telegraf configuration(s). Subcommands manage Teleg                                                                                             raf configurations.
   dashboards           List Dashboard(s).
   export               Export existing resources as a template
   secret               Secret management commands
   v1                   InfluxDB v1 management commands
   auth, authorization  Authorization management commands
   apply                Apply a template to manage resources
   stacks               List stack(s) and associated templates. Subcommands mana                                                                                             ge stacks.
   template             Summarize the provided template
   bucket-schema        Bucket schema management commands
   scripts              Scripts management commands
   ping                 Check the InfluxDB /health endpoint
   setup                Setup instance with initial user, org, bucket
   backup               Backup database
   restore              Restores a backup directory to InfluxDB
   remote               Remote connection management commands
   replication          Replication stream management commands
   server-config        Display server config
   help, h              Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h  show help

通过 UI 设置 InfluxDB

在 InfluxDB 运行的情况下,访问 http://localhost:8086

  1. 点击开始

  1. 设置您的初始用户

  1. 输入初始用户的用户名。
  2. 为您的用户输入密码和确认密码。
  3. 输入您的初始组织名称。
  4. 输入您的初始Bucket Name。
  5. 单击继续。

  1. 您的 InfluxDB 实例现已初始化。
Username : "influxdb"
Password : "SsFhNK6BQqhVCjg"
Initial Organization Name : test
Initial Bucket Name:telegraf

cSwrqv6ztcCEmTB7ETbvnGeG-hrRv58UAiuRY7tTQmhS_Y5l4ETWPxb-NZD5oden4rLDBt7u11dyvkgyJhuLvA==

作者:Jeebiz  创建时间:2023-02-21 13:13
最后编辑:Jeebiz  更新时间:2024-11-01 12:19