InfluxDB 提供了客户端 influx 用于管理数据库。自2.1版本,客户端influx就和服务端influxd分离开了,需要单独安装。安装方法非常检查,解压缩复制到到/user/bin 下面即可。
在1.x版本中客户端支持SQL语句,但在2.x版本中,已经不支持SQL语法了。这对熟悉关系型数据库的人来说不太友好。
官方文档:https://docs.influxdata.com/influxdb/v2.2/reference/cli/influx/
1.客户端初始化
InfluxDB 服务端启动后,使用Influx CLI 进行初始化(使用web管理界面操作更加方便,http://IP:port ,默认端口8086,我在配置文件将端口修改成了8080,配置方法见: InfluxDB 参数详解)。
依次输入:用户名、密码、组织名称、桶名称、数据保存时间(过期自动删除,0表示永久保存)。
复制
#influx setup --host http://localhost:8080
> Welcome to InfluxDB 2.0!
? Please type your primary username admin
? Please type your password *********
? Please type your password again *********
? Please type your primary organization name test
? Please type your primary bucket name db01
? Please type your retention period in hours, or 0 for infinite 0
? Setup with these parameters?
Username: admin
Organization: test
Bucket: db01
Retention Period: infinite
Yes
User Organization Bucket
admin test db01
查看当前客户端配置
#influx config
Active Name URL Org
* default http://localhost:8080 test
创建 Token,Token 在以后的操作中非常必要。
#influx auth create -o test --all-access
2.数据写入
准备写入第一条数据,数据规划如下:
influx write \
-b db01 \
-o test \
-p s \
't01,building=boli,floor=702a temp=24.5 1651036342'
3.数据查询
查询刚才写入的数据
influx query 'from(bucket: "db01")
|> range(start: -60h)
|> filter(fn: (r) => r._measurement == "t01" and r.building == "boli" and r.floor=="702a")
|> filter(fn: (r) => r._field == "temp")'
#influx query 'from(bucket: "test")
4.备份恢复
备份恢复需要admin 用户token,在第一步创建过了。
4.1.备份数据库
influx backup /data/dump/ -t dK-GjQBMFVBw_cjaxhI7ekuGi3ouJ8FkJ1plEE39iOHnqRedZuTXCy96jQhqOEa1Rdb9A5jEin-GxKDsp7DbWw==
4.2.恢复数据库
influx restore /data/dump/ -t dK-GjQBMFVBw_cjaxhI7ekuGi3ouJ8FkJ1plEE39iOHnqRedZuTXCy96jQhqOEa1Rdb9A5jEin-GxKDsp7DbWw==
4.2.恢复数据库
influx restore /data/dump/ -t dK-GjQBMFVBw_cjaxhI7ekuGi3ouJ8FkJ1plEE39iOHnqRedZuTXCy96jQhqOEa1Rdb9A5jEin-GxKDsp7DbWw==
##恢复指定bucket
influx restore /data/dump/ --bucket db01 -t dK-GjQBMFVBw_cjaxhI7ekuGi3ouJ8FkJ1plEE39iOHnqRedZuTXCy96jQhqOEa1Rdb9A5jEin-GxKDsp7DbWw==
5.用户管理
5.1.用户创建
为组织test创建用户billy,密码 Passw0rd
#influx user create -n billy -p 'Passw0rd' -o test
ID Name
09476ebecfe24000 billy
查看当前用户
# influx user list
ID Name
094769346d624000 admin
09476ebecfe24000 billy
5.2.修改密码
#influx user password -n billy
? Please type new password for "billy" *********
? Please type new password for "billy" again *********
Successfully updated password for user "billy"
5.3.删除用户
WEB管理界面无法删除用户,只能通过CLI来进行。删除用户只能通过user-id来完成。
6.数据库管理
InfluxDB中没有Database,只有Organization 和 Bucket。用关系库的理解,Organization 对应数据库示例,Bucket对应Database
6.1.Org管理
##创建org
# influx org create -n db02
ID Name
4e4317920dba2bb5 db02
# influx org list
ID Name
4e4317920dba2bb5 db02
d781e1ab6a34faad test
##重命名org
# influx org update -i 4e4317920dba2bb5 -n test2
ID Name
4e4317920dba2bb5 test2
# influx org list
ID Name
4e4317920dba2bb5 test2
d781e1ab6a34faad test
##删除org
# influx org delete -i 4e4317920dba2bb5
ID Name Deleted
4e4317920dba2bb5 test2 true
# influx org list
ID Name
d781e1ab6a34faad test
6.2.Bucket管理
##创建bucket
# influx bucket create -n db02 -o test -r 1w
ID Name Retention Shard group duration Organization ID Schema Type
e6e6f7ae16812784 db02 168h0m0s 24h0m0s d781e1ab6a34faad implicit
# influx bucket list -o test
ID Name Retention Shard group duration Organization ID Schema Type
74091a2d2a220be1 _monitoring 168h0m0s 24h0m0s d781e1ab6a34faad implicit
5175f85981b38eef _tasks 72h0m0s 24h0m0s d781e1ab6a34faad implicit
493461b293cb9760 db01 infinite 168h0m0s d781e1ab6a34faad implicit
e6e6f7ae16812784 db02 168h0m0s 24h0m0s d781e1ab6a34faad implicit
##重命名bucket
# influx bucket update -i e6e6f7ae16812784 -n db03 -r 2w
ID Name Retention Shard group duration Organization ID Schema Type
e6e6f7ae16812784 db03 336h0m0s 24h0m0s d781e1ab6a34faad implicit
# influx bucket list -o test
ID Name Retention Shard group duration Organization ID Schema Type
74091a2d2a220be1 _monitoring 168h0m0s 24h0m0s d781e1ab6a34faad implicit
5175f85981b38eef _tasks 72h0m0s 24h0m0s d781e1ab6a34faad implicit
493461b293cb9760 db01 infinite 168h0m0s d781e1ab6a34faad implicit
e6e6f7ae16812784 db03 336h0m0s 24h0m0s d781e1ab6a34faad implicit
##删除bucket
# influx bucket delete -n db03 -o test
ID Name Retention Shard group duration Organization ID Schema Type Deleted
e6e6f7ae16812784 db03 336h0m0s 24h0m0s d781e1ab6a34faad implicit true
# influx bucket list -o test
ID Name Retention Shard group duration Organization ID Schema Type
74091a2d2a220be1 _monitoring 168h0m0s 24h0m0s d781e1ab6a34faad implicit
5175f85981b38eef _tasks 72h0m0s 24h0m0s d781e1ab6a34faad implicit
493461b293cb9760 db01 infinite 168h0m0s d781e1ab6a34faad implicit
Influx 命令汇总
转载连接:https://blog.51cto.com/dbadadong/5270370
标签:bucket,InfluxDB,Organization,d781e1ab6a34faad,test,操作,24h0m0s,influx,客户端 From: https://www.cnblogs.com/lvjinlin/p/18158078