一、概要

1、折腾codis集群已经快两个月了,感谢一直以来codis的作者刘奇和黄东旭的耐心支持,在这里给你们点个赞,现在我司已经有一个业务跑在了 codis集群上,目前只是切了整个业务的10%的量,预计下周会全量切到codis上,这个时候大家肯定特别想知道codis稳定吗?有没有什么bug 啊,你想知道的也是我想知道的,搞起吧,用了才知道,反正目前我们这没发现啥问题,一些小的问题已经及时联系作者改掉了,好吧,不扯淡了,写这篇文章的目 的是帮助想了解codis的初学者快速部署(官方的部署文档对应运维知识弱一点的童鞋看来还是有点费力)还有就是给自己做一个备录以便后期集群的部署。

2、Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有明显的区别 (有一些命令不支持), 上层应用可以像使用单机的 Redis 一样使用, Codis 底层会处理请求的转发, 不停机的数据迁移等工作, 所有后边的一切事情, 对于前面的客户端来说是透明的, 可以简单的认为后边连接的是一个内存无限大的 Redis 服务,当然,前段时间redis官方的3.0出了稳定版,3.0支持集群功能,codis的实现原理和3.0的集群功能差不多,我了解的现在 美团、阿里已经用了3.0的集群功能了,我们这边的业务主要是php,3.0集群的sdk目前貌似还没有支持php语言的,大家谁的php应用上了3.0 集群,请联系我,我去取经,有关redis常见的集群技术,请移步到 @萧田国 萧老师的infoq专栏Redis集群技术及Codis实践

二、架构

三、角色分批

1

2

3

4

5

6

7

8

9

10

11

12

13

zookeeper集群:

10.10.0.47

10.10.0.48

10.10.1.76

codis-config、codis-ha:

10.10.32.10:18087

codis-proxy:

10.10.32.10:19000

10.10.32.49:19000

codis-server:

10.10.32.42:6379、10.10.32.43:6380(主、从)

10.10.32.43:6379、10.10.32.44:6380(主、从)

10.10.32.44:6379、10.10.32.42:6380(主、从)

四、部署

1、安装zookeeper

1

yum -y install zookeeper jdk  ##安装服务

1

2

3

4

vim /etc/hosts  ##添加host

10.10.0.47 ZooKeeper-node1

10.10.0.48 ZooKeeper-node2

10.10.1.76 ZooKeeper-node3

1

2

3

4

5

6

7

8

9

10

vim /etc/zookeeper/conf/zoo.cfg ##撰写zk的配置文件

maxClientCnxns=50

tickTime=2000

initLimit=10

syncLimit=5

dataDir=/data/zookeeper/

clientPort=2181

server.1=ZooKeeper-node1:2888:3888

server.2=ZooKeeper-node2:2888:3888

server.3=ZooKeeper-node3:2888:3888

1

2

3

mkdir /data/zookeeper/ ##创建zk的datadir目录

echo "2" >/data/zookeeper/myid  ##生成ID,这里需要注意, myid对应的zoo.cfg的server.ID,比如ZooKeeper-node2对应的myid应该是2

/usr/lib/zookeeper/bin/zkServer.sh start  ## 服务启动

2、go安装(codis是go语言写的,所以那些机器需要安装你懂得)

1

2

3

4

5

6

7

8

9

10

11

12

wget https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz

tar -zxvf go1.4.1.linux-amd64.tar.gz

mv go /usr/local/

cd /usr/local/go/src/

bash all.bash

cat >> ~/.bashrc << _bashrc_export

export GOROOT=/usr/local/go

export PATH=$PATH:$GOROOT/bin

export GOARCH=amd64

export GOOS=linux

_bashrc_export

source ~/.bashrc

3、下载并编译codis(codis-config、codis-proxy、codis-server所在的机器)

1

2

3

4

5

6

mkdir /data/go

export GOPATH=/data/go

/usr/local/go/bin/go get github.com/wandoulabs/codis

cd  /data/go/src/github.com/wandoulabs/codis/

./bootstrap.sh

make gotest

五、服务启动及初始化集群

1、启动 dashboard(codis-config上操作)

1

2

3

4

5

6

7

cat /etc/codis/config_10.ini ##撰写配置文件

zk=10.10.0.47:2181,10.10.0.48:2181,10.10.1.76:2181

product=zh_news

proxy_id=codis-proxy_10

net_timeout=5000

proto=tcp4

dashboard_addr=10.10.32.10:18087

1

cd /data/go/src/github.com/wandoulabs/codis/ &&  ./bin/codis-config -c /etc/codis/config_10.ini  dashboard &

2、初始化 slots (codis-config上操作)

1

cd /data/go/src/github.com/wandoulabs/codis/ &&  ./bin/codis-config -c /etc/codis/config_10.ini slot init

3、启动 Codis Redis , 和官方的Redis Server参数一样(codis-server上操作)

1

cd /data/go/src/github.com/wandoulabs/codis/ && ./bin/codis-server /etc/redis_6379.conf &

4、添加 Redis Server Group , 每一个 Server Group 作为一个 Redis 服务器组存在, 只允许有一个 master, 可以有多个 slave, group id 仅支持大于等于1的整数(codis-config上操作)

1

2

3

4

5

6

7

cd /data/go/src/github.com/wandoulabs/codis/

./bin/codis-config -c /etc/codis/config_10.ini server add 1 10.10.32.42:6379 master

./bin/codis-config -c /etc/codis/config_10.ini server add 1 10.10.32.43:6380 slave

./bin/codis-config -c /etc/codis/config_10.ini server add 2 10.10.32.43:6379 master

./bin/codis-config -c /etc/codis/config_10.ini server add 2 10.10.32.44:6380 slave

./bin/codis-config -c /etc/codis/config_10.ini server add 3 10.10.32.44:6379 master

./bin/codis-config -c /etc/codis/config_10.ini server add 3 10.10.32.42:6380 slave

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

1

2

3

4

cd /data/go/src/github.com/wandoulabs/codis/

./bin/codis-config -c /etc/codis/config_10.ini slot range-set 0 300 1 online

./bin/codis-config -c /etc/codis/config_10.ini slot range-set 301 700 2 online

./bin/codis-config -c /etc/codis/config_10.ini slot range-set 701 1023 3 online

6、启动 codis-proxy  (codis-proxy上操作)

1

2

3

4

5

6

7

cat /etc/codis/config_10.ini ##撰写配置文件

zk=10.10.0.47:2181,10.10.0.48:2181,10.10.1.76:2181

product=zh_news

proxy_id=codis-proxy_10  ##10.10.32.49上改成codis-proxy_49,多个proxy,proxy_id 需要唯一

net_timeout=5000

proto=tcp4

dashboard_addr=10.10.32.10:18087

1

2

cd /data/go/src/github.com/wandoulabs/codis/ &&  ./bin/codis-proxy  -c /etc/codis/config_10.ini -L /data/log/codis-proxy_10.log  --cpu=4 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &

cd /data/go/src/github.com/wandoulabs/codis/ &&  ./bin/codis-proxy  -c /etc/codis/config_49.ini -L /data/log/codis-proxy_49.log  --cpu=4 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &

OK,整个集群已经搭建成功了

六、codis-server的HA

codis-ha实现codis-server的主从切换,codis-server主库挂了会提升一个从库为主库,从库挂了会设置这个从库从集群下线

1、安装

1

2

3

4

5

6

7

export GOPATH=/data/go

/usr/local/go/bin/go get github.com/ngaut/codis-ha

cd  /data/go/src/github.com/ngaut/codis-ha

go build

cp codis-ha /data/go/src/github.com/wandoulabs/codis/bin/

使用方法:

codis-ha --codis-config=dashboard地址:18087 --productName=集群项目名称

2、使用supervisord管理codis-ha进程

1

yum -y install supervisord

1

2

3

4

5

6

7

8

9

10

11

/etc/supervisord.conf中添加如下内容:

[program:codis-ha]

autorestart = True

stopwaitsecs = 10

startsecs = 1

stopsignal = QUIT

command /data/go/src/github.com/wandoulabs/codis/bin/codis-ha --codis-config=10.10.32.17:18087 --productName=dh_tianqi

user = root

startretries = 3

autostart = True

exitcodes = 0,2

3、启动supervisord服务

1

2

/etc/init.d/supervisord start

chkconfig supervisord  on

此时,ps -ef |grep codis-ha 你回发现codis-ha进程已经启动,这个时候你去停掉一个codis-server的master,看看slave会不会提升为master呢

七、关于监控

关于整个codis集群的监控,我们这边用的是zabbix,监控的指标比较简单,所以这块大家有什么好的建议多给我提提哈

zookeeper:监控各个节点的端口联通性(以后想着把进程也监控上)

codis-proxy:监控了端口的联通性,这个监控远远不够呀

codis-server:监控了内存使用率、连接数、联通性

codis-ha:监控进程

dashboard:监控端口联通性

八、使用过程中遇到的问题

1、codis-proxy的日志切割,codis-proxy的默认日志级别是info,日志量很大,我们这边每天产生50多G日志,目前codis-proxy还不支持热重启,想修改启动参数还是比较麻烦的,日志切割推荐用logrotate

2、codis-proxy的监听地址默认没有具体ipv4,也就是codis-proxy启动之后没有0.0.0.0:19000这样的监听,这 样会导致的问题就是前端lvs没有办法负载均衡codis-proxy,不能转发请求过,这个问题已联系作者处理了,在codis-proxy启动的配置 文件中加上proto=tcp4这个参数就支持监听ipv4了

3、添加 Redis Server Group的时候,非codis-server(原生的redis)竟然也能加入到codis集群里面,在redis和codis-server共存在一 个物理机上的清楚,很容易加错,希望能有个验证,非codis-server不能加入到codis集群

4、codis集群内部通讯是通过主机名的,如果主机名没有做域名解析那dashboard是通过主机名访问不到proxy的http-addr地 址的,这会导致从web界面上看不到 OP/s的数据,至于还有没有其他问题,目前我这边还没有发现,建议内部通讯直接用内网IP

本文转自 msj0905 51CTO博客,原文链接:http://blog.51cto.com/sky66/1719187

codis集群部署实战相关推荐

  1. php codis,codis集群部署实战

    codis介绍 Codis是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有明显的区别 (有一些命令不支持), 上 ...

  2. redis 槽点重新分配 集群_5000+字硬核干货!Redis 分布式集群部署实战

    原理: Redis集群采用一致性哈希槽的方式将集群中每个主节点都分配一定的哈希槽,对写入的数据进行哈希后分配到某个主节点进行存储. 集群使用公式(CRC16 key)& 16384计算键key ...

  3. Linux服务集群部署实战--MySQL、Redis、ES、RocketMQ、Zookeeper

    部署架构 部署计划 MySQL服务部署 架构 规划 部署pxc集群 部署MySQL主从架构 部署mycat集群 创建表以及测试 部署HAProxy redis集群部署 redis集群采用3主3从的架构 ...

  4. down redis集群_硬核干货!Redis 分布式集群部署实战

    原理: Redis集群采用一致性哈希槽的方式将集群中每个主节点都分配一定的哈希槽,对写入的数据进行哈希后分配到某个主节点进行存储. 集群使用公式(CRC16 key)& 16384计算键key ...

  5. redis分片_5000+字硬核干货!Redis 分布式集群部署实战

    原理: Redis集群采用一致性哈希槽的方式将集群中每个主节点都分配一定的哈希槽,对写入的数据进行哈希后分配到某个主节点进行存储. 集群使用公式(CRC16 key)& 16384计算键key ...

  6. 硬核干货!Redis 分布式集群部署实战

    原理: Redis集群采用一致性哈希槽的方式将集群中每个主节点都分配一定的哈希槽,对写入的数据进行哈希后分配到某个主节点进行存储. 集群使用公式(CRC16 key)& 16384计算键key ...

  7. Redis(3.2.3)集群部署实战

    一.Redis简介 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. Redis官网地址:http://red ...

  8. (三)RocketMQ集群部署实践

    2019独角兽企业重金招聘Python工程师标准>>> 全篇参照–<MyRocketMQ集群部署实战-双master-双slave-同步双写-异步刷盘(7台机器) - tant ...

  9. 数据库系列之SequoiaDB高可用集群部署(一)

    SequoiaDB作为存储引擎,支持高并发的HTAP场景.本位总结运维分析项目中使用SequoiaDB作为数据存储的高可用部署实战,并接入Kafka进行高并发的更新业务和Spark进行高并发的批量查询 ...

最新文章

  1. Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo
  2. 【Win32汇编】五种寻址方式
  3. 如果华为自主的操作系统,对消费者和华为会有什么影响?
  4. linux c语言编写聊天室mysql_Linux平台上用C语言实现与MySQL数据库的连接
  5. 6-5-2:STL之stack和queue——双端队列deque
  6. 评分9.7! 这本Python神作,火爆编程圈!网友:太香!
  7. java 存储输入_java将用户输入信息保存至txt文件
  8. 万字长文丨大白话带你由浅入深Python编程语言
  9. lammps教程:原子平动和振动的设置方法
  10. arcgis中将地理坐标转换为投影坐标 / 经纬度坐标转换
  11. Mysql 语法执行顺序
  12. 解决fences2.01在win8.1的状态下无法移动桌面图标问题
  13. 服务计算——Selpg
  14. 带左右箭头的图片滚动html,js实现图片上显示左右箭头类似翻页效果的代码
  15. Windows 2012 NIC teaming多网卡高可用Powershell版
  16. STM8入门以及程序编译、烧录、IAR使用方法(扫盲篇)
  17. STM32——TIM1的TIM1_CH1N通道PWM初始化
  18. linux中搭建git与链接github的用法
  19. JAVA基础知识学习全覆盖
  20. 2021年小红书电商直播趋势报告-小红书数据分析报告

热门文章

  1. Java中常见数据结构Map之LinkedHashMap
  2. 《分布式系统:概念与设计》一1.3 分布式系统的趋势
  3. 帝国cms文章页调用当前文章URL如何操作?
  4. 简单帐表插件开发示例分享
  5. 01-Windows Server 2012 R2 远程桌面服务部署指南
  6. 深入研究Servlet线程安全性问题
  7. 显卡A卡和N卡有什么区别
  8. pytorch | Softmax->Log->NLLLoss->CrossEntropyLoss
  9. qt非thread使用sleep_.NET进阶篇06-async异步、thread多线程3
  10. 大疆精灵2v+怎么连接手机_车载蓝牙播放器怎么用,手机蓝牙怎么连接车载蓝牙放音乐...