天天看點

在阿裡雲伺服器上搭建redis叢集4.x并用JedisCluster2.9.0通路!!

在網上很多都是在虛拟機上搭建redis僞分布式的,很少在阿裡雲伺服器搭建的。在這次搭建中我遇到了很多坑,分享出來希望能幫到你。整個步驟就不說了,說一下在這個過程中遇到的問題:

redis.conf中屬性bind:

1.(1)預設的是127.0.0.1不能使用這個否則隻能内部通路,在連接配接時使用的搭建的指令:./redis-trib.rb create --replicas 1 127.0.0.1:7001 127.0.0.1.171:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006(7001-7006是我使用的端口)

(2)私網就是使用ifconfig指令出來的那個,搭建是指令:./redis-trib.rb create --replicas 1 私網ip:7001 私網ip:7002 127.0.0.1:7003 私網ip:7004 私網ip:7005 私網ip:7006。如果使用這個用RedisDesktManager(windows下的一個圖形界面用戶端)能夠通路和連接配接,但用JedisCluster連接配接連接配接時會報異常(redis.clients.jedis.exceptions.JedisConnectionException:Could not get a resource from the pool)。

(3)公網ip(就是你通路的伺服器的位址)emmm就會發現連服務都啟動不起來。

(4)正确版本,注釋掉用#bind XXXXXXX并且在redis.conf中需要将改為:protected-mode no。然而執行:./redis-trib.rb create --replicas 1 公網ip:7001 公網ip:7002 公網ip:7003 公網ip:7004 公網ip:7005 公網ip:7006執行到一半的時候會卡住(waiting for the cluster to join…),這時需要将你的端口+10000開放我的是把17001,17002等開放了(本機包括阿裡雲的的安全規則)。之後再從新搭建就可以成功了,使用JedisCluster2.9.0通路也能通路了。

繼續閱讀