基于DOCKER安装Redis Sentinel 集群导致的NAT网络问题解决方法
在之前的文章
https://blog.youkuaiyun.com/yingziisme/article/details/83034298
记录了如何基于Docker搭建Redis Sentinel 集群
那个时候留下了一个网络的问题
在服务器使用docker部署的,但是本地远程的时候,sentinel集群返回的地址是docker内部配置的地址,如何指定返回对外的ip
刚开始使用sentinel announce-ip这个配置,后来发现这个配置是用来声明sentinel的ip,并不会改变返回给客户端的redis的ip
查阅了redis官方配置文档之后找到了一个配置,附上官方说明和配置项
# A Redis master is able to list the address and port of the attached
# slaves in different ways. For example the "INFO replication" section
# offers this information, which is used, among other tools, by
# Redis Sentinel in order to discover slave instances.
# Another place where this info is available is in the output of the
# "ROLE" command of a master.
#
# The listed IP and address normally reported by a slave is obtained
# in the following way:
#
# IP: The address is auto detected by checking the peer address
# of the socket used by the slave to connect with the master.
#
# Port: The port is communicated by the slave during the replication
# handshake, and is normally the port that the slave is using to
# list for connections.
#
# However when port forwarding or Network Address Translation (NAT) is
# used, the slave may be actually reachable via different IP and port
# pairs. The following two options can be used by a slave in order to
# report to its master a specific set of IP and port, so that both INFO
# and ROLE will report those values.
#
# There is no need to use both the options if you need to override just
# the port or the IP address.
#
# slave-announce-ip 5.5.5.5
# slave-announce-port 1234
以及附上正确网络连接的配置文