1.集群架構(gòu):
成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比甘南網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式甘南網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋甘南地區(qū)。費(fèi)用合理售后完善,十載實(shí)體公司更值得信賴。
解釋:
Redis 集群中內(nèi)置了 16384 個(gè)哈希槽,當(dāng)需要在 Redis 集群中放置一個(gè) key-value 時(shí), redis 先對(duì) key 使用 crc16 算法算出一個(gè)結(jié)果,然后把結(jié)果對(duì) 16384 求余數(shù), 這樣每個(gè) key 都會(huì)對(duì)應(yīng)一個(gè)編號(hào)在 0-16383 之間的哈希槽,redis 會(huì)根據(jù)節(jié)點(diǎn)數(shù)量大致均等的將哈希槽映射到不同的節(jié)點(diǎn) ? |
誤區(qū)解釋:這里的集群和主從復(fù)制不同,這里的集群中所有的都是mater,都有單節(jié)點(diǎn)顧長(zhǎng)官問(wèn)題,而主從復(fù)制只是解決單點(diǎn)故障問(wèn)題,
如果想讓集群模式下午單點(diǎn)故障問(wèn)題,需要給每一個(gè)master進(jìn)行主從復(fù)制。
?
2.redis-cluster 投票容錯(cuò)
集群不可用狀態(tài)的判斷:
?
3.redis集群的搭建
??? ①ruby的安裝
???????? 由于集群管理工具(redis-trib.rb)是使用ruby腳本語(yǔ)言編寫(xiě)的,所以需要ruby的環(huán)境
第一步:安裝ruby [root@hdp01 bin2]# yum install ruby [root@hdp01 bin2]# yum install rubygems 第二步:將redis-3.0.0.gem文件上傳到linux系統(tǒng) 第三步:安裝ruby和redis接口 [root@hdp01 ~]# gem install redis-3.0.0.gem 第四步:將redis-3.0.0包下src目錄中的以下文件拷貝到redis19/redis-cluster/ 第五步:查看是否拷貝成功 |
?
②搭建集群:
這里使用3臺(tái)服務(wù)器模擬redis集群。 第一步:復(fù)制出redis到一個(gè)機(jī)器中 [root@hdp01 redis]# scp? /xxx/redis-3.0.0 -r? hostname01:~/apps 第二步:如果存在持久化文件,則刪除 [root@hdp01 app]# rm -rf appendonly.aof dump.rdb 第三步:設(shè)置集群參數(shù) 開(kāi)啟集群模式: ? 第五步:復(fù)制redis服務(wù)到其他機(jī)器中 [root@hdp01 redis]# scp? /xxx/redis-3.0.0 -r? hostname02:~/apps[root@hdp01 redis]# scp? /xxx/redis-3.0.0 -r? hostname03:~/apps 第七步:?jiǎn)?dòng)三臺(tái)機(jī)器 [root@hdp01 redis]#redis-server redis.conf(三臺(tái)機(jī)器中都開(kāi)啟) 第九步:創(chuàng)建集群 [root@hdp01 redis-cluster]# ./redis-trib.rb create --replicas 1\ 192.168.130.128:6379 \ 192.168.130.129:6379 \ 192.168.130.130:6379 \ >>> Creating cluster Connecting to node 192.168.242.137:7001: OK Connecting to node 192.168.242.137:7002: OK Connecting to node 192.168.242.137:7003: OK Connecting to node 192.168.242.137:7004: OK Connecting to node 192.168.242.137:7005: OK Connecting to node 192.168.242.137:7006: OK >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 192.168.242.137:7001 192.168.242.137:7002 192.168.242.137:7003 Adding replica 192.168.242.137:7004 to 192.168.242.137:7001 Adding replica 192.168.242.137:7005 to 192.168.242.137:7002 Adding replica 192.168.242.137:7006 to 192.168.242.137:7003 M: 8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24 192.168.242.137:7001 slots:0-5460 (5461 slots) master M: 4f52a974f64343fd9f1ee0388490b3c0647a4db7 192.168.242.137:7002 slots:5461-10922 (5462 slots) master M: cb7c5def8f61df2016b38972396a8d1f349208c2 192.168.242.137:7003 slots:10923-16383 (5461 slots) master S: 66adf006fed43b3b5e499ce2ff1949a756504a16 192.168.242.137:7004 replicates 8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24 S: cbb0c9bc4b27dd85511a7ef2d01bec90e692793b 192.168.242.137:7005 replicates 4f52a974f64343fd9f1ee0388490b3c0647a4db7 S: a908736eadd1cd06e86fdff8b2749a6f46b38c00 192.168.242.137:7006 replicates cb7c5def8f61df2016b38972396a8d1f349208c2 Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join.. >>> Performing Cluster Check (using node 192.168.242.137:7001) M: 8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24 192.168.242.137:7001 slots:0-5460 (5461 slots) master M: 4f52a974f64343fd9f1ee0388490b3c0647a4db7 192.168.242.137:7002 slots:5461-10922 (5462 slots) master M: cb7c5def8f61df2016b38972396a8d1f349208c2 192.168.242.137:7003 slots:10923-16383 (5461 slots) master M: 66adf006fed43b3b5e499ce2ff1949a756504a16 192.168.242.137:7004 slots: (0 slots) master replicates 8240cd0fe6d6f842faa42b0174fe7c5ddcf7ae24 M: cbb0c9bc4b27dd85511a7ef2d01bec90e692793b 192.168.242.137:7005 slots: (0 slots) master replicates 4f52a974f64343fd9f1ee0388490b3c0647a4db7 M: a908736eadd1cd06e86fdff8b2749a6f46b38c00 192.168.242.137:7006 slots: (0 slots) master replicates cb7c5def8f61df2016b38972396a8d1f349208c2 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. |
??? ③測(cè)試集群是否搭建成功
????? [root@hdp01 7001]# ./redis-cli -h 192.168.130.130-p 6379 –c #連接集群
????? 相關(guān)命令介紹:
192.168.130.130:6379> cluster info? #查看集群信息 192.168.130.130:6379> cluster nodes? #查看集群節(jié)點(diǎn) |