1、bind公網IP地址時,會出現異常:【Cannot assign requested address】 2、SpringBoot配置Redis主備哨兵集群後,無法連接 ...
一、部署
詳細部署步驟:https://blog.csdn.net/lihongtai/article/details/82826809
Redis5.0版本需要註意的參數配置:https://www.cnblogs.com/ibethfy/p/9965902.html
二、遇到的問題
1、bind公網IP地址時,會出現異常:【Cannot assign requested address】
首先理解bind的含義:https://blog.csdn.net/cw_hello1/article/details/83444013
原因:這裡無法bind公網IP地址,是因為ECS的本地IP是通過NAT技術轉換成了公網IP,即公網IP不是ECS任意一個網卡上的IP
解決方案:bind 0.0.0.0,這樣不論阿裡雲私網還是公網均可以訪問
2、SpringBoot配置Redis主備哨兵集群後,無法連接
原因:ECS實例既綁定了私網IP地址,也綁定了公網IP地址,哨兵會將監控的Redis實例IP地址收集管理起來,設置bind 0.0.0.0後,使得哨兵會收集這兩個IP地址,而連接時使用的是私網IP地址,故無法連接
解決方案:修改哨兵配置文件sentinel.conf,【sentinel announce-ip 哨兵所在的公網IP】
announce-ip配置項的官方解釋如下:
# sentinel announce-ip <ip> # sentinel announce-port <port> # # The above two configuration directives are useful in environments where, # because of NAT, Sentinel is reachable from outside via a non-local address. # # When announce-ip is provided, the Sentinel will claim the specified IP address # in HELLO messages used to gossip its presence, instead of auto-detecting the # local address as it usually does. # # Similarly when announce-port is provided and is valid and non-zero, Sentinel # will announce the specified TCP port. # # The two options don't need to be used together, if only announce-ip is # provided, the Sentinel will announce the specified IP and the server port # as specified by the "port" option. If only announce-port is provided, the # Sentinel will announce the auto-detected local IP and the specified port.
大致意思是:考慮到NAT網路的存在,設置非本地IP後,哨兵可以正常地被外部訪問
同時,哨兵啟動後,通過觀察配置文件sentinel.conf,發現已不會收集Redis實例的私網IP
最後SpringBoot可以正常連接Redis主備哨兵集群
註:以上場景為一主三備兩哨兵,一主一備一哨兵在同一個ECS實例上,兩備一哨兵在另一個ECS實例上,這兩個ECS實例在同一個區域,屬於同一個私有網段,且均綁定了公網IP