实践作业:将数据迁移到华为云Redis
基于前面的介绍,完成以下任务:
1.在ECS上安装一个Redis服务,并且启动Redis。
2.使用Redis-cli连接本地Redis服务,并使用set命令插入几条数据。
3.使用Redis-cli或者redis-port,将第二步生成的数据迁移到华为云Redis实例。
4.连接华为云Redis实例,验证数据是否正确迁移。
作业步骤如下:
第一步:在ecs启动redis服务
[root@ecs-391c ~]# service redis start
第二步:连接本地redis服务,因redis3.x默认是rdb备份模式,本次我们采用aof方式导入导出,所以需要修改配置为aof模式。
[root@ecs-391c ~]# redis-cli
127.0.0.1:6379> CONFIG SET appendonly yes
OK
第三步:创建key-value数据,并查看创建的记录后退出。
127.0.0.1:6379> set a 1
OK
127.0.0.1:6379> set b 2
OK
127.0.0.1:6379> set b 3
OK
127.0.0.1:6379> set d 4
OK
127.0.0.1:6379> keys *
1) "a"
2) "b"
3) "c"
4) "d"
127.0.0.1:6379> info keyspace
# Keyspace
db0:keys=4,expires=0,avg_ttl=0
127.0.0.1:6379> exit
第四步:因为是采用yum方式安装,可能不知道redis的安装目录,需要找到redis产生的aof文件
[root@ecs-391c ~]# find / -name *.aof
/var/lib/redis/appendonly.aof
第五步:通过redis-cli方式导入本地aof文件到分布式缓存服务
[root@ecs-391c ~]# redis-cli -h 192.168.0.128 -p 6379 -a Test@1234 --pipe < /var/lib/redis/appendonly.aof
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 10
第六步:验证导入是否成功。
[root@ecs-391c ~]# redis-cli -h 192.168.0.128 -p 6379 -a Test@1234
192.168.0.128:6379> keys *
1) "d"
2) "a"
3) "c"
4) "b"
192.168.0.128:6379> info keyspace
# Keyspace
db0:keys=4,expires=0,avg_ttl=0
192.168.0.128:6379> get a
"1"
192.168.0.128:6379> get b
"3"
192.168.0.128:6379> get c
"3"
192.168.0.128:6379> get d
"4"