本篇文章为大家展示了Redis 4.0主从复制配置是怎样的,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
Master: 192.168.174.201
Slave: 192.168.174.202
在两台服务器上面安装Redis,
http://blog.itpub.net/26506993/viewspace-2146826/
在主节点上,编辑配置文件
[root@MySQL01 redis-4.0.2]# vim redis.conf
# 指定端口
port 6379
# 配置密码
requirepass abc
# 监听来自网络的所有连接
# bind 127.0.0.1
在从节点上,编辑配置文件
[root@localhost redis-4.0.2]# vim redis.conf
# 配置主节点的IP和端口
slaveof 192.168.174.201 6379
# 配置连接到主库所使用的密码
masterauth abc
# 配置密码
requirepass abc
# 监听来自网络的所有连接
# bind 127.0.0.1
# 指定端口
port 6380
在主节点上,启动redis
[root@MySQL01 redis-4.0.2]# src/redis-server redis.conf
51173:C 04 Nov 07:12:09.019 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
51173:C 04 Nov 07:12:09.019 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=51173, just started
51173:C 04 Nov 07:12:09.019 # Configuration loaded
在从节点上,启动redis
[root@localhost redis-4.0.2]# src/redis-server /opt/redis-4.0.2/redis.conf
61391:C 04 Nov 07:14:10.695 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
61391:C 04 Nov 07:14:10.695 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=61391, just started
61391:C 04 Nov 07:14:10.695 # Configuration loaded
验证复制
在主节点上面插入链表数据
[root@MySQL01 redis-4.0.2]# src/redis-cli -a abc
127.0.0.1:6379> rpush list-key item1
(integer) 1
127.0.0.1:6379> rpush list-key item2
(integer) 2
127.0.0.1:6379> rpush list-key item3
(integer) 3
127.0.0.1:6379> lrange list-key 0 -1
1) "item1"
2) "item2"
3) "item3"
查看复制状态
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.174.202,port=6380,state=online,offset=1785,lag=0
master_replid:17cc14861639f71ed1f82ce9999f22ff337014e4
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1785
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:1785
在从节点上面查看链表数据
[root@localhost redis-4.0.2]# src/redis-cli -h 192.168.174.202 -p 6380 -a abc
192.168.174.202:6380> lrange list-key 0 -1
1) "item1"
2) "item2"
3) "item3"
查看复制状态
192.168.174.202:6380> info replication
# Replication
role:slave
master_host:192.168.174.201
master_port:6379
master_link_status:up
master_last_io_seconds_ago:6
master_sync_in_progress:0
slave_repl_offset:1771
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:17cc14861639f71ed1f82ce9999f22ff337014e4
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1771
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:1771
上述内容就是Redis 4.0主从复制配置是怎样的,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。
原创文章,作者:kirin,如若转载,请注明出处:https://blog.ytso.com/203975.html