Docker安装InfluxDB_用户名密码和策略使用

Docker安装InfluxDB

InfluxDB和IotDB介绍与性能对比

Centos7离线安装Docker

InfluxDB官方下载地址

#先不启用密码验证, 创建用户和密码,启动后进入创建好用户和密码后,修改auth-enabled = true 重启容器生效,就必须要用户和密码

docker pull influxdb

docker run -d --name my-influxdb \
-p 8086:8086 \
-p 8083:8083 \
-p 2003:2003 \
-e INFLUXDB_GRAPHITE_ENABLED=true \
-v /data/influxdb/conf/influxdb.conf:/etc/influxdb/influxdb.conf \
-v /data/influxdb:/var/lib/influxdb \
-v /etc/localtime:/etc/localtime \
influxdb

#进入容器
docker exec -it my-influxdb /bin/bash
输入 influx
#创建用户和密码
create user "admin" with password 'admin' with all privileges
create user "admin" with password 'beyond_2021' with all privileges

auth admin admin 登录

show databases; 展示数据库

create database demo 创建表
#默认是不用用户密码的, 是否开启认证,默认值:false
cat /data/influxdb/conf/influxdb.conf 
[meta]
  dir = "/var/lib/influxdb/meta"

[data]
  dir = "/var/lib/influxdb/data"
  engine = "tsm1"
  wal-dir = "/var/lib/influxdb/wal"

[http]
  auth-enabled = false
#容器外面执行命令
curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE testdb"

curl -XPOST http://localhost:8086/query --data-urlencode "q=create user "admin123" with password 'admin123' with all privileges"

./influx -database 'testdb' -execute 'auth admin123 admin123'

./influx -database 'testdb' -execute 'auth admin123 admin123'

show users; 启用用户密码后,会报错

输入 influx -username 'admin' -password 'beyond_2021'

保存策略

show retention policies on test 显示test数据库策略 如果没有指定策略默认是autogen

对test数据库创建一个策略,2小时之前数据删除,一个副本,设置为默认策略
create retention policy "abc" on "test" duration 2h replication 1 default

10天前数据删除  比如:h(小时),w(星期)
create retention policy "rp_10d" on "testdata" duration 10d replication 1 default

修改默认策略
alter retention policy "autogen" on "demo" duration 10d replication 1 default

alter retention policy "autogen" on "demo" duration 15d replication 1 default

修改策略
alter retention policy "rp_10d" ON "demo" duration 10d replication 1 default

插入数据不指定策略,按默认策略保存
insert into devops,host=server01 cpu=23.1,mem=0.61

指定策略保存数据
insert into "autogen" devops,host=server01 cpu=23.1,mem=0.71

查询时不指定策略,按默认策略查询
select * from "devdata"

指定策略查询数据
select * from "autogen"."devdata"

show tag keys from 表名

show field keys from 表名

修改容器时区

docker exec -it my-influxdb /bin/bash

date 查看时区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

修改后查看 date

你可能感兴趣的:(docker,docker,容器,influxdb)