一、部署
詳細部署步驟:https://blog.csdn.net/lihongtai/article/details/82826809
Redis5.0版本需要注意的參數配置:https://www.cnblogs.com/ibethfy/p/9965902.html
二、遇到的問(wèn)題
1、bind公網(wǎng)IP地址時(shí),會(huì )出現異常:【Cannot assign requested address】
首先理解bind的含義:https://blog.csdn.net/cw_hello1/article/details/83444013
原因:這里無(wú)法bind公網(wǎng)IP地址,是因為ECS的本地IP是通過(guò)NAT技術(shù)轉換成了公網(wǎng)IP,即公網(wǎng)IP不是ECS任意一個(gè)網(wǎng)卡上的IP
解決方案:bind 0.0.0.0,這樣不論阿里云私網(wǎng)還是公網(wǎng)均可以訪(fǎng)問(wèn)
2、SpringBoot配置Redis主備哨兵集群后,無(wú)法連接
原因:ECS實(shí)例既綁定了私網(wǎng)IP地址,也綁定了公網(wǎng)IP地址,哨兵會(huì )將監控的Redis實(shí)例IP地址收集管理起來(lái),設置bind 0.0.0.0后,使得哨兵會(huì )收集這兩個(gè)IP地址,而連接時(shí)使用的是私網(wǎng)IP地址,故無(wú)法連接
解決方案:修改哨兵配置文件sentinel.conf,【sentinel announce-ip 哨兵所在的公網(wǎng)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網(wǎng)絡(luò )的存在,設置非本地IP后,哨兵可以正常地被外部訪(fǎng)問(wèn)
同時(shí),哨兵啟動(dòng)后,通過(guò)觀(guān)察配置文件sentinel.conf,發(fā)現已不會(huì )收集Redis實(shí)例的私網(wǎng)IP
最后SpringBoot可以正常連接Redis主備哨兵集群
注:以上場(chǎng)景為一主三備兩哨兵,一主一備一哨兵在同一個(gè)ECS實(shí)例上,兩備一哨兵在另一個(gè)ECS實(shí)例上,這兩個(gè)ECS實(shí)例在同一個(gè)區域,屬于同一個(gè)私有網(wǎng)段,且均綁定了公網(wǎng)IP
聯(lián)系客服