天天看点

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