2020-10-26

1、RDB和AOF的優(yōu)缺點

RDB模式的優(yōu)點:

1、RDB快照保存了某個時間點的數(shù)據(jù),可以通過腳本執(zhí)行redis指令bgsave(非阻塞,后臺執(zhí)行)或者

save(會阻塞寫操作,不推薦)命令自定義時間點備份,可以保留多個備份,當(dāng)出現(xiàn)問題可以恢復(fù)到不

同時間點的版本,很適合備份,并且此文件格式也支持有不少第三方工具可以進(jìn)行后續(xù)的數(shù)據(jù)分析

比如: 可以在最近的24小時內(nèi),每小時備份一次RDB文件,并且在每個月的每一天,也備份一個

ROB文件。這樣的話,即使遇上問題,也可以隨時將數(shù)據(jù)集還原到不同的版本。

2、RDB可以最大化Redis的性能,父進(jìn)程在保存 RDB文件時唯一要做的就是fork出一個子進(jìn)程,然后

這個子進(jìn)程就會處理接下來的所有保存工作,父進(jìn)程無須執(zhí)行任何磁盤工/0操作。

3、RDB在大量數(shù)據(jù),比如幾個G的數(shù)據(jù),恢復(fù)的速度比AOF的快

RDB模式的缺點:

1、不能實時保存數(shù)據(jù),可能會丟失自上一次執(zhí)行RDB備份到當(dāng)前的內(nèi)存數(shù)據(jù)

如果你需要盡量避免在服務(wù)器故障時丟失數(shù)據(jù),那么RDB不適合你。雖然Redis允許你設(shè)置不同的

保存點(save point)來控制保存RDB文件的頻率,但是,因為ROB文件需要保存整個數(shù)據(jù)集的狀

態(tài),所以它并不是一個輕松的操作。因此你可能會至少5分鐘才保存一次RDB文件。在這種情況

下,一旦發(fā)生故障停機(jī),你就可能會丟失好幾分鐘的數(shù)據(jù)。

2、當(dāng)數(shù)據(jù)量非常大的時候,從父進(jìn)程fork子進(jìn)程進(jìn)行保存至RDB文件時需要一點時間,可能是毫秒或

者秒,取決于磁盤IO性能

在數(shù)據(jù)集比較龐大時,fork()可能會非常耗時,造成服務(wù)器在一定時間內(nèi)停止處理客戶端﹔如果數(shù)

據(jù)集非常巨大,并且CPU時間非常緊張的話,那么這種停止時間甚至可能會長達(dá)整整一秒或更久。

雖然 AOF重寫也需要進(jìn)行fork(),但無論AOF重寫的執(zhí)行間隔有多長,數(shù)據(jù)的持久性都不會有任何

損失。

AOF模式的優(yōu)點:

1. 數(shù)據(jù)安全性相對較高,根據(jù)所使用的fsync策略(fsync是同步內(nèi)存中redis所有已經(jīng)修改的文件到存

儲設(shè)備),默認(rèn)是appendfsync everysec,即每秒執(zhí)行一次 fsync,在這種配置下,Redis 仍然可以

保持良好的性能,并且就算發(fā)生故障停機(jī),也最多只會丟失一秒鐘的數(shù)據(jù)( fsync會在后臺線程執(zhí)

行,所以主線程可以繼續(xù)努力地處理命令請求)

2. 由于該機(jī)制對日志文件的寫入操作采用的是append模式,因此在寫入過程中不需要seek, 即使出

現(xiàn)宕機(jī)現(xiàn)象,也不會破壞日志文件中已經(jīng)存在的內(nèi)容。然而如果本次操作只是寫入了一半數(shù)據(jù)就出

現(xiàn)了系統(tǒng)崩潰問題,不用擔(dān)心,在Redis下一次啟動之前,可以通過 redis-check-aof 工具來解決

數(shù)據(jù)一致性的問題

3.Redis可以在 AOF文件體積變得過大時,自動地在后臺對AOF進(jìn)行重寫,重寫后的新AOF文件包含了

恢復(fù)當(dāng)前數(shù)據(jù)集所需的最小命令集合。整個重寫操作是絕對安全的,因為Redis在創(chuàng)建新 AOF文件

的過程中,append模式不斷的將修改數(shù)據(jù)追加到現(xiàn)有的 AOF文件里面,即使重寫過程中發(fā)生停

機(jī),現(xiàn)有的 AOF文件也不會丟失。而一旦新AOF文件創(chuàng)建完畢,Redis就會從舊AOF文件切換到新

AOF文件,并開始對新AOF文件進(jìn)行追加操作。

4.AOF包含一個格式清晰、易于理解的日志文件用于記錄所有的修改操作。事實上,也可以通過該文

件完成數(shù)據(jù)的重建

AOF的缺點

1. 即使有些操作是重復(fù)的也會全部記錄,AOF 的文件大小要大于 RDB 格式的文件

2. AOF 在恢復(fù)大數(shù)據(jù)集時的速度比 RDB 的恢復(fù)速度要慢

3. 根據(jù)fsync策略不同,AOF速度可能會慢于RDB

4. bug 出現(xiàn)的可能性更多

RDB和AOF的區(qū)別:

RDB持久化是指在指定的時間間隔內(nèi)將內(nèi)存中的數(shù)據(jù)集快照寫入磁盤,實際操作過程是fork一個子進(jìn)程,先將數(shù)據(jù)集寫入臨時文件,寫入成功后,在替換之前的文件,用二進(jìn)制壓縮存儲

AOF持久化日志的形式記錄服務(wù)器所處理的每一個寫、刪除操作,查詢操作不會記錄,以文本的方式記錄,可以打開文件看到詳細(xì)的操作記錄。

RDB和AOF的選擇

如果主要充當(dāng)緩存功能,或者可以承受數(shù)分鐘的丟失,通常生產(chǎn)環(huán)境一般只需要啟用RDB即可,此也是默認(rèn)值

如果數(shù)據(jù)需要持久保存,一點不能丟失,可以選擇同時開啟RDB和AOF,一般不建議只開啟AOF。

2、master和slave同步過程

1、slave啟動后向master發(fā)送同步指令SYNC,master接收到SYNC指令后將調(diào)用該命令的處理函數(shù)syncCommand()進(jìn)行同步處理

2、在函數(shù)syncCommand中,將調(diào)用函數(shù)rdbSaveBackground啟動以個備份進(jìn)程用于同步數(shù)據(jù),如果已經(jīng)有一個備份進(jìn)程在運行,將不會在重新啟動了

3、備份進(jìn)程將執(zhí)行函數(shù)rdbSave()完成將redis的全部數(shù)據(jù)保存為rdb文件

4、在redis的時間事件函數(shù)serverCron中,將對備份后的數(shù)據(jù)進(jìn)行處理,在serverCron函數(shù)將會檢查備份,進(jìn)程是否已經(jīng)執(zhí)行完畢,如果備份進(jìn)程已經(jīng)完成備份,則調(diào)用函數(shù)backgroundSaveDoneHandler完成后續(xù)處理

5、在函數(shù)backgroundSaveDoneHandler中,首先更新master的各種狀態(tài)

6、在函數(shù)updateSlavesWaitingBgsave中,將遍歷所有的等待此次備份的slave,另外,這里并不是立即就把數(shù)據(jù)發(fā)送過去,而是將為每個等待的slave注冊寫事件,并注冊寫事件的響應(yīng)函數(shù)sendBulkToSlave,即當(dāng)slave對應(yīng)的socket能夠發(fā)送數(shù)據(jù)時就調(diào)用函數(shù)sendBulkToSlave(),實際發(fā)送rdb文件的操作都在函數(shù)sendBulkToSlave中完成的

7、sendBulkToSlave函數(shù)將把備份的rdb文件發(fā)送給slave。

3、哨兵的使用和實現(xiàn)機(jī)制

#在所有主從節(jié)點上執(zhí)行

[root@master ~]#dnf -y install redis

[root@slave1 ~]#dnf -y install redis

[root@slave2 ~]#dnf -y install redis

#在所有主從節(jié)點上執(zhí)行,修改redis的配置文件 交互式修改

[root@master ~]#sed -i -e 's/bind 127.0.0.1/bind 0.0.0.0/' -e 's/^# masterauth .*/masterauth 1234567/' -e 's/^# requirepass .*/requirepass 1234567/' /etc/redis.conf

[root@slave1 ~]#sed -i -e 's/bind 127.0.0.1/bind 0.0.0.0/' -e 's/^# masterauth .*/masterauth 1234567/' -e 's/^# requirepass .*/requirepass 1234567/' /etc/redis.conf

[root@slave2 ~]#sed -i -e 's/bind 127.0.0.1/bind 0.0.0.0/' -e 's/^# masterauth .*/masterauth 1234567/' -e 's/^# requirepass .*/requirepass 1234567/' /etc/redis.conf

#在所有從節(jié)點上執(zhí)行

[root@slave1 ~]#echo "replicaof 10.0.0.8 6379" >> /etc/redis.conf

[root@slave2 ~]#echo "replicaof 10.0.0.8 6379" >> /etc/redis.conf

#在所有主從節(jié)點上執(zhí)行

![](https://img2020.cnblogs.com/blog/1979780/202010/1979780-20201024144439773-574411739.png)

#查看master服務(wù)器狀態(tài)

[root@master ~]#redis-cli -a 123456

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

127.0.0.1:6379> INFO replication

# Replication

role:master

connected_slaves:2

slave0:ip=10.0.0.28,port=6379,state=online,offset=126,lag=0

slave1:ip=10.0.0.18,port=6379,state=online,offset=126,lag=0

master_replid:458f6d2c11e76b3be7747a027dc0b481b3794faa

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:126

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1

repl_backlog_histlen:126

#配置slave1

[root@slave1 ~]#redis-cli -a 123456

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

127.0.0.1:6379> REPLICAOF 10.0.0.8 6379

OK Already connected to specified master

127.0.0.1:6379> CONFIG SET masterauth "123456"

OK

127.0.0.1:6379> INFO relication

127.0.0.1:6379> INFO replication

# Replication

role:slave

master_host:10.0.0.8

master_port:6379

master_link_status:up

master_last_io_seconds_ago:8

master_sync_in_progress:0

slave_repl_offset:588

slave_priority:100

slave_read_only:1

connected_slaves:0

master_replid:458f6d2c11e76b3be7747a027dc0b481b3794faa

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:588

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1

repl_backlog_histlen:588

127.0.0.1:6379>

#配置slave2

[root@slave2 ~]#redis-cli -a 123456

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

127.0.0.1:6379> REPLICAOF 10.0.0.8 6379

OK Already connected to specified master

127.0.0.1:6379> CONFIG SET masterauth "123456"

OK

127.0.0.1:6379> INFO replication

# Replication

role:slave

master_host:10.0.0.8

master_port:6379

master_link_status:up

master_last_io_seconds_ago:3

master_sync_in_progress:0

slave_repl_offset:826

slave_priority:100

slave_read_only:1

connected_slaves:0

master_replid:458f6d2c11e76b3be7747a027dc0b481b3794faa

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:826

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1

repl_backlog_histlen:826

127.0.0.1:6379>

#三個哨兵服務(wù)器的配置都如下

[root@master ~]#grep -vE "^#|^$" /etc/redis-sentinel.conf

bind 0.0.0.0

port 26379

daemonize no

pidfile "/var/run/redis-sentinel.pid"

logfile "/var/log/redis/sentinel.log"

dir "/tmp"

sentinel myid 91d1527420e293e7d3f0ab726ff1f62c71239e39

sentinel deny-scripts-reconfig yes

sentinel monitor mymaster 10.0.0.8 6379 2

sentinel down-after-milliseconds mymaster 3000

sentinel auth-pass mymaster 123456

sentinel config-epoch mymaster 0

protected-mode no

supervised systemd

sentinel leader-epoch mymaster 0

sentinel known-replica mymaster 10.0.0.18 6379

sentinel known-replica mymaster 10.0.0.28 6379

sentinel current-epoch 0

[root@master ~]#scp /etc/redis-sentinel.conf 10.0.0.18:/etc/

[root@master ~]#scp /etc/redis-sentinel.conf 10.0.0.28:/etc/

#啟動哨兵(三臺哨兵都要啟動)

#確保每個哨兵主機(jī)myid不同

[root@master ~]#vim /etc/redis-sentinel.conf

sentinel myid 91d1527420e293e7d3f0ab726ff1f62c71239e39

[root@slave1 ~]#vim /etc/redis-sentinel.conf

sentinel myid 91d1527420e293e7d3f0ab726ff1f62c71239e3a

[root@slave2 ~]#vim /etc/redis-sentinel.conf

sentinel myid 91d1527420e293e7d3f0ab726ff1f62c71239e3b

#重新啟動服務(wù)

[root@master ~]#systemctl enable --now redis-sentinel.service

[root@slave1 ~]#systemctl enable --now redis-sentinel.service

[root@slave2 ~]#systemctl enable --now redis-sentinel.service

#驗證哨兵端口

[root@master ~]#ss -ntl

State? Recv-Q? Send-Q? ? ? ? Local Address:Port? ? ? ? Peer Address:Port?

LISTEN? 0? ? ? ? 128? ? ? ? ? ? ? ? 0.0.0.0:22? ? ? ? ? ? ? 0.0.0.0:*? ? ?

LISTEN? 0? ? ? ? 128? ? ? ? ? ? ? ? 0.0.0.0:26379? ? ? ? ? ? 0.0.0.0:*? ? ?

LISTEN? 0? ? ? ? 128? ? ? ? ? ? ? ? 0.0.0.0:6379? ? ? ? ? ? 0.0.0.0:*? ? ?

LISTEN? 0? ? ? ? 128? ? ? ? ? ? ? ? ? ? [::]:22? ? ? ? ? ? ? ? ? [::]:*? ? ?

#master的哨兵日志

[root@master ~]#tail -f /var/log/redis/sentinel.log

2720:X 25 Oct 2020 00:23:23.267 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

2720:X 25 Oct 2020 00:23:23.267 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=2720, just started

2720:X 25 Oct 2020 00:23:23.267 # Configuration loaded

2720:X 25 Oct 2020 00:23:23.267 * supervised by systemd, will signal readiness

2720:X 25 Oct 2020 00:23:23.268 * Running mode=sentinel, port=26379.

2720:X 25 Oct 2020 00:23:23.268 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

2720:X 25 Oct 2020 00:23:23.270 # Sentinel ID is 91d1527420e293e7d3f0ab726ff1f62c71239e39

2720:X 25 Oct 2020 00:23:23.270 # +monitor master mymaster 10.0.0.8 6379 quorum 2

2720:X 25 Oct 2020 00:23:23.270 * +slave slave 10.0.0.28:6379 10.0.0.28 6379 @ mymaster 10.0.0.8 6379

2720:X 25 Oct 2020 00:23:23.272 * +slave slave 10.0.0.18:6379 10.0.0.18 6379 @ mymaster 10.0.0.8 6379

#slave的哨兵日志

[root@slave1 ~]#tail -f /var/log/redis/sentinel.log

2306:X 25 Oct 2020 00:24:32.202 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

2306:X 25 Oct 2020 00:24:32.202 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=2306, just started

2306:X 25 Oct 2020 00:24:32.202 # Configuration loaded

2306:X 25 Oct 2020 00:24:32.202 * supervised by systemd, will signal readiness

2306:X 25 Oct 2020 00:24:32.203 * Running mode=sentinel, port=26379.

2306:X 25 Oct 2020 00:24:32.203 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

2306:X 25 Oct 2020 00:24:32.203 # Sentinel ID is 91d1527420e293e7d3f0ab726ff1f62c71239e39

2306:X 25 Oct 2020 00:24:32.203 # +monitor master mymaster 10.0.0.8 6379 quorum 2

#當(dāng)前sentinel狀態(tài)

[root@master ~]#redis-cli -p 26379

127.0.0.1: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.8:6379,slaves=2,sentinels=3

127.0.0.1:26379>

#停止Redis Master測試故障轉(zhuǎn)移

127.0.0.1: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.18:6379,slaves=2,sentinels=3

故障轉(zhuǎn)移時sentinel的信息

[root@master ~]#tail -f /var/log/redis/sentinel.log

2720:X 25 Oct 2020 01:12:10.286 # +vote-for-leader 91d1527420e293e7d3f0ab726ff1f62c71239f39 1

2720:X 25 Oct 2020 01:12:10.288 # +odown master mymaster 10.0.0.8 6379 #quorum 3/2

2720:X 25 Oct 2020 01:12:10.288 # Next failover delay: I will not start a failover before Sun Oct 25 01:18:10 2020

2720:X 25 Oct 2020 01:12:11.423 # +config-update-from sentinel 91d1527420e293e7d3f0ab726ff1f62c71239f39 10.0.0.18 26379 @ mymaster 10.0.0.8 6379

2720:X 25 Oct 2020 01:12:11.423 # +switch-master mymaster 10.0.0.8 6379 10.0.0.18 6379

2720:X 25 Oct 2020 01:12:11.423 * +slave slave 10.0.0.28:6379 10.0.0.28 6379 @ mymaster 10.0.0.18 6379

2720:X 25 Oct 2020 01:12:11.423 * +slave slave 10.0.0.8:6379 10.0.0.8 6379 @ mymaster 10.0.0.18 6379

2720:X 25 Oct 2020 01:12:14.430 # +sdown slave 10.0.0.8:6379 10.0.0.8 6379 @ mymaster 10.0.0.18 6379

2720:X 25 Oct 2020 01:28:13.050 # -sdown slave 10.0.0.8:6379 10.0.0.8 6379 @ mymaster 10.0.0.18 6379

2720:X 25 Oct 2020 01:30:05.586 # +sdown slave 10.0.0.8:6379 10.0.0.8 6379 @ mymaster 10.0.0.18 6379

#故障轉(zhuǎn)移后redis配置文件會被自動修改

[root@slave2 ~]#grep ^replicaof /etc/redis.conf

replicaof 10.0.0.18 6379

#哨兵配置文件sentinel monitor IP 同樣也會被修改

[root@slave1 ~]#grep "^[a-Z]" /etc/redis-sentinel.conf

bind 0.0.0.0

port 26379

daemonize no

pidfile "/var/run/redis-sentinel.pid"

logfile "/var/log/redis/sentinel.log"

dir "/tmp"

sentinel myid 91d1527420e293e7d3f0ab726ff1f62c71239e3a

sentinel deny-scripts-reconfig yes

sentinel monitor mymaster 10.0.0.18 6379 2? ? ? ? #此行被修改了

sentinel down-after-milliseconds mymaster 3000

sentinel auth-pass mymaster 123456

sentinel config-epoch mymaster 1

protected-mode no

supervised systemd

sentinel leader-epoch mymaster 1

sentinel known-replica mymaster 10.0.0.8 6379

sentinel known-replica mymaster 10.0.0.28 6379

sentinel known-sentinel mymaster 10.0.0.8 26379 91d1527420e293e7d3f0ab726ff1f62c71239e39

sentinel known-sentinel mymaster 10.0.0.28 26379 91d1527420e293e7d3f0ab726ff1f62c71239e3b

sentinel current-epoch 1

[root@slave2 ~]#grep "^[a-Z]" /etc/redis-sentinel.conf

bind 0.0.0.0

port 26379

daemonize no

pidfile "/var/run/redis-sentinel.pid"

logfile "/var/log/redis/sentinel.log"

dir "/tmp"

sentinel myid 91d1527420e293e7d3f0ab726ff1f62c71239e3b

sentinel deny-scripts-reconfig yes

sentinel monitor mymaster 10.0.0.18 6379 2? ? # 此行被修改

sentinel down-after-milliseconds mymaster 3000

sentinel auth-pass mymaster 123456

sentinel config-epoch mymaster 1

protected-mode no

supervised systemd

sentinel leader-epoch mymaster 1

sentinel known-replica mymaster 10.0.0.8 6379

sentinel known-replica mymaster 10.0.0.28 6379

sentinel known-sentinel mymaster 10.0.0.8 26379 91d1527420e293e7d3f0ab726ff1f62c71239e39

sentinel known-sentinel mymaster 10.0.0.18 26379 91d1527420e293e7d3f0ab726ff1f62c71239f39

sentinel current-epoch 1

#新的master狀態(tài)

[root@slave1 ~]#redis-cli -a 123456

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

127.0.0.1:6379> info replication

# Replication

role:master

connected_slaves:1

slave0:ip=10.0.0.28,port=6379,state=online,offset=839313,lag=1

master_replid:04d719e05ec3aaf8cf4d1c6b8857c0a95e373b44

master_replid2:458f6d2c11e76b3be7747a027dc0b481b3794faa

master_repl_offset:839460

second_repl_offset:548810

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1

repl_backlog_histlen:839460

#另一個slave指向新的master

[root@slave2 ~]#redis-cli -a 123456

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

127.0.0.1:6379> info replication

# Replication

role:slave

master_host:10.0.0.18

master_port:6379

master_link_status:up

master_last_io_seconds_ago:1

master_sync_in_progress:0

slave_repl_offset:925499

slave_priority:100

slave_read_only:1

connected_slaves:0

master_replid:04d719e05ec3aaf8cf4d1c6b8857c0a95e373b44

master_replid2:458f6d2c11e76b3be7747a027dc0b481b3794faa

master_repl_offset:925499

second_repl_offset:548810

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1

repl_backlog_histlen:925499

#恢復(fù)故障的原master重新加入redis集群

#sentinel會自動修改下面行指向新的master

[root@master ~]#cat /etc/redis.conf

# Generated by CONFIG REWRITE

replicaof 10.0.0.18 6379

#在原master上觀察狀態(tài)

[root@master ~]#redis-cli -a 123456

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

127.0.0.1:6379> info replication

# Replication

role:slave

master_host:10.0.0.18

master_port:6379

master_link_status:up

master_last_io_seconds_ago:1

master_sync_in_progress:0

slave_repl_offset:2091286

slave_priority:100

slave_read_only:1

connected_slaves:0

master_replid:04d719e05ec3aaf8cf4d1c6b8857c0a95e373b44

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:2091286

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1978239

repl_backlog_histlen:113048

[root@master ~]#redis-cli -p 26379

127.0.0.1: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.18:6379,slaves=2,sentinels=3

#觀察新的master上狀態(tài)和日志

[root@slave1 ~]#redis-cli -a 123456

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

127.0.0.1:6379> info replication

# Replication

role:master

connected_slaves:2

slave0:ip=10.0.0.28,port=6379,state=online,offset=2126150,lag=0

slave1:ip=10.0.0.8,port=6379,state=online,offset=2126150,lag=1

master_replid:04d719e05ec3aaf8cf4d1c6b8857c0a95e373b44

master_replid2:458f6d2c11e76b3be7747a027dc0b481b3794faa

master_repl_offset:2126283

second_repl_offset:548810

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1077708

repl_backlog_histlen:1048576

127.0.0.1:6379>

[root@slave1 ~]#tail /var/log/redis/sentinel.log

2469:X 25 Oct 2020 01:12:15.924 # +sdown slave 10.0.0.8:6379 10.0.0.8 6379 @ mymaster 10.0.0.18 6379

2469:X 25 Oct 2020 01:28:13.251 # -sdown slave 10.0.0.8:6379 10.0.0.8 6379 @ mymaster 10.0.0.18 6379

4、redis cluster集群創(chuàng)建和使用

#在每個節(jié)點上安裝redis

[root@centos8 ~]#dnf -yinstall redis

#每個節(jié)點修改redis配置,必須開啟cluster功能的參數(shù),批量修改

[root@centos8 ~]#sed-i.bak -e's/bind 127.0.0.1/bind 0.0.0.0/'-e's/masterauth/masterauth 123456'-e's/^#requirepass/requirepass 123456'-e's/^# cluster-enabled yes/cluster-enabled yes'-e's/^# cluster-config-file nodes-6379.conf/a cluster-config-file nodes-6379.conf'-e's/clusterrequirefull-coverage yes/c cluster-require-full-coverage no'/etc/redis.conf

#重啟服務(wù)

[root@centos8 ~]#systemctl enable --now redis

#驗證當(dāng)前redis服務(wù)狀態(tài)

開啟了16379的cluster的端口,實際的端口=redis prot +10000[root@centos8 ~]#ss -ntl

State? Recv-Q? Send-Q? ? Local Address:Port? ? Peer Address:Port?

LISTEN 01280.0.0.0:220.0.0.0:*? ?

LISTEN 01280.0.0.0:163790.0.0.0:*? ?

LISTEN 01280.0.0.0:63790.0.0.0:*? ?

LISTEN 0128[::]:22[::]:*?

#注意進(jìn)程有【cluster】狀態(tài)

[root@centos8 ~]#ps-ef |grep redis

redis? ? ? 95451004:37?00:00:00/usr/bin/redis-server0.0.0.0:6379 [cluster]

root? ? ? 95591350004:45pts/000:00:00grep--color=auto redis

#創(chuàng)建集群

[root@centos8 ~]#redis-cli -a123456--cluster create10.0.0.8:637910.0.0.18:637910.0.0.28:637910.0.0.38:637910.0.0.48:637910.0.0.58:6379--cluster-replicas1

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.>>> Performing hash slots allocation on6 nodes...

Master[0] -> Slots0-5460Master[1] -> Slots5461-10922Master[2] -> Slots10923-16383Adding replica 10.0.0.38:6379to10.0.0.8:6379Adding replica 10.0.0.48:6379to10.0.0.18:6379Adding replica 10.0.0.58:6379to10.0.0.28:6379M: 72630b08354c8b67d7dd7af467b5b1c21efc05e7 10.0.0.8:6379? slots:[0-5460] (5461 slots) master

M: f7bb0a1728ec381483f464ab68c16edc2041fe10 10.0.0.18:6379? slots:[5461-10922] (5462 slots) master

M: 8ffc94e86dbf7f3477b77db130538d2219022bba 10.0.0.28:6379? slots:[10923-16383] (5461 slots) master

S: f67fb2a9264bdcddc3311956798e9f5c1d43fd0d 10.0.0.38:6379? replicates 72630b08354c8b67d7dd7af467b5b1c21efc05e7

S: 36b3aa7483d2ba99e69db995c5b1e0a73b9ca937 10.0.0.48:6379? replicates f7bb0a1728ec381483f464ab68c16edc2041fe10

S: 7060d1ab30b41709903bf4e901aa3a8d14749ab0 10.0.0.58:6379? replicates 8ffc94e86dbf7f3477b77db130538d2219022bba

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 tojoin the cluster

Waiting forthe cluster tojoin.....>>> Performing Cluster Check (using node10.0.0.8:6379)

M: 72630b08354c8b67d7dd7af467b5b1c21efc05e7 10.0.0.8:6379? slots:[0-5460] (5461 slots) master

? 1 additional replica(s)

S: f67fb2a9264bdcddc3311956798e9f5c1d43fd0d 10.0.0.38:6379? slots: (0 slots) slave

? replicates 72630b08354c8b67d7dd7af467b5b1c21efc05e7

S: 36b3aa7483d2ba99e69db995c5b1e0a73b9ca937 10.0.0.48:6379? slots: (0 slots) slave

? replicates f7bb0a1728ec381483f464ab68c16edc2041fe10

M: 8ffc94e86dbf7f3477b77db130538d2219022bba 10.0.0.28:6379? slots:[10923-16383] (5461 slots) master

? 1 additional replica(s)

M: f7bb0a1728ec381483f464ab68c16edc2041fe10 10.0.0.18:6379? slots:[5461-10922] (5462 slots) master

? 1 additional replica(s)

S: 7060d1ab30b41709903bf4e901aa3a8d14749ab0 10.0.0.58:6379? slots: (0 slots) slave

? replicates 8ffc94e86dbf7f3477b77db130538d2219022bba

[OK] All nodes agree about slots configuration.>>> Checkfor open slots...>>> Check slots coverage...

[OK] All 16384 slots covered.

#觀察上述結(jié)果,可以看到三組master/slave

Adding replica 10.0.0.38:6379to10.0.0.8:6379Adding replica 10.0.0.48:6379to10.0.0.18:6379Adding replica 10.0.0.58:6379to10.0.0.28:6379#查看主從狀態(tài)

[root@redis-node1 ~]#redis-cli -a123456-cinfo replication

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

# Replication

role:master

connected_slaves:1slave0:ip=10.0.0.38,port=6379,state=online,offset=798,lag=1master_replid:c6d03ac327373545ec13a6e02d7796000c8cf519

master_replid2:0000000000000000000000000000000000000000master_repl_offset:798second_repl_offset:-1repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:1repl_backlog_histlen:798[root@redis-node2 ~]#redis-cli -a123456info replication

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

# Replication

role:master

connected_slaves:1slave0:ip=10.0.0.48,port=6379,state=online,offset=882,lag=0master_replid:e38086a24e8d7babe45bb460fe1f3754e188c119

master_replid2:0000000000000000000000000000000000000000master_repl_offset:882second_repl_offset:-1repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:1repl_backlog_histlen:882[root@redis-node3 ~]#redis-cli -a123456info replication

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

# Replication

role:master

connected_slaves:1slave0:ip=10.0.0.58,port=6379,state=online,offset=924,lag=1master_replid:5fa0c5b0ff68a053f890d345b37723a7995db382

master_replid2:0000000000000000000000000000000000000000master_repl_offset:938second_repl_offset:-1repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:1repl_backlog_histlen:938[root@redis-node4 ~]#

[root@redis-node4 ~]#redis-cli -a123456info replication

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

# Replication

role:slave

master_host:10.0.0.8master_port:6379master_link_status:up

master_last_io_seconds_ago:4master_sync_in_progress:0slave_repl_offset:1106slave_priority:100slave_read_only:1connected_slaves:0master_replid:c6d03ac327373545ec13a6e02d7796000c8cf519

master_replid2:0000000000000000000000000000000000000000master_repl_offset:1106second_repl_offset:-1repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:1repl_backlog_histlen:1106[root@redis-node5 ~]#redis-cli -a123456info replication

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

# Replication

role:slave

master_host:10.0.0.18master_port:6379master_link_status:up

master_last_io_seconds_ago:2master_sync_in_progress:0slave_repl_offset:1106slave_priority:100slave_read_only:1connected_slaves:0master_replid:e38086a24e8d7babe45bb460fe1f3754e188c119

master_replid2:0000000000000000000000000000000000000000master_repl_offset:1106second_repl_offset:-1repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:1repl_backlog_histlen:1106[root@redis-node6 ~]#redis-cli -a123456info replication

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

# Replication

role:slave

master_host:10.0.0.28master_port:6379master_link_status:up

master_last_io_seconds_ago:1master_sync_in_progress:0slave_repl_offset:1106slave_priority:100slave_read_only:1connected_slaves:0master_replid:5fa0c5b0ff68a053f890d345b37723a7995db382

master_replid2:0000000000000000000000000000000000000000master_repl_offset:1106second_repl_offset:-1repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:1repl_backlog_histlen:1106#驗證集群狀態(tài)

[root@redis-node1 ~]#redis-cli -a123456clusterinfo

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

cluster_state:ok

cluster_slots_assigned:16384cluster_slots_ok:16384cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:6cluster_size:3cluster_current_epoch:6cluster_my_epoch:1cluster_stats_messages_ping_sent:1060cluster_stats_messages_pong_sent:961cluster_stats_messages_sent:2021cluster_stats_messages_ping_received:956cluster_stats_messages_pong_received:1056cluster_stats_messages_meet_received:5cluster_stats_messages_received:2017#查看任意節(jié)點的集群狀態(tài)

[root@redis-node1 ~]#redis-cli -a123456--clusterinfo10.0.0.38:6379Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.10.0.0.18:6379(f7bb0a17...) ->0keys |5462slots |1 slaves.10.0.0.28:6379(8ffc94e8...) ->0keys |5461slots |1 slaves.10.0.0.8:6379(72630b08...) ->0keys |5461slots |1 slaves.

[OK] 0keysin3 masters.0.00 keys per slot on average.

#查看集群node對應(yīng)關(guān)系

[root@redis-node1 ~]#redis-cli -a123456 cluster nodes

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

f67fb2a9264bdcddc3311956798e9f5c1d43fd0d 10.0.0.38:6379@16379slave 72630b08354c8b67d7dd7af467b5b1c21efc05e7016036116944494 connected

36b3aa7483d2ba99e69db995c5b1e0a73b9ca937 10.0.0.48:6379@16379slave f7bb0a1728ec381483f464ab68c16edc2041fe10016036116924295 connected

72630b08354c8b67d7dd7af467b5b1c21efc05e7 10.0.0.8:6379@16379myself,master -016036116940001connected0-54608ffc94e86dbf7f3477b77db130538d2219022bba 10.0.0.28:6379@16379master -016036116964693connected10923-16383f7bb0a1728ec381483f464ab68c16edc2041fe10 10.0.0.18:6379@16379master -016036116940002connected5461-109227060d1ab30b41709903bf4e901aa3a8d14749ab0 10.0.0.58:6379@16379slave 8ffc94e86dbf7f3477b77db130538d2219022bba016036116954596 connected

[root@redis-node1 ~]#redis-cli -a123456--cluster check10.0.0.38:6379

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.10.0.0.18:6379(f7bb0a17...) ->0keys |5462slots |1 slaves.10.0.0.28:6379(8ffc94e8...) ->0keys |5461slots |1 slaves.10.0.0.8:6379(72630b08...) ->0keys |5461slots |1 slaves.

[OK] 0keysin3 masters.0.00 keys per slot on average.>>> Performing Cluster Check (using node10.0.0.38:6379)

S: f67fb2a9264bdcddc3311956798e9f5c1d43fd0d 10.0.0.38:6379? slots: (0 slots) slave

? replicates 72630b08354c8b67d7dd7af467b5b1c21efc05e7

M: f7bb0a1728ec381483f464ab68c16edc2041fe10 10.0.0.18:6379? slots:[5461-10922] (5462 slots) master

? 1 additional replica(s)

S: 7060d1ab30b41709903bf4e901aa3a8d14749ab0 10.0.0.58:6379? slots: (0 slots) slave

? replicates 8ffc94e86dbf7f3477b77db130538d2219022bba

M: 8ffc94e86dbf7f3477b77db130538d2219022bba 10.0.0.28:6379? slots:[10923-16383] (5461 slots) master

? 1 additional replica(s)

S: 36b3aa7483d2ba99e69db995c5b1e0a73b9ca937 10.0.0.48:6379? slots: (0 slots) slave

? replicates f7bb0a1728ec381483f464ab68c16edc2041fe10

M: 72630b08354c8b67d7dd7af467b5b1c21efc05e7 10.0.0.8:6379? slots:[0-5460] (5461 slots) master

? 1 additional replica(s)

[OK] All nodes agree about slots configuration.>>> Checkfor open slots...>>> Check slots coverage...

[OK] All 16384 slots covered.

#redis cluster 寫入key

經(jīng)算法計算,當(dāng)前key的槽位需要寫入指定的node

[root@redis-node1 ~]#redis-cli -a123456-h10.0.0.8 set key1 values1

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

(error) MOVED 918910.0.0.18:6379? ? #槽位不在當(dāng)前node所以無法寫入

[root@redis-node1 ~]#redis-cli -a123456-h10.0.0.18 set key1 values1

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

OK

#指定node可以寫入

[root@redis-node1 ~]#redis-cli -a123456-h10.0.0.18 get key1

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe."values1"[root@redis-node1 ~]#

#對應(yīng)的slave節(jié)點可以keys*,但get key1失敗,可以到master上執(zhí)行g(shù)et key1

[root@redis-node1 ~]#redis-cli -a123456-h10.0.0.48keys"*"Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.1)"key1"[root@redis-node1 ~]#redis-cli -a123456-h10.0.0.48 get key1

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

(error) MOVED 918910.0.0.18:6379#redis cluster 計算key所屬的slot

[root@redis-node1 ~]#redis-cli -h10.0.0.8-a123456--no-auth-warning cluster nodes

f67fb2a9264bdcddc3311956798e9f5c1d43fd0d 10.0.0.38:6379@16379slave 72630b08354c8b67d7dd7af467b5b1c21efc05e7016036123480004 connected

36b3aa7483d2ba99e69db995c5b1e0a73b9ca937 10.0.0.48:6379@16379slave f7bb0a1728ec381483f464ab68c16edc2041fe10016036123510005 connected

72630b08354c8b67d7dd7af467b5b1c21efc05e7 10.0.0.8:6379@16379myself,master -016036123480001connected0-54608ffc94e86dbf7f3477b77db130538d2219022bba 10.0.0.28:6379@16379master -016036123504823connected10923-16383f7bb0a1728ec381483f464ab68c16edc2041fe10 10.0.0.18:6379@16379master -016036123514912connected5461-109227060d1ab30b41709903bf4e901aa3a8d14749ab0 10.0.0.58:6379@16379slave 8ffc94e86dbf7f3477b77db130538d2219022bba016036123500006 connected

#計算的發(fā)哦hello對應(yīng)的slot

[root@redis-node1 ~]#redis-cli -h10.0.0.8-a123456--no-auth-warning cluster keyslot hello

(integer) 866[root@redis-node1 ~]#redis-cli -h10.0.0.8-a123456--no-auth-warning set hello magedu

OK

[root@redis-node1 ~]#redis-cli -h10.0.0.8-a123456--no-auth-warning cluster keyslot name

(integer) 5798[root@redis-node1 ~]#redis-cli -h10.0.0.8-a123456--no-auth-warning set name wang

(error) MOVED 579810.0.0.18:6379[root@redis-node1 ~]#redis-cli -h10.0.0.18-a123456--no-auth-warning set name wang

OK

[root@redis-node1 ~]#redis-cli -h10.0.0.18-a123456--no-auth-warning get name "wang"#使用選項-c 以集群模式連接

[root@redis-node1 ~]#redis-cli -c -h10.0.0.8-a123456--no-auth-warning 10.0.0.8:6379> cluster keyslot linux

(integer) 1229910.0.0.8:6379> set linux love -> Redirected to slot [12299] located at10.0.0.28:6379OK10.0.0.28:6379> exit

[root@redis-node1 ~]#redis-cli -h10.0.0.28-a123456--no-auth-warning get linux "love"#使用python腳本實現(xiàn)rediscluster集群寫入

[root@redis-node1 ~]#dnf -yinstall python3

[root@redis-node1 ~]#pip3installredis-py-cluster

[root@redis-node1 ~]#vim redis_cluster_test.py![](https://img2020.cnblogs.com/blog/1979780/202010/1979780-20201025161938978-1854678095.png)[root@redis-node1 ~]#./redis_cluster_test.py![](https://img2020.cnblogs.com/blog/1979780/202010/1979780-20201025162023921-1143351531.png)[root@redis-node1 ~]#redis-cli -a123456-h10.0.0.8Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.10.0.0.8:6379> dbsize

(integer) 333210.0.0.8:6379> get key1

(error) MOVED 918910.0.0.18:637910.0.0.8:6379> get key2"value2"10.0.0.8:6379> get key3"value3"10.0.0.8:6379>keys * ![](https://img2020.cnblogs.com/blog/1979780/202010/1979780-20201025162320897-563304046.png)[root@redis-node1 ~]#redis-cli -a123456-h10.0.0.18 dbsize

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

(integer) 3341[root@redis-node1 ~]#redis-cli -a123456-h10.0.0.18 get key1

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe."value1"[root@redis-node1 ~]#redis-cli -a123456-h10.0.0.28 dbsize

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

(integer) 3330[root@redis-node1 ~]#redis-cli -a123456-h10.0.0.18 get key5

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe."value5"#模擬master故障,對應(yīng)的slave節(jié)點自動提升為新master

#模擬node2節(jié)點出故障,需要對應(yīng)的數(shù)秒故障轉(zhuǎn)移時間

[root@redis-node2 ~]#tail-f /var/log/redis/redis.log 9697:M25Oct202016:19:02.384*1changesin900 seconds. Saving...9697:M25Oct202016:19:02.386* Background saving started by pid98739873:C25Oct202016:19:02.389* DB saved on disk9873:C25Oct202016:19:02.390* RDB:6MB of memory used by copy-on-write9697:M25Oct202016:19:02.487* Background saving terminated with success9697:M25Oct202016:24:03.087*10changesin300 seconds. Saving...9697:M25Oct202016:24:03.089* Background saving started by pid98759875:C25Oct202016:24:03.092* DB saved on disk9875:C25Oct202016:24:03.092* RDB:4MB of memory used by copy-on-write9697:M25Oct202016:24:03.189* Background saving terminated with success

[root@redis-node2 ~]#redis-cli -a123456

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.127.0.0.1:6379> shutdown

not connected> exit

[root@redis-node2 ~]#ss -ntl

State? Recv-Q? Send-Q? ? Local Address:Port? ? Peer Address:Port?

LISTEN 01280.0.0.0:220.0.0.0:*? ?

LISTEN 0128[::]:22[::]:*[root@redis-node2 ~]#redis-cli -a123456--clusterinfo10.0.0.8:6379

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

Could not connect to Redis at 10.0.0.18:6379: Connection refused10.0.0.8:6379(72630b08...) ->3332keys |5461slots |1 slaves.10.0.0.48:6379(36b3aa74...) ->3341keys |5462slots |0slaves.? #10.0.0.48為新的master10.0.0.28:6379(8ffc94e8...) ->3330keys |5461slots |1 slaves.

[OK] 10003keysin3 masters.0.61 keys per slot on average.

[root@redis-node2 ~]#redis-cli -a123456--cluster check10.0.0.8:6379

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.

Could not connect to Redis at 10.0.0.18:6379: Connection refused10.0.0.8:6379(72630b08...) ->3332keys |5461slots |1 slaves.10.0.0.48:6379(36b3aa74...) ->3341keys |5462slots |0 slaves.10.0.0.28:6379(8ffc94e8...) ->3330keys |5461slots |1 slaves.

[OK] 10003keysin3 masters.0.61 keys per slot on average.>>> Performing Cluster Check (using node10.0.0.8:6379)

M: 72630b08354c8b67d7dd7af467b5b1c21efc05e7 10.0.0.8:6379? slots:[0-5460] (5461 slots) master

? 1 additional replica(s)

S: f67fb2a9264bdcddc3311956798e9f5c1d43fd0d 10.0.0.38:6379? slots: (0 slots) slave

? replicates 72630b08354c8b67d7dd7af467b5b1c21efc05e7

M: 36b3aa7483d2ba99e69db995c5b1e0a73b9ca937 10.0.0.48:6379? slots:[5461-10922] (5462 slots) master

M: 8ffc94e86dbf7f3477b77db130538d2219022bba 10.0.0.28:6379? slots:[10923-16383] (5461 slots) master

? 1 additional replica(s)

S: 7060d1ab30b41709903bf4e901aa3a8d14749ab0 10.0.0.58:6379? slots: (0 slots) slave

? replicates 8ffc94e86dbf7f3477b77db130538d2219022bba

[OK] All nodes agree about slots configuration.>>> Checkfor open slots...>>> Check slots coverage...

[OK] All 16384 slots covered.

[root@redis-node2 ~]#redis-cli -a123456-h10.0.0.48

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.10.0.0.48:6379>info replication

# Replication

role:master

connected_slaves:0master_replid:79b9fca6844610ee6a6d1dd0f2a3ef5434a9be45

master_replid2:e38086a24e8d7babe45bb460fe1f3754e188c119

master_repl_offset:141751second_repl_offset:141752repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:1repl_backlog_histlen:14175110.0.0.48:6379>

#故障恢復(fù)節(jié)點node2

[root@redis-node2 ~]#systemctl start redis

#查看自動生成的配置文件,可以查看node2自動成為slave節(jié)點

[root@redis-node2 ~]#cat/var/lib/redis/nodes-6379.conf

36b3aa7483d2ba99e69db995c5b1e0a73b9ca937 10.0.0.48:6379@16379master -016036148222747connected5461-109227060d1ab30b41709903bf4e901aa3a8d14749ab0 10.0.0.58:6379@16379slave 8ffc94e86dbf7f3477b77db130538d2219022bba016036148222746 connected

72630b08354c8b67d7dd7af467b5b1c21efc05e7 10.0.0.8:6379@16379master -016036148222741connected0-54608ffc94e86dbf7f3477b77db130538d2219022bba 10.0.0.28:6379@16379master -016036148222743connected10923-16383f67fb2a9264bdcddc3311956798e9f5c1d43fd0d 10.0.0.38:6379@16379slave 72630b08354c8b67d7dd7af467b5b1c21efc05e7016036148222744 connected

f7bb0a1728ec381483f464ab68c16edc2041fe10 10.0.0.18:6379@16379myself,slave 36b3aa7483d2ba99e69db995c5b1e0a73b9ca937016036148222662 connected

vars currentEpoch 7lastVoteEpoch0[root@redis-node2 ~]#redis-cli -a123456-h10.0.0.48

Warning: Using a password with '-a'or'-u' option on the command line interface may not be safe.10.0.0.48:6379>info replication

# Replication

role:master

connected_slaves:1slave0:ip=10.0.0.18,port=6379,state=online,offset=141905,lag=0master_replid:79b9fca6844610ee6a6d1dd0f2a3ef5434a9be45

master_replid2:e38086a24e8d7babe45bb460fe1f3754e188c119

master_repl_offset:141905second_repl_offset:141752repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:1repl_backlog_histlen:14190510.0.0.48:6379>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容