参考文章:
https://www.cnblogs.com/suiyueqiannian/p/7808190.html
最近在使用Redis 图形化界面工具 RedisDesktopManager 去连接 Redis,
遇到了连接不同的问题。
最终排查原因是 Redis 配置的问题,现将解决过程记录如下。
连接工具:
1.bind 问题
2.启动指定配置文件问题
3.安全性问题
1.bind 问题
首先, 此类问题 最可能产生的原因就是 配置文件中绑定 IP 的限制。
为了限制 Redis 的对外连接,Redis 的默认配置 是设置 bind 本地ip 127.0.0.1, 我们看下 配置文件
################################## NETWORK #####################################
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected 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 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1
可以看到我们这里绑定的是本地ip, 127.0.0.1
这里我们需要注意一点 ,bind ip 的 ip 应该是 对外能够访问到的ip , 也就是Redis 机器所在的 内网或者外网地址。
注意:bind的意思不是绑定外部服务器的IP,而是绑定本机可以接受访问的IP
2.启动指定配置文件问题
另外,我们一般启动 redis 。都是直接执行如下的指令 :
redis-server &
此时我们应该指定启动的配置文件,例如, 如下指令 :
redis-server ./redis.conf &
3.安全性问题
如果到这步还不能生效,可以在配置文件中将redis保护模式关闭,但记得使用密码来保证安全性(使用复杂密码)。
protected-mode no requirepass a1s2W3l4%G
题外话:查看Redis 服务
查询Redis 服务是否启动 ,我们一般使用 ps -ef | grep redis 的方式进行查看服务是否启动
[root@master redis-4.0.1]# ps -ef | grep redis
root 1426 1 0 11:48 ? 00:00:06 redis-server 127.0.0.1:6379
root 6991 1048 0 14:16 pts/0 00:00:00 grep --color=auto redis