1.概要
- 什么是主从复制
- 主从复制的配置
- 全量复制和部分复制
- 故障处理
- 开发运维的常见问题
2.什么是主从复制
Redis单机问题.png
Redis主从1.png
Redis主从2.png
Redis主从复制作用1.png
主从复制的作用.png
主从复制总结.png
3.主从复制的配置
-
slaveof
命令实现1.png
命令实现2.png -
配置
修改配置.png
主从复制配置比较.png
4.实操
- 命令
- 配置
- 主从关系
- 主从数据
- 开启主从配置
vim redis-6379.conf
daemonize yes pidfile /var/run/redis-6379.pid logfile "6379.log" #save 900 1 #save 300 10 #save 60 10000 dbfilename dump-6379.rdb dir /opt/soft/redis/redis/data
vim redis-6380.conf
port 6380 daemonize yes pidfile /var/run/redis-6380.pid logfile "6380.log" #save 900 1 #save 300 10 #save 60 10000 dbfilename dump-6380.rdb dir /opt/soft/redis/redis/data replicaof 127.0.0.1 6379
[root@master redis]# redis-server redis-6379.conf [root@master redis]# redis-cli 127.0.0.1:6379> info replication # Replication role:master connected_slaves:0 master_replid:77c12844b3370cd33e5ec421891f6c400d12ee28 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:0 second_repl_offset:-1 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0 127.0.0.1:6379> exit [root@master redis]# redis-server redis-6380.conf [root@master redis]# redis-cli -p 6380 info-replication (error) ERR unknown command `info-replication`, with args beginning with: [root@master redis]# redis-cli -p 6380 info replication # Replication role:slave master_host:127.0.0.1 master_port:6379 master_link_status:up master_last_io_seconds_ago:10 master_sync_in_progress:0 slave_repl_offset:56 slave_priority:100 slave_read_only:1 connected_slaves:0 master_replid:e21d4f3793ad9495f4cf9ae6d23d3e426df72cb2 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:56 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:56 [root@master redis]# redis-cli 127.0.0.1:6379> set hello world OK 127.0.0.1:6379> quit [root@master redis]# redis-cli -p 6380 get hello "world"
5.全量复制
[root@master redis]# redis-cli -p 6379 info server | grep run
run_id:26a8b09874078fda0a18b7a1f08c05ddb7ac8ab0
[root@master redis]# redis-cli -p 6380 info server | grep run
run_id:10858f81e4b3be96fefa9b07af1f9e87c31100ea
[root@master redis]# redis-cli -p 6380 info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_repl_offset:6218
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:e21d4f3793ad9495f4cf9ae6d23d3e426df72cb2
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:6218
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:6218
[root@master redis]# redis-cli -p 6379 info replication
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=6380,state=online,offset=6246,lag=0
master_replid:e21d4f3793ad9495f4cf9ae6d23d3e426df72cb2
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:6246
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:6246
全量复制.png
6.全量复制开销
- bgsave时间
- RDB文件网络传输时间
- 从节点清空数据时间
- 从节点加载RDB的时间
- 可能的AOF重写时间
部分复制.png
7.故障处理
故障转移.png
slave宕掉1.png
slave宕掉2.png
slave宕掉3.png
master宕掉1.png
master宕掉2.png
master宕掉3.png
master宕掉4.png
故障转移问题.png
7.主从复制开发与运维中的问题
-
读写分离
Redis读写分离.png
-
主从配置不一致
Redis配置不一致.png
-
规避全量复制
Redis规避全量复制.png
-
规避复制风暴
Redis规避复制风暴.png
网友评论