influxdb基础(一)——influxdb安装与基本配置(centos)

前言

最近工作中有用到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的网站

PS: 如若文章中有错误理解,欢迎批评指正,同时非常期待你的评论、点赞和收藏。我是徐同学,愿与你共同进步!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐同学呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值