1. 程式人生 > >Centos系統安裝InfluxDB

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


啟動

sudo service influxdb start

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

CREATE USER littlewrong WITH PASSWORD 'littlewrong' 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