redis多用户管理

devtools/2024/9/22 9:36:42/

最近在学redis,由于笔者是学运维的,所以推荐学习运维的小伙伴参考,希望对大家有帮助!

redis运维上篇:http://t.csdnimg.cn/MfPud

redis运维下篇:http://t.csdnimg.cn/83sQ1

redis6开始,默认用户名为default,之前的版本不存在用户名列出所有用户,默认只有default为超级用户,拥有所有的权限
>acl list
"user default on #9cd9ab402f4115ed9921a7e4f7fc89330c8fe9283a8b1cdef203f7a7e622c68f ~* &* +@all">acl getuser default  #查看default用户的相关信息
1) "flags"1) "on"2) "allkeys"3) "allchannels"4) "allcommands"3) "passwords">acl cat  #查看权限
1) "keyspace"2) "read"3) "write"4) "set"5) "sortedset"6) "list"7) "hash"

实例1:创建test用户只给一个get命令权限、读权限、并且只能get是name开头的key:name*

127.0.0.1:6379> set name1 n1
OK
127.0.0.1:6379> set name2 n2
OK
127.0.0.1:6379> set name3 n3
OK
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k2 v2
OK
127.0.0.1:6379> acl setuser test on >testpwd ~name* +get		#创建test用户,密码:testpwd 只对name开头的有get权限
OK
127.0.0.1:6379> acl setuser test on >testpwd ~name* +@read	#增加read权限
OK登录验证:
[root@bogon ~]# redis-cli --user test --pass testpwd    #test用户登录
127.0.0.1:6379> get name1
"n1"
127.0.0.1:6379> get name2
"n2"
127.0.0.1:6379> get name3
"n3"
127.0.0.1:6379> get k1
(error) NOPERM this user has no permissions to access one of the keys used as arguments
127.0.0.1:6379> get k2
(error) NOPERM this user has no permissions to access one of the keys used as arguments

实例2:创建用户赋值给所有权限

127.0.0.1:6379> acl setuser test1 on >test1pwd ~* +@all	#给用户test1添加所有权限
OK
127.0.0.1:6379> acl getuser test1	#查看test1的权限
[root@bogon ~]# redis-cli
验证权限
127.0.0.1:6379> auth test1 test1pwd
OK
127.0.0.1:6379> get k1
"v1"

实例3:去除config命令后的权限

127.0.0.1:6379> acl setuser test2 on >test2pwd ~* +@all -config		#去除test2的config权限
OK
验证权限
127.0.0.1:6379> auth test2 test2pwd
OK
127.0.0.1:6379> config get requirepass	#获取不到config权限
(error) NOPERM this user has no permissions to run the 'config' command or its subcommand
127.0.0.1:6379> keys *
1) "name3"
2) "name2"
3) "name1"
4) "k2"
5) "k1"

实例4:创建一个用户,只给info和monitor权限

127.0.0.1:6379> acl setuser monitor on >monitorpwd ~* +info +monitor
OK
权限验证
127.0.0.1:6379> auth monitor monitorpwd
OK
127.0.0.1:6379> keys *
(error) NOPERM this user has no permissions to run the 'keys' command or its subcommand
127.0.0.1:6379> get k1
(error) NOPERM this user has no permissions to run the 'get' command or its subcommand
127.0.0.1:6379> info
# Server
redis_version:6.2.1
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:c9de016bf71cd57f
redis_mode:standalone
命令小结:
列出所有用户:
>acl list删除用户:
>acl deluser test1让命令永久生效
>config rewrite 


http://www.ppmy.cn/devtools/27364.html

相关文章

c++容器与算法概述

容器与算法 每个标准库容器都提供了begin() end() 函数&#xff0c;分别返回容器的头部位置和尾部位置。 I/O 流 对于自定义的类型&#xff1a; struct Entry {std::string name;int number;};如果需要使用标准输出需要重载<< 运算符&#xff0c;特别注意&#xff1a…

云计算中的网络服务

网络服务是云计算平台不可或缺的一部分&#xff0c;为用户提供构建、管理、保护云环境中网络资源的能力。以下是对列举的七种网络服务——虚拟私有云&#xff08;VPC&#xff09;、负载均衡、内容分发网络&#xff08;CDN&#xff09;、云防火墙、专用网络连接&#xff08;专线…

Windows操作系统安全精讲视频课程

Windows操作系统安全精讲视频课程 1.1IT运维职位需要学习的技能.mp4 1-2利用缓存的网络凭据入侵服务器.mp4 1-3信息安全包括哪些方面.mp4 1-4管理本地用户账户和组.mp4 1-5创建检查删除计算机上隐藏的账户.mp4 1-6用户账户控制&#xff08;UAC&#xff09;详解.mp4 1-7使用win…

数据结构(八)——排序

八、排序 8.1 排序的基本概念 排序(Sort)&#xff0c;就是重新排列表中的元素&#xff0c;使表少的元素满足按关键字有序的过程。 输入∶n个记录R1,R2...., Rn&#xff0c;对应的关键字为k1, k2,... , kn 输出:输入序列的一个重排R1,R2....,Rn&#xff0c;使得有k1≤k2≤...≤…

新观点下的熊胆替代研究:探寻未来(鸡胆)发展的神酉异熊之路

熊胆作为中国四大传统珍贵动物药材&#xff08;熊胆、虎骨、牛黄、麝香&#xff09;之一&#xff0c;自古至今已使用数千年。从汉代到清代&#xff0c;有300多本中医经典记录了熊胆的功效应用&#xff0c;主要用于治疗肝经热、湿热黄疸和儿童惊厥。现代研究发现&#xff0c;熊胆…

websocket集成文档

1.添加依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId> </dependency>2.添加配置 Configuration public class WebSocketConfig {Beanpublic ServerEndpointExpo…

【MySQL 数据宝典】【索引原理】- 006 慢查询日志分析优化

一、介绍 https://dev.mysql.com/doc/refman/8.0/en/slow-query-log.html MySQL的慢查询&#xff0c;全名是慢查询日志&#xff0c;是MySQL提供的一种日志记录&#xff0c;用来记录在MySQL中响应时间超过阈值的语句。默认情况下&#xff0c;MySQL数据库并不启动慢查询日志&am…

SpringBoot+MyBatis-Plus+jsqlparser实现多租户功能

前言 多租户技术&#xff08;multi-tenancy technology&#xff09;是一种软件架构技术&#xff0c;它允许在单个系统实例上为多个用户或组织提供服务&#xff0c;同时确保这些用户之间数据的隔离性。在多租户架构中&#xff0c;每个租户&#xff08;可以是个人用户、企业、组…