Windows上安装
1、在InfluxDB官网中获取InfluxDB 3 Core 压缩包,并解压到目录(D:\influxDB\influxdb3-core-3.1.0-windows_amd64)下;
2、使用 influxdb3 serve 命令来启动服务器,并可以通过参数指定对象存储类型和数据目录。以下命令需在解压目录下运行:
.\influxdb3.exe serve --object-store file --node-id mywindowsnode --data-dir "D:\influxdb3\data"
参数解释:
- object-store file: 指定使用本地文件系统作为对象存储。这是默认选项,但明确指出总是个好习惯。
- node-id <你的节点ID>: 为你的InfluxDB节点指定一个唯一的ID,例如 mynode 或 win11node。
- data-dir "<你的数据目录>": 指定数据存储的目录
3、创建管理员令牌 (Admin Token):
在你启动InfluxDB 3服务器之后,你就可以创建管理员令牌了。管理员令牌拥有对InfluxDB 3实例所有操作的最高权限。
打开一个新的命令提示符 (CMD) 或 PowerShell 窗口(不要关闭正在运行服务器的那个窗口),运行一下命令:
cd D:\influxDB\influxdb3-core-3.1.0-windows_amd64
.\influxdb3.exe create token --admin --host http://localhost:8181
--admin
:表示你正在创建一个管理员级别的令牌;
--host http://localhost:8181
:指定了InfluxDB服务器正在监听的地址和端口。如果你的服务器运行在其他地址或端口,请相应修改。
复制该令牌,保存在一个安全的地方,此令牌只显示一次。
4、创建数据库
在安装目录下(D:\influxDB\influxdb3-core-3.1.0-windows_amd64> )运行以下命令:
influxdb3 create database test --token YOUR_AUTH_TOKEN
将以上命令中的YOUR_AUTH_TOKEN替换为第3步中生成的
Admin Token;
上述命令中的test为创建的新的数据库的名称(更具实际需要修改数据库名称);
5、写入数据到数据库
influxdb3 write --database test --token YOUR_AUTH_TOKEN
--precision s 'home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1641024000
home,room=Kitchen temp=21.0,hum=35.9,co=0i 1641024000
home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1641027600
home,room=Kitchen temp=23.0,hum=36.2,co=0i 1641027600
home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1641031200
home,room=Kitchen temp=22.7,hum=36.1,co=0i 1641031200
home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1641034800
home,room=Kitchen temp=22.4,hum=36.0,co=0i 1641034800
home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1641038400
home,room=Kitchen temp=22.5,hum=36.0,co=0i 1641038400
home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1641042000
home,room=Kitchen temp=22.8,hum=36.5,co=1i 1641042000
home,room=Living\ Room temp=22.3,hum=36.1,co=0i 1641045600
home,room=Kitchen temp=22.8,hum=36.3,co=1i 1641045600
home,room=Living\ Room temp=22.3,hum=36.1,co=1i 1641049200
home,room=Kitchen temp=22.7,hum=36.2,co=3i 1641049200
home,room=Living\ Room temp=22.4,hum=36.0,co=4i 1641052800
home,room=Kitchen temp=22.4,hum=36.0,co=7i 1641052800
home,room=Living\ Room temp=22.6,hum=35.9,co=5i 1641056400
home,room=Kitchen temp=22.7,hum=36.0,co=9i 1641056400
home,room=Living\ Room temp=22.8,hum=36.2,co=9i 1641060000
home,room=Kitchen temp=23.3,hum=36.9,co=18i 1641060000
home,room=Living\ Room temp=22.5,hum=36.3,co=14i 1641063600
home,room=Kitchen temp=23.1,hum=36.6,co=22i 1641063600
home,room=Living\ Room temp=22.2,hum=36.4,co=17i 1641067200
home,room=Kitchen temp=22.7,hum=36.5,co=26i 1641067200'
6、从数据库查询数据
influxdb3 query --database test "SELECT * FROM home ORDER BY time" --token YOUR_AUTH_TOKE