日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 人文社科 > 生活经验 >内容正文

生活经验

Redis集群官方推荐方案 Redis-Cluster

發(fā)布時(shí)間:2023/11/27 生活经验 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Redis集群官方推荐方案 Redis-Cluster 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

      Redis-Cluster

redis使用中遇到的瓶頸

  我們?nèi)粘T趯?duì)于redis的使用中,經(jīng)常會(huì)遇到一些問(wèn)題

  1、高可用問(wèn)題,如何保證redis的持續(xù)高可用性。

  2、容量問(wèn)題,單實(shí)例redis內(nèi)存無(wú)法無(wú)限擴(kuò)充,達(dá)到32G后就進(jìn)入了64位世界,性能下降。

  3、并發(fā)性能問(wèn)題,redis號(hào)稱單實(shí)例10萬(wàn)并發(fā),但也是有盡頭的。

?

redis-cluster的優(yōu)勢(shì)  

  1、官方推薦,毋庸置疑。

  2、去中心化,集群最大可增加1000個(gè)節(jié)點(diǎn),性能隨節(jié)點(diǎn)增加而線性擴(kuò)展。

  3、管理方便,后續(xù)可自行增加或摘除節(jié)點(diǎn),移動(dòng)分槽等等。

  4、簡(jiǎn)單,易上手。

?

redis-cluster名詞介紹

  1、master  主節(jié)點(diǎn)、

  2、slave   從節(jié)點(diǎn)

  3、slot    槽,一共有16384數(shù)據(jù)分槽,分布在集群的所有主節(jié)點(diǎn)中。

?

redis-cluster簡(jiǎn)介

?

?

?

圖中描述的是六個(gè)redis實(shí)例構(gòu)成的集群

6379端口為客戶端通訊端口

16379端口為集群總線端口

集群內(nèi)部劃分為16384個(gè)數(shù)據(jù)分槽,分布在三個(gè)主redis中。

從redis中沒(méi)有分槽,不會(huì)參與集群投票,也不會(huì)幫忙加快讀取數(shù)據(jù),僅僅作為主機(jī)的備份。

三個(gè)主節(jié)點(diǎn)中平均分布著16384數(shù)據(jù)分槽的三分之一,每個(gè)節(jié)點(diǎn)中不會(huì)存有有重復(fù)數(shù)據(jù),僅僅有自己的從機(jī)幫忙冗余。

?

集群部署

測(cè)試部署方式,一臺(tái)測(cè)試機(jī)多實(shí)例啟動(dòng)部署。

安裝redis

$ wget http://download.redis.io/releases/redis-3.2.8.tar.gz
$ tar xzf redis-3.2.8.tar.gz
$ cd redis-3.2.8
$ make

修改配置文件 redis.conf

#redis.conf默認(rèn)配置
daemonize yes
pidfile /var/run/redis/redis.pid  #多實(shí)例情況下需修改,例如redis_6380.pid
port 6379        #多實(shí)例情況下需要修改,例如6380
tcp-backlog 511
bind 0.0.0.0      
timeout 0
tcp-keepalive 0
loglevel notice
logfile /var/log/redis/redis.log      #多實(shí)例情況下需要修改,例如6380.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb  #多實(shí)例情況下需要修改,例如dump.6380.rdb
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly yes
appendfilename "appendonly.aof"  #多實(shí)例情況下需要修改,例如 appendonly_6380.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10#################自定義配置
#系統(tǒng)配置
#vim /etc/sysctl.conf
#vm.overcommit_memory = 1aof-rewrite-incremental-fsync yes
maxmemory 4096mb
maxmemory-policy allkeys-lru
dir /opt/redis/data      #多實(shí)例情況下需要修改,例如/data/6380#集群配置
cluster-enabled yes
cluster-config-file /opt/redis/6380/nodes.conf   #多實(shí)例情況下需要修改,例如/6380/
cluster-node-timeout 5000#從ping主間隔默認(rèn)10秒
#復(fù)制超時(shí)時(shí)間
#repl-timeout 60#遠(yuǎn)距離主從
#config set client-output-buffer-limit "slave 536870912 536870912 0"
#config set repl-backlog-size 209715200

啟動(dòng)六個(gè)實(shí)例:

/編譯安裝目錄/src/redis-server redis.conf

注意,redis.conf應(yīng)為6個(gè)不同的修改過(guò)的多實(shí)例配置文件。?

注意,配置文件復(fù)制六分后,有許多需要你修改的地方。

?

?

創(chuàng)建redis-cluster

redis-trib.rb命令與redis-cli命令放置在同一個(gè)目錄中,可全路徑執(zhí)行或者創(chuàng)建別名。

redis-trib.rb create --replicas 0 127.0.0.1:6310 127.0.0.1:6320 127.0.0.1:6330 127.0.0.1:6340 127.0.0.1:6350 127.0.0.1:6360 只要缺失了任意一部分的槽,redis-cluster便無(wú)法讀取。 測(cè)試強(qiáng)行停機(jī)一臺(tái),既顯示: 127.0.0.1:6310> get key (error) CLUSTERDOWN The cluster is down 注:這里分片設(shè)置為了0 啟動(dòng)丟失的那一臺(tái)后既恢復(fù)。數(shù)據(jù)不會(huì)丟失。

移動(dòng)槽

redis-trib.rb reshard 127.0.0.1:6360 執(zhí)行集群reshard操作,通過(guò)集群中127.0.0.1:6360這一臺(tái)機(jī)器 [OK] All 16384 slots covered. How many slots do you want to move (from 1 to 16384)? 2731 輸入需要移動(dòng)的槽數(shù)量 What is the receiving node ID? 21c93aa709e10f7a9064faa04539b3ecd 輸入接收的節(jié)點(diǎn)的ID How many slots do you want to move (from 1 to 16384)? 2731 What is the receiving node ID? 0abf4ca21c93aa709e10f7a9064faa04539b3ecd Please enter all the source node IDs. ? Type 'all' to use all the nodes as source nodes for the hash slots. ? Type 'done' once you entered all the source nodes IDs. Source node #1:0ddb4e430dda8778ac873dd169951c7d71b8235e Source node #2:done 輸入所有被移動(dòng)的節(jié)點(diǎn)ID,確認(rèn)后輸入done ??? Moving slot 5460 from 0ddb4e430dda8778ac873dd169951c7d71b8235e ??? Moving slot 13653 from 0ddb4e430dda8778ac873dd169951c7d71b8235e Do you want to proceed with the proposed reshard plan (yes/no)? 檢查后輸入yes進(jìn)行移動(dòng)分槽 至此,分槽移動(dòng)完畢。

刪除節(jié)點(diǎn)

redis-trib.rb del-node 127.0.0.1:6360 'f24c0c1ecf629b5413cbca632d389efcad7c8346' 最后跟著的是這個(gè)節(jié)點(diǎn)的ID,可在redis-cli終端中使用CLUSTER NODES查看 必要條件,此節(jié)點(diǎn)所有分槽均已移除。

添加master節(jié)點(diǎn)

redis-trib.rb add-node 127.0.0.1:6360 127.0.0.1:6350 新節(jié)點(diǎn)必須是空的,不能包含任何數(shù)據(jù)。請(qǐng)把之前aof和dump文件刪掉,并且若有nodes.conf也需要?jiǎng)h除。 add-node? 將一個(gè)節(jié)點(diǎn)添加到集群里面, 第一個(gè)是新節(jié)點(diǎn)ip:port, 第二個(gè)是任意一個(gè)已存在節(jié)點(diǎn)ip:port node:新節(jié)點(diǎn)沒(méi)有包含任何數(shù)據(jù), 因?yàn)樗鼪](méi)有包含任何slot。新加入的加點(diǎn)是一個(gè)主節(jié)點(diǎn), 當(dāng)集群需要將某個(gè)從節(jié)點(diǎn)升級(jí)為新的主節(jié)點(diǎn)時(shí), 這個(gè)新節(jié)點(diǎn)不會(huì)被選中,同時(shí)新的主節(jié)點(diǎn)因?yàn)闆](méi)有包含任何slot,不參加選舉和failover。

添加一個(gè)從節(jié)點(diǎn)

前三步操作同添加master一樣 第四步:redis-cli連接上新節(jié)點(diǎn)shell,輸入命令:cluster replicate 對(duì)應(yīng)master的node-id

?

注:

安裝部署部分不是無(wú)腦復(fù)制即可,請(qǐng)結(jié)合你的主機(jī)情況進(jìn)行操作,若有問(wèn)題可以聯(lián)系我 ?QQ:2169866431

謝土豪

?

轉(zhuǎn)載于:https://www.cnblogs.com/kerwinC/p/6611634.html

總結(jié)

以上是生活随笔為你收集整理的Redis集群官方推荐方案 Redis-Cluster的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。