权限认证机制,顾名思义,就是对 InfluxDB 数据库添加权限访问控制,在默认状况下,InfluxDB 的权限认证机制是关闭的,也就是说全部用户都有全部权限。shell
老规矩,直接实践上手,下图是 InfluxDB 开启权限认证机制后,登陆数据库后 'show databases;' 提示权限认证失败,即没法查看数据库信息。数据库
$ influx -precision rfc3339 Connected to http://localhost:8086 version 1.7.7 InfluxDB shell version: 1.7.7 > show databases; ERR: unable to parse authentication credentials Warning: It is possible this error is due to not setting a database. Please set a database with the command "use <database>". >
接下来,咱们执行 auth 来进行用户权限认证,认证成功后则能查看用户权限内的数据库信息。this
> auth username: rw_influxdb_de password: > show databases; name: databases name ---- _internal kwang_db
看到这里,应该大概明白了 InfluxDB 权限认证机制的基本做用了吧,那 InfluxDB 如何开启权限认证机制呢,别着急,继续往下看。spa
开启 InfluxDB 权限认证机制有三步:rest
在初次登陆时,InfluxDB 是没有开启权限认证的,能够经过以下操做添加一个 admin 帐号:code
> create user rw_influxdb with password '12345' with all privileges;
查看 rw_influxdb 帐号是否属于 admin 帐号blog
> show users; user admin ---- ----- rw_influxdb true
ok,admin 帐号已添加成功。flux
修改 /etc/influxdb/influxdb.conf 配置文件:ci
[http] auth-enabled = true
将配置文件中 [http] 模块中的 auth-enabled 参数设置成 true,即表示开启权限认证机制,是否是so easy。get
service influxdb restart
再次登陆 InfluxDB 出现以下结果则表示权限认证机制成功开启。
$ influx -precision rfc3339 Connected to http://localhost:8086 version 1.7.7 InfluxDB shell version: 1.7.7 > show databases; ERR: unable to parse authentication credentials Warning: It is possible this error is due to not setting a database. Please set a database with the command "use <database>". >
看到这里,不少用户可能还有个疑惑,在 2.1 中添加了 admin 帐号,那在 InfluxDB 中帐号/用户是如何管理的呢,在 “InfluxDB用户管理“一文中将会进行介绍。
【参考资料】