Ubuntu 上安装 InfluxDB 2.0

更新日期: 2022-08-18 阅读次数: 10047 字数: 653 分类: InfluxDB

环境

Ubuntu 20.04 WSL 开发环境

下载并安装 InfluxDB

到官方下载页:

https://portal.influxdata.com/downloads/

选择版本,及平台类型。例如,我这里选的就是 Ubuntu & Debian:

wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.0.7-amd64.deb
sudo dpkg -i influxdb2-2.0.7-amd64.deb

输出信息中,可以看到自动创建了 systemd 的配置:

Created symlink /etc/systemd/system/influxd.service → /lib/systemd/system/influxdb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/influxdb.service → /lib/systemd/system/influxdb.service.

启动服务

> sudo service influxdb start
influxdb: unrecognized service

估计是 WSL1 不支持 systemd。

> which influxd
/usr/bin/influxd

可以看到,实际上有 influxd 的启动命令,可以直接执行。

所以在 WSL 上就将就一下吧

influxd

需要等待一会,才能看到日志输出,很奇葩的是,日志是 JSON 格式。。。

例如:

2021-06-09T07:53:34.035380Z     info    Welcome to InfluxDB     {"log_id": "0Ucx28Kl000", "version": "2.0.7", "commit": "2a45f0c037", "build_date": "2021-06-04T19:17:40Z"}
2021-06-09T07:53:34.045015Z     info    Resources opened        {"log_id": "0Ucx28Kl000", "service": "bolt", "path": "/home/zhongwei/.influxdbv2/influxd.bolt"}

如果是 Ubuntu 服务器,还是用 systemd 启动吧。

存储路径

按照文档的说明,influxdb 的存储路径有以下三个:

When installed as a service, InfluxDB stores data in the following locations:

Time series data: /var/lib/influxdb/engine/
Key-value data: /var/lib/influxdb/influxd.bolt.
influx CLI configurations: ~/.influxdbv2/configs (see influx config for more information) .

而直接运行 influxd 命令,按照提示,会看到存储路径是在用户目录下:

> tree ~/.influxdbv2/
/home/zhongwei/.influxdbv2/
├── engine
│   └── data
└── influxd.bolt

使用 influx 命令进行配置

设置管理员,及数据库信息。

> which influx
/usr/bin/influx

执行 influx setup:

> influx setup

Welcome to InfluxDB 2.0!
Please type your primary username: zhongwei

Please type your password:

Please type your password again:

Please type your primary organization name: sunzhongwei.com

Please type your primary bucket name: oxygen

Please type your retention period in hours.
Or press ENTER for infinite:


You have entered:
  Username:          zhongwei
  Organization:      sunzhongwei.com
  Bucket:            oxygen
  Retention Period:  infinite
Confirm? (y/n): y

Config default has been stored in /home/zhongwei/.influxdbv2/configs.
User            Organization    Bucket
zhongwei        sunzhongwei.com oxygen

其中 retention period 的配置,得了解一下。

web 管理界面

InfluxDB 默认自带了一个 web 管理后台,地址:

http://localhost:8086/

使用上面创建的账号,密码即可登录。

如果是线上服务器,由于腾讯云的服务器默认没有防火墙规则,所以可以直接通过 IP 或者域名访问; 如果是阿里云,需要手动开一下端口。

如何从命令行获取 influx token

Create an API token with read and write permissions
influx auth create -o 组织名 \
  --read-buckets \
  --read-checks \
  --read-dashboards \
  --read-dbrps \
  --read-notificationEndpoints \
  --read-notificationRules \
  --read-orgs \
  --read-tasks \
  --read-telegrafs \
  --read-user \
  --write-buckets \
  --write-checks \
  --write-dashboards \
  --write-dbrps \
  --write-notificationEndpoints \
  --write-notificationRules \
  --write-orgs \
  --write-tasks \
  --write-telegrafs \
  --write-user

参考:

https://docs.influxdata.com/influxdb/cloud/security/tokens/create-token/#create-a-token-using-the-influx-cli

InfluxDB OSS 是什么

InfluxDB OSS 是 InfluxDB Open Source 的缩写。相对的,还有一个 Cloud 版本。

参考

https://docs.influxdata.com/influxdb/v2.0/install/?t=Linux

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式