文章导读:
跟mysql数据库一样,修改访问权限,以前默认的是只允许本机进行登录,即127.0.0.1,我们现在进行修改成远程可链接状态。
----------->>很简单,就是找到配置文件代码,注释一行代码,解除远程连接。
默认情况下,访问Redis服务器是不需要密码的,为了增加安全性我们需要设置Redis服务器的访问密码。注释解除就可以有密码了。requirepass
===================1、windows下:=============
1.1、打开redis的redis.windows.conf配置文件
image1.2、注释掉就打开了远程连接 ------->【加#】
image如果不行,改成no【75行】
【在redis3.2之后,redis增加了protected-mode,在这个模式下,即使注释掉了bind 127.0.0.1,再访问redisd时候还是报错,如下】
命令行连接远程:redis-cli -h 10.0.5.40 -p 6379
注意:必须得加空格
1)打开配置文件把下面对应的注释掉# bind 127.0.0.1
- Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程,设置为nodaemonize no
3)保护模式protected-mode no 报错处理:一、在对应配置conf文件中去掉注释,把yes改为no#protected-mode yesprotected-mode no重启redis(注意有数据时慎重启)kill -9 进程号redis-cli -h 192.168.32.12 -p 6887 shutdown二、添加认证,设置密码# requirepass foobaredrequirepass redis123456验证再次用Java程序建立连接池,没有报错,且可以对redis server进行数据正常处理。程序报错日志不再显示问题解决
连接错误问题:
ResponseError: 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 perman
ent. 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 res
tarting 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 authen
tication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
===================1、Linux下:=============
也是一样,在上一章找找,注释那行代码就行。
网友评论