码迷,mamicode.com
首页 > 其他好文 > 详细

redis主从复制

时间:2020-03-14 20:14:27      阅读:55      评论:0      收藏:0      [点我收藏+]

标签:cti   tin   slaves   state   span   second   replica   sentinel   dump   

配置从机命令 : slaveof 127.0.0.1 6379

信息

127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127.0.0.1:6379> 

 

一主两从

127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=6380,state=online,offset=1133,lag=0
slave1:ip=127.0.0.1,port=6381,state=online,offset=1133,lag=0
master_repl_offset:1133
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:1132
127.0.0.1:6379>

127.0.0.1:6380> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:6
master_sync_in_progress:0
slave_repl_offset:1175
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:407
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:406
127.0.0.1:6380>


127.0.0.1:6381> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:3
master_sync_in_progress:0
slave_repl_offset:1203
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:0
127.0.0.1:6381>

 

 

薪火相传

127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=6380,state=online,offset=797,lag=1
master_repl_offset:797
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:796

127.0.0.1:6380> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:9
master_sync_in_progress:0
slave_repl_offset:797
slave_priority:100
slave_read_only:1
connected_slaves:1
slave0:ip=127.0.0.1,port=6381,state=online,offset=29,lag=1
master_repl_offset:29
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:28
127.0.0.1:6380>

127.0.0.1:6381> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6380
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:15
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:0
127.0.0.1:6381> 

 

反客为主

127.0.0.1:6379> shutdown
not connected> exit
[root@hadoop100 myredis]# redis-server /myredis/redis6379.conf
[root@hadoop100 myredis]# redis-cli -p 6379
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127.0.0.1:6379> 

127.0.0.1:6380> slaveof no one
OK
127.0.0.1:6380> info replication
# Replication
role:master
connected_slaves:0
master_repl_offset:1303
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:1302
127.0.0.1:6380> set k12 v12
OK
127.0.0.1:6380> 


127.0.0.1:6381> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6380
master_link_status:up
master_last_io_seconds_ago:2
master_sync_in_progress:0
slave_repl_offset:1539
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:0
127.0.0.1:6381> 

 

[root@hadoop100 myredis]# ll
总用量 284
-rw-r--r--. 1 root root 14817 3月  14 18:36 6379.log
-rw-r--r--. 1 root root 25084 3月  14 18:36 6380.log
-rw-r--r--. 1 root root 38364 3月  14 18:36 6381.log
-rw-r--r--. 1 root root    68 3月  14 18:36 dump6379.rdb
-rw-r--r--. 1 root root    68 3月  14 18:36 dump6380.rdb
-rw-r--r--. 1 root root    68 3月  14 18:36 dump6381.rdb
-rw-r--r--. 1 root root 41420 3月  14 16:48 redis6379.conf
-rw-r--r--. 1 root root 41420 3月  14 16:49 redis6380.conf
-rw-r--r--. 1 root root 41420 3月  14 16:50 redis6381.conf
-rw-r--r--. 1 root root 41405 3月  14 11:49 redis_aof.conf
-rw-r--r--. 1 root root    43 3月  14 18:43 sentinel.conf

[root@hadoop100 myredis]# cat sentinel.conf 
sentinel monitor host6379 127.0.0.1 6379 1
[root@hadoop100 myredis]#

[root@hadoop100 bin]# ll
总用量 15464
-rw-r--r--. 1 root root 281 3月 14 13:20 appendonly.aof
-rw-r--r--. 1 root root 18 3月 14 17:07 dump.rdb
-rwxr-xr-x. 1 root root 4589155 3月 6 19:30 redis-benchmark
-rwxr-xr-x. 1 root root 22217 3月 6 19:30 redis-check-aof
-rwxr-xr-x. 1 root root 45435 3月 6 19:30 redis-check-dump
-rwxr-xr-x. 1 root root 4693114 3月 6 19:30 redis-cli
lrwxrwxrwx. 1 root root 12 3月 6 19:30 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 6466389 3月 6 19:30 redis-server
[root@hadoop100 bin]# redis-sentinel /myredis/sentinel.conf    //启动哨兵模式

哨兵模式

127.0.0.1:6379> shutdown
not connected> exit
[root@hadoop100 myredis]# redis-server /myredis/redis6379.conf
[root@hadoop100 myredis]# redis-cli -p 6379
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6381
master_link_status:up
master_last_io_seconds_ago:2
master_sync_in_progress:0
slave_repl_offset:2217
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:0
127.0.0.1:6379> 

127.0.0.1:6380> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6381
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:570
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:2
repl_backlog_histlen:47596
127.0.0.1:6380> 

127.0.0.1:6381> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=6380,state=online,offset=836,lag=0
master_repl_offset:836
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:835
127.0.0.1:6381> 

 

redis主从复制

标签:cti   tin   slaves   state   span   second   replica   sentinel   dump   

原文地址:https://www.cnblogs.com/liuyi13535496566/p/12493602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!