redis数据库把它分散到两台机器

【字号: 日期:2022-09-03浏览:51作者:雯心

问题描述

我有一个4G的redis数据库,现在已经存在,我想要把它分散到两台机器,一台机器2G,该怎么做?

看了一下redis cluster,都是讲单点失败,主从复制,这个不是我的需求。

sf的redis服务器是多大的内存?

问题解答

回答1:

不太确定你在用什么客户端,不同的客户端有 distributed 的最基本实现,但是这些都是客户端实现,在增加删除节点时需要你自己重新算 hash 迁移数据。Redis 3 会有服务端的支持,就会简单很多了。

基本目前的客户端实现都是基于 @TechAd 说的 consistent hashing,比如 ruby 客户端就有 Redis::Distributed 可以用,你的需求把 4G 数据分到两台机器也很简单,已经有 https://github.com/yankov/redis-migra... 可以直接用,看下实现,其实也很简单。

希望对你有帮助。

回答2:

推荐你搜搜一致性哈希的相关算法,大体思路是,在客户端做一个路由,对key做一个hash,然后mod 2, 分别将key-value存储到0, 1两台机器上去,读取的时候也是这样。可以参考memcache的,给你一个参考链接http://blogread.cn/it/article/5271

回答3:

可以使用3L的做法,或者最直接的办法就是在业务层把数据分开,写在配置里面就可以了,这样以后在拆分的时候会很方便,逻辑也简单,如果真的需要做分布式,建议使用mongoDB

回答4:

如果你不需要pepline的话推荐使用https://github.com/twitter/twemproxy Twitter退出的代理,自动hash,故障自动切换

回答5:

问一下,twemproxy是不是不支持主备自动切换?

回答6:

如果你是用redis cluster来做这个数据迁移的话,可以看看其官方的介绍:Assuming you have your preexisting data set split into N masters, where N=1 if you have no preexisting sharding, the following steps are needed in order to migrate your data set to Redis Cluster:Stop your clients. No automatic live-migration to Redis Cluster is currently possible. You may be able to do it orchestrating a live migration in the context of your application / environment.Generate an append only file for all of your N masters using the BGREWRITEAOF command, and waiting for the AOF file to be completely generated.Save your AOF files from aof-1 to aof-N somewhere. At this point you can stop your old instances if you wish (this is useful since in non-virtualized deployments you often need to reuse the same computers).Create a Redis Cluster composed of N masters and zero slaves. You’ll add slaves later. Make sure all your nodes are using the append only file for persistence.Stop all the cluster nodes, substitute their append only file with your pre-existing append only files, aof-1 for the first node, aof-2 for the second node, up to aof-N.Restart your Redis Cluster nodes with the new AOF files. They’ll complain that there are keys that should not be there according to their configuration.Use redis-trib fix command in order to fix the cluster so that keys will be migrated according to the hash slots each node is authoritative or not.Use redis-trib check at the end to make sure your cluster is ok.Restart your clients modified to use a Redis Cluster aware client library.w

相关文章: