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命名可以訪問這裏

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