InfluxDB安装及使用
1 安裝
1.1 Tar包安裝
??(1)獲取tar包
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.0_linux_amd64.tar.gz??(2)解壓tar包
??tar xvfz influxdb-1.8.0_linux_amd64.tar.gz
??(3)修改配置文件
??可執行文件路徑為:{influxdb目錄}/usr/bin
??安裝InfluxDB之后,在/usr/bin下會有如下幾個文件:
??默認配置文件所在路徑:{influxdb目錄}/etc/influxdb/influxdb.conf
[tigk@fbi-local-02 .local]$ mkdir /data/tigk/influxdb/conf [tigk@fbi-local-02 .local]$ cp /home/tigk/.local/influxdb/etc/influxdb/influxdb.conf /data/tigk/influxdb/conf/ [tigk@fbi-local-02 .local]$ cd /data/tigk/influxdb/conf/influxdb.conf [tigk@fbi-local-02 influxdb]$ mkdir meta [tigk@fbi-local-02 influxdb]$ mkdir data [tigk@fbi-local-02 influxdb]$ mkdir wal??然后進行修改配置文件
?? (4)配置文件說明
# reporting-disabled = false # 該選項用于上報influxdb的使用信息給InfluxData公司,默認值為false # bind-address = "127.0.0.1:8088" # 備份恢復時使用,默認值為8088 ### [meta] [meta]dir = "/data/tigk/influxdb/meta" # meta數據存放目錄# retention-autocreate = true # 用于控制默認存儲策略,數據庫創建時,會自動生成autogen的存儲策略,默認值:true# logging-enabled = true # 是否開啟meta日志,默認值:true ### [data] [data]dir = "/data/tigk/influxdb/data" # 最終數據(TSM文件)存儲目錄wal-dir = "/data/tigk/influxdb/wal" # 預寫日志存儲目錄# wal-fsync-delay = "0s" #在同步寫入之前等待的總時間,默認0s# index-version = "inmem" #用于新碎片的切分索引的類型。# trace-logging-enabled = false #跟蹤日志記錄在tsm引擎周圍提供了更詳細的輸出# query-log-enabled = true # 是否開啟tsm引擎查詢日志,默認值: true# Valid size suffixes are k, m, or g (case insensitive, 1024 = 1k).# cache-max-memory-size = "1g" # 用于限定shard最大值,大于該值時會拒絕寫入,默認值:1000MB,單位:byte# Valid size suffixes are k, m, or g (case insensitive, 1024 = 1k).# cache-snapshot-memory-size = "25m" # 用于設置快照大小,大于該值時數據會刷新到tsm文件,默認值:25MB,單位:byte# cache-snapshot-write-cold-duration = "10m" # tsm引擎 snapshot寫盤延遲,默認值:10Minute# compact-full-write-cold-duration = "4h" # tsm文件在壓縮前可以存儲的最大時間,默認值:4Hour# max-concurrent-compactions = 0 #壓縮并發的最大數量,默認設置為0表示runtime.GOMAXPROCS(0)*50% ,否則以設置的非零值為準# Valid size suffixes are k, m, or g (case insensitive, 1024 = 1k).# max-index-log-file-size = "1m" #限制索引日志文件大小# max-series-per-database = 1000000 # 限制數據庫的級數,該值為0時取消限制,默認值:1000000# max-values-per-tag = 100000 # 一個tag最大的value數,0取消限制,默認值:100000# tsm-use-madv-willneed = false #如果為true,mmap的建議值MADV_WILLNEED會被提供給內核 ### [coordinator] [coordinator]# write-timeout = "10s" # 寫操作超時時間,默認值: 10s# max-concurrent-queries = 0 # 最大并發查詢數,0無限制,默認值: 0# query-timeout = "0s" # 查詢操作超時時間,0無限制,默認值:0s# log-queries-after = "0s" # 慢查詢超時時間,0無限制,默認值:0s# max-select-point = 0 # SELECT語句可以處理的最大點數(points),0無限制,默認值:0# max-select-series = 0 # SELECT語句可以處理的最大級數(series),0無限制,默認值:0# max-select-buckets = 0 # SELECT語句可以處理的最大"GROUP BY time()"的時間周期,0無限制,默認值:0 ### [retention] [retention]# enabled = true # 是否啟用該模塊,默認值 : true# check-interval = "30m" # 檢查時間間隔,默認值 :"30m" ### [shard-precreation] [shard-precreation]# enabled = true # 是否啟用該模塊,默認值 : true# check-interval = "10m" # 檢查時間間隔,默認值 :"10m"# advance-period = "30m" # 預創建分區的最大提前時間,默認值 :"30m" [monitor]# store-enabled = true # 是否啟用該模塊,默認值 :true# store-database = "_internal" # 默認數據庫:"_internal"# store-interval = "10s" # 統計間隔,默認值:"10s" ### [http] [http]# enabled = true # 是否啟用該模塊,默認值 :true# bind-address = ":8086" # 綁定地址,默認值 :":8086"# auth-enabled = false # 是否開啟認證,默認值:false# realm = "InfluxDB" # 配置JWT realm,默認值: "InfluxDB"# log-enabled = true # 是否開啟日志,默認值:true# suppress-write-log = false #在啟用日志時是否抑制HTTP寫請求日志# access-log-path = "" #當啟用HTTP請求日志時,該選項指定了路徑。如influxd不能訪問指定的路徑,它將記錄一個錯誤并將請求日志寫入stderr# write-tracing = false # 是否開啟寫操作日志,如果置成true,每一次寫操作都會打日志,默認值:false# pprof-enabled = true # 是否開啟pprof,默認值:true# debug-pprof-enabled = false # 是否開啟pprof,默認值:true# https-enabled = false # 是否開啟https ,默認值 :false# https-certificate = "/etc/ssl/influxdb.pem" # 設置https證書路徑,默認值:"/etc/ssl/influxdb.pem"# https-private-key = ""# 設置https私鑰,無默認值# shared-secret = "" # 用于JWT簽名的共享密鑰,無默認值# max-row-limit = 0 # 配置查詢返回最大行數,0無限制,默認值:0# max-connection-limit = 0 # 配置最大連接數,0無限制,默認值:0# unix-socket-enabled = false # 是否使用unix-socket,默認值:false# bind-socket = "/var/run/influxdb.sock" # unix-socket路徑,默認值:"/var/run/influxdb.sock"# max-body-size = 25000000 #客戶端請求主體的最大值,以字節為單位。0無限制,默認值0# max-concurrent-write-limit = 0 #并發處理的最大寫入次數,0無限制,默認值0# max-enqueued-write-limit = 0 #排隊等待處理的最大數量,0無限制,默認值0# enqueued-write-timeout = 0 #在隊列中等待處理的最長時間,0或者setting max-concurrent-write-limit=0無限制,默認值0 ### [ifql] [ifql]# enabled = true# 是否啟用該模塊,默認值 :true# log-enabled = true# 是否開啟日志,默認值:true# bind-address = ":8082" #ifql RPC服務使用的綁定地址默認是8082 ### [logging] [logging]# format = "auto" #日志格式,默認是自動# level = "info" #日志級別默認info# suppress-logo = false #當程序啟動時,會抑制打印出來的logo輸出 ### [subscriber] [subscriber]# enabled = true # 是否啟用該模塊,默認值 :true# http-timeout = "30s" # http超時時間,默認值:"30s"# insecure-skip-verify = false # 是否允許不安全的證書# ca-certs = "" # 設置CA證書# write-concurrency = 40 #設置并發數目,默認值:40# write-buffer-size = 1000 # 設置buffer大小,默認值:1000 ### [[graphite]] [[graphite]]# enabled = false# 是否啟用該模塊,默認值 :false# database = "graphite"# 數據庫名稱,默認值:"graphite"# retention-policy = "" # 存儲策略,無默認值# bind-address = ":2003"# 綁定地址,默認值:":2003"# protocol = "tcp"# 協議,默認值:"tcp"# consistency-level = "one" # 一致性級別,默認值:"one# batch-size = 5000 # 批量size,默認值:5000# batch-pending = 10# 配置在內存中等待的batch數,默認值:10# batch-timeout = "1s" # 超時時間,默認值:"1s"# udp-read-buffer = 0# udp讀取buffer的大小,0表示使用操作系統提供的值,如果超過操作系統的默認配置則會出錯。 該配置的默認值:0# separator = "." # 多個measurement間的連接符,默認值: "."# tags = ["region=us-east", "zone=1c"] #將被添加到所有指標的默認標簽。這些可以在模板級別上覆蓋或者從指標中提取的標簽# templates = [ # "*.app env.service.resource.measurement",# # Default template# "server.*",# ] ### [collectd] [[collectd]]# enabled = false# 是否啟用該模塊,默認值 :false# bind-address = ":25826" # 綁定地址,默認值: ":25826"# database = "collectd"# 數據庫名稱,默認值:"collectd"# retention-policy = "" # 存儲策略,無默認值# typesdb = "/usr/local/share/collectd" # 路徑,默認值:"/usr/share/collectd/types.db"# security-level = "none" #安全級別# auth-file = "/etc/collectd/auth_file"# batch-size = 5000 #從緩存中批量獲取數據的量,默認值:5000# batch-pending = 10 #可能在內存中等待的批次的數量,默認值:10# batch-timeout = "10s" #即使沒有達到緩沖區的限制,至少要刷新一下,默認值:"10s"# read-buffer = 0 #udp讀取buffer的大小,0表示使用操作系統提供的值,如果超過操作系統的默認配置則會出錯。默認值:0# parse-multivalue-plugin = "split" #兩種處理方式split和join,split會分到不同的表中,join會將記錄作為一個單獨的記錄處理。默認是split ### [opentsdb] [[opentsdb]]# enabled = false# 是否啟用該模塊,默認值 :false# bind-address = ":4242"# 綁定地址,默認值:":4242"# database = "opentsdb" # 默認數據庫:"opentsdb"# retention-policy = ""# 存儲策略,無默認值# consistency-level = "one" # 一致性級別,默認值:"one"# tls-enabled = false # 是否開啟tls,默認值:false# certificate= "/etc/ssl/influxdb.pem" # 證書路徑,默認值:"/etc/ssl/influxdb.pem"# log-point-errors = true# 出錯時是否記錄日志,默認值:true# batch-size = 1000 #從緩存中批量獲取數據的量,默認值:1000# batch-pending = 5 #可能在內存中等待的批次的數量,默認值:5# batch-timeout = "1s" #即使沒有達到緩沖區的限制,至少要刷新一下,默認值:"1s" ### [[udp]] [[udp]]# enabled = false# 是否啟用該模塊,默認值 :false# bind-address = ":8089" # 綁定地址,默認值:":8089"# database = "udp"# 數據庫名稱,默認值:"udp"# retention-policy = "" # 存儲策略,無默認值# precision = "" #接收點的時間點的精度("" or "n", "u", "ms", "s", "m", "h")# batch-size = 5000#從緩存中批量獲取數據的量,默認值:5000 # batch-pending = 10 #可能在內存中等待的批次的數量,默認值:10# batch-timeout = "1s" #即使沒有達到緩沖區的限制,至少要刷新一下,默認值:"1s"# read-buffer = 0# udp讀取buffer的大小,0表示使用操作系統提供的值,如果超過操作系統的默認配置則會出錯。 該配置的默認值:0 ### [continuous_queries] [continuous_queries]# enabled = true# 是否啟用該模塊,默認值 :true# log-enabled = true# 是否開啟日志,默認值:true# query-stats-enabled = false #控制查詢是否被記錄到自我監控數據存儲中# run-interval = "1s" # 時間間隔,默認值:"1s" ### [tls] [tls]# ciphers = [# "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305",# "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",# ]# min-version = "tls1.2"# max-version = "tls1.2"??(5)啟動
?? cd {influxdb目錄}
$ cd /home/tigk/.local/influxdb/usr/bin/ $ ./influxd -config /data/tigk/influxdb/conf/influxdb.conf??(6)啟動失敗
$ netstat -tunlp|grep 8086 (No info could be read for "-p": geteuid()=1005 but you should be root.) tcp 0 0 10.0.165.2:8086 0.0.0.0:* LISTEN -??修改端口 bind-address = “:8085”
??(7)后臺啟動服務
$ nohup ./influxd -config /data/tigk/influxdb/conf/influxdb.conf &??(8)啟動influxdb控制臺,第一次啟動會較慢,耐心等待
$ ./influx -port 8085 Connected to http://localhost:8085 version 1.8.0 InfluxDB shell version: 1.8.0 >??(9)創建一個tigk用戶,作為管理用戶
> create user "tigk" with password 'tigk' with all privileges > show users user admin ---- ----- tigk true2 使用
2.1 常用命令
??(1)命令展示influx –help
$ ./influx –help unknown arguments: –help Usage of influx:-versionDisplay the version and exit.-path-prefix 'url path'Path that follows the host and port-host 'host name'Host to connect to.-port 'port #'Port to connect to.-socket 'unix domain socket'Unix socket to connect to.-database 'database name'Database to connect to the server.-password 'password'Password to connect to the server. Leaving blank will prompt for password (--password '').-username 'username'Username to connect to the server.-sslUse https for requests.-unsafeSslSet this when connecting to the cluster using https and not use SSL verification.-execute 'command'Execute command and quit.-type 'influxql|flux'Type specifies the query language for executing commands or when invoking the REPL.-format 'json|csv|column'Format specifies the format of the server responses: json, csv, or column.-precision 'rfc3339|h|m|s|ms|u|ns'Precision specifies the format of the timestamp: rfc3339, h, m, s, ms, u or ns.-consistency 'any|one|quorum|all'Set write consistency level: any, one, quorum, or all-prettyTurns on pretty print for the json format.-importImport a previous database export from file-ppsHow many points per second the import will allow. By default it is zero and will not throttle importing.-pathPath to file to import-compressedSet to true if the import file is compressedExamples:# Use influx in a non-interactive mode to query the database "metrics" and pretty print json:$ influx -database 'metrics' -execute 'select * from cpu' -format 'json' -pretty# Connect to a specific database on startup and set database context:$ influx -database 'metrics' -host 'localhost' -port '8086'??(2)Influx命令使用
??Influx是連接influxdb的一個CLI程序,在本地成功安裝influxdb后,influxdb啟動,influx命令就可以直接使用。Influxdb默認在8086端口運行。Influx cli默認使用localhost:8086連接。可以使用-host和-port選項,連接到其他機器或者端口。
??(3)Influx-sql使用舉例
??Influx命令連接數據庫后,可以使用類sql語句查詢數據
| CREATE DATABASE database_name | 建立數據庫 |
| SHOW DATABASES | 查詢所有數據庫 |
| USE database_name | 使用database_name 庫 |
| INSERT cpu,host=host_name,region=cn value=66 | 插數據入cpu measurement,標簽host=host_name,region=cn, field是value=66 |
| SELECT “host”, “region”, “value” FROM “cpu” | 從cpu measurement查詢數據 |
| SELECT * FROM “cpu” | 從cpu measurement查詢所有數據 |
??(4)Influxdb的數據格式
??Influxdb是一個時序數據庫,其保存metric的在某一系列時間點的狀態。這些點狀態包含時間戳,一個所謂的“measurement”名稱,至少一個稱為filed的鍵值對,以及0到多個標簽(如 host=bigdata01)。
??在influxdb中可以把measurement看為關系數據庫中的table,tag和field是其中的列。其中Tag都加了索引、field不加。和關系數據庫不同的是,不用預先定義schema,沒有value的點不會被保存。其格式如下:
??舉例:
cpu,host=bigdata01,region=cn value=66payment,device=mobile,product=Notepad,method=credit billed=88,licenses=2i 1434067469156329323總結
以上是生活随笔為你收集整理的InfluxDB安装及使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js动态添加控件服务器响应,JS实现动态
- 下一篇: 静态路由实验