如何在Ubuntu 18.04上使用复制迁移Redis数据

介绍 (Introduction)

Redis is an in-memory, key-value data store known for its flexibility, performance, wide language support, and built-in features like replication. Replication is the practice of regularly copying data from one database to another in order to have a replica that always remains an exact duplicate of the primary instance. One common use of Redis replication is to migrate an existing Redis data store to a new server, as one might do when scaling up their infrastructure for better performance.

Redis是一个内存中的键值数据存储,以其灵活性,性能,广泛的语言支持以及诸如复制之类的内置功能而闻名。 复制是一种定期将数据从一个数据库复制到另一个数据库,以使副本始终始终与主实例完全相同的做法。 Redis复制的一种常见用法是将现有Redis数据存储迁移到新服务器,就像在扩展其基础架构以提高性能时可能所做的那样。

This tutorial outlines the process of using Redis’s built-in replication features to migrate data from one Ubuntu 18.04 server (the “source”) to another (the “target”). This involves making a few configuration changes to each server, setting the target server to function as a replica of the source, and then promoting the replica back to a primary after the migration is completed.

本教程概述了使用Redis的内置复制功能将数据从一台Ubuntu 18.04服务器(“源”)迁移到另一台(“目标”)的过程。 这涉及对每个服务器进行一些配置更改,将目标服务器设置为充当源服务器的副本,然后在迁移完成后将副本提升回主服务器。

先决条件 (Prerequisites)

To complete this tutorial, you will need:

要完成本教程,您将需要:

步骤1 —(可选)使用示例数据加载源Redis实例 (Step 1 — (Optional) Loading Your Source Redis Instance with Sample Data)

This optional step involves loading your source Redis instance with some sample data so you can experiment with migrating data to your target instance. If you already have data that you want to migrate over to your target, you can move ahead to Step 2 which will go over how to back it up.

此可选步骤涉及使用一些示例数据加载源Redis实例,以便您可以尝试将数据迁移到目标实例。 如果已经有要迁移到目标的数据,则可以继续执行步骤2 ,该步骤将介绍如何备份数据。

To begin, connect to the Ubuntu server you’ll use as your source Redis instance as your non-root user:

首先,以非root用户身份连接到将用作源Redis实例的Ubuntu服务器:

  • ssh sammy@source_server_ip

    ssh sammy @ source_server_ip

Then run the following command to access your Redis server:

然后运行以下命令来访问您的Redis服务器:

  • redis-cli

    redis-cli

If you’ve configured your Redis server to require password authentication, run the auth command followed by your Redis password:

如果已将Redis服务器配置为要求密码认证,请运行auth命令,然后输入Redis密码:

  • auth source_redis_password

    验证source_redis_password

Next, run the following commands. These will create a number of keys holding a few strings, a hash, a list, and a set:

接下来,运行以下命令。 这些将创建一些包含几个字符串,哈希,列表和集合的键:

  • mset string1 "Redis" string2 "is" string3 "fun!"

    mset string1“ Redis” string2“是” string3“有趣!
  • hmset hash1 field1 "Redis" field2 "is" field3 "fast!"

    hmset hash1 field1“ Redis” field2“ is” field3“ fast!”
  • rpush list1 "Redis" "is" "feature-rich!"

    rpush list1“ Redis”“是”“功能丰富!”
  • sadd set1 "Redis" "is" "free!"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值