redis:RDB AOF -master &slave -sentinel-cluster
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis:RDB AOF -master &slave -sentinel-cluster相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/replicate' title='replicate'>replicate
fsync 鏀寔 鍝ㄥ叺 run 閰嶇疆鏂囦欢 cpu 蹇収 鍐呭瓨鏁版嵁1銆丷DB鍜孉OF鐨勪紭缂虹偣
2銆乵aster鍜宻lave鍚屾杩囩▼
3銆佸摠鍏电殑浣跨敤鍜屽疄鐜版満鍒?br>4銆乺edis cluster闆嗙兢鍒涘缓鍜屼娇鐢?/p>
绗竴涓鐩€丷DB鍜孉OF鐨勪紭缂虹偣
涓€銆?RDB鐨勪紭鐐?br>1銆佷紭鐐筧锛歊DB 蹇収淇濆瓨浜嗘煇涓椂闂寸偣鐨勬暟鎹紝鍙互閫氳繃鑴氭湰鎵цredis鎸囦护bgsave锛堥潪闃诲锛屽悗鍙版墽琛岋級鎴栬€卻ave锛堜細闃诲鍐欐搷浣滐紝涓嶆帹鑽愶級鍛戒护鑷畾涔夋椂闂寸偣澶囦唤锛屽彲浠ヤ繚澶氫釜澶囦唤锛屽綋鍑虹幇闂鍙互鎭㈠鍒颁笉鍚屾椂闂寸偣鐨勭増鏈紝寰堥€傚悎澶囦唤骞朵笖姝ゆ枃浠舵牸寮忎篃鏈夋敮鎸佹湁涓嶅皯绗笁鏂瑰伐鍏峰彲浠ヨ繘琛屽悗缁殑鏁版嵁鍒嗘瀽銆?br> 姣斿锛氬彲浠ュ湪鏈€杩戠殑24灏忔椂鍐呮瘡灏忔椂澶囦唤涓€娆DB鏂囦欢锛屽苟涓斿湪姣忎竴澶╋紝涔熷浠戒竴涓猂DB鏂囦欢锛岃繖鏍风殑璇濆嵆浣块亣涓婇棶棰橈紝涔熷彲浠ラ殢鏃跺皢鏁版嵁闆嗚繕鍘熷埌涓嶅悓鐨勭増鏈€?br> 浼樼偣b锛歊DB鍙互鏈€澶у寲Redis 鐨勬€ц兘锛岀埗杩涚▼鍦ㄤ繚瀛楻DB鏂囦欢鏃跺敮涓€瑕佸仛鐨勫氨鏄痜ork鍑轰竴涓瓙杩涚▼锛岀劧鍚庤繖涓瓙杩涚▼灏变細澶勭悊鎺ヤ笅鏉ョ殑鎵€鏈変繚瀛樺伐浣滐紝鐖惰繘绋嬫棤闇€鎵ц浠讳綍纾佺洏I/O鎿嶄綔銆?br> 浼樼偣c锛歊DB鍦ㄥぇ閲忔暟鎹紝姣斿鍑犱釜G鐨勬暟鎹紝鎭㈠鐨勯€熷害姣擜OF蹇?br> 2銆丷DB鐨勭己鐐?br> 缂虹偣a锛氫笉鑳藉疄鏃朵繚瀛樻暟鎹紝鍙兘浼氫涪澶辫嚜涓婁竴娆℃墽琛孯DB澶囦唤鍒板綋鍓嶇殑鍐呭瓨鏁版嵁
濡傛灉浣犻渶瑕佸敖閲忛伩鍏嶅湪鏈嶅姟鍣ㄦ晠闅滄椂涓㈠け鏁版嵁锛岄偅涔圧DB涓嶉€傚悎浣犮€傝櫧鐒禦edis鍏佽浣犺缃笉鍚岀殑淇濆瓨鐐癸紙save point ) 鏉ユ帶鍒朵繚瀛楻DB鏂囦欢鐨勯鐜囷紝浣嗘槸锛屽洜涓篟D鏂囦欢闇€瑕佷繚瀛樻暣涓暟鎹泦鐨勭姸鎬侊紝鎵€浠ュ畠骞朵笉鏄竴涓交鏉剧殑鎿嶄綔銆傚洜姝や綘鍙兘浼氳嚦灏?鍒嗛挓鎵嶄繚瀛樹竴娆DB鏂囦欢銆傚湪杩欑鎯呭喌涓嬶紝涓€鏃﹀彂鐢熸晠闅滃仠鏈猴紝浣犲氨鍙兘浼氫涪澶卞ソ鍑犲垎閽熺殑鏁版嵁銆?br> 缂虹偣b锛氬綋鏁版嵁閲忛潪甯稿ぇ鐨勬椂鍊欙紝浠庣埗杩涚▼fork瀛愯繘绋嬭繘琛屼繚瀛樿嚦RDB鏂囦欢鏃堕渶瑕佷竴鐐规椂闂达紝鍙兘鏄绉掓垨绉掞紝鍙栧喅浜庣鐩樼殑IO鎬ц兘銆?br> 鍦ㄦ暟鎹泦姣旇緝搴炲ぇ鏃讹紝fork锛堬級鍙兘浼氶潪甯歌€楁椂锛岄€犳垚鏈嶅姟鍣ㄥ湪涓€瀹氭椂闂村唴鍋滄澶勭悊瀹㈡埛绔細濡傛灉鏁版嵁闆嗛潪甯稿法澶э紝骞朵笖CPU鏃堕棿闈炲父绱у紶鐨勮瘽锛岄偅涔堣繖绉嶅仠姝㈡椂闂寸敋鑷冲彲鑳戒細闀胯揪鏁存暣涓€绉掓垨鏇翠箙銆傝櫧鐒禔OF閲嶅啓涔熼渶瑕佽繘琛宖ork锛堬級锛屼絾鏃犺AOF閲嶅啓鐨勬墽琛岄棿闅旀湁澶氶暱锛屾暟鎹殑鎸佷箙鎬ч兘涓嶄細鏈変换浣曟崯澶便€?/p>
浜屻€丄OF鐨勪紭缂虹偣
1銆佷紭鐐筧 鏁版嵁瀹夊叏鎬х浉瀵硅緝楂橈紝鏍规嵁鎵€浣跨敤鐨刦snc绛栫暐锛坒sync鏄悓姝ュ唴瀛樹腑redis鎵€鏈夊凡缁忎慨鏀圭殑鏂囦欢鍒板瓨鍌ㄨ澶囷級锛岄粯璁ゆ槸appendfsync everysec锛屽嵆姣忕鎵ц涓€娆sync锛屽湪杩欑閰嶇疆涓嬶紝Redis浠嶇劧鍙互淇濇寔鑹ソ鐨勬€ц兘锛屽苟涓斿氨绠楀彂鐢熸晠闅滃仠鏈猴紝涔熸渶澶氬彧浼氫涪澶变竴绉掗挓鐨勬暟鎹紙fsync浼氬湪鍚庡彴绾跨▼鎵ц锛屾墍浠ヤ富绾跨▼鍙互缁х画鍔姏鍦板鐞嗗懡浠よ姹傦級
浼樼偣b锛氱敱浜庤鏈哄埗瀵规棩蹇楁枃浠剁殑鍐欏叆鎿嶄綔閲囩敤鐨勬槸append妯″紡锛屽洜姝ゅ湪鍐欏叆杩囩▼涓笉闇€瑕乻eek锛屽嵆浣垮嚭鐜板畷鏈虹幇璞★紝涔熶笉浼氱牬鍧忔棫鏃ュ織鏂囦欢涓凡缁忓瓨鍦ㄧ殑鍐呭銆傜劧鑰屽鏋滄湰娆℃搷浣滃彧鏄啓鍏ヤ簡涓€鍗婃暟鎹氨鍑虹幇浜嗗穿婧冮棶棰橈紝涓嶇敤鎷呭績锛屽湪Redis涓嬩竴娆″惎鍔ㄥ墠锛屽彲浠ラ€氳繃redis-check-aof宸ュ叿鏉ヨВ鍐虫暟鎹竴鑷存€х殑闂銆?br> 浼樼偣c: Redis 鍙互鍦ˋOF鏂囦欢浣撶Н鍙樺緱杩囧ぇ鏃讹紝鑷姩鍦板湪鍚庡彴瀵笰OF杩涜閲嶅啓锛氶噸鍐欏悗鐨勬柊AOF鏂囦欢鍖呭惈浜嗘仮澶嶅綋鍓嶆暟鎹泦鎵€闇€瑕佺殑鏈€灏忓懡浠ら泦鍚堛€傛暣涓噸鍐欐搷浣滄椂缁濆瀹夊叏鐨勫洜涓篟edis鍦ㄥ垱寤烘柊AOF鏂囦欢鐨勮繃绋嬩腑锛宎ppend妯″紡涓嶆柇鐨勫皢淇敼鏁版嵁杩藉姞鍒扮幇鏈夌殑AOF鏂囦欢閲岄潰锛屽嵆浣块噸鍐欒繃绋嬩腑鍙戠敓鍋滄満锛岀幇鏈夌殑AOF鏂囦欢涔熶笉浼氫涪澶便€傝€屼竴鏃︽柊鐨凙OF鏂囦欢鍒涘缓瀹屾瘯锛孯edis灏变細浠庢棫AOF鏂囦欢鍒囨崲鍒?鏂扮殑AOF鏂囦欢锛屽苟寮€濮嬪鏂癆OF鏂囦欢杩涜杩藉姞鎿嶄綔銆?br> 浼樼偣d锛欰OF鍖呭惈涓€涓牸寮忔竻鏅般€佹槗浜庣悊瑙g殑鏃ュ織鏂囦欢鐢ㄤ簬璁板綍鎵€鏈夌殑淇敼鎿嶄綔銆備簨瀹炰笂锛屼篃鍙互閫氳繃璇ユ枃浠跺畬鎴愭暟鎹殑閲嶅缓銆侫OF鏂囦欢鏈夊簭鍦颁繚瀛樹簡瀵规暟鎹簱鎵ц鐨勬墍鏈夊啓鍏ユ搷浣滐紝杩欎簺鍐欏叆鎿嶄綔Redis鍗忚鐨勬牸寮忎繚瀛橈紝鍥犳AOF鏂囦欢鐨勫唴瀹归潪甯稿鏄撹浜鸿鎳傦紝瀵规枃浠惰繘琛屽垎鏋愶紙parse)涔熷緢杞绘澗銆傚鍑猴紙export锛堿OF鏂囦欢涔熼潪甯哥畝鍗曪細涓句釜渚嬪瓙锛屽鏋滀綘涓嶅皬蹇冩墽琛屼簡FLUSHALL.鍛戒护锛屼絾鍙AOF鏂囦欢鏈閲嶅啓锛岄偅涔堝彧瑕佸仠姝㈡湇鍔″櫒锛岀Щ闄OF鏂囦欢鏈熬鐨凢ULUSHALL鍛戒护锛屽苟閲嶅惎Redis锛屽氨鍙互灏嗘暟鎹泦鎭㈠鍒癋LUSHALL鎵ц涔嬪墠鐨勭姸鎬?/p>
2銆佺己鐐筧: 鍗充娇鏈変簺鎿嶄綔鏃堕噸澶嶇殑涔熶細鍏ㄩ儴璁板綍锛孉OF鐨勬枃浠跺ぇ灏忚澶т簬RDB鏍煎紡鐨勬枃浠?br> 缂虹偣b:AOF鍦ㄦ仮澶嶅ぇ鏁版嵁闆嗘椂鐨勯€熷害姣擱DBB鐨勬仮澶嶉€熷害瑕佹參
缂虹偣c锛氭牴鎹甪sync绛栫暐涓嶅悓锛孉OF閫熷害鍙兘浼氭參浜嶳DB
缂虹偣d锛沚ug鍑虹幇鐨勫彲鑳芥€ф洿澶?/p>
RDB鍜孉OF鐨勯€夋嫨
濡傛灉涓昏鍏呭綋缂撳啿鍔熻兘锛屾垨鑰呭彲浠ユ壙鍙楁暟鍒嗛挓鏁版嵁鐨刬涓㈠け锛岄€氬父鐢熶骇鐜涓€鑸彧闇€鍚敤RDB鍗冲彲锛屾涔熸槸榛樿鍊笺€?br> 濡傛灉鏁版嵁闇€瑕佹寔涔呬繚瀛橈紝涓€鐐逛笉鑳戒涪澶憋紝鍙互閫夋嫨鍚屾椂寮€鍚疪DB鍜孉OF锛屼竴鑸笉寤鸿鍙紑鍚疉OF
绗簩涓鐩甿aster鍜宻lave鍚屾杩囩▼
瀹為獙濡備笅
鍑嗗锛氫富鑺傜偣MASTER-IP 10.0.0.128
浠庤妭鐐筍LAVE-IP 10.0.0.137
涓€銆佸湪涓昏妭鐐逛笂淇敼閰嶇疆鏂囦欢
[root@master ~]#vim /etc/redis.config
bind 0.0.0.0
requirepass 123456
configset masterauth 123456
閲嶅惎鏈嶅姟
systemclt restart redis
浜屻€佸湪浠庤妭鐐逛笂淇敼閰嶇疆鏂囦欢
[root@slave ~]#vim /etc/redis.config
bind 0.0.0.0
requirepass 123456
configset masterauth 123456
replicaof 10.0.0.110 6379
閲嶅惎鏈嶅姟
systemclt restart redis
涓夈€侀獙璇佷富浠庢槸鍚﹀悓姝?br>[root@slave ~]#redis-cli -a 123456 info replication
# Replication
role:slave 鏈満瑙掕壊鏄痵lave
master_host:10.0.0.128 涓昏妭鐐逛负10.0.0.128鍚屾鎴愬姛
master_port:6379
master_link_status:up
master_last_io_seconds_ago:9
master_sync_in_progress:0
slave_repl_offset:593
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen
绗笁涓鐩€佸摠鍏电殑浣跨敤鍜屽疄鐜版満鍒?/em>
闃叉鑴戣锛屽噯澶囧鏁板彴涓绘満瀹為獙
master: 10.0.0.110
slave1: 10.0.0.120
slave2: 10.0.0.123
涓€銆乵aster閰嶇疆
1銆佺敤sed瀹炵幇master閰嶇疆淇敼
bind 0.0.0.0
masterauth 123456
requirepass 12345
[root@10.0.0.128]#sed -i -e 鈥榮/bind 127.0.0.1/bind 0.0.0.0/鈥? -e 鈥榮/^# masterauth .*/masterauth 123456/鈥? -e 鈥榮/^# requirepass .*/requirepass 123456/鈥?/etc/redis.conf
妫€鏌ラ厤缃槸鍚︽湁鏁?br>grep -Ev 鈥榐#|^$鈥? /etc/redis.conf
2銆佷慨鏀瑰摠鍏祍entinel閰嶇疆鏂囦欢
[root@10.0.0.128]#vim /etc/redis-sentinel.conf
sentinel monitor mymaster 10.0.0.8 6379 2 锛坢ymaster鏄泦缇ょ殑鍛藉悕锛岄泦缇ゆ€昏妭鐐规暟/2鍙栨暣鏁帮紝灏忔暟鍒欏洓鑸嶄簲鍏?/2+1=2锛?br>sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 3000
grep -Ev 鈥榐#|^$鈥? /etc/redis.conf
grep -Ev 鈥榐#|^$鈥? /etc/redis-sentinel.conf
cat /etc/redis-sentinel.conf | grep sentinel
閲嶅惎鏈嶅姟
systemctl restart redis redis-sentinel
浜屻€佷慨鏀箂lave1閰嶇疆鏂囦欢
1銆乻lave1淇敼閰嶇疆 鐢╯ed瀹炵幇浠ヤ笅閰嶇疆 骞舵坊鍔爉aster10.0.0.110涓轰富鑺傜偣
[root@10.0.0.120]#sed -i -e 鈥榮/bind 127.0.0.1/bind 0.0.0.0/鈥? -e 鈥榮/^# masterauth .*/masterauth 123456/鈥? -e 鈥榮/^# requirepass .*/requirepass 123456/鈥?/etc/redis.conf
[root@10.0.0.120]#echo replicaof 10.0.0.110 6379
妫€鏌ラ厤缃槸鍚︽湁鏁?br>grep -Ev 鈥榐#|^$鈥? /etc/redis.conf
2銆佷慨鏀瑰摠鍏祍entinel閰嶇疆鏂囦欢
[root@10.0.0.120]#vim /etc/redis-sentinel.conf
sentinel monitor mymaster 10.0.0.110 6379 2 锛坢ymaster鏄泦缇ょ殑鍛藉悕锛岄泦缇ゆ€昏妭鐐规暟/2鍙栨暣鏁帮紝灏忔暟鍒欏洓鑸嶄簲鍏?/2+1=2锛?br>sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 3000
妫€鏌ラ厤缃槸鍚︽湁鏁?br>grep -Ev 鈥榐#|^$鈥? /etc/redis-sentinel.conf
涓夈€佷慨鏀箂lave2閰嶇疆鏂囦欢
1銆乻lave2淇敼閰嶇疆 鐢╯ed瀹炵幇浠ヤ笅閰嶇疆 骞舵坊鍔爉aster10.0.0.110涓轰富鑺傜偣
[root@10.0.0.123]#sed -i -e 鈥榮/bind 127.0.0.1/bind 0.0.0.0/鈥? -e 鈥榮/^# masterauth .*/masterauth 123456/鈥? -e 鈥榮/^# requirepass .*/requirepass 123456/鈥?/etc/redis.conf
[root@10.0.0.123]#echo replicaof 10.0.0.110 6379
妫€鏌ラ厤缃槸鍚︽湁鏁?br>grep -Ev 鈥榐#|^$鈥? /etc/redis.conf
2銆佷慨鏀瑰摠鍏祍entinel閰嶇疆鏂囦欢
[root@10.0.0.123]#vim /etc/redis-sentinel.conf
sentinel monitor mymaster 10.0.0.110 6379 2 锛坢ymaster鏄泦缇ょ殑鍛藉悕锛岄泦缇ゆ€昏妭鐐规暟/2鍙栨暣鏁帮紝灏忔暟鍒欏洓鑸嶄簲鍏?/2+1=2锛?br>sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 3000
妫€鏌ラ厤缃槸鍚︽湁鏁?br>grep -Ev 鈥榐#|^$鈥? /etc/redis-sentinel.conf
鍥涖€佹鏌ュ悇鑺傜偣瑙掕壊鏄惁1涓讳袱浠庯紵鍚勮妭鐐圭殑myid鏄惁涓嶅悓锛屽摠鍏祍entinel鎬绘暟鏄惁涓?
1銆佹鏌ヤ富浠庤鑹?br>[root@master ~]#redis-cli -a 123456 info replication
Warning: Using a password with 鈥?a鈥?or 鈥?u鈥?option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:2
slave0:ip=10.0.0.120,port=6379,state=online,offset=4087,lag=1
slave1:ip=10.0.0.123,port=6379,state=online,offset=4087,lag=1
master_replid:2be1cf7dfeed95e22c139873b62a3cf6e153b41d
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:4101
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:4101
2銆佹鏌ュ摠鍏垫€绘暟
[root@centos ~]#redis-cli -p 26379 info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=10.0.0.110:6379,slaves=2,sentinels=3
3銆佹瘮杈冧笁涓妭鐐圭殑myid锛屼笉鍚屽垯閰嶇疆姝g‘銆?br>[root@master ~]#grep -Ev 鈥榐#|^$鈥? /etc/redis-sentinel.conf |grep myid
sentinel myid e9112c856e07f57b42156fff06aa9e0524bb5395
[root@slave1 ~]#grep -Ev 鈥榐#|^$鈥? /etc/redis-sentinel.conf |grep myid
sentinel myid a0d3ffed61130e96a384649d0538b082ae8137cd
[root@slav2 ~]#grep -Ev 鈥榐#|^$鈥? /etc/redis-sentinel.conf |grep myid
sentinel myid 3c81969730106b45a8988a859360535f682d197e
妯℃嫙涓昏妭鐐筸aster鍑虹幇鏁呴殰
[root@master ~]#systemctl stop redis
鏃ュ織鏌ョ湅鏁呴殰杞Щ杩囩▼(浠绘剰鑺傜偣鐨嗗彲鏌ヨ锛?br>tail -f /var/log/redis/sentinel.log
3092:X 06 Dec 2020 10:22:11.468 * +slave slave 10.0.0.120:6379 10.0.0.120 6379 @ mymaster 10.0.0.110 6379
3092:X 06 Dec 2020 10:22:11.470 * +slave slave 10.0.0.123:6379 10.0.0.123 6379 @ mymaster 10.0.0.110 6379
3092:X 06 Dec 2020 10:22:11.534 # -sdown master mymaster 10.0.0.110 6379
3092:X 06 Dec 2020 10:22:11.535 # -odown master mymaster 10.0.0.110 6379
3092:X 06 Dec 2020 10:55:30.121 # +sdown master mymaster 10.0.0.110 6379
3092:X 06 Dec 2020 10:55:30.177 # +new-epoch 4
3092:X 06 Dec 2020 10:55:30.177 # +vote-for-leader a0d3ffed61130e96a384649d0538b082ae8137cd 4
3092:X 06 Dec 2020 10:55:30.191 # +odown master mymaster 10.0.0.110 6379 #quorum 3/2
3092:X 06 Dec 2020 10:55:30.191 # Next failover delay: I will not start a failover before Sun Dec 6 11:01:30 2020
3092:X 06 Dec 2020 10:55:31.260 # +config-update-from sentinel a0d3ffed61130e96a384649d0538b082ae8137cd 10.0.0.120 26379 @ mymaster 10.0.0.110 6379
3092:X 06 Dec 2020 10:55:31.260 # +switch-master mymaster 10.0.0.110 6379 10.0.0.120 6379
3092:X 06 Dec 2020 10:55:31.261 * +slave slave 10.0.0.123:6379 10.0.0.123 6379 @ mymaster 10.0.0.120 6379 鍙湅鍒皊lave1 10.0.0.120琚€変妇涓轰富鑺傜偣master
3092:X 06 Dec 2020 10:55:31.261 * +slave slave 10.0.0.110:6379 10.0.0.110 6379 @ mymaster 10.0.0.120 6379
3092:X 06 Dec 2020 10:55:34.291 # +sdown slave 10.0.0.110:6379 10.0.0.110 6379 @ mymaster 10.0.0.120 6379
[root@slave1 ~]#redis-cli -a 123456 info replication
Warning: Using a password with 鈥?a鈥?or 鈥?u鈥?option on the command line interface may not be safe.
# Replication
role:master 宸茬粡涓簃aster
connected_slaves:1 鐢变簬鍘熸潵涓昏妭鐐瑰畷鏈猴紝鎵€浠ョ幇鍦ㄦ槸鏂癿aster鍜宻lave2
slave0:ip=10.0.0.123,port=6379,state=online,offset=98579,lag=0
master_replid:e7114ed4c2fee39cf0463a573d4b90fc15d245f5
master_replid2:85631e9b1fb9d1790e8966d05ccd50356d6d9cb0
master_repl_offset:98579
second_repl_offset:969
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:98579
妫€鏌lave2鐨勯厤缃枃浠?etc/redis.conf宸茬粡鑷姩鏇存柊涓?0.0.0.120
[root@slave2 ~]#grep -Ev 鈥榐#|^$鈥?/etc/redis.conf | grep replicaof
replicaof 10.0.0.120 63
妫€鏌lave2鐨勯厤缃枃浠?/etc/redis-sentinel.conf 鏄惁鑷姩鏇存柊鎴愬姛
[root@slave2 ~]#grep -Ev 鈥榐#|^$鈥?/etc/redis-sentinel.conf | grep mymaster
sentinel monitor mymaster 10.0.0.120 6379 2 宸叉洿鏂?br>sentinel down-after-milliseconds mymaster 3000
sentinel auth-pass mymaster 123456
sentinel config-epoch mymaster 4
sentinel leader-epoch mymaster 4
sentinel known-replica mymaster 10.0.0.110 6379
sentinel known-replica mymaster 10.0.0.123 6379
sentinel known-sentinel mymaster 10.0.0.120 26379 a0d3ffed61130e96a384649d0538b082ae8137cd
sentinel known-sentinel mymaster 10.0.0.110 26379 e9112c856e07f57b42156fff06aa9e0524bb5395
绗洓涓鐩畆edis cluster闆嗙兢鍒涘缓鍜屼娇鐢?/strong>
鍑嗗涓夊彴涓绘満
maser1:10.0.0.110
master2:10.0.0.120
master3:10.0.0.123
鏂板姞鍏ョ殑master4:10.0.0.130
鏂板姞鍏ョ殑slave1:10.0.0.138
涓€銆乺edis cluster闆嗙兢鐨勫垱寤?br>1鍦ㄤ笁鍙颁富鏈轰慨鏀瑰悓鏍风殑鎿嶄綔锛氬畨瑁卹edis鏈嶅姟
[root@master1/2/3~]#yum -y install redis
2銆佸湪涓夊彴涓绘満淇敼鍚屾牱鐨勬搷浣滐細淇敼閰嶇疆鏂囦欢/etc/redis.conf
鏂规硶a vim
[root@master1~]#vim /etc/redis.conf
bind 0.0.0.0
masterauth 123456
requirepass 123456
cluster-enabled yes 榛樿鍏抽棴
cluster-config-file nodes-6379.conf 鍘绘帀娉ㄩ噴
cluster-require-full-coverage no
鏂规硶b 鐢╯ed鍛戒护淇敼涓婚厤缃枃浠?br>[root@master1 ~]#sed -i.bak -e 鈥榮/bind 127.0.0.1/bind 0.0.0.0/鈥? -e 鈥?masterauth/a masterauth 123456鈥? -e 鈥?# requirepass/a requirepass 123456鈥? -e 鈥?# cluster-enabled yes/a cluster-enabled yes鈥? -e 鈥?# cluster-config-file nodes-6379.conf/a cluster-config-file nodes-6379.conf鈥? -e 鈥?cluster-require-full-coverage yes/c cluster-require-full-coverage no鈥? /etc/redis.conf
3銆侀噸鍚痳edis鏈嶅姟
[root@master1 ~]#systemctl enable --now redis
4銆佸娉細mastter2 鍜宮aster3閰嶇疆鍚屼笂闈㈢殑master1
5銆佸悇涓妭鐐逛箣闂村缓绔嬪弸璋婂叧绯籱eet
[root@mster1 ~]#redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.120 6379
OK
[root@master1 ~]#redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.123 6379
OK
[root@master2~]#redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.123 6379
OK
6銆佷换鎰忚妭鐐规煡鐪嬭闆嗙兢褰撳墠鍑犱釜涓昏妭鐐?br>[root@master1 ~]#redis-cli -a 123456 cluster nodes
Warning: Using a password with 鈥?a鈥?or 鈥?u鈥?option on the command line interface may not be safe.
c1fdf4469f7e5047caf930326e742da0adfbcd73 10.0.0.123:6379@16379 master - 0 1607226490256 2 connected
d7fdc965f3d5c6f6c22d049233f90fa97594e0a8 10.0.0.110:6379@16379 myself,master - 0 1607226488000 0 connected
01f1dd9c14ea7f886456a7758f4198d6280ae390 10.0.0.120:6379@16379 master - 0 1607226491279 1 connected
*******璇ラ泦缇ゆ湁涓変釜涓昏妭鐐瑰凡缁忓垱寤哄ソ銆?*******
浜屻€乺edis cluster闆嗙兢鐨勪娇鐢?锛堣瀹為獙浠edis5鐗堟湰涓轰緥锛岃嫢3/4鐗堟湰锛岄渶瑕佺敤ruby宸ュ叿瀹夎渚濊禆鍖呮潵鎼缓ruby鐨勭幆澧冿級
涓嬮潰浠庢墿瀹癸紝缂╁鏉ュ垎鍒疄楠?br>A鎵╁瀹為獙
1銆佸湪鍏朵腑涓€鍙颁富鑺傜偣鍒嗛厤妲戒綅鍗冲彲锛氱敱浜庢湁16834涓猻lots(妲戒綅锛夛紝鎵€浠ラ渶瑕?缂栬緫鑴氭湰鍒嗗埆鍦ㄥ悇鑺傜偣鍒嗛厤妲戒綅
[root@master1 ~]#vim addslot.sh
host=$1
port=$2
start=$3
end=$4
pass=123456
for slot in `seq ${start} ${end}` ;do
echo slot:$slot
redis-cli -h ${host} -p $port -a ${pass} --no-auth-warning cluster addslots ${slot}
done
2銆佹墽琛岃剼鏈敓鎴愰鍏堣鍒掑ソ鐨勬Ы浣?br>[root@master1 ~]#bash addslot.sh 10.0.0.110 6379 0 5461
[root@master1 ~]#bash addslot.sh 10.0.0.120 6379 5462 10922
[root@master1 ~]#bash addslot.sh 10.0.0.123 6379 10923 16383
鏌ョ湅妲戒綅鏄惁鍒嗛厤濂?br>[root@centos ~]#redis-cli -a 123456 --no-auth-warning cluster nodes
c1fdf4469f7e5047caf930326e742da0adfbcd73 10.0.0.123:6379@16379 master - 0 1607239685000 2 connected 10923-16383
d7fdc965f3d5c6f6c22d049233f90fa97594e0a8 10.0.0.110:6379@16379 myself,master - 0 1607239683000 0 connected 0-5461
01f1dd9c14ea7f886456a7758f4198d6280ae390 10.0.0.120:6379@16379 master - 0 1607239685330 1 connected 5462-10922
3銆佹坊鍔犱粠鑺傜偣骞舵寚瀹氫粠鑺傜偣鍜屼富鑺傜偣
[root@master1 ~]#redis-cli -a 123456 --cluster add-node 10.0.0.130:6379 10.0.0.110:6379
鐢变簬鏂癿aster鍔犲叆锛岄渶瑕侀噸鏂板垎閰嶆Ы浣嶏紝鎬濊矾锛氬皢鍘熸潵鐨勮妭鐐圭殑鎵€鏈夋Ы浣嶅钩鍧囧垎閰嶇粰瀹冨嵆鍙€?br>鍦ㄤ换鎰忎竴鍙颁富鏈哄嵆鍙垎閰嶆Ы浣?br>[root@master1 ~]#redis-cli -a 123456 --cluster reshard 10.0.0.130:6379
Warning: Using a password with 鈥?a鈥?or 鈥?u鈥?option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 10.0.0.130:6379)
M: 8683d12e877291842b2dadb428fd8b72ab294425 10.0.0.130:6379
slots: (0 slots) master
M: d7fdc965f3d5c6f6c22d049233f90fa97594e0a8 10.0.0.110:6379
slots:[0-5461] (5462 slots) master
M: c1fdf4469f7e5047caf930326e742da0adfbcd73 10.0.0.123:6379
slots:[10923-16383] (5461 slots) master
M: 01f1dd9c14ea7f886456a7758f4198d6280ae390 10.0.0.120:6379
slots:[5462-10922] (5461 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 4096 4涓猰aster骞冲潎鍒嗛厤妲戒綅= 锛?6384/4=4096锛?br>What is the receiving node ID? 8683d12e877291842b2dadb428fd8b72ab294425 鏂癿aster鐨処D鍙?br>Please enter all the source node IDs.
Type 鈥榓ll鈥?to use all the nodes as source nodes for the hash slots.
Type 鈥榙one鈥?once you entered all the source nodes IDs.
Source node #1: all 璇存槑灏嗘墍鏈夎妭鐐圭殑妲戒綅閮戒細骞冲潎鍒嗛厤鍒版柊master
...........................................................................
Moving slot 6824 from 01f1dd9c14ea7f886456a7758f4198d6280ae390
Moving slot 6825 from 01f1dd9c14ea7f886456a7758f4198d6280ae390
Moving slot 6826 from 01f1dd9c14ea7f886456a7758f4198d6280ae390
Do you want to proceed with the proposed reshard plan (yes/no)? yes
4銆佷换鎰忎竴鍙颁富鏈烘煡鐪嬫Ы浣?br>[root@master1~]#redis-cli -a 123456 cluster nodes
Warning: Using a password with 鈥?a鈥?or 鈥?u鈥?option on the command line interface may not be safe.
d7fdc965f3d5c6f6c22d049233f90fa97594e0a8 10.0.0.110:6379@16379 master - 0 1607241112000 0 connected 1366-5461
8683d12e877291842b2dadb428fd8b72ab294425 10.0.0.130:6379@16379 myself,master - 0 1607241110000 4 connected 0-1365 5462-6826 10923-12287
c1fdf4469f7e5047caf930326e742da0adfbcd73 10.0.0.123:6379@16379 master - 0 1607241111000 2 connected 12288-16383
01f1dd9c14ea7f886456a7758f4198d6280ae390 10.0.0.120:6379@16379 master - 0 1607241111779 1 connected 6827-10922
5銆佺幇鍦ㄥ姞鍏ヤ竴鍙颁粠鑺傜偣鍔犲叆鎴愪负10.0.0.110鐨勪粠鑺傜偣
淇敼閰嶇疆鏂囦欢 /etc/redis.conf
[root@10.0.0.138 ~]#sed -i.bak -e 鈥榮/bind 127.0.0.1/bind 0.0.0.0/鈥? -e 鈥?masterauth/a masterauth 123456鈥? -e 鈥?# requirepass/a requirepass 123456鈥? -e 鈥?# cluster-enabled yes/a cluster-enabled yes鈥? -e 鈥?# cluster-config-file nodes-6379.conf/a cluster-config-file nodes-6379.conf鈥? -e 鈥?cluster-require-full-coverage yes/c cluster-require-full-coverage no鈥? /etc/redis.conf
6銆侀噸鍚湇鍔?br>[root@10.0.0.138 ~]#systemctl enable --now redis
灏嗘柊鑺傜偣138鍔犲叆闆嗙兢锛岄粯璁ゆ槸鍔犲叆鍚庝负涓昏妭鐐筸aster
[root@10.0.0.138~]#redis-cli -a 123456 --cluster add-node 10.0.0.138:6379 10.0.0.120:6379 --cluster-slave --cluster-master-id d7fdc965f3d5c6f6c22d049233f90fa97594e0a8
Warning: Using a password with 鈥?a鈥?or 鈥?u鈥?option on the command line interface may not be safe.
>>> Adding node 10.0.0.138:6379 to cluster 10.0.0.120:6379
>>> Performing Cluster Check (using node 10.0.0.120:6379)
M: 01f1dd9c14ea7f886456a7758f4198d6280ae390 10.0.0.120:6379
slots:[6827-10922] (4096 slots) master
M: 8683d12e877291842b2dadb428fd8b72ab294425 10.0.0.130:6379
slots:[0-1365],[5462-6826],[10923-12287] (4096 slots) master
M: c1fdf4469f7e5047caf930326e742da0adfbcd73 10.0.0.123:6379
slots:[12288-16383] (4096 slots) master
M: d7fdc965f3d5c6f6c22d049233f90fa97594e0a8 10.0.0.110:6379
slots:[1366-5461] (4096 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 10.0.0.138:6379 to make it join the cluster.
Waiting for the cluster to join
...
>>> Configure node as replica of 10.0.0.110:6379.
[OK] New node added correctly. 娣诲姞鎴愬姛
7銆佹煡鐪?0.0.0.110鐨勪粠鑺傜偣鏄惁鏄?38鐨勪富鑺傜偣
[root@localhost ~]#redis-cli -a 123456 --no-auth-warning cluster nodes
901c99dbad1fbbd86bc469015ac99469341bead0 10.0.0.138:6379@16379 slave d7fdc965f3d5c6f6c22d049233f90fa97594e0a8 0 1607242075152 5 connected 宸叉洿鏂颁负110鐨勪粠
d7fdc965f3d5c6f6c22d049233f90fa97594e0a8 10.0.0.110:6379@16379 master - 0 1607242076159 0 connected 1366-5461
B缂╁瀹為獙 锛堝垹闄ゅ啑浣欑殑涓昏妭鐐?0.0.0.130锛夊疄楠屽涓?br>1銆佸厛杞Щ璇ヨ妭鐐圭殑妲戒綅鍒板叾浠栧悇鑺傜偣
[root@localhost ~]#redis-cli -a 123456 --cluster reshard 10.0.0.130:6379
[root@localhost ~]#redis-cli -a 123456 --cluster reshard 10.0.0.130:6379
Warning: Using a password with 鈥?a鈥?or 鈥?u鈥?option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 10.0.0.130:6379)
M: 8683d12e877291842b2dadb428fd8b72ab294425 10.0.0.130:6379
slots:[0-1365],[5462-6826],[10923-12287] (4096 slots) master 鏈?涓Ы浣?锛屽鏋滆浆绉绘暟鎹紝闇€瑕佽浆3娆°€?br>S: 901c99dbad1fbbd86bc469015ac99469341bead0 10.0.0.138:6379
slots: (0 slots) slave
replicates d7fdc965f3d5c6f6c22d049233f90fa97594e0a8
M: 01f1dd9c14ea7f886456a7758f4198d6280ae390 10.0.0.120:6379
slots:[6827-10922] (4096 slots) master
M: d7fdc965f3d5c6f6c22d049233f90fa97594e0a8 10.0.0.110:6379
slots:[1366-5461] (4096 slots) master
1 additional replica(s)
M: c1fdf4469f7e5047caf930326e742da0adfbcd73 10.0.0.123:6379
slots:[12288-16383] (4096 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 1366 绗?涓Ы浣?br>What is the receiving node ID? 01f1dd9c14ea7f886456a7758f4198d6280ae390
Please enter all the source node IDs.
Type 鈥榓ll鈥?to use all the nodes as source nodes for the hash slots.
Type 鈥榙one鈥?once you entered all the source nodes IDs.
Source node #1: 8683d12e877291842b2dadb428fd8b72ab294425 鍒嗛厤缁?0.0.0.120
Source node #2: done 缁撴潫
2銆佸悓鐞嗗垎鍒浆绉籟5462-6826],[10923-12287]
3銆佹煡鐪?0.0.0.130鏄惁杩樻湁妲戒綅
[root@centos ~]#redis-cli -a 123456 cluster nodes
8683d12e877291842b2dadb428fd8b72ab294425 10.0.0.130:6379@16379 master - 0 1607243239000 4 connected 宸叉棤妲戒綅
4銆佸垹闄や富鑺傜偣10.0.0.130
[root@centos ~]#redis-cli -a 123456 --cluster del-node 10.0.0.20锛?379 8683d12e877291842b2dadb428fd8b72ab294425
Warning: Using a password with 鈥?a鈥?or 鈥?u鈥?option on the command line interface may not be safe.
>>> Removing node 8683d12e877291842b2dadb428fd8b72ab294425 from cluster 10.0.0.20:6379
Could not connect to Redis at 10.0.0.20:6379: No route to host
5鏌ョ湅涓昏妭鐐?0.0.0.130鏄惁瀛樺湪
[root@centos ~]#redis-cli -a 123456 cluster nodes 鍙湅鍒?0.0.0.130鍒犻櫎鎴愬姛
Warning: Using a password with 鈥?a鈥?or 鈥?u鈥?option on the command line interface may not be safe.
d7fdc965f3d5c6f6c22d049233f90fa97594e0a8 10.0.0.110:6379@16379 myself,master - 0 1607243608000 8 connected 1366-5461 10923-12287
c1fdf4469f7e5047caf930326e742da0adfbcd73 10.0.0.123:6379@16379 master - 0 1607243608842 7 connected 5462-6826 12288-16383
01f1dd9c14ea7f886456a7758f4198d6280ae390 10.0.0.120:6379@16379 master - 0 1607243607000 6 connected 0-1365 6827-10922
901c99dbad1fbbd86bc469015ac99469341bead0 10.0.0.138:6379@16379 slave d7fdc965f3d5c6f6c22d049233f90fa97594e0a8 0 1607243607833 8 connecte
6銆佸垹闄?0.0.0.130鐨勫弬涓庢暟鎹苟閲嶅惎
[root@10.0.0.130 ~]#rm -f /var/lib/redis/nodes-6379.conf
[root@10.0.0.130 ~]#systemctl restart redis
7
鏌ョ湅鏄惁鏈夐泦缇や俊鎭?br>[root@localhost ~]#redis-cli -a 123456 cluster nodes
Warning: Using a password with 鈥?a鈥?or 鈥?u鈥?option on the command line interface may not be safe.
210560ccd0b2767b73d40dacf8ef7727fdf2c21e :6379@16379 myself,master - 0 0 0 connected
鍒?闄や粠鑺傜偣10.0.0.138锛屼竴鏉″懡浠ゅ嵆鍙?br>[root@localhost ~]#redis-cli -a 123456 --cluster del-node 10.0.0.120:6379 901c99dbad1fbbd86bc469015ac99469341bead0
C灏嗗閮ㄦ暟鎹鍏ラ泦缇や腑
鍋囪锛宺edis鏈嶅姟鍣ㄥ凡杩愯涓€娈垫椂闂达紝鐢变簬涔熻閲忓簽澶э紝闇€瑕佸缓绔媍luster鏉ョ鍚堝叕鍙歌姹傘€?br>濡備綍灏唕edis鏈嶅姟鍣?0.0.0.130鐨勬暟鎹鍏ユ柊寤虹殑闆嗙兢涓?
1銆佸皢130鐨勪富鏈烘仮澶嶅崟鏈簉edis鏈嶅姟鍣ㄧ殑閰嶇疆锛屽彇娑堥泦缇ょ浉鍏抽厤缃€?br>2銆佸垹闄ゆ墍鏈夎妭鐐圭殑瀵嗙爜
[root@localhost ~]#redis-cli -a 123456 --no-auth-warning config set requirepass "" ( ""琛ㄧず涓虹姝㈡墍鏈夛級5鐗堟湰
[root@localhost ~]#redis-cli --cluster import 10.0.0.128:6379 --cluster-from 10.0.0.136:6379 --cluster-replace --cluster-copy 鑻ユ湁鐩稿悓Key鍒欒鐩栧師鏉ョ殑key鍊?
[root@localhost ~]#redis-cli --cluster import 10.0.0.128:6379 --cluster-from 10.0.0.136:6379 5 鑻ユ湁鐩稿悓key 涓嶈鐩栧師鏉ョ殑鍊硷紝澶栭儴鏁版嵁涔熼粯璁ょ姝㈠啓鍏ャ€?br>redis-cli --cluster import 10.0.0.128:6379 --cluster-from 10.0.0.130:6379
以上是关于redis:RDB AOF -master &slave -sentinel-cluster的主要内容,如果未能解决你的问题,请参考以下文章