天天看點

Centos系統安裝InfluxDB

概述

安裝influxDB時需要root使用者或者管理者權限。

端口

預設情況下,InfluxDB會使用如下的端口:

* TCP8086端口是伺服器監聽端口,對HTTP API響應

* TCP8088端口是RPC服務端口,用于資料備份和儲存

更多的端口使用細節和配置方式可以在配置檔案/etc/influxdb/influxdb.conf進行了解和設定。

網絡時間協定(Network Time Protocol, NTP)

InfluxDB使用主機的本地UTC時間來配置設定時間戳,并用于協調。InfluxDB使用NTP協定來同步不同主機之間的時間,如果不同主機的時鐘沒有同步,那麼寫入資料庫中的資料的時間戳有可能是不準确的。

安裝

安裝包位址InfluxDB download,安裝

wget https://dl.influxdata.com/influxdb/releases/influxdb-1.5.3.x86_64.rpm

sudo yum localinstall influxdb-1.5.3.x86_64.rpm

sudo service influxdb start

systemctl start influxdb

influx

CREATE DATABASE "Tw.InfluxDB"

CREATE USER littlewrong WITH PASSWORD 'littlewrong' WITH ALL PRIVILEGES

exit

修改influxdb.conf配置檔案:

[http]

  bind-address= ":8086"

  auth-enable=true

啟動

systemctl start influxdb

常用:

> select * from test_table (查詢語句,類似sql語句)

>select * from test_table where cpu = 22 ( where用法,類似sql)

>select * from test_table where host = 'web1' (同上)

>select * from test_table order by time [desc] (按時間排序,預設為順序,加上desc為倒序)

>show users (檢視使用者)

>create user "username" with password 'password' (建立普通使用者)

>create user "username" with password 'password' with all privileges (建立管理者使用者)

>drop user "username" (删除使用者)

>auth (使用者認證,用于設定了密碼後,登陸influxdb的認證)

username: username

password: password

重新開機:

/usr/bin/influxd -config /etc/influxdb/influxdb.conf

service influxdb restart

systemctl start influxdb

systemctl stop influxdb

systemctl restart influxdb

管理者使用者管理:

建立一個新的管理者使用者

CREATE USER <username> WITH PASSWORD '<password>' WITH ALL PRIVILEGES

為一個已有使用者授權管理者權限

GRANT ALL PRIVILEGES TO <username>

取消使用者權限

REVOKE ALL PRIVILEGES FROM <username>

展示使用者及其權限

SHOW USERS

基礎語句

create database “db_name” 建立資料庫

drop database “db_name” 删除資料庫

show databases; 查詢幾個資料庫

use database_name; 使用資料庫

show measurements; 顯示該資料庫中的表

建立表,直接在插入資料的時候指定表名(weather就是表名)

insert weather,altitude=1000,area=北 temperature=11,humidity=-4

drop measurement “measurement_name” 删除表

建立保留政策(retention policy)

create retention policy rp_collectd on collectd duration 1w replication 1 default

duration: 1h, 90m, 12h, 7d, 4w, INF 最小1h, 最大INF

通過http添加資料

curl -i -XPOST ‘http://localhost:8086/write?db=testDB’ –data-binary ‘weather,altitude=1000,area=北 temperature=11,humidity=-4’

使用者管理

show users ; 顯示使用者

相關配置檔案

/etc/influxdb/influxdb.conf 預設的配置檔案

/var/log/influxdb/influxd.log 日志檔案

/var/lib/influxdb/data 資料檔案

/usr/lib/influxdb/scripts 初始化腳本檔案夾

/usr/bin/influx 啟動資料庫

從InfluxDB看時序資料的處理

以時間次元資料分析

###### 時序資料庫的關鍵特性

以時間次元的高效查詢

友善的down sampling (采樣)

自動高效的處理過期時間

###### 使用場景

監控

lot

measurement

tag/tagset(被索引)

series

field

timestamp

continuous queries

retention policy

influxdb案例

grafana 的安裝使用

rpm -ivh grafana-3.1.1-1470047149.x86_64.rpm

sudo /sbin/chkconfig –add grafana-server 添加到啟動項

sudo service grafana-server start 啟動 grafana

/etc/grafana 啟動的指令

/usr/share/grafana

通路http://youIp:3333 or 3000

Package details

Installs binary to /usr/sbin/grafana-server

Copies init.d script to /etc/init.d/grafana-server

Installs default file (environment vars) to /etc/sysconfig/grafana-server

Copies configuration file to /etc/grafana/grafana.ini

Installs systemd service (if systemd is available) name grafana-server.service

The default configuration uses a log file at /var/log/grafana/grafana.log

The default configuration specifies an sqlite3 database at /var/lib/grafana/grafana.db

 grafana 的插件

Grafana plugin directory

/var/lib/grafana/plugins

Grafana-cli commands

展示所有可用的插件

grafana-cli plugins list-remote

Install a plugin type

grafana-cli plugins install

List installed plugins

grafana-cli plugins ls

Update all installed plugins

grafana-cli plugins update-all

Update one plugin

grafana-cli plugins update

Remove one plugin

grafana-cli plugins remove

相關的分析

Telegraf

Time-Series Data Collector

InfluxDB

Time-Series Data Storage

Chronograf

Time-Series Data Visualization

Kapacitor

Time-Series Data Processing