当前位置:网站首页>Cloud Migration Practice of Redis

Cloud Migration Practice of Redis

2022-08-10 13:21:00 51CTO

简介

随着云产品的完善,Most companies have already started using cloud products,Cloud products can indeed solve many infrastructure conveniences,Improve the stability of the business structure,如何将RedisData is migrated online to the cloud,And guarantee the loss of business,The following points must be considered from the selection of migration scenarios and tools:

兼容性:RedisThe Community Edition is backward compatible,在上云的过程中,Try to keep the major version consistent,In order to avoid the problem of client incompatibility caused by version inconsistency

迁移工具:While fully considering the functionality of the tool,Convenience and operability are also important considerations,The tool needs to have a complete logging and monitoring system

数据完成性:数据大于一切,Data integrity cannot be guaranteed,Do not do related actions,RedisAs cached data changes faster,It is necessary to perform data comparison and related work in real time

Effective assessment of resources: Resource specifications on cloud resources have been standardized,When evaluating resources on the cloud,Fully refer to the self-built computer room example,As far as possible higher than self-built resources

迁移流程

资源评估

  • Fully consider self-built computer roomRedis实例的架构,Extract instances from monitoring systemsQPS,内存大小,,连接数,Bandwidth and other three indicators,The specifications and performance of the instances on the cloud need to be self-builtRedis对齐,Instances on the cloud have bandwidth limitations,这点需要注意
  • Try to use the slave library of the self-built instance as the data source for data synchronization,In order to reduce the pressure on the business to access the main library

兼容性评估

版本确认

Try to keep the major version of the instance on the cloud consistent with the self-built instance,The current major version is 4.0

Command compatibility confirmation

Cloud vendors in order to support some features,Castrated some commands,For command compatibility support, see the cloud vendor documentation

Whether to use a password

Some older businesses may not support passwords,在上云的过程中,Keep it as confidential as possible,Even some apps have passwords,也可以兼容

业务评估

是否使用lua脚本

检查原因:社区版4.0.2Versions and below will not synchronize the secondary slave libraryluaScript to tertiary slave library,可对Redis进行monitor抓包查看
解决方法:同步主库

是否使用lua客户端

检查原因:Some applications applyluaClients may use built-in domain name resolution,导致无法解析Redis域名

解决方法:Modify the built-in domain name resolution or use the system domain name resolution

Whether read and write requests are detachable

检查原因:The main library read and write cannot be disassembled,There is no guarantee that a read and write request of an application will be completely migrated,This leads to data inconsistency issues

解决方法:Use a proxy for the main library,一般使用Haproxy

Identify the business visitor

检查原因:Prevent business leakage,导致数据不一致

解决方法:Turn on regularlyredis monitor或tcpdumpCapture packets of master and slave instances,Learn about business visitors

Check whether the service has a reconnection mechanism

检查原因:There is research and development confirmed

解决方法:The application side tries to maintain the reconnection mechanism as much as possible,No reconnection mechanism,更改配置后,The business application needs to be restarted

确定方案

After formulating an initial migration plan,It is necessary to connect the plan with the business R&D person in charge,Avoid problems that have not been considered in the business,Make a plan rollback plan

方案实施

  • Build a data synchronization tool,A completed monitoring system is required,The source and target instances need to have complete logs,Periodically capture packets in real time for instances
  • 迁移过程中,R&D leaders and operation and maintenance personnel participated in the whole process,Avoid unforeseen problems
  • 迁移时间,The off-peak business period should be selected

Migration closes

善后处理

迁移完成后,After confirming that there is no abnormality in the business,Try to close the source instance as much as possible,及时发现问题,And real-time packet capture of the agent,Avoid data inconsistencies caused by missing migrations

总结经验

Summarize the problems that occurred during the migration process,并形成文档,It is convenient for subsequent migration and summary

迁移方案

原理

This program adopts open sourceRedis-shake作为数据同步工具,haroxy作为代理.架构如下图:

RedisCloud migration practice_redis上云

      
      
阶段一(图一):
Mainly for constructionredis-shakeand proxy nodes,The business remains the same for access,The proxy configuration is self-built for backend connectionsredis实例

阶段二(图二):
1、Compare data between source and destination
2、After data comparison is correct,Configure the application to be self-builtRedisaddress changed toharoxy代理地址
3、对自建RedisInstance to capture packets,Check to see if there is no access

阶段三(图三):
1、自建RedisAfter no visit,将haproxyThe back-end connection address is changed to the cloud vendor address
2、重启haproxy,Determine the business situation
2、云厂商RedisWhether all visits come fromhaproxy地址

阶段四(图四):
1、determine cloudredisWhether the access is fromhaproxy地址
2、The business will apply the configuration withhaproxyThe address is modified to the cloudRedis地址
3、对haproxyCapture packets in real time,Avoid escaping
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

迁移方法

数据同步

Open source is availableRedis数据同步工具,redis-shake的基本原理就是模拟一个从节点加入源redis集群,首先进行全量拉取并回放,然后进行增量的拉取(通过psync命令),具体配置请参考​ ​文档​

RedisCloud migration practice_数据比对_02

数据比对

Open source data comparison tools can be used,By comparing the source end and the destination end in fullredis中的数据的方式来进行数据校验,The comparison method is through multiple rounds of comparison:每次都会抓取源和目的端的数据进行差异化比较,记录不一致的数据进入下轮对比(记录在sqlite3 db中).然后通过多伦比较不断收敛,减少因数据增量同步导致的源库和目的库的数据不一致.最后sqlite中存在的数据就是最终的差异结果.具体配置请参考​ ​文档​

RedisCloud migration practice_redis迁移_03

业务迁移

For business only,只提供了redis地址和haproxy的地址,The business configuration needs to be modified to haproxy地址,haproxy的配置如下:

      
      
global
log 127.0.0.1 local1 notice
daemon
stats socket /tmp/haproxy.sock
nbproc 5
maxconn 40000

defaults
log global
mode tcp
option tcplog
option dontlognull
retries 3
option abortonclose
maxconn 20000
timeout connect 10s
timeout client 3m
timeout server 3m
timeout check 10s
balance static-rr

listen stats
bind 127.0.0.1:11080
mode http
option httplog
maxconn 20
stats enable
stats refresh 3s
stats uri /stats
stats realm DBA Haproxy
stats auth *********
stats auth *********
stats hide-version
stats admin if TRUE

listen redisRead
bind 127.0.0.1:18982
mode tcp
option tcplog
balance static-rr
# server streamconf_6010 127.0.0.1:6010 check inter 2000 rise 3 fall 3 weight 10
server streamconf_6010 10.255.10.1:6379 check inter 2000 rise 3 fall 3 weight 10
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.


总结

  • Be sure to do a plan research before migrating、资源评估,兼容性评估
  • Monitoring is the eyes of operation and maintenance personnel,After program selection,监控是必不可少的
  • 业务迁移,Try to choose a low-peak business period,and do relevant tests

参考

 ​redis数据同步​

 ​redis 数据比对​

原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208101233203379.html