概述
安装 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
来源: http://www.bubuko.com/infodetail-2850412.html