码迷,mamicode.com
首页 > 其他好文 > 详细

Redis集群方案Codis部署手册

时间:2015-08-06 20:03:52      阅读:722      评论:0      收藏:0      [点我收藏+]

标签:

参考:https://github.com/wandoulabs/codis/blob/master/doc/tutorial_zh.md

 

1、安装go

2、安装codis

go get -d github.com/wandoulabs/codis

cd $GOPATH/src/github.com/wandoulabs/codis

./bootstrap.sh

cd sample

3、安装zookeeper

wget http://mirror.bit.edu.cn/apache/zookeeper/stable/zookeeper-3.4.6.tar.gz

tar -xzvf zookeeper-3.4.6.tar.gz

cd zookeeper-3.4.6

cp conf/zoo_sample.cfg conf/zoo.cfg

./bin/zkServer.sh start

4、启动服务(sample目录下)

4.1、初始化slots

../bin/codis-config -c config.ini slot init -f

4.2、启动codis-server

nohup ../bin/codis-server ./redis.conf >./log/redis.log &

4.3、启动dashboard

nohup ../bin/codis-config -c config.ini -L ./log/dashboard.log dashboard --addr=:18087 --http-log=./log/requests.log &>/dev/null &

注意:要修改监听端口号,要通过--addr=:8000指定端口,config.ini中的dashboard_addr不起作用,不明白有什么用,建议改成一致。

若遇到dashboard已存在的错误,要删除zk下的dashboard节点。

若遇到部分命令无法执行,可能是zk下有LOCK,检查LOCK信息,删除即可。

4.4、添加Redis Server Group

通过dashboard管理,http://localhost:18087

技术分享 

或命令:

../bin/codis-config -c config.ini server add-group 1

4.5、配置group中的server实例,并设置masterslave

通过dashboard管理,http://localhost:18087

技术分享 

或命令:

../bin/codis-config -c config.ini server add 1 localhost:6380 master

提升master

技术分享 

或命令:

../bin/codis-config -c config.ini server promote 1 localhost:6380

 

4.6、设置slotsgroup的映射

说明:Codis 采用 Pre-sharding 的技术来实现数据的分片默认分成 1024 个 slots (0-1023), 对于每个key来说通过以下公式确定所属的 Slot Id : SlotId = crc32(key) % 1024 每一个 slot 都会有一个特定的 server group id 来表示这个 slot 的数据由哪个 server group 来提供。

0511节点分配到group_1上:

../bin/codis-config -c config.ini slot range-set 0 511 1 online

512-1023节点分配到group_2上:

../bin/codis-config -c config.ini slot range-set 512 1023 1 online

4.7、启动codis-proxy(提供给redis client的代理服务)

nohup ../bin/codis-proxy -c config.ini -L ./log/proxy.log --cpu=8 --addr=0.0.0.0:19000 &

监听在19000端口,启用8cpu解决redis单线程的瓶颈。

设置proxy上下线:

技术分享 

或命令:

../bin/codis-config -c config.ini proxy online proxy_1

../bin/codis-config -c config.ini proxy offline proxy_1

 

4.8、迁移数据

slot节点100-200的数据迁移到group_2中,通过dashboard管理:

技术分享 

或命令:

../bin/codis-config slot migrate 0 511 2 --delay=10

4.9、自动负载节点

slot节点自动负载到各group中,通过dashboard管理:

技术分享 

或命令:

../bin/codis-config slot rebalance

4.10、通过dashboard查看slot节点状态

http://localhost:18087/slots

技术分享 

 

 

 

 


系统架构图:

技术分享 

 

 

更多资料参考:https://github.com/wandoulabs/codis

 

 

 

 





Redis集群方案Codis部署手册

标签:

原文地址:http://www.cnblogs.com/ChrisJY/p/4708827.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!