Redis- Redis 中 bind 问题 设置Redis 可以对外访问

 

参考文章: 

redis bind连不上的坑

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

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值