zoukankan      html  css  js  c++  java
  • [InfluxDB] 安装与配置

    [InfluxDB] 安装与配置

    1- 下载

    ubtuntu:

    wget https://dl.influxdata.com/influxdb/releases/influxdb_1.5.2_amd64.deb
    sudo dpkg -i influxdb_1.5.2_amd64.deb
    

    centos

    wget https://dl.influxdata.com/influxdb/releases/influxdb-1.5.2.x86_64.rpm
    sudo yum localinstall influxdb-1.5.2.x86_64.rpm
    

    2 - 配置

    安装后, 在/usr/bin下面有如下文件:

    influxd          influxdb服务器
    influx           influxdb命令行客户端
    influx_inspect   查看工具
    influx_stress    压力测试工具
    influx_tsm       数据库转换工具(将数据库从b1或bz1格式转换为tsm1格式)
    

    /var/lib/influxdb/下面会有如下文件夹:

    data            存放最终存储的数据,文件以.tsm结尾
    meta            存放数据库元数据
    wal             存放预写日志文件
    

    配置文件路径 :/etc/influxdb/influxdb.conf

    3 - 启动

    以服务方式启动

    sudo service influxdb start
    # or
    sudo systemctl start influxdb
    

    以非服务方式启动

    influxd
    

    需要指定配置文件的话,可以使用 --config 选项,具体可以help下看看。

    4 - 基本操作

    • 数据库与表的操作
      可以直接在web管理页面, 也可以用命令行。
    #创建数据库
    create database "db_name"
    #显示所有的数据库
    show databases
    #删除数据库
    drop database "db_name"
    #使用数据库
    use db_name
    #显示该数据库中所有的表
    show measurements
    #创建表,直接在插入数据的时候指定表名
    insert test,host=127.0.0.1,monitor_name=test count=1
    #删除表
    drop measurement "measurement_name"
    

    向数据库插入数据

    命令行:

    use testDb
    insert test,host=127.0.0.1,monitor_name=test count=1
    

    HTTP接口:

    curl -i -XPOST 'http://127.0.0.1:8086/write?db=testDb' --data-binary 'test,host=127.0.0.1,monitor_name=test count=1'
    

    Line Protocol格式:写入数据库的Point的固定格式。在上面的两种插入数据的方法中都有这样的一部分:

    test,host=127.0.0.1,monitor_name=test count=1
    

    其中:

    1. test:表名;
    2. host=127.0.0.1,monitor_name=test:tag;
    3. count=1:field

    命令行:

    select * from test order by time desc
    

    HTTP:

    curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=testDb" --data-urlencode "q=select * from test order by time desc"
    

    5 - 数据保存策略(Retention Policies)

    influxDB是没有提供直接删除数据记录的方法,但是提供数据保存策略,主要用于指定数据保留时间,超过指定时间,就删除这部分数据。

    查看当前数据库Retention Policies:

    show retention policies on "db_name"
    

    创建新的Retention Policies:

    create retention policy "rp_name" on "db_name" duration 3w replication 1 default
    
    CREATE RETENTION POLICY "tlv_hours" ON "coins" DURATION 12h REPLICATION 1 DEFAULT
    

    修改Retention Policies:

    alter retention policy "rp_name" on "db_name" duration 30d default
    

    删除Retention Policies:

    drop retention policy "rp_name"
    

    6 - 连续查询(Continous Queries)

    当数据超过保存策略里指定的时间之后就会被删除,但是这时候可能并不想数据被完全删掉,怎么办?
    influxdb提供了联系查询,可以做数据统计采样。

    查看数据库的Continous Queries:

    show continuous queries
    

    创建新的Continous Queries:

    create continous query cq_name on db_name begin select sum(count) into new_table_name from table_name group by time(30m) end
    

    删除Continous Queries:

    drop continous query cp_name on db_name
    

    8 - Web 页面

    在1.5版本, Influxdb添加了 Chronograf 组件作为web管理端。
    Chronograf下载与安装:

    # centos
    wget https://dl.influxdata.com/chronograf/releases/chronograf-1.4.4.1.x86_64.rpm
    sudo yum localinstall chronograf-1.4.4.1.x86_64.rpm
    
    # ubuntu
    wget https://dl.influxdata.com/chronograf/releases/chronograf_1.4.4.1_amd64.deb
    sudo dpkg -i chronograf_1.4.4.1_amd64.deb
    

    启动web服务:

    sudo systemctl start chronograf
    

    然后通过 http://localhost:8888 连接Web页面。

    9 - 用户管理

    可以直接在web管理页面做操作,也可以命令行。

    #显示用户  
    show users
    #创建用户
    create user "username" with password 'password'
    #创建管理员权限用户create user "username" with password 'password' with all privileges
    #删除用户
    drop user "username"
    

    进一步使用详解参考 : https://www.jianshu.com/p/a1344ca86e9b

    作者:miaoLoveCode
    链接:https://www.jianshu.com/p/d2935e99006e

    小礼物走一走,来简书关注我



    作者:Merz
    链接:https://www.jianshu.com/p/e3eba4dc7439
    來源:简书
    简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
  • 相关阅读:
    CF1202F You Are Given Some Letters...
    CF1178E Archaeology
    PTA (Advanced Level) 1005 Spell It Right
    PTA (Advanced Level) 1004 Counting Leaves
    Qt5——从零开始的Hello World教程(Qt Creator)
    PTA (Advanced Level) 1003 Emergency
    PTA (Advanced Level) 1002 A+B for Polynomials
    HDU 1272 小希的迷宫
    FZU 2150 Fire Game
    HihoCoder
  • 原文地址:https://www.cnblogs.com/zouhao/p/9864142.html
Copyright © 2011-2022 走看看