centos下搭建redis叢集,centosredis叢集
必備的工具:redis-3.0.0.tarredis-3.0.0.gem(ruby和redis介面)分析:首先,叢集數需要基數,這裡搭建一個簡單的redis叢集(6個redis執行個體進行叢集)。在一台伺服器上操作,因此僅需要6個不同的連接埠號碼即可。分別是:7001、7002、7003、7004、7005、7006。步驟:1、上傳redis-3.0.0.tar到伺服器(自己指定自己的軟體目錄),解壓redis-3.0.0.tar。2、安裝c語言環境(安裝centos之後,內建c語言環境)yuminstallgcc-c++3、進入到redis-3.0.0目錄make4、安裝redis到/usr/local/redis目錄makeinstallPREFIX=/usr/local/redis5、查看是否安裝成功(出現bin目錄即可)6、前端啟動redis(進入的bin目錄)./redis-server(開啟)./redis-clishutdown7、後端啟動需要將redis解壓之後的源碼包中(redis-3.0.0目錄下)的redis.conf檔案拷貝到bin目錄下修改redis.conf檔案,將daemonize改為yes先要使用vimredis.conf使用命令後端啟動redisbin目錄下執行./redis-serverredis.conf查看是否啟動成功關閉後端啟動的方式:以上是單獨的redis安裝,接下來搭建叢集!安裝rubyyuminstallrubyyuminstallrubygems將以下檔案上傳到linux系統進入該目錄執行:geminstallredis-3.0.0.gem將redis-3.0.0包下src目錄中的以下檔案拷貝到/usr/local/redis/redis-cluster/前提:先建立一個redis-cluster目錄搭建叢集最少也得需要3台主機,如果每台主機再配置一台從機的話,則最少需要6台機器。連接埠設計如下:7001-7006第一步:複製出一個7001機器進入/usr/local/redis/目錄執行cpbin./redis-cluster/7001–r第二步:如果存在持久化檔案,則刪除rm-rfappendonly.aofdump.rdb第三步:設定叢集參數第四步:修改連接埠第五步:複製出7002-7006機器給出我案頭系統下的目錄結構:接下來設定一鍵啟動全部redis或者關閉redis群:首先,建立一個檔案,可以用vim開啟一個不存在的檔案,然後儲存就存在了。(的start-all.sh和shutdow-all.sh就是我建立的)start-all.sh:cd7001./redis-serverredis.confcd..cd7002./redis-serverredis.confcd..cd7003./redis-serverredis.confcd..cd7004./redis-serverredis.confcd..cd7005./redis-serverredis.confcd..cd7006./redis-serverredis.confcd..shutdow-all.sh:cd7001./redis-cli-p7001shutdowncd..cd7002./redis-cli-p7002shutdowncd..cd7003./redis-cli-p7003shutdowncd..cd7004./redis-cli-p7004shutdowncd..cd7005./redis-cli-p7005shutdowncd..cd7006./redis-cli-p7006shutdowncd..接下來修改那兩個檔案許可權,設定其為可開機指令檔chmodu+xstart-all.shchmodu+xshutdown-all.sh接下來用ruby串連這幾個叢集,進行管理/redis-trib.rbcreate--replicas1192.168.78.133:7001192.168.78.133:7002192.168.78.133:7003192.168.78.133:7004192.168.78.133:7005192.168.78.133:7006出現:Connectingtonode192.168.242.137:7001:OKConnectingtonode192.168.242.137:7002:OKConnectingtonode192.168.242.137:7003:OKConnectingtonode192.168.242.137:7004:OKConnectingtonode192.168.242.137:7005:OKConnectingtonode192.168.242.137:7006:OK>>>Performinghashslotsallocationon6nodes...Using3masters:192.168.242.137:7001192.168.242.137:7002192.168.242.137:7003Addingreplica192.168.242.137:7004to192.168.242.137:7001Addingreplica192.168.242.137:7005to192.168.242.137:7002Addingreplica192.168.242.137:7006to192.168.242.137:7003M:8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24192.168.242.137:7001slots:0-5460(5461slots)masterM:4f52a974f64343fd9f1ee0388490b3c0647a4db7192.168.242.137:7002slots:5461-10922(5462slots)masterM:cb7c5def8f61df2016b38972396a8d1f349208c2192.168.242.137:7003slots:10923-16383(5461slots)masterS:66adf006fed43b3b5e499ce2ff1949a756504a16192.168.242.137:7004replicates8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24S:cbb0c9bc4b27dd85511a7ef2d01bec90e692793b192.168.242.137:7005replicates4f52a974f64343fd9f1ee0388490b3c0647a4db7S:a908736eadd1cd06e86fdff8b2749a6f46b38c00192.168.242.137:7006replicatescb7c5def8f61df2016b38972396a8d1f349208c2CanIsettheaboveconfiguration?(type'yes'toaccept):yes>>>Nodesconfigurationupdated>>>Assignadifferentconfigepochtoeachnode>>>SendingCLUSTERMEETmessagestojointheclusterWaitingfortheclustertojoin..>>>PerformingClusterCheck(usingnode192.168.242.137:7001)M:8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24192.168.242.137:7001slots:0-5460(5461slots)masterM:4f52a974f64343fd9f1ee0388490b3c0647a4db7192.168.242.137:7002slots:5461-10922(5462slots)masterM:cb7c5def8f61df2016b38972396a8d1f349208c2192.168.242.137:7003slots:10923-16383(5461slots)masterM:66adf006fed43b3b5e499ce2ff1949a756504a16192.168.242.137:7004slots:(0slots)masterreplicates8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24M:cbb0c9bc4b27dd85511a7ef2d01bec90e692793b192.168.242.137:7005slots:(0slots)masterreplicates4f52a974f64343fd9f1ee0388490b3c0647a4db7M:a908736eadd1cd06e86fdff8b2749a6f46b38c00192.168.242.137:7006slots:(0slots)masterreplicatescb7c5def8f61df2016b38972396a8d1f349208c2[OK]Allnodesagreeaboutslotsconfiguration.>>>Checkforopenslots...>>>Checkslotscoverage...[OK]All16384slotscovered.則代表成功了!測試一下,進入7001目錄執行:./redis-cli-h192.168.242.137-p7001–c