文章目录
- 前言
- 安装
- 在centos安装influxdb
- 启动与关闭
- 基本使用
- 连接客户端
- 创建用户+设置密码+权限管理
- help查看常用指令
- 推荐学习influxdb的网站
前言
最近工作中有用到influxdb
(时序库),故整理一些influxdb
的基本概念和日常使用的心得。influxdb
是由InfluxData公司开发的开源时序型数据库,专注于海量时序数据的高性能读写、高效存储与实时分析,广泛应用于DevOps监控、IoT监控、实时分析等场景。
安装
在centos安装influxdb
输入网址https://www.influxdata.com/get-influxdb/,从官方获得各种安装方式
#下载
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.3.x86_64.rpm
#安装
sudo yum localinstall influxdb-1.8.3.x86_64.rpm
influxdb安装好之后,输入influx -version
可查看版本,配置文件默认路径/etc/influxdb/influxdb.conf
。(本人安装influxdb时版本还是1.8.0)
启动与关闭
# 启动命令
service influxdb start
#重启命令
service influxdb restart
# 关闭命令
service influxdb stop
用命令service influxdb start
启动influxdb使用的是默认配置/etc/influxdb/influxdb.conf
。
如需指定配置启动可使用:
#指定配置启动
influxd -config /etc/influxdb/influxdb.conf
注意:influx启动后默认占用默8086/8088两个端口号,如下是influxdb.conf
部分配置:
# Bind address to use for the RPC service for backup and restore.
# bind-address = "127.0.0.1:8088"
# The bind address used by the HTTP service.
# bind-address = ":8086"
如需要修改端口,可将注释打开,修改即可。
基本使用
连接客户端
influxdb是没有密码的,输入influx
回车即可进入到influxdb的客户端,输入exit
或者quit
退出客户端。
可执行influx -help
,查看相关命令参数:
[root@xfyLinux ~]# influx -help
Usage of influx:
-version
Display the version and exit.
-path-prefix 'url path'
Path that follows the host and port
-host 'host name'
Host to connect to.
-port 'port #'
Port to connect to.
-socket 'unix domain socket'
Unix socket to connect to.
-database 'database name'
Database to connect to the server.
-password 'password'
Password to connect to the server. Leaving blank will prompt for password (--password '').
-username 'username'
Username to connect to the server.
-ssl
Use https for requests.
-unsafeSsl
Set this when connecting to the cluster using https and not use SSL verification.
-execute 'command'
Execute command and quit.
-type 'influxql|flux'
Type specifies the query language for executing commands or when invoking the REPL.
-format 'json|csv|column'
Format specifies the format of the server responses: json, csv, or column.
-precision 'rfc3339|h|m|s|ms|u|ns'
Precision specifies the format of the timestamp: rfc3339, h, m, s, ms, u or ns.
-consistency 'any|one|quorum|all'
Set write consistency level: any, one, quorum, or all
-pretty
Turns on pretty print for the json format.
-import
Import a previous database export from file
-pps
How many points per second the import will allow. By default it is zero and will not throttle importing.
-path
Path to file to import
-compressed
Set to true if the import file is compressed
Examples:
# Use influx in a non-interactive mode to query the database "metrics" and pretty print json:
$ influx -database 'metrics' -execute 'select * from cpu' -format 'json' -pretty
# Connect to a specific database on startup and set database context:
$ influx -database 'metrics' -host 'localhost' -port '8086'
创建用户+设置密码+权限管理
没有密码也可以正常使用,但是为了安全起见,可以为其创建用户和设置密码。输入influx
,连上influxdb客户端,然后在客户端里输入:
# 创建用户并设置密码
create user xxx with password '123456'
# 查看所有用户
show users
# 修改密码
set password for xxx='1234'
# 删除用户
drop user xxx
# 查询用户的权限
show grants for <username>
# 授权
GRANT ALL PRIVILEGES TO <username>
GRANT [READ,WRITE,ALL] ON <database_name> TO <username>
# 回收权限
REVOKE ALL PRIVILEGES FROM <username>
REVOKE [READ,WRITE,ALL] ON <database_name> FROM <username>
# 创建用户+密码+授权(一条语句搞定)
create user xxx with password '123456' with all privileges
创建用户+设置密码+权限管理之后,还需要修改配置/etc/influxdb/influxdb.conf
,开启权限验证:
vim /etc/influxdb/influxdb.conf
# 开启权限验证
auth-enabled = true
重启influxdb并连接测试:
# 重启
service influxdb restart
# 输入用户名+密码连接
influx -username xxx -password 123456
还可以输入influx
,在客户端输入auth验证用户名和密码:
help查看常用指令
连上influxdb
客户端,输入help
,可查看常用操作命令:
推荐学习influxdb的网站
- influxdb官方英文文档:https://docs.influxdata.com/influxdb/v1.8/query_language/spec/
- influxdb中文文档:https://jasper-zhang1.gitbooks.io/influxdb/content/
PS: 如若文章中有错误理解,欢迎批评指正,同时非常期待你的评论、点赞和收藏。我是徐同学,愿与你共同进步!