笔记:
更新时间: 2025年5月7日13:17:11
1. 安装
dnf install redis -y
2. 启动/关闭/重启
# 启动
systemctl start redis
# 关闭
systemctl stop redis
# 开机自启
systemctl enable redis
3. 访问
[root@VM_0_3_centos ~]# redis-cli
127.0.0.1:6379> set userName "admin"
OK
127.0.0.1:6379> get userName
"admin"
127.0.0.1:6379> exit
[root@VM_0_3_centos ~]#
# 说明可以正常使用。
4. Redis 密码设置
# 其实设置密码有两种方式: 1、 命令 2、修改配置,先尝试第一种
# 我们通过命令来设置密码, 默认是没有密码的
127.0.0.1:6379> CONFIG get requirepass
1) "requirepass"
2) ""
127.0.0.1:6379>
# 设置密码
127.0.0.1:6379> CONFIG set requirepass "123123"
OK
# 验证密码
127.0.0.1:6379> auth "123123"
127.0.0.1:6379> CONFIG get requirepass
1) "requirepass"
2) "123123"
# 密码设置完毕, 测试一下
[root@VM_0_3_centos ~]# redis-cli
127.0.0.1:6379> get userName
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123123
OK
127.0.0.1:6379> get userName
"admin"
127.0.0.1:6379> exit
[root@VM_0_3_centos ~]#
# 通过修改配置文件来修改密码, 同样的找到
[root@VM_0_3_centos ~]# vim /etc/redis/redis.conf
################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass 123123
5. Windows用户可以安装redis-desktop-manager,Linux用户想必大家也没必要用桌面工具,网盘地址
- 安装之后准备连接

- 如果连接失败,修改配置文件
# 打开redis配置文件, 找到 bind 127.0.0.1 将其注释, 所在位置上面点。 [root@VM_0_3_centos ~]# vim /etc/redis/redis.conf # 注释bind 127.0.0.1或者改为0.0.0.0 bind 0.0.0.0 # 找到 protected-mode yes 将其改为 no protected-mode no # 然后重启 [root@VM_0_3_centos ~]# systemctl restart redis # 配置 Firewall 防火墙规则 firewall-cmd --zone=public --add-port=6379/tcp --permanent # 生效配置 firewall-cmd --complete-reload -
再次连接。连接成功

Redis安装与配置教程
1047

被折叠的 条评论
为什么被折叠?



