服务器配置
| 操作系统 | 主机名 | ip | redis版本 | |-----------|--------------|---------------|---------| | CentOS7.6 | redis-node-1 | 192.168.7.100 | 4.0.14 | | CentOS7.6 | redis-node-2 | 192.168.7.103 | 4.0.14 |
环境配置
1.关闭防火墙
2.时间同步
3.关闭selinux
安装redis
编译安装redis
配置主从架构
redis-node-2为从(slave)
[root@redis-node-2 redis]redis-cli
127.0.0.1:6379> slaveof 192.168.7.100 6379
OK
127.0.0.1:6379> info Replication
# Replication
role:slave
master_host:192.168.7.100
master_port:6379
master_link_status:up
master_last_io_seconds_ago:6
master_sync_in_progress:0
slave_repl_offset:562
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:f59143794f51399f6e2a7aa52f60118e25bffd94
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:562
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:562
查看redis-node-1
[root@redis-node-1 redis]redis-cli
127.0.0.1:6379> info Replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.7.103,port=6379,state=online,offset=884,lag=1
master_replid:f59143794f51399f6e2a7aa52f60118e25bffd94
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:898
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:898
修改配置文件
为了重启从节点后主从架构依旧生效,我们需要修改配置文件
[root@redis-node-2 ~]# vim /apps/redis/etc/redis.conf
[root@redis-node-2 ~]# cat /apps/redis/etc/redis.conf | grep slaveof
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
slaveof 192.168.7.103 6379
[root@redis-node-2 ~]# systemctl restart redis