Predixy的docker化

发布于:2025-05-30 ⋅ 阅读:(20) ⋅ 点赞:(0)

概述

当前已有一套redis cluster的集群,但是fs中的hiredis只能配置单实例redis。

AI了一下方案,可以使用redis的proxy组件来实现从hiredis到redis cluster的互通。

代码地址:https://github.com/joyieldInc/predixy

Predixy特性介绍:https://github.com/joyieldInc/predixy/blob/master/README_CN.md

环境

CentOS 7.9

下载

下载源码,使用1.0.5版本,足以满足我们的版本需求,如果要对接redis cluster7.0以上,需要更新的predixy版本。

git clone -b 1.0.5 https://github.com/joyieldInc/predixy.git predixy.1.0.5

dockerfile

dockerfile文件内容如下,dockerfile文件和源码目录“predixy.1.0.5”在同一目录下。

FROM centos:7

WORKDIR /root

ADD ./predixy.1.0.5 /root/predixy.1.0.5
COPY ./CentOS-Base.repo /etc/yum.repos.d/
COPY ./CentOS-SCLo-scl.repo /etc/yum.repos.d/
COPY ./CentOS-SCLo-scl-rh.repo /etc/yum.repos.d/
COPY ./epel-7.repo /etc/yum.repos.d/

RUN cd /root/ \
    && yum -y update \
    # && yum install -y devtoolset-9-gcc \
    && yum install -y gcc-c++ libstdc++-devel libstdc++-static \
    && yum install -y make \
    && cd /root/predixy.1.0.5/ \
    && make \
    && cp ./src/predixy /usr/local/bin/ \
    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && yum -y autoremove \
    && yum clean all \
    && rm -rf /var/cache/yum \
    && rm -rf /root/predixy.1.0.5 \
    && rm -rf /usr/share/icons /usr/share/themes/ /usr/share/doc /usr/share/man 

VOLUME ["/usr/local/predixy/conf", "/usr/local/predixy/log"]

CMD /usr/local/bin/predixy /usr/local/predixy/conf/predixy.conf

运行命令,创建docker镜像。

sudo docker build --no-cache -t 10.55.55.136:5000/zr/centos.7-predixy.1.0.5-release:v1.1 .

配置

配置文件放在宿主机,方便修改,创建如下目录。

sudo mkdir -p /usr/local/predixy/conf

配置文件主要修改2个,predixy.conf和cluster.conf。

predixy.conf 主要配置如下。

Name Predixy136

Bind 10.55.55.136:7777

WorkerThreads 4

MaxMemory 0

ClientTimeout 0

Log /usr/local/predixy/log/predixy.log

LogRotate 1d

LogVerbSample 0

LogDebugSample 0

LogInfoSample 10000

LogNoticeSample 1

LogWarnSample 1

LogErrorSample 1

Include cluster.conf

Include latency.conf

cluster.conf 主要配置如下。

ClusterServerPool {

MasterReadPriority 60

StaticSlaveReadPriority 50

DynamicSlaveReadPriority 50

RefreshInterval 1

ServerTimeout 1

ServerFailureLimit 10

ServerRetryTimeout 1

KeepAlive 120

Servers {

+ 10.55.55.101:7000

+ 10.55.55.101:7001

+ 10.55.55.102:7000

+ 10.55.55.102:7001

+ 10.55.55.103:7000

+ 10.55.55.103:7001

}

}

启动

编写docker-compose.yml,启动docker容器。

docker-compose.yml内容如下。

services:

predixy:

image: 10.55.55.136:5000/zr/centos.7-predixy.1.0.5-release:v1.1

container_name: centos.7-predixy.1.0.5-1.1

volumes:

- /usr/local/predixy/conf:/usr/local/predixy/conf

- /usr/local/predixy/log:/usr/local/predixy/log

working_dir: /root

command: ["/usr/local/bin/predixy", "/usr/local/predixy/conf/predixy.conf"]

restart: unless-stopped

# privileged: true

network_mode: "host"

logging:

driver: "none"

ulimits:

nproc: 65535

nofile:

soft: 40000

hard: 40000

启动命令。

sudo docker-compose up -d

查看进程和端口,运行正常。

测试

在fs的api命令行界面查询。

freeswitch@as137> limit_usage hiredis default test2

0

2025-04-22 14:38:14.099856 [DEBUG] hiredis_profile.c:61 hiredis: waiting for [10.55.55.136, 7777]

2025-04-22 14:38:14.099856 [INFO] hiredis_profile.c:65 hiredis: attempting[10.55.55.136, 7777]

2025-04-22 14:38:14.099856 [DEBUG] hiredis_profile.c:68 hiredis: connection success[10.55.55.136, 7777]

2025-04-22 14:38:14.099856 [DEBUG] hiredis_profile.c:206 hiredis: get test2

2025-04-22 14:38:14.099856 [DEBUG] hiredis_profile.c:52 hiredis: release back to pool [10.55.55.136, 7777]

查看predixy的log日志。

2025-04-22 14:38:14.107827 N Handler.cpp:371 h 1 accept c 10.55.55.137:52856 34 assign to h 0

2025-04-22 14:38:14.107905 D Handler.cpp:511 h 0 c 10.55.55.137:52856 34 handle req 299 get test2

2025-04-22 14:38:14.107928 D ServerGroup.cpp:68 server group 8f75cec1c6ab2e4ab7dff125d5206a391c4ae620 for req 299 get server 10.55.55.102:7000

2025-04-22 14:38:14.107942 D ConnectConnection.cpp:71 h 0 s 10.55.55.102:7000 13 writev 1

2025-04-22 14:38:14.108427 D ConnectConnection.cpp:212 h 0 s 10.55.55.102:7000 13 create res 299 match req 299

2025-04-22 14:38:14.108462 D Handler.cpp:779 h 0 s 10.55.55.102:7000 13 req 299 get test2 res 299 Str

2025-04-22 14:38:14.108481 D AcceptConnection.cpp:78 h 0 c 10.55.55.137:52856 34 req 299 fill res 299

2025-04-22 14:38:14.108496 D AcceptConnection.cpp:97 h 0 c 10.55.55.137:52856 34 writev 1

总结

利用predixy作为代理,实现从hiredis到redis cluster的查询中转。

代理的性能和稳定性有待进一步测试确认。

空空如常

求真得真