当你的服务器是 linux 时想直观的用 Redis 客户端来观察 Redis 里面的数据态度,就要做到以下几步。
一、更改Redis的配置文件.
1.修改redis.conf
文件
将绑定本机注释掉,,在bind 127.0.0.1地址前面加个#,若是想指定多个ip访问,但并不是全部的ip访问,可以bind多个ip。
# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
bind 127.0.0.1 # 看这里将其改为箭头中的内容 ---># bind 127.0.0.1<---
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
# unixsocket /var/run/redis/redis.sock
# unixsocketperm 700
在 Redis3.2 之后,redis 增加了 protected-mode
protected-mode no # 修改办法:即将protected-mode改为--->no<---
注! 若不做更改,即使注释掉了bind 127.0.0.1,再访问redisd时候还是报错,如下:
(error) 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.
2.重启redis服务
// 关闭redis服务
service redis-server stop
// 启动redis服务
redis-server /etc/redis/redis.conf
二、使用密码登录redis
(非必备选项)
修改redis.conf文件,若 redis 客户端连接成功,但是操作报异常 ☞ (error) NOAUTH Authentication required 错误的含义是说你没有认证,说明没有使用密码连接
################################## 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 foobared # 看这里将其改为箭头中的内容 --->requirepass 你的密码<---
requirepass 123456 # 例如这样你的密码就是123456
# Command renaming.
#
# It is possible to change the name of dangerous commands in a shared
# environment. For instance the CONFIG command may be renamed into something
# hard to guess so that it will still be available for internal-use tools
# but not available for general clients.
修改保存完之后要再次重启 Redis
三、添加安全组规则(阿里云控制台)
开放redis
端口


在上述都做完成后,还是无法连接的话,就要检查防火墙,或者是宝塔中的安全是否开启对端口放行。
转载请注明:隨習筆記 » 阿里云(ECS)服务器中的Redis远程访问