InfluxDB初探

安装

下载Ubuntu系统下的安装介质,之后直接解压安装

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

配置

使用命令sudo vi /etc/influxdb/influxdb.conf用vim编辑配置文件:
这里写图片描述
这里,我取消了第209行的注释,打开了管理页面端口
如果忘记sudo就编辑没权限写的文件后无法保存的话,这里有个技巧,这也是我经常要使用的
保存的时候输入:w !sudo tee %即可

启动

输入sudo service influxdb start即可启动数据库库服务
这里有两个重要端口要说明下:

  • port 8083:管理页面端口,访问localhost:8083可以进入你本机的influxdb管理页面
  • port 8086:http连接influxdb client端口,一般使用该端口往本机的influxdb读写数据
    现在可以使用influx打开CLI或者浏览器访问目标地址的8083端口对数据库管理
    CLI:
    这里写图片描述
    浏览器:
    这里写图片描述

一些CLI的常用命令:

Usage:
        connect <host:port>   connects to another node specified by host:port
        auth                  prompts for username and password
        pretty                toggles pretty print for the json format
        chunked               turns on chunked responses from server
        chunk size <size>     sets the size of the chunked responses.  Set to 0 to reset to the default chunked size
        use <db_name>         sets current database
        format <format>       specifies the format of the server responses: json, csv, or column
        precision <format>    specifies the format of the timestamp: rfc3339, h, m, s, ms, u or ns
        consistency <level>   sets write consistency level: any, one, quorum, or all
        history               displays command history
        settings              outputs the current settings for the shell
        clear                 clears settings such as database or retention policy.  run 'clear' for help
        exit/quit/ctrl+d      quits the influx shell

    show databases        show database names
    show series           show series information
    show measurements     show measurement information
    show tag keys         show tag key information
    show field keys       show field key information

选择要插入的数据库:

use mydb

插入数据:

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

test:table
host=127.0.0.1,monitor_name=test:tag
count=1:field

查询数据:

select * from test order by time desc

数据保存策略(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
  • rp_name:策略名;
  • db_name:具体的数据库名;
  • 3w:保存3周,3周之前的数据将被删除,influxdb具有各种事件参数,比如:h(小时),d(天),w(星期);
  • replication 1:副本个数,一般为1就可以了;
  • default:设置为默认策略

修改Retention Policies

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

删除Retention Policies

drop retention policy "rp_name"

用户管理

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

show users

创建用户

create user "username" with password 'password'

创建管理员权限用户

create user "username" with password 'password' with all privileges

删除用户

drop user "username"

完整的influxql命名可以访问这里

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章