• 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
  • 相关阅读:
    详解:飞讯是如何助力集团型制造企业实现数字化转型的
    计算机网络必须知道的点
    C#使用DataTable的Select方法来选择特定的字段
    计算机视觉40例之案例05物体计数
    如何修复损坏的excel文件?
    最新区块链论文录用资讯CCF B—DSN 2024 共8篇
    C语言每日一题
    String类的详解
    2.0SpringMVC中文件上传、拦截器和异常处理器
    trino tpcds测试
  • 原文地址:https://blog.csdn.net/yinjl123/article/details/133470609