這篇文章主要介紹“Docker中的Influxdb研究與實(shí)踐”,在日常操作中,相信很多人在Docker中的Influxdb研究與實(shí)踐問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Docker中的Influxdb研究與實(shí)踐”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、秀山土家族苗族網(wǎng)絡(luò)推廣、小程序設(shè)計(jì)、秀山土家族苗族網(wǎng)絡(luò)營銷、秀山土家族苗族企業(yè)策劃、秀山土家族苗族品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供秀山土家族苗族建站搭建服務(wù),24小時(shí)服務(wù)熱線:18982081108,官方網(wǎng)址:chinadenli.net
influxdb介紹:
使用TSM(Time Structured Merge)存儲引擎,允許高攝取速度和數(shù)據(jù)壓縮;
使用go編寫,無需其他依賴;
簡單,高性能寫查詢httpAPI接口;
支持其他數(shù)據(jù)獲取協(xié)議的插件,比如graphite,collected,OpenTSDB;
使用relay構(gòu)建高可用https://docs.influxdata.com/influxdb/v1.0/high_availability/relay/;
擴(kuò)展的類sql語言,很容易查詢匯總數(shù)據(jù);
tag的支持,可用讓查詢變的更加高效和快速;
保留策略有效地自動(dòng)淘汰過期的數(shù)據(jù);
持續(xù)所產(chǎn)生的自動(dòng)計(jì)算的數(shù)據(jù)會使得頻繁的查詢更加高效;
web管理頁面的支持
下載安裝:
github:https://github.com/influxdata/influxdb 源碼編譯
官網(wǎng)下載:
Centos系列:wgethttps://dl.influxdata.com/influxdb/releases/influxdb-1.0.0.x86_64.rpm && sudo yum localinstall influxdb-1.0.0.x86_64.rpm
源碼包系列:wgethttps://dl.influxdata.com/influxdb/releases/influxdb-1.0.0_linux_amd64.tar.gz && tar xvfz influxdb-1.0.0_linux_amd64.tar.gz
docker系列:docker pull influxdb
安裝手冊:https://docs.influxdata.com/influxdb/v0.9/introduction/installation/
配置:
#cat /etc/influxdb/influxdb.conf reporting-disabled = false [registration] [meta] dir = "/var/lib/influxdb/meta" hostname = "10.0.0.2" #此hostname必須寫本機(jī),否則無法連接到數(shù)據(jù)操作的API bind-address = ":8088" retention-autocreate = true election-timeout = "1s" heartbeat-timeout = "1s" leader-lease-timeout = "500ms" commit-timeout = "50ms" cluster-tracing = false [data] dir = "/var/lib/influxdb/data" max-wal-size = 104857600 # Maximum size the WAL can reach before a flush. Defaults to 100MB. wal-flush-interval = "10m" # Maximum time data can sit in WAL before a flush. wal-partition-flush-delay = "2s" # The delay time between each WAL partition being flushed. wal-dir = "/var/lib/influxdb/wal" wal-logging-enabled = true [hinted-handoff] enabled = true dir = "/var/lib/influxdb/hh" max-size = 1073741824 max-age = "168h" retry-rate-limit = 0 retry-interval = "1s" retry-max-interval = "1m" purge-interval = "1h" [admin] enabled = true bind-address = ":8083" https-enabled = false https-certificate = "/etc/ssl/influxdb.pem" [http] enabled = true bind-address = ":8086" auth-enabled = false log-enabled = true write-tracing = false pprof-enabled = false https-enabled = false https-certificate = "/etc/ssl/influxdb.pem" [opentsdb] enabled = false [collectd] enabled = false
注意:
influxdb服務(wù)會啟動(dòng)三個(gè)端口:8086為服務(wù)的默認(rèn)數(shù)據(jù)處理端口,主要用來influxdb數(shù)據(jù)庫的相關(guān)操作,可提供相關(guān)的API;8083為管理員提供了一個(gè)可視化的web界面,用來為用戶提供友好的可視化查詢與數(shù)據(jù)管理;8088主要為了元數(shù)據(jù)的管理。需要注意的是,influxdb默認(rèn)是需要influxdb用戶啟動(dòng),且數(shù)據(jù)存放在/var/lib/influxdb/下面,生產(chǎn)環(huán)境需要注意這個(gè)。
啟動(dòng):
和telegraf啟動(dòng)方式一樣,可以使用init.d或者systemd進(jìn)行管理influxdb 注意,啟動(dòng)之后需要查看相關(guān)的端口是否正在監(jiān)聽,并檢查日志確保服務(wù)正常啟動(dòng)
使用:
如果說使用telegraf最核心的部分在配置,那么influxdb最核心的就是SQL語言的使用了。influxdb默認(rèn)支持三種操作方式:
登錄influxdb的shell中操作:
創(chuàng)建數(shù)據(jù)庫: create database mydb 創(chuàng)建用戶: create user "bigdata" with password 'bigdata' with all privileges 查看數(shù)據(jù)庫: show databases; 數(shù)據(jù)插入: insert bigdata,host=server001,regin=HC load=88 切換數(shù)據(jù)庫: use mydb 查看數(shù)據(jù)庫中有哪些measurement(類似數(shù)據(jù)庫中的表): show measurements 查詢: select * from cpu limit 2 查詢一小時(shí)前開始到現(xiàn)在結(jié)束的: #select load from cpu where time > now() - 1h 查詢從歷史紀(jì)元開始到1000天之間: #select load from cpu where time < now() + 1000d 查找一個(gè)時(shí)間區(qū)間: #select load from cpu where time > '2016-08-18' and time < '2016-09-19' 查詢一個(gè)小時(shí)間區(qū)間的數(shù)據(jù),比如在September 18, 2016 21:24:00:后的6分鐘: #select load from cpu where time > '2016-09-18T21:24:00Z' +6m 使用正則查詢所有measurement的數(shù)據(jù): #select * from /.*/ limit 1 #select * from /^docker/ limit 3 #select * from /.*mem.*/ limit 3 正則匹配加指定tag:(=~ !~) #select * from cpu where "host" !~ /.*HC.*/ limit 4 #SELECT * FROM "h3o_feet" WHERE ("location" =~ /.*y.*/ OR "location" =~ /.*m.*/) AND "water_level" > 0 LIMIT 4 排序:group by的用法必須得是在復(fù)合函數(shù)中進(jìn)行使用 #select count(type) from events group by time(10s) #select count(type) from events group by time(10s),type 給查詢字段做tag: #select count(type) as number_of_types group by time(10m) #select count(type) from events group by time(1h) where time > now() - 3h 使用fill字段: #select count(type) from events group by time(1h) fill(0)/fill(-1)/fill(null) where time > now() - 3h 數(shù)據(jù)聚合: select count(type) from user_events merge admin_events group by time(10m)
使用API進(jìn)行操作數(shù)據(jù):
創(chuàng)建數(shù)據(jù)庫: curl -G "http://localhost:8086/query" --data-urlencode "q=create database mydb" 插入數(shù)據(jù): curl -XPOST 'http://localhost:8086/write?db=mydb' -d 'biaoge,name=xxbandy,xingqu=coding age=2' curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000' curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server02 value=0.67 cpu_load_short,host=server02,region=us-west value=0.55 1422568543702900257 cpu_load_short,direction=in,host=server01,region=us-west value=2.0 1422568543702900257' 將sql語句寫入文件,并通過api插入: #cat sql.txt cpu_load_short,host=server02 value=0.67 cpu_load_short,host=server02,region=us-west value=0.55 1422568543702900257 cpu_load_short,direction=in,host=server01,region=us-west value=2.0 1422568543702900257 #curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary @cpu_data.txt 查詢數(shù)據(jù):(--data-urlencode "epoch=s" 指定時(shí)間序列 "chunk_size=20000" 指定查詢塊大?。? # curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=ydb" --data-urlencode "q=select * from biaoge where xingqu='coding'" 數(shù)據(jù)分析: #curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=mydb" --data-urlencode "q=select mean(load) from cpu" #curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=mydb" --data-urlencode "q=select load from cpu" 可以看到load的值分別是42 78 15.4;用mean(load)求出來的值為45,13 curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=ydb" --data-urlencode "q=select mean(load) from cpu where host='server01'"
使用influxdb提供的web界面進(jìn)行操作:
這里只是簡單的介紹了influxdb的使用,后期如果想在grafana中匯聚并完美地展示數(shù)據(jù),可能需要熟悉influxdb的各種查詢語法。(其實(shí)就是sql語句的一些使用技巧,聚合函數(shù)的使用,子查詢等等)
到此,關(guān)于“Docker中的Influxdb研究與實(shí)踐”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
本文名稱:Docker中的Influxdb研究與實(shí)踐
文章鏈接:http://chinadenli.net/article28/podjjp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、企業(yè)網(wǎng)站制作、定制網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)、云服務(wù)器、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)