ubuntu虚拟机中redis的安装与使用
官网:Redis
我的redis版本:6.2
我的安装方式: 来自官方 Ubuntu PPA
$ sudo add-apt-repository ppa:redislabs/redis
$ sudo apt-get update
$ sudo apt-get install redis
我的ubuntu版本:20.04.2.0
我的redis默认安装位置:
/usr/local/bin
我的redis配置文件位置:
/etc/redis
进入配置文件目录,修改配置文件
使用"#"注释bind 127.0.0.1 好像是这个:127.0.0.1 -::1
允许非本机访问
protected-mode yes 改为 protected-mode no
关闭保护模式,允许远程访问
在安装位置,后台运行模式启动redis
./redis-server &
在安装位置,用正常模式关闭redis
./redis-cli shutdown
启动redis后,编辑防火墙过滤规则
iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
在用springboot调用redis时报错RedisConnectionFailureException
通过另一台虚拟机连接尝试连接该redis:
./redis-cli -h "IP地址" -p "端口号" -a "密码"
报错如下:
AUTH failed: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
Error:
redis在保护模式下运行,配置文件似乎没有生效,在客户端中关闭保护模式:
安装目录运行客户端
redis-cli
查看保护模式状态
config get protected-mode
修改保护模式状态
config set protected-mode no
或 指定配置文件启动
redis-server /etc/redis/redis.conf
虽然另一台虚拟机可以连上redis了,但是springboot还是一直报错RedisConnectionFailureException,但有了提示:redis在保护模式下运行,需要输入config set protected-mode no。又尝试了一会儿,找不到问题在哪儿,重启项目后报错没了,项目可以成功运行了。
版权声明:本文为Study_forwhat原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。