開源時序資料庫influxDB解決方案
InfluxDB 是一個開源分散式時序、事件和指標資料庫。
使用 Go 語言編寫,無需外部依賴。其設計目標是實現分散式和水平伸縮擴充套件。
一、與傳統資料庫中的名詞做比較
nfluxDB中的名詞 | 傳統資料庫中的概念 |
database | 資料庫 |
measurement | 資料庫中的表 |
points | 表裡面的一行資料 |
二、InfluxDB中獨有的概念
1)database--資料庫,這個同傳統資料庫的資料庫概念。
2)measurement--資料表,在InfluxDB中,measurement即為表的作用,同傳統資料庫中的table作用一致。
1)tag--標籤,在InfluxDB中,tag是一個非常重要的部分,表名+tag一起作為資料庫的索引,是“key-value”的形式。
2)field--資料,field主要是用來存放資料的部分,也是“key-value”的形式。
3)timestamp--時間戳,作為時序型資料庫,時間戳是InfluxDB中最重要的部分,在插入資料時可以自己指定也可留空讓系統指定。
說明:在插入新資料時,tag、field和timestamp之間用空格分隔。
4)series--序列,所有在資料庫中的資料,都需要通過圖表來展示,而這個series表示這個表裡面的資料,可以在圖表上畫成幾條線。
5)Retention policy--資料保留策略,可以定義資料保留的時長,每個資料庫可以有多個數據保留策略,但只能有一個預設策略。。
6)Point--點,表示每個表裡某個時刻的某個條件下的一個field的資料,因為體現在圖表上就是一個點,於是將其稱為point。
1)Point
Point由時間戳(time)、資料(field)、標籤(tags)組成。
Point相當於傳統資料庫裡的一行資料,如下表所示:
Point屬性 | 傳統資料庫中的概念 |
time | 每個資料記錄時間,是資料庫中的主索引(會自動生成) |
fields | 各種記錄值(沒有索引的屬性)也就是記錄的值:溫度, 溼度 |
tags | 各種有索引的屬性:地區,海拔 |
2)series
所有在資料庫中的資料,都需要通過圖表來展示,而這個series表示這個表裡面的資料,可以在圖表上畫成幾條線:通過tags排列組合算出來。
如下所示:
>show series from cpu key cpu,cpu=cpu-total,host=ResourcePool-0246-billing07 cpu,cpu=cpu-total,host=billing07 cpu,cpu=cpu0,host=ResourcePool-0246-billing07 cpu,cpu=cpu0,host=billing07 cpu,cpu=cpu1,host=ResourcePool-0246-billing07 cpu,cpu=cpu1,host=billing07 cpu,cpu=cpu10,host=ResourcePool-0246-billing07 cpu,cpu=cpu10,host=billing07 cpu,cpu=cpu11,host=ResourcePool-0246-billing07 cpu,cpu=cpu11,host=billing07 cpu,cpu=cpu12,host=ResourcePool-0246-billing07 cpu,cpu=cpu12,host=billing07 cpu,cpu=cpu13,host=ResourcePool-0246-billing07 cpu,cpu=cpu13,host=billing07 cpu,cpu=cpu14,host=ResourcePool-0246-billing07 cpu,cpu=cpu14,host=billing07 cpu,cpu=cpu15,host=ResourcePool-0246-billing07 cpu,cpu=cpu15,host=billing07 cpu,cpu=cpu16,host=ResourcePool-0246-billing07 cpu,cpu=cpu17,host=ResourcePool-0246-billing07 cpu,cpu=cpu18,host=ResourcePool-0246-billing07 cpu,cpu=cpu19,host=ResourcePool-0246-billing07 cpu,cpu=cpu2,host=ResourcePool-0246-billing07 cpu,cpu=cpu2,host=billing07 cpu,cpu=cpu20,host=ResourcePool-0246-billing07 cpu,cpu=cpu21,host=ResourcePool-0246-billing07 cpu,cpu=cpu22,host=ResourcePool-0246-billing07 cpu,cpu=cpu23,host=ResourcePool-0246-billing07 cpu,cpu=cpu3,host=ResourcePool-0246-billing07 cpu,cpu=cpu3,host=billing07 cpu,cpu=cpu4,host=ResourcePool-0246-billing07 cpu,cpu=cpu4,host=billing07 cpu,cpu=cpu5,host=ResourcePool-0246-billing07 cpu,cpu=cpu5,host=billing07 cpu,cpu=cpu6,host=ResourcePool-0246-billing07 cpu,cpu=cpu6,host=billing07 cpu,cpu=cpu7,host=ResourcePool-0246-billing07 cpu,cpu=cpu7,host=billing07 cpu,cpu=cpu8,host=ResourcePool-0246-billing07 cpu,cpu=cpu8,host=billing07 cpu,cpu=cpu9,host=ResourcePool-0246-billing07 cpu,cpu=cpu9,host=billing07
它有三大特性:
1. Time Series (時間序列):你可以使用與時間有關的相關函式(如最大,最小,求和等)
2. Metrics(度量):你可以實時對大量資料進行計算
3. Eevents(事件):它支援任意的事件資料
特點
schemaless(無結構),可以是任意數量的列
Scalable
min, max, sum, count, mean, median 一系列函式,方便統計
Native HTTP API, 內建http支援,使用http讀寫
Powerful Query Language 類似sql
Built-in Explorer 自帶管理工具
安裝好influxdb後通過終端登入到資料庫,http api over 8086,頁面為8083
[[email protected] ~]# inf
influx influx_inspect influx_tsm infocmp infotocap
influxd influx_stress info infokey
通過influx登陸終端
[[email protected] ~]# influx
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 0.13.0
InfluxDB shell version: 0.13.0
1、Creating a database,注意關鍵詞的大小寫
> CREATE DATABASE mydb;
> SHOW DATABASES;
name: databases
---------------
name
telegraf
_internal
mytab
mydb
2、切換庫,有的關鍵字也沒那麼規範
> use mydb
Using database mydb
> USE mydb
Using database mydb
3、Writing and exploring data,寫入一條資料需要基礎格式
1、a short primer on the datastore#存放資料的實體物件,相當在關係型資料的表名
資料在時序資料庫(influxDB)是有組織的時間序列,包含一個 測量值(即在RMDB中的欄位),在INFLUXDB中如cpu_load或者temperature,
Points are written to InfluxDB using the Line Protocol, which follows the following format:
<measurement>[,<tag-key>=<tag-value>...] <field-key>=<field-value>[,<field2-key>=<field2-value>...] [unix-nano-timestamp]
The following lines are all examples of points that can be written to InfluxDB:
cpu,host=serverA,region=us_west value=0.64
payment,device=mobile,product=Notepad,method=credit billed=33,licenses=3i 1434067467100293230
stock,symbol=AAPL bid=127.46,ask=127.48
temperature,machine=unit42,type=assembly external=25,internal=37 1434067467000000000
這3條例子具體寫法:
InfluxDB中沒有顯式的新建表的語句,只能通過insert資料的方式來建立新表。如下所示:
insert disk_free,hostname=server01 value=442221834240i 1435362189575692182
其中 disk_free 就是表名,hostname是索引,value=xx是記錄值,記錄值可以有多個,最後是指定的時間
> insert cpu,host=serverA,region=us_west value=0.64
> select host,region ,value from cpu ##官方寫法是把這些測量值加引號
name: cpu
---------
timehostregionvalue
1481203149917071248serverAus_west0.64
insert disk_free,hostname=server01 value=442221834240i 1435362189575692182
在這條語句中,disk_free是表名,hostname=server01是tag,屬於索引,value=xx是field,這個可以隨意寫,隨意定義。
A point with the measurement name of cpu and tags host and region has now been written to the database, with the measured value of 0.64.
另一種型別的資料儲存,在相同的測量兩個欄位:
相同的測量值包含兩個欄位型別的資料
INSERT temperature,machine=unit42,type=assembly external=25,internal=37
> select * from temperature
name: temperature
-----------------
timeexternalinternalmachinetype
14812037975306309012537unit42assembly
刪除一個度量值
delete from cpu
show 支援的方法
CONTINUOUS, DATABASES, DIAGNOSTICS, FIELD, GRANTS, MEASUREMENTS, QUERIES,
RETENTION, SERIES, SHARD, SHARDS, STATS, SUBSCRIPTIONS, TAG, USERS
SHOW TAG KEYS FROM "temperature" 顯示度量值的標籤===show create table aa
influxdb支援正則
series操作
series表示這個表裡面的資料,可以在圖表上畫成幾條線,series主要通過tags排列組合算出來
show series from mem
設定TS的authorized,提高安全性,針對指定使用者擁有許可權才能訪問資料庫的資料,TS預設使用者分為普通使用者和管理員使用者,許可權分為read,write,all privileges三種許可權
新增使用者可以通過終端或者WEB方式2種方式:
開啟一個使用者許可權的過程:
1、在安裝好資料庫後,通過預設方式登陸資料庫:[[email protected] ~]# influx
2、新增使用者
CREATE USER "influxdb" WITH PASSWORD 'root123' WITH ALL PRIVILEGES
3、修改配置檔案:
4、設定好後重啟服務
5、WEB驗證登陸資料:
注意這裡若不是admin許可權登入的,會ERROR
Server returned error: error authorizing query: dlan not authorized to execute statement 'SHOW DATABASES', requires admin privilege
終端登入:
influx -host 'localhost' -port '8086' -username 'admin' -password 'root123'
目前測試遇到問題:
新增普通使用者,授權write或者read或者all都不能生效,用普通方式建立的使用者登入會提示:
[[email protected] ~]# influx -host '192.168.1.114' -port '8086' -username 'dlan2' -password 'root123'
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://192.168.1.114:8086 version 0.13.0
InfluxDB shell version: 0.13.0
> show databases
ERR: error authorizing query: dlan2 not authorized to execute statement 'SHOW DATABASES', requires admin privilege
Warning: It is possible this error is due to not setting a database.
Please set a database with the command "use <database>".
>show grants for dlan2
databaseprivilege
mytabREAD #許可權修改依然無法訪問,一樣提示錯誤
根據目前測試只能使用admin許可權才可以操作資料庫,或者需要設定那裡,需要驗證,,,,,
刪除使用者:
drop user dlan
使用者授權:
grant all on mydb to dlan
使用者授權只能對單個measurement
刪除許可權:
revoke read on mydb from dlan
貌似目前開啟auth只能通過admin許可權管理庫,其他等待驗證
influxdb的幾種操作方法,有喜歡用http API的方式來寫入資料,或者通過influxdb的終端來操作(我喜歡的型別),每種方式都適合的場景。
介紹通過API介面和終端方式來操作:
http://192.168.15.104:8086/write?db=mydb&cpu_load_short,host=server01,dc=mycat,region=us-west value=0.64
終端寫入:
use mydb
insert cpu_load_short,host=server01,dc=mycat,region=us-west value=0.64
查詢資料:(在URL的窗口裡),開始以為是在8083的頁面那查詢,一直烏龍著......
##小記事:
%20是空格
%22是“
相關推薦
開源時序資料庫influxDB解決方案
InfluxDB 是一個開源分散式時序、事件和指標資料庫。 使用 Go 語言編寫,無需外部依賴。其設計目標是實現分散式和水平伸縮擴充套件。 一、與傳統資料庫中的名詞做比較 nfluxDB中的名詞 傳統資料庫中的概念 database 資料庫 measu
Amoeba:開源的分散式資料庫Porxy解決方案
來源:https://www.biaodianfu.com/amoeba.html 什麼是Amoeba? Amoeba(變形蟲)專案,該開源框架於2008年 開始釋出一款 Amoeba for Mysql軟體。這個軟體致力於MySQL的分散式資料庫前端代理層,它主要在應用層訪問MySQL的
效能測試監控平臺:InfluxDB+Grafana+Jmeter linux環境執行jmeter並生成報告 時序資料庫InfluxDB:簡介及安裝 視覺化工具Grafana:簡介及安裝
前面的部落格介紹了InfluxDB、Telegraf、Grafana的安裝和使用方法,這篇部落格,介紹下如何利用這些開源工具搭建效能測試監控平臺。。。 前言 效能測試工具jmeter自帶的監視器對效能測試結果的實時展示,在Windows系統下的GUI模式執行,渲染和效果不是太好,在linu
資料庫高效能解決方案
高效能資料庫叢集的第一種方式是: 讀寫分離,其本質是將訪問壓力分散到叢集中的多個節點,但是沒有分散 儲存壓力;第二種方式是:分庫分表,既可以分散訪問壓力,又可以分散儲存壓力。 一 讀寫分離 讀寫分離的基本原來是將資料庫讀寫操作分散到不同的節點上,讀寫分離的基本實現如下: 資料庫伺服
mysql字符集設定(web程式插入資料庫亂碼解決方案)
mysql資料庫字符集 問題:最近在做專案時,打算在本地搭建專案執行的全部環境,當環境搭建好之後,在進行測試時,突然發現程式向資料庫插入資料時發生了亂碼。 最先想到的解決方案: 檢查eclipse的字符集(頁面字符集、code字符集等) 檢查tomcat的URI
用Navicat連線Oracle資料庫出錯解決方案
用Navicat連線Oracle資料庫時出現如下錯誤 上網一查原來是oci.dll版本不對。因為Navicat是通過oracle客戶端連線Oracle伺服器的,Oracle的客戶端分為兩種,一種是標準版,一種是簡潔版,即Or
java大併發之資料庫層面解決方案
前言:當一個網站開始剛剛建立時,可能只是考慮一天只有幾十或者幾百個人訪問,資料庫可能就個db,所有表都放一起,一臺普通的伺服器可能就夠了,而且開發人員也非常高興,而且信心十足,因為所有的表都在一個庫中,這樣查詢語句就可以隨便關聯了,多美的一件事情。但是隨著訪問壓力的增加,
時序資料庫InfluxDB
在系統服務部署過後,線上執行服務的穩定性是系統好壞的重要體現,監控系統狀態至關重要,經過調研瞭解,時序資料庫influxDB在此方面表現優異。 influxDB介紹 時間序列資料是以時間欄位為每行資料的標示,比如股票市場的價格,環境中的溫度,主機的CPU使用率等。但是又有什麼資料是不包含timestam
用plsql developer登入時不顯示已經建立過的資料庫的解決方案
剛開始接觸Oracle,安裝時出現了這個問題,就是用plsql developer登入時不顯示已經建立過的資料庫,然後在E:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora檔案下,末尾
log4j 日誌檔案儲存資料庫的解決方案一(配置檔案中寫sql語句)
log4jmysql.properties: log4j.rootLogger=ERROR,console,db log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.
在ios開發中資料庫升級解決方案
在iOS開發中,經常會用到sqlite,在app迭代過程中,可能會有需求變更,需求的改變可能會影響資料庫結構的改變;那麼在不丟失原有資料的同時,又要修改資料庫結構,就要進行資料遷移。 我的做法是本地儲存一個app版本號,每次app啟動都會與Info.plist裡面的版本號比
64位伺服器IIS7.5執行ASP網站連線資料庫錯誤解決方案
在排除了許可權設定問題後終於想起是不是因為64位的問題呢,於是想到應用程式池的32位選項,於是解決了。下面總結下ASP網站連線資料庫出錯的解決方案,以後遇到連不上資料庫就從下面找原因。 1、啟用父路徑支援: 在站點主頁上選擇“ASP”,然後在“行為”組中將“啟用父路徑”
【G】開源的分散式部署解決方案(一)
做這個開源專案的意義是什麼?(口水自問自答,不喜可略過) 從功能上來說,請參考 預告篇,因自知當時預告篇沒有任何含金量,所以並沒有主動推送到首頁,而是私下的給一些人發的。 從個人角度上來說,我希望.net的環境會越來越好,就我自己的成長曲線是從mxdn開始自學、cxdn嘗試
Flink流計算與時序資料庫Influxdb+grafana
1、簡介 關於Influxdb和grafana,可以參考:介紹或者influxdb官方文件,grafana官方文件。這裡預設已經將influxdb和grafana安裝完成。 2、Flink sink to Influxdb influxdb不屬於Fli
live555開源RTSP流媒體解決方案說明
liveMedia 專案(http://www.live555.com/)的原始碼包括四個基本的庫、測試程式碼及Media Server。 四個基本庫分別是:UsageEnvironment&TaskScheduler、groupsock、liveMedia、Ba
ORA-03113: 通訊通道的檔案結尾以及用備份的資料檔案恢復原資料庫的解決方案
環境:win 2003 + oracle 10g 情景: 2013年4月7號晚上20點30分左右,資料庫伺服器莫名down了,開發人員嘗試啟動instance,報錯ORA-01034: ORACLE not availableORA-27101: shared memor
時序資料庫InfluxDB之備份和恢復策略
influxdb 備份與恢復 環境: influxdb v1.6.0 使用influx自動的控制檯進行 I. 備份 備份命令 influxd backup [ -database <db_name> ] -
win8.1 64bit下IIS8.5無法連線Access資料庫的解決方案
win8.1 64bit下IIS8.5無法連線Access資料庫,這個問題著實讓我搞了好多天啊,搞到淚奔了,專案催著呢,但伺服器搞不好,讓人痛苦了好一陣子啊,各種方法用盡就是連不上,但最終還是解決了,寫此博文以積累,也助和我遇到同樣問題的程式猿&&程式媛們。
Elastic Stack 開源的大資料解決方案
目的 本文主要介紹的內容有以下三點: 一. Elastic Stack是什麼以及組成部分 二. Elastic Stack前景以及業務應用 三. Elasticsearch原理(索引方向) 四. Elasticsearch相對薄弱的地方 一、Elastic Stack是什麼以及組成部分 介紹Elastic
開源解決方案一:快速搭建單機版 LAMP 網站
opera clas 資源管理 都在 ger source environ 本地 tin LAMP 通常表示 Linux + Apache + MySQL/MariaDB + Perl/PHP/Python,LAMP 的各個組件不是一成不變的,並不局限於它最初的選擇。作為一