InfluxDB数据库入门
1、关于InfluxDBInfluxDB 是一个开源分布式的时序、事件和指标数据库。使用 Go 语言编写,无需外部依赖。其设计目标是实现分布式和水平伸缩扩展。 它有三大特性:
㈠Time Series (时间序列):你可以使用与时间有关的相关函数(如最大,最小,求和等)
㈡Metrics(度量):你可以实时对大量数据进行计算
㈢Eevents(事件):它支持任意的事件数据
又有如下特点:
schemaless(无结构),可以是任意数量的列
Scalable
min, max, sum, count, mean, median 一系列函数,方便统计
一般情况下,influxdb主要做为grafana收集数据存储使用,如下图场景
Grafana 是纯 Javascript 开发的前端工具,用于访问 InfluxDB,自定义报表、显示图表等。2、安装InfluxDB
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.2 (Maipo)
配置添加InfluxDB的yum源
cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF
安装InfluxDB
sudo yum install influxdb
安装后,主要文件分部目录
# ll /usr/bin/influx*
/usr/bin/influx
/usr/bin/influxd
/usr/bin/influx_inspect
/usr/bin/influx_stress
/usr/bin/influx_tsm
配置 InfluxDB
默认配置文件 /etc/influxdb/influxdb.conf
注:
重新生成一个新的配置文件: influxd config > /etc/influxdb/influxdb.generated.conf
启动influxd进程并检测配置文件: influxd -config /etc/influxdb/influxdb.generated.conf
配置开机自启动
systemctl enable influxdb.service
启动 InfluxDB
systemctl start influxdb
查看InfluxDB状态
# systemctl status influxdb
● influxdb.service - InfluxDB is an open-source, distributed, time series database
Loaded: loaded (/usr/lib/systemd/system/influxdb.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2017-07-18 00:31:21 CST; 46s ago
Docs: https://docs.influxdata.com/influxdb/
Main PID: 15620 (influxd)
CGroup: /system.slice/influxdb.service
└─15620 /usr/bin/influxd -config /etc/influxdb/influxdb.conf
3、连接InfluxDB并创建iops、compute数据库
# influx // 直接回车,进行命令行操作终端
Connected to https://localhost:8086 version 1.2.4
InfluxDB shell version: 1.2.4
> create database iops // 创建数据库iops
> create database compute // 创建数据库compute
> show databases // 显示数据库
name: databases
name
----
_internal
iops
compute
>
4、配置浏览器登陆
InfluxDB Web 访问接口
https://<ip address>:8083
默认情况下influxdb会监听一下端口:
8083端口,供HTTP web管理平台使用。
8086端口,供HTTP API接口使用,例如写入数据、查询数据等等
8088端口, 供集群使用,RPC备份和恢复
编辑文件/etc/influxdb/influxdb.conf
[admin]
# Determines whether the admin service is enabled.
enabled = true
# The default bind address used by the admin service.
bind-address = ":8083"
[http]
# Determines whether HTTP endpoint is enabled.
enabled = true
然后重启InfluxDB
# systemctl restart influxdb
点击右侧的Query Templates,选择相关查询语句,即可通过界面输入查询结果。5、参考
https://docs.influxdata.com/influxdb/v1.2/introduction/installation/
评论