文章目录
环境: centos7, 操作用户: root
1. 安装influxdb
1.存储库添加到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
2. 安装
yum install influxdb
systemctl start influxdb
3. 启动失败:systemctl status influxdb查看启动状态发现报错
Failed to start InfluxDB is an open-source, distributed, time series database.
查看/var/log/messages发现是权限问题:
run: create server: mkdir all: mkdir /var/lib/influxdb: permission denied
或者run: open server: open tsdb store: open /var/lib/influxdb/data/_internal/_series/00/0000: permission denied
4. 解决权限问题:
通过查看`cat /usr/lib/influxdb/scripts/influxdb.service`
发现用户是influxdb
5. 为用户授权(这里如果在配置文件中修改了对应的文件存储路径也需要对修改后的文件路径授权)
chown -R influxdb:influxdb /var/lib/influxdb/
6. 重新启动: systemctl start influxdb
7. 启动客户端
influx
8. 添加用户登录认证:
-
创建一个新的管理员用户:
CREATE USER <username> WITH PASSWORD '<password>' WITH ALL PRIVILEGES
(只操作这一个即可) -
为一个已有用户授权管理员权限:
GRANT ALL PRIVILEGES TO <username>
-
展示用户及其权限:
SHOW USERS
-
取消用户权限:
REVOKE ALL PRIVILEGES FROM <username>
-
创建一个新的普通用户:
CREATE USER <username> WITH PASSWORD '<password>'
-
为一个已有用户授权:
GRANT [READ,WRITE,ALL] ON <database_name> TO <username>
-
取消权限:
REVOKE [READ,WRITE,ALL] ON <database_name> FROM <username>
-
展示用户在不同数据库上的权限:
SHOW GRANTS FOR <username>
-
重设密码:
SET PASSWORD FOR <username> = '<password>'
-
删除用户:
DROP USER <username>
9. 修改配置文件(默认/etc/influxdb/influxdb.conf):
找到http模块:
修改
auth-enabled = true
还可以修改对应的端口(bind-address = ":8086")
10. 重启influxdb
systemctl restart influxd
11. 再次登录就需要进行用户验证了
输入: auth
回车进去用户验证界面
2. 配置远程读写
1. 下载prometheus安装remote_storage_adapter
路径: /prometheus/documentation/examples/remote_storage/remote_storage_adapter
直接使用go编译
export INFLUXDB_PW=xxxxxx, 将influxdb的密码写入环境变量
启动并后台运行
nohup ./main --influxdb-url=http://localhost:8086 --influxdb.username=root --influxdb.database=prometheus --influxdb.retention-policy=autogen &
2. 在prometheus.yml
中配置读写
remote_write:
- url: "http://localhost:9201/write"
# Remote read configuration (for InfluxDB only at the moment).
remote_read:
- url: "http://localhost:9201/read"
3. 重新加载prometheus
进入influxdb进行查看(查看prometheus的表)
SHOW MEASUREMENTS
能够查看到说明远程写成功
测试远程读可以将现在prometheus下的data下的数据清空,重启prometheus,这时重新打开Grafana,是可以看到以前的历史数据,说明远程读取配置成功