Redis——predixy源码安装和配置

predixy的安装和配置:

predixy 是高性能的适用于 redis 集群和哨兵的代理。

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

predixy 编译安装需要 C++11 版本的编译器,至少需要 CentOS 7及以上版本才能编译安装。

下载 

wget https://gitee.com/mirrors/predixy/repository/archive/master.zip

unzip  master.zip

cd predixy

make

报错

make[1]: Entering directory `/root/data/soft/predixy/predixy/src'
g++ -std=c++11 -Wall -w -g -O3 -D_PREDIXY_BACKTRACE_ -D_EPOLL_ -c Crc16.cpp 
make[1]: g++: Command not found
make[1]: *** [Crc16.o] Error 127
make[1]: Leaving directory `/root/data/soft/predixy/predixy/src'
make: *** [default] Error 2

安装 yum install gcc gcc-c++

报错

/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
make[1]: *** [predixy] Error 1

安装 stdc

yum list | grep "stdc"

yum install -y libstdc++-static.x86_64

再次  make  成功

把编译好的src/predixy  与配置文件conf,拷贝出来,目录如下:

[root@izm5eb28tnyvb00rm7as8wz predixy]# tree build/ 
build/
├── conf
│   ├── auth.conf
│   ├── cluster.conf
│   ├── command.conf
│   ├── dc.conf
│   ├── latency.conf
│   ├── predixy.conf
│   ├── sentinel.conf
│   ├── standalone.conf
│   └── try.conf
├── logs
│   ├── predixy.20210511.log
│   └── predixy.log -> predixy.20210511.log
├── predixy
└── run.sh
2 directories, 13 files

修改  predixy.conf 

Bind 0.0.0.0:7617
Log /root/data/soft/predixy/build/logs/predixy.log
LogRotate 1d
Include cluster.conf

修改  cluster.conf , 172.31.140.161:6321为三主三从集群中任意一个节点。

ClusterServerPool {
    MasterReadPriority 60
    StaticSlaveReadPriority 50
    DynamicSlaveReadPriority 50
    RefreshInterval 1
    ServerTimeout 1
    ServerFailureLimit 10
    ServerRetryTimeout 1
    KeepAlive 120
    Servers {
        + 172.31.140.161:6321
    }
}

启动 run.sh

screen -dmS MyPredixy ./predixy conf/predixy.conf 
screen -wipe
echo "ok"

查看集群状态,或者测试集群的使用

redis-cli -h 172.31.140.161 -p 7617 info

  redis-cli -h 172.31.140.161 -p 7617 get "name"

[root@izm5e6u39ae8sj3eivv3rvz data]# redis-cli -h 172.31.140.161 -p 7617 info
# Proxy
Version:1.0.5
Name:PredixyExample
Bind:0.0.0.0:7617
RedisMode:proxy
SingleThread:false
WorkerThreads:1
Uptime:1620703395
UptimeSince:2021-05-11 11:23:15

# SystemResource
UsedMemory:49000
MaxMemory:0
MaxRSS:1826816
UsedCpuSys:0.089
UsedCpuUser:0.102

# Stats
Accept:34
ClientConnections:1
TotalRequests:784
TotalResponses:625
TotalRecvClientBytes:899
TotalSendServerBytes:16719
TotalRecvServerBytes:447092
TotalSendClientBytes:18884

# Servers
Server:172.31.140.161:6321
Role:master
Group:60988515df740ac95be96140f8eb8e7f4e51cf2c
DC:
CurrentIsFail:0
Connections:1
Connect:1
Requests:100
Responses:100
SendBytes:2776
RecvBytes:76428

Server:172.31.140.161:6323
Role:master
Group:90b34bf34f7061dc5f9d61f3561086f2ba180bab
DC:
CurrentIsFail:1
Connections:1
Connect:78
Requests:230
Responses:67
SendBytes:1852
RecvBytes:50907

Server:172.31.140.161:6324
Role:slave
Group:430d3250d575ec138cdd15a9d9cd65f0b96ae668
DC:
CurrentIsFail:0
Connections:1
Connect:1
Requests:111
Responses:111
SendBytes:3084
RecvBytes:84726

Server:172.31.140.161:6326
Role:slave
Group:60988515df740ac95be96140f8eb8e7f4e51cf2c
DC:
CurrentIsFail:0
Connections:1
Connect:1
Requests:99
Responses:99
SendBytes:2748
RecvBytes:75705

Server:172.31.140.161:6322
Role:master
Group:430d3250d575ec138cdd15a9d9cd65f0b96ae668
DC:
CurrentIsFail:0
Connections:1
Connect:1
Requests:120
Responses:120
SendBytes:3231
RecvBytes:75882

Server:172.31.140.161:6325
Role:master
Group:824a62be2ca3f9a1614e8fd73813b5a304ccba18
DC:
CurrentIsFail:0
Connections:1
Connect:1
Requests:109
Responses:109
SendBytes:3028
RecvBytes:83444
# LatencyMonitor
LatencyMonitorName:all
<=          100                 1456               27 67.50%
<=          200                 1424               13 100.00%
T            72                 2880               40

LatencyMonitorName:get
<=          100                  734                8 38.10%
<=          200                 1424               13 100.00%
T           102                 2158               21
LatencyMonitorName:set
LatencyMonitorName:blist
[root@izm5e6u39ae8sj3eivv3rvz data]# 

 

 

对于 CentOS 6或更低版本,可以直接使用在 github release 中的二进制版本。

##安装

tar -xzf predixy-1.0.5-bin-amd64-linux.tar.gz

mv predixy-1.0.5 /usr/local/

cd /usr/local/predixy-1.0.5/conf/

修改里边的两个配置文件:predixy.conf   cluster.conf

###predixy 支持多种架构,由于使用的是 redis cluster,只需配置 redis cluster 对应的配置文件cluster.conf 即可。

内容如下:

ClusterServerPool {

    MasterReadPriority 60

    StaticSlaveReadPriority 50

    DynamicSlaveReadPriority 50

    RefreshInterval 1

    ServerTimeout 1

    ServerFailureLimit 10

    ServerRetryTimeout 1

    KeepAlive 120

    Servers {

        + 127.0.0.1:6379

        + 127.0.0.1:6380

        + 127.0.0.1:6381

        + 127.0.0.1:6382

        + 127.0.0.1:6383

        + 127.0.0.1:6384

    }

}

在 Servers 部分配置集群中任意一个节点即可,predixy 会自动发现整个集群的信息,即使配置的节点挂掉后,predixy 代理仍然可正常工作。通过自动发现集群,可以减少 cluster.conf 配置文件的修改及对 predixy 的重启操作。但 predixy 无法删除曾经自动发现的节点,如果某节点下掉,predixy 仍会看到之前的节点,虽然不影响正常使用,日志则会不断报出错误信息。需重启 predixy 解决。

 

配置 predixy.conf

Name Predixy001

Bind 0.0.0.0:7617

Include cluster.conf 

注意 Include 部分,只需包括 cluster.conf,其他的则注释掉,否则可能会影响到 predixy的使用。

 

启动predixy

cd /usr/local/predixy-1.0.5/bin/

cp predixy /usr/local/bin/

##启动

nohup predixy predixy.conf   > /tmp/predixy.log 2>&1 & 

##查看日志

 tail -f /tmp/predixy.log

 

 predixy 添加环境变量,在 /etc/profile 中添加,然后在 /etc/rc.local 中设置开机启动 nohup predixy /usr/local/predixy-1.0.5/conf/predixy.conf > /tmp/predixy.log 2>&1 &

 

 ##可以看到集群的信息

redis-cli -p 7617 info

 

参数说明:

MasterReadPriority,StaticSlaveReadPriority,DynamicSlaveReadPriority 三个参数和 redis 本身配置文件中的  slave-priority 没任何关系的。

如果是自动发现找到的节点,则 DynamicSlaveReadPriority 会起作用,如果是直接配置的节点,则 StaticSlaveReadPriority 会起作用。

Master/SlaveReadPriority

Master

Slave1

Slave2

Fail-over notes

60/50 all requests 0 requests 0 requests Master dead, read requests deliver to slave until master(maybe new master) alive
60/0 all requests 0 requests 0 requests Master dead, all requests fail
50/50 all write requests, 33.33%read requests 33.33% read requests 33.33% read requests -
0/50 all write requests, 0 read requests 50% read requests 50% read requests all slaves dead, all read requests fail
10/50 all write requests, 0 read requests 50% read requests 50% read requests all slaves dead, read requests deliver to master
RefreshInterval : predixy 获取节点信息和集群 hash slot 集群信息的间隔
ServerFailureLimit : predixy 停止路由到节点之前失败的次数
ServerTimeout : 单个命令执行的超时时间

 

 
 
posted @ 2021-05-10 21:12  会飞的斧头  阅读(914)  评论(0编辑  收藏  举报