codis

时间:April 16, 2019 分类:

目录:

环境

IP 服务
172.21.0.2
172.21.0.4
172.21.0.10
172.21.0.11

安装java

$ yum install -y java

安装zookeeper

$ wget http://ftp.twaren.net/Unix/Web/apache/zookeeper/zookeeper-3.5.4-beta/zookeeper-3.5.4-beta.tar.gz
$ tar xf zookeeper-3.5.4-beta.tar.gz
$ mkdir -p /data/zookeeper/data
$ mkdir -p /data/zookeeper/log
$ cat  << EOF > zookeeper-3.5.4-beta/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper/data
dataLogDir=/data/zookeeper/log
clientPort=2181
maxClientCnxns=300
server.1=172.21.0.2:2888:3888
server.2=172.21.0.4:2888:3888
server.3=172.21.0.10:2888:3888
EOF

对应节点写入id,启动服务

$ echo 1 > /data/zookeeper/data/myid
$ ./zookeeper-3.5.4-beta/bin/zkServer.sh start

验证服务启动

$ ./zookeeper-3.5.4-beta/bin/zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /root/zookeeper-3.5.4-beta/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
$ ./zookeeper-3.5.4-beta/bin/zkCli.sh 

安装codis

dashboard

$ wget https://codeload.github.com/CodisLabs/codis/zip/release3.2
$ unzip release3.2
$ vi codis-release3.2/config/dashboard.toml
coordinator_name = "zookeeper"
coordinator_addr = "172.21.0.2:2181,172.21.0.4:2181,172.21.0.10:2181"
$ wget https://github.com/CodisLabs/codis/releases/download/3.2.2/codis3.2.2-go1.8.5-linux.tar.gz
$ tar xf codis3.2.2-go1.8.5-linux.tar.gz 
$ vi codis-release3.2/admin/codis-dashboard-admin.sh
CODIS_BIN_DIR=/root/codis3.2.2-go1.8.5-linux/

启动dashboard

$ codis-release3.2/admin/codis-dashboard-admin.sh start
$ ss -nlpt | grep 18080
LISTEN     0      128         :::18080                   :::*                   users:(("codis-dashboard",pid=21415,fd=5))

fe

$ vi codis-release3.2/admin/codis-fe-admin.sh
CODIS_BIN_DIR=/root/codis3.2.2-go1.8.5-linux/
COORDINATOR_NAME="zookeeper"
COORDINATOR_ADDR="172.21.0.2:2181,172.21.0.4:2181,172.21.0.10:2181"

启动fe

$ codis-release3.2/admin/codis-fe-admin.sh start
$ ss -nlpt | grep 9090
LISTEN     0      128         :::9090                    :::*                   users:(("codis-fe",pid=22235,fd=4))

codis-server

$ vi codis-release3.2/admin/codis-server-admin.sh
CODIS_BIN_DIR=/root/codis3.2.2-go1.8.5-linux/
$ vi /root/codis-release3.2/admin/../config/redis.conf
bind 0.0.0.0

在所有节点启动codis服务

$ codis-release3.2/admin/codis-server-admin.sh start
$ ss -nlpt | grep 6379
LISTEN     0      128    127.0.0.1:6379                     *:*                   users:(("codis-server",pid=23140,fd=4))

创建group

group添加server

可以创建多个group

测试

写入

$ redis-cli 
127.0.0.1:6379> set why 1
OK

在另一台从节点查

$ redis-cli 
127.0.0.1:6379> get why
"1"

在从节点写入

$ redis-cli 
127.0.0.1:6379> 
127.0.0.1:6379> 
127.0.0.1:6379> 
127.0.0.1:6379> set why 1
(error) READONLY You can't write against a read only slave.

proxy

$ vi /root/codis-release3.2/config/proxy.toml
jodis_name = "zookeeper"
jodis_addr = "172.21.0.2:2181,172.21.0.4:2181,172.21.0.10:2181"
$ vi /root/codis-release3.2/admin/codis-proxy-admin.sh
CODIS_BIN_DIR=/root/codis3.2.2-go1.8.5-linux/

启动proxy

$ codis-release3.2/admin/codis-proxy-admin.sh start
$ ss -nlpt | grep 19000
LISTEN     0      128          *:19000                    *:*                   users:(("codis-proxy",pid=25219,fd=4))

进行redis-benchmark

$ redis-benchmark -p 19000 -n 100000 -c 20

一个proxy压测,10w次请求,20个并发

sentinel

主从切换则通过sentinel实现