×
Community Blog Migrating and Backing up with Tair (Redis® OSS-Compatible)

Migrating and Backing up with Tair (Redis® OSS-Compatible)

This tutorial shows how to migrate and back up a local database with Alibaba Cloud Tair (Redis® OSS-Compatible).

Alibaba Cloud's Tair (Redis®* OSS-Compatible) is a key-value pair storage database that offers in-memory caching and high-speed access to applications hosted on the cloud. The ApsaraDB stack is part of Alibaba Cloud's wider suite of database services. The ApsaraDB suite includes support for RDS, Memcache, MongoDB and Redis®. Alibaba Cloud's ApsaraDB frees you from common system admin tasks associated with managing large web application in-memory caches and corporate databases. Tair (Redis® OSS-Compatible) includes an automatic backup system as standard.

In this tutorial, you'll get started using Alibaba Cloud Tair (Redis® OSS-Compatible), and explore how you can migrate and back up a local database with Alibaba Cloud Tair (Redis® OSS-Compatible).

Setting up the Backup File

Tair (Redis® OSS-Compatible) allows you to migrate with the EOF file. Make sure you set appendonly on your Redis® database with the following command:

config set appendonly yes

1

Creating an Alibaba Cloud ECS Instance

Now, let's setup Redis® on Alibaba Cloud's Tair (Redis® OSS-Compatible). To do this, we will have to first create an Alibaba Cloud ECS Instance on which you will then attach the Redis® service. Let's create an ECS instance installed with Ubuntu 16.04. Choose the region based on your requirements.

2

Don't forget to set a password so you can connect to the instance.

3

Agree to the terms and then create the instance.

4

Setting up the Instance and Redis®

Now, let's install everything we need on the instance. First, we need to do the required Ubuntu updates:

apt-get update
apt-get upgrade
apt-get dist-upgrade

Then, now that that's finished, let's install Redis® on the ECS instance:

apt install redis-tools 

Creating an Tair (Redis® OSS-Compatible) Instance

Now you can create an Tair (Redis® OSS-Compatible) instance that is connected to the default VPC and ECS which we just created.

5

Pick the Redis® version you require.

6

Notice that Alibaba Cloud auto-populates the VPC/vSwitch details with the defaults just created. When you're ready, click Buy Now, then agree to the terms and click Activate.

7

Connecting to Tair (Redis® OSS-Compatible)

Now let's connect to the Tair (Redis® OSS-Compatible) instance on the ECS instance we have just created. We will use the SSH protocol for this.

8

Next, in the Tair (Redis® OSS-Compatible) details page, we have to whitelist a network CIDR block in order to access the Redis® instance. The default whitelist blocks all access with 127.0.0.1.

9

For this tutorial, we will modify the whitelist setting to allow access from anywhere. Remember that, in a real production scenario, you will want to whitelist just a section of a VPC CIDR block for Redis®.

10

11

After the whitelist has been set, the Connection Address appears on the Tair (Redis® OSS-Compatible) Instance Information tab. Make a note of it.

12

Now, from the terminal connected to the ECS instance, you can access the Tair (Redis® OSS-Compatible) instance with the following command:

redis-cli -h [Connection Address] -a [password]

For example:

13

Getting Tair (Redis® OSS-Compatible) Ready for Migration

Follow these steps to make sure that your installation is in proper working order. To do this, you'll need to follow these steps:

First, start Redis® with the redis-server command.

14

Then, run the command line interface with redis-cli and check the server is running with a ping. And, set and get a test key-value pair and save it to the backup file.

15

You can also connect to a Redis® instance using other client software such as Jedis for Java, for example.

16

Migrating Redis® to Alibaba Cloud

In a terminal window, cd to the local directory in which your appendonly.aof file resides and run the following scp command:

scp appendonly.aof root@47.90.244.142:/home

17

Now, find the copied appendonly.aof file in the ECS instance.

18

Pipe the appendonly.aof to the Tair (Redis® OSS-Compatible) instance with the following command in the ECS terminal.

redis-cli -h [Connection Address] -p 6379 -a [password] --pipe < appendonly.aof

19

Now, log in to your Tair (Redis® OSS-Compatible) service and with the get command, check the data by getting something you set on the database locally. You will see that your data has been successfully migrated over to the Alibaba Cloud.

20

Connecting with Jedis

You can also connect to your Alibaba Cloud Tair (Redis® OSS-Compatible) instance with Jedis for Java in Eclipse. Before you can access the Redis® instance in the cloud you have to open some ports with network configuration changes on the ECS instance.

First, install rinetd on the Ubuntu instance. Note that the details given here will be different for other operating systems.

wget http://www.boutell.com/rinetd/http/rinetd.tar.gz&&tar -xvf rinetd.tar.gz&&cd rinetd
sed -i 's/65536/65535/g' rinetd.c 
mkdir /usr/man&&make&&make install

Next, add the following configuration details to the rinetd configuration file:

nano /etc/rinetd.conf
0.0.0.0 6379 r-7go1a73cf051c984.redis.rds.aliyuncs.com 6379 
logfile /var/log/rinetd.log

Then, start the rinetd service:

rinetd

Check whether rinetd is running and working properly.

21

Also, you have to make sure to open the Redis® port in the Security Group details page of the ECS instance. Go to the ECS Management Console Security Groups page and select your Security Group. Click Configure Rules, and then click Add Security Group Rules.

Open port range 6379/6379 to the IP range you wish to have access to your Redis® instance. We have used 0.0.0.0/0 for this tutorial.

22

Now you can code directly to the Redis® instance from your local development environment. For Jedis, create a new class and add the appropriate configuration details to match your cloud instance.

23

Setting up Backup Configurations

As with all the other Alibaba Cloud ApsaraDB services, in the Tair (Redis® OSS-Compatible) instance details, you can set backup configurations for your Redis® instance.

24

Summary

To summarize what we did in this tutorial, we first had set up our Redis® database and made sure it was working, and we set an example key-value pair. Then, we made sure we saved our local Redis® database with the appendonly option. Next, after that, we created an Alibaba Cloud ECS Instance on which to host our Tair (Redis® OSS-Compatible) instance. We configured the instance to have Ubuntu 16.04 as our operating system and setup Redis® on the instance. Next, we created an Alibaba Cloud Tair (Redis® OSS-Compatible) instance, which was attached to the ECS instance we had just created. We migrated our local database to the Alibaba Cloud instance and checked whether it had migrated successfully. Finally, we performed some network administration in order to be able to access our Alibaba Cloud Tair (Redis® OSS-Compatible) instance from outside the cloud console. We chose the Java Jedis client and wrote a test class to check that we could connect to the cloud database.

Enjoyed this tutorial? Learned something? Don't forget to check out our other Alibaba Cloud ApsaraDB tutorials for setting up ApsaraDB for Memcache, ApsaraDB for RDS and ApsaraDB for MongoDB, along with several other tutorials for several other products and services offered by Alibaba Cloud.


*Redis is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Any use by Alibaba Cloud is for referential purposes only and does not indicate any sponsorship, endorsement or affiliation between Redis and Alibaba Cloud.

0 0 0
Share on

Alibaba Clouder

2,599 posts | 764 followers

You may also like

Comments