欢迎大家关注我公众号“从零开始的it转行生”

使用docker 部署codis

使用docker 部署codis

原文地址:https://www.jianshu.com/p/85e72ae6fec3

codis的架构图

codis架构图

1、zookeeeper,用于存放统一配置信息和集群状态
2、codis-fe,codis管理后台的前端页面。(可以看到是vue的地位)
3、codis-dashboard,coids的管理后台系统。(可以看成是提供后端接口的服务)
4、codis-proxy。工作服务器,负责redsi命令的的分发。
5、codis-group。真正存数据取数据的地方。
6、redis-sentinel。用来监控codis-group的主redis是否工作,用于redsi的主挂了之后,触发主从切换。

部署流程

一、下载源码

mkdir codis && cd codis
git clone https://github.com/CodisLabs/codis.git -b release3.2

二、构建镜像imag
1、使用Docker multi-stage build多阶段构建机制,编译alpine版本的codis,使用阿里云的软件源,加速依赖安装,然后设置时区为上海,打包后200M左右,修改Dockerfile如下。

修改dockerFile文件

FROM golang:1.10.3-alpine3.8 as builder

ENV GOPATH /go
ENV CODIS  ${GOPATH}/src/github.com/CodisLabs/codis
ENV PATH   ${GOPATH}/bin:${PATH}:${CODIS}/bin
COPY . ${CODIS}

RUN echo -e "https://mirrors.aliyun.com/alpine/v3.8/main/\nhttps://mirrors.aliyun.com/alpine/v3.8/community/" > /etc/apk/repositories ;\
    apk add --no-cache --virtual .build-deps \
        make \
        bash \
        gcc \
        musl-dev \
        autoconf \
        linux-headers \
    ; \
    make -C ${CODIS} distclean ;\
    make -C ${CODIS} build-all ;\
    apk del .build-deps

FROM alpine:3.8
ENV PATH   ${PATH}:/codis/bin

RUN echo -e "https://mirrors.aliyun.com/alpine/v3.8/main/\nhttps://mirrors.aliyun.com/alpine/v3.8/community/" > /etc/apk/repositories ;\
    apk add --no-cache tzdata ;\
    cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

COPY --from=builder /go/src/github.com/CodisLabs/codis /codis

WORKDIR /codis

执行
docker build -f Dockerfile -t codis-image .
构建镜像
构建过程
构建过程比较长,因为codis的运行需要go环境,需要把go环境打包到image里面

三、修改配置文件
在config目录下面
目录

修改dashboard.toml

dashboard

修改proxy.toml

proxy

配置redis.toml

protected-mode no
dir "/codis"

修改docker.sh里面的server

dockersh

server)
    for ((i=0;i<4;i++)); do
        let port="26379 + i"
        docker rm -f      "Codis-S${port}" &> /dev/null
        docker run --net=host --name "Codis-S${port}" -d \
            -v `realpath ../config/redis.conf`:/codis/redis.conf \
            -v `realpath log`:/codis/log \
            codis-image \
            codis-server redis.conf  --logfile log/${port}.log --port ${port}
    done
    ;;

四、启动应用

sh docker.sh zookeeper
sh docker.sh dashboard
sh docker.sh fv
sh docker.sh proxy
sh docker.sh server

启动3个sentinel

docker run --net=host --name "Codis-T46380" -d \
            -v `realpath ../config/sentinel.conf`:/codis/sentinel.conf \
            -v `realpath log`:/codis/log \
            codis-image \
            redis-sentinel sentinel.conf  --port 46380 --protected-mode no

docker run --net=host --name "Codis-T46381" -d \
            -v `realpath ../config/sentinel.conf`:/codis/sentinel.conf \
            -v `realpath log`:/codis/log \
            codis-image \
            redis-sentinel sentinel.conf  --port 46381 --protected-mode no
docker run --net=host --name "Codis-T46382" -d \
            -v `realpath ../config/sentinel.conf`:/codis/sentinel.conf \
            -v `realpath log`:/codis/log \
            codis-image \
            redis-sentinel sentinel.conf  --port 46382 --protected-mode no

浏览器进入192.168.2.136:8080端口(IP换成自己的服务器ip)
8080
1、新增proxy
proxy

2、新增group和redis-server
这里我们有4台redsi-server分成2组;每组两台
2.1、点击新增group
2.2、再点击新增server
2.3、再点击标记为从redsi
group
2.4点击分配group的solt
slot
2.5新增3个sentinel,然后点击syn
sentinel

有2个master组,3个sentinel。
效果

五、测试高可用
现在可以通过redis-cli192.168.2.136:29000端口去连接redis;
执行set a a ,set b b后的页面显示
测试

执行docker stop Codis-S26381把group2的主停掉
6381停机

6382成为主

执行get a,get b查看结果,依旧有数据

执行docker start Codis-S26381重启26381
26381

posted @ 2020-07-17 10:03  大佬健  阅读(828)  评论(0编辑  收藏  举报

欢迎大家关注我公众号“从零开始的it转行生”