Redis主从复制搭建步骤

1.什么是主从复制

主服务器写数据会实时同步(复制)到从服务器

2.主从复制搭建步骤

搭建主从复制架构

1.主不需要配置

2.从机:

     1.cd /usr/local/redis.6.0.6 cp -r bin bin2

     2.修改从机的redis.conf,保存:

            1.replicaof 127.0.0.1 6379

             2.port 6380

            3.清除从机中的持久化文件: rm -rf dump.rdb appendonly.aof

3.启动从机:

      1.cd bin2

       2 ./redis-server ./redis.conf

4.这时从机重新生成了appendonly.aof dump.rdb文件

5.在主机设置值

      1./redis-cli;:set a 1

       2.get a

6.在从机取值

        1./redis-cli -p 6380: get a 取值成功

7.在从机不能设置,只能读

        1./redis-cli -p 6380:

              127.0.0.1:6380> set a 3

               (error) READONLY You can't write against a read only replica.

8.搭建第二个从机

        1.cd /usr/local/redis.6.0.6/

        2.cp -r bin2 bin3

        3.修改从机bin3的redis.conf,保存:    

              1.port 6381

              2.清除从机中的持久化文件: rm -rf dump.rdb appendonly.aof

         4.启动从机: 1.cd bin3 2 ./redis-server ./redis.conf

         5.这时从机重新生成了appendonly.aof dump.rdb文件

         6.在主机设置值 1./redis-cli;:set a 2 2.get a

         7.在从机取值 1./redis-cli -p 6381: get a 取值成功

         8.在从机不能设置,只能读

                 1./redis-cli -p 6381:

                      127.0.0.1:6380> set a 3

                       (error) READONLY You can't write against a read only

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值