Docker:docker安装操作InfluxDB时序数据库
= = = = = Docker安装InfluxDB时序数据库 = = = = =
1. 下载influxdb镜像
## 从DockerHub拉取镜像
docker pull tutum/influxdb:latest
2. 查询influxdb是否下载成功
# 查看镜像
docker images
3. 运行influxdb容器
#启动容器 开启8083、8086端口 docker run -p 8083:8083 -p 8086:8086 --name influxdb -td tutum/influxdb:latest
4. 查看容器运行状态
# 查看容器 docker ps
= = = = = Influx命令 = = = = =
1. 进入influxdb数据库
# 进入容器
docker exec -it influxdb bash
2. 查看influxdb路径
# 查看bin目录 cd /usr/bin # 查找influxdb数据操作命令 find | grep influx
3. 查看influx参数
# 查看influxdb操作参数
influx --help
4. 显示版本 -version
# 查看版本
influx -version
5. 连接指定主机 -host
# 本地连接数据库
influx -host localhost
6. 端口连接主机 -port
# 指定端口登录数据库 influx -host localhost -port 8086
7. 连接指定数据库 -database
# 指定数据库登录 influx -host localhost -port 8086 -database mydb
8. 配置用户名密码
# 登录数据库配置用户密码 influx -host localhost -port 8086 -database mydb # 指定数据库 show users # 创建用户赋予密码 create user "admin" with password '123456' # 查看用户表 show users
9. 指定的用户名和密码 -password -username
# 指定用户密码登录数据库 influx -host localhost -port 8086 -database mydb -username 'admin' -password '123456'
10. 执行一次命令并退出 -execute
# 登录执行一次命令后退出 influx -host localhost -port 8086 -database mydb -username 'admin' -password '123456' -execute 'select * from cpu_load_short'
11. 指定查询数据的显示格式 -format
# 指定查询数据的显示格式 influx -host localhost -port 8086 -database mydb -format json
12. 美化Json数据显示 -pretty
# 美化Json格式显示 influx -host localhost -port 8086 -database mydb -username 'admin' -password '123456' -execute 'select * from cpu_load_short' -format json -pretty
13. 时间戳精度显示设置 -precision
#数据显示时间戳的精度 influx -host localhost -port 8086 -database mydb -username 'admin' -password '123456' -execute 'select * from cpu_load_short' -format column -precision ms
14. 普通sql文件导入 -import
sql文件格式(分两部分 DDL:数据定义语言 DML:数据操作语言)后缀.txt文件
## 示例 [root@test25 ~]# cat dataarr.txt # DDL CREATE DATABASE pirates CREATE RETENTION POLICY oneday ON pirates DURATION 1d REPLICATION 1 # DML # CONTEXT-DATABASE: pirates # CONTEXT-RETENTION-POLICY: oneday treasures,captain_id=dread_pirate_roberts value=801 1536658695 treasures,captain_id=flint value=29 1536658695
导入操作
#导入sql文件 [root@test25 ~]# influx -import -path=dataarr.txt -precision=s 2018/09/11 17:40:39 Processed 2 commands 2018/09/11 17:40:39 Processed 2 inserts 2018/09/11 17:40:39 Failed 0 inserts
15. 压缩sql文件导入 -import -compressed
压缩sql文件
# 压缩sql文件 gzip dataarr.txt
导入操作
# 导入压缩sql文件
influx -import -path=dataarr.txt.gz -precision=s -compressed
= = = = = Influx数据库内部命令 = = = = =
1. 查看内部操作命令文档 help
# 数据库内部操作 [root@test25 ~]# influx Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > help
2. 新增、删除、权限赋予用户操作
# 查看所有用户 > show users user admin ---- ----- > # 创建一个root用户,设置密码为newpwd,主要不要使用双引号" 括起来,不然会报错 > create user "root" with password 'newpwd' > # 再次查看用户信息,发现admin为false,说明还要设置一下权限。 > show users user admin ---- ----- root false > # 删除root用户 > drop user root > > show users user admin ---- ----- > # 重新设置root用户,并设置带上所有权限 > create user "root" with password 'zh123456' with all privileges > # 发现admin权限为true,那么admin的用户就创建好了。 > show users user admin ---- ----- root true
3. 连接服务器并认证权限 connect auth
[root@test25 ~]# influx -database 'mydb' -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > connect localhost:8086 > auth username: admin password:
4. 显示配置信息 settings
# 查看数据库配置信息 [root@test25 ~]# influx -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > settings
5. 显示所有数据库 show databases
[root@test25 ~]# influx -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > show databases name: databases name ---- jmeter _internal test mydb pirates
6. 切换(指定)数据库 use
[root@test25 ~]# influx -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > use mydb Using database mydb
7. 显示所有指标(类似表) show measurements
[root@test25 ~]# influx -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > use mydb Using database mydb > show measurements name: measurements name ---- cpu_load_short
8. 显示所有标签(类似索引) show tag keys
[root@test25 ~]# influx -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > use mydb Using database mydb > show measurements name: measurements name ---- cpu_load_short > show tag keys name: cpu_load_short tagKey ------ direction host region
9. 显示表内所有字段
[root@test25 ~]# influx -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > use mydb Using database mydb > show measurements name: measurements name ---- cpu_load_short > show field keys from cpu_load_short name: cpu_load_short fieldKey fieldType -------- --------- age float blog string id float
10. 指定格式输出数据 format json
[root@test25 ~]# influx -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > format json > show databases {"results":[{"series":[{"name":"databases","columns":["name"],"values":[["jmeter"],["_internal"],["test"],["mydb"],["pirates"]]}]}]}
11. 美化Json数据显示 pretty
[root@test25 ~]# influx -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > pretty Pretty print enabled > show databases { "results": [ { "series": [ { "name": "databases", "columns": [ "name" ], "values": [ [ "jmeter" ], [ "_internal" ], [ "test" ], [ "mydb" ], [ "pirates" ] ] } ] } ] }
12. 显示执行命令历史 history
[root@test25 ~]# influx -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > history create database test show databases format json show databases pretty show databases
13. 查询语句 select
[root@test25 ~]# influx -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > use mydb Using database mydb > show measurements name: measurements name ---- cpu_load_short > select * from cpu_load_short name: cpu_load_short time direction host region value ---- --------- ---- ------ ----- 1422568543702900257 in server01 us-west 2 1422568543702900257 server02 us-west 0.55 1434055562000000000 server01 us-west 0.64 1536579271011551389 server02 0.67
14. 添加语句 insert
在InfluxDB的insert中,表名与数据之间用逗号(,)分隔; tag和field之间用 空格分隔; 多个tag或者多个field之间用逗号(,)分隔。
[root@test25 ~]# influx -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > use mydb Using database mydb > show measurements name: measurements name ---- cpu_load_short > INSERT treasures,captain_id=pirate_king value=2 > INSERT INTO autogen treasures,captain_id=pirate_king value=2
15. 删除语句(可删除measurement和database) drop
[root@test25 ~]# influx -host 'localhost' -port '8086' Connected to http://localhost:8086 version 1.6.1 InfluxDB shell version: 1.6.2 > show databases name: databases name ---- jmeter _internal test mydb pirates > use test Using database test > show measurements name: measurements name ---- disk_free > drop measurement disk_free > show measurements > drop database test > show databases name: databases name ---- jmeter _internal mydb pirates
文章整合至:https://blog.csdn.net/yue530tomtom/article/details/82625561、https://blog.csdn.net/lomodays207/article/details/109748284、
-----------------------------------
作者:怒吼的萝卜
链接:http://www.cnblogs.com/nhdlb/
-----------------------------------