• 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 创建表
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    #默认是不用用户密码的, 是否开启认证,默认值: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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    #容器外面执行命令
    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'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    保存策略

    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 表名
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    修改容器时区

    docker exec -it my-influxdb /bin/bash
    
    date 查看时区
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    
    修改后查看 date
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 相关阅读:
    【JAVA并发】二、JAVA是如何解决并发问题的
    Linux.14_多线程(重点总结)
    Python:实现logistic regression逻辑回归算法(附完整源码)
    实用新型专利的注意事项
    Rt-Thread 4-线程
    vue3后台管理系统之路由守卫
    17. Spring类型转换之PropertyEditor
    HDC2022的无障碍参会体验,手语服务是如何做到的?
    cpp编写的tcpserver,python编写的tcpclient,使用自定义的通讯协议
    k8s基础
  • 原文地址:https://blog.csdn.net/yinjl123/article/details/133470609