云计算运维

Windows Server 2003 - Windows Server 2019 系统工具,Linux系统脚本,Mysql、Nginx、PHP、Redis、K8S、Seafile、Weblogic 、Jenkins、DNS、DHCP、FTP、IIS、Zookeeper、Rabbitmq、Oracle、Tomcat、Mavrn等服务搭建维护,请关注我.

redis主从复制


服务器配置

操作系统主机名ipredis版本
CentOS7.6redis-node-1192.168.7.1004.0.14
CentOS7.6redis-node-2192.168.7.1034.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
  • 分享:
评论
还没有评论
    发表评论 说点什么