Codis集群部署

一、架构

1569302469938.png

1569377329021.png

二、服务器规划

服务 ip vip 代理端口 管理端口
Codis config 192.168.3.74
dashboard 65180
codis-fe 65190
LVS 192.168.3.70 192.168.3.120
codis proxy 192.168.3.74 192.168.3.120 65121 65122
codis proxy 192.168.3.75 192.168.3.120 65121 65122
zookeeper1/sentinel1 192.168.3.77 2181/65100
zookeeper2/sentinel2 192.168.3.78 2181/65100
zookeeper3/sentinel3 192.168.3.79 2181/65100
codis server g1 192.168.3.83 6379/6380
codis server g2 192.168.3.84 6379/6380
codis server g3 192.168.3.85 6379/6380

codis: 一主一从

codis server group master:port slave:port
codis server g1 192.168.3.83:6379 192.168.3.84:6380
codis server g2 192.168.3.84:6379 192.168.3.85:6380
codis server g3 192.168.3.85:6379 192.168.3.83:6380

三、环境需求

  • jdk-1.8
  • centos6/7
  • go

1、安装jdk1.8

# yum search java
# yum install -y java-1.8.0-openjdk.x86_64
# java -version

2、GO 环境

# wget https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz
# tar -xzf go1.11.4.linux-amd64.tar.gz
# mv go1.11.4.linux-amd64 /usr/local/go
# vim /etc/profile
# GOPATH
export PATH=$PATH:/usr/local/go/bin
# source /etc/profile

3、codis安装

#所有机器
url:https://github.com/CodisLabs/codis/releases
#这里选择3.2.1版本
# tar xzf codis3.2.1-go1.7.6-linux.tar.gz
# mv codis3.2.1-go1.7.6-linux /usr/local/codis
# 新建工作目录
# mkdir -p /data/redis/{conf,data,logs,script}

四、安装

1、加入解析

# vim /etc/hosts
192.168.3.77 zookeeper-node1
192.168.3.78 zookeeper-node2
192.168.3.79 zookeeper-node3

2、ZooKeeper集群部署

2.1、安装
# wget https://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz
# tar -xzf zookeeper-3.4.13.tar.gz
# mv zookeeper-3.4.13 /usr/local/zookeeper
# cd /usr/local/zookeeper/conf
# cp zoo_sample.cfg zoo.cfg
# vim zoo.cfg
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
# 新建数据目录
# mkdir -p /data/zookeeper/
2.2、输入myid值
#依照配置文件在数据目录下新建myid文件并输入相关id数值,如本机为zooKeeper-node1,对应配置文件中的server.1,则在myid文件中输入数值 1,依此类推
# 192.168.3.77 zookeeper-node1
# echo "1" > /data/zookeeper/myid

# 192.168.3.78 zookeeper-node2
# echo "2" > /data/zookeeper/myid

# 192.168.3.79 zookeeper-node3
# echo "3" > /data/zookeeper/myid
2.3、启动
# /usr/local/zookeeper/bin/zkServer.sh start

其他略

3、Redis集群

3.1、集群架构
集群 codis server g1 codis server g2 codis server g3
192.168.3.83:6379 192.168.3.84:6379 192.168.3.85:6379
192.168.3.84:6380 192.168.3.85:6380 192.168.3.83:6380
3.2、Redis_192.168.3.83
# vim /data/redis/conf/redis_6379.conf
daemonize yes
port 6379
bind 192.168.3.83
pidfile "/data/redis/data/redis_6379.pid"
logfile "/data/redis/logs/redis_6379.log"
dbfilename "dump_6379.rdb"
dir "/data/redis/data"
requirepass "123"
maxmemory 100000kb
maxmemory-policy allkeys-lru
masterauth "123"

# vim /data/redis/conf/redis_6380.conf
daemonize yes
port 6380
bind 192.168.3.83
pidfile "/data/redis/data/redis_6380.pid"
logfile "/data/redis/logs/redis_6380.log"
dbfilename "dump_6380.rdb"
dir "/data/redis/data"
requirepass "123"
maxmemory 100000kb
maxmemory-policy allkeys-lru
masterauth "123"
slaveof 192.168.3.85 6379
3.3、Redis_192.168.3.84
# vim /data/redis/conf/redis_6379.conf
daemonize yes
port 6379
bind 192.168.3.84
pidfile "/data/redis/data/config/redis_6379.pid"
logfile "/data/redis/logs/redis_6379.log"
dbfilename "dump_6379.rdb"
dir "/data/redis/data"
requirepass "123"
maxmemory 100000kb
maxmemory-policy allkeys-lru
masterauth "123"

# vim /data/redis/conf/redis_6380.conf
daemonize yes
port 6380
bind 192.168.3.84
pidfile "/data/redis/data/config/redis_6380.pid"
logfile "/data/redis/logs/redis_6380.log"
dbfilename "dump_6380.rdb"
dir "/data/redis/data"
requirepass "123"
maxmemory 100000kb
maxmemory-policy allkeys-lru
masterauth "123"
slaveof 192.168.3.83 6379

#启动
# /usr/local/codis/codis-server /data/redis/conf/redis_6379.conf
# /usr/local/codis/codis-server /data/redis/conf/redis_6380.conf
3.4、Redis_192.168.3.85
# vim /data/redis/conf/redis_6379.conf
daemonize yes
port 6379
bind 192.168.3.85
pidfile "/data/redis/data/config/redis_6379.pid"
logfile "/data/redis/logs/redis_6379.log"
dbfilename "dump_6379.rdb"
dir "/data/redis/data"
requirepass "123"
maxmemory 100000kb
maxmemory-policy allkeys-lru
masterauth "123"

# vim /data/redis/conf/redis_6380.conf
daemonize yes
port 6380
bind 192.168.3.85
pidfile "/data/redis/data/config/redis_6380.pid"
logfile "/data/redis/logs/redis_6380.log"
dbfilename "dump_6380.rdb"
dir "/data/redis/data"
requirepass "123"
maxmemory 100000kb
maxmemory-policy allkeys-lru
masterauth "123"
slaveof 192.168.3.84 6379

#启动
# /usr/local/codis/codis-server /data/redis/conf/redis_6379.conf
# /usr/local/codis/codis-server /data/redis/conf/redis_6380.conf

4、Codis-sentinel

注:三台配置服务器一样!

# vim /data/redis/conf/codis-sentinel.conf
bind 0.0.0.0
protected-mode no
port 65100
dir "/data/redis/data"
pidfile "/data/redis/data/sentinel_65100.pid"
logfile "/data/redis/logs/sentinel_65100.log"
daemonize yes

#编写启动脚本
# vim /data/redis/script/codis-sentinel_start.sh
#!/bin/bash
/usr/local/codis/redis-sentinel /data/redis/conf/codis-sentinel.conf

#运行
# sh /data/redis/script/codis-sentinel_start.sh

5、Codis-proxy

注:两台proxy配置相同哟!

# vim /data/redis/conf/codis-proxy.conf
#项目名称,会登记在zookeeper里,如果你想一套zookeeper管理多套codis,就必须区分好
product_name = "codis-test1"
# 设置登录dashboard的密码(与真实redis中requirepass一致)
product_auth = "123"
#客户端(redis-cli)的登录密码(与真实redis中requirepass不一致),是登录codis的密码
session_auth = "123456"
#管理的端口,0.0.0.0即对所有ip开放,基于安全考虑,可以限制内网
admin_addr = "0.0.0.0:65121"
#用那种方式通信,假如你的网络支持tcp6的话就可以设别的
proto_type = "tcp4"
#客户端(redis-cli)访问代理的端口,0.0.0.0即对所有ip开放
proxy_addr = "0.0.0.0:65122"
#外部配置存储类型,我们用的就是zookeeper,当然也是还有其他可以支持,这里不展开说
jodis_name = "zookeeper"
#配置zookeeper的连接地址,这里是三台就填三台
jodis_addr = "192.168.3.77:2181,192.168.3.78:2181,192.168.3.79:2181"
#zookeeper的密码,假如有的话
jodis_auth = ""
#codis代理的最大连接数,默认是1000,并发大要调大
proxy_max_clients = 1000
#假如并发太大,你可能需要调这个pipeline参数,大多数情况默认就够了
session_max_pipeline = 10000

# 启动脚本
# vim /data/redis/script/codis-proxy_start.sh
#!/bin/bash
/usr/local/codis/codis-proxy --ncpu=8 --config=/data/redis/conf/codis-proxy.conf --log=/data/redis/logs/codis-proxy.log &

# 启动
# sh /data/redis/script/codis-proxy_start.sh

6、Codis-config

# vim /data/redis/conf/codis-dashboard.conf
#外部配置存储类型,我们用的就是zookeeper,当然也是还有其他可以支持,这里不展开说
coordinator_name = "zookeeper"
#配置zookeeper的连接地址,这里是三台就填三台
coordinator_addr = "192.168.3.77:2181,192.168.3.78:2181,192.168.3.79:2181"
#项目名称,会登记在zookeeper里,如果你想一套zookeeper管理多套codis,就必须区分好
product_name = "codis-test1"
#所有redis的登录密码(与真实redis中requirepass一致),因为要登录进去修改数据
product_auth = "123"
#codis-dashboard的通信端口,0.0.0.0表示对所有开放,最好使用内网地址
admin_addr = "0.0.0.0:65180"
#如果想要在codis集群在故障切换功能上执行一些脚本,可以配置以下两个配置
sentinel_notification_script = ""
sentinel_client_reconfig_script = ""

#启动脚本
# vim /data/redis/script/codis-dashboard_start.sh
#!/bin/bash
/usr/local/codis/codis-dashboard --ncpu=8 --config=/data/redis/conf/codis-dashboard.conf --log=/data/redis/logs/codis-dashboard.log --log-level=WARN &

# 启动
# sh /data/redis/script/codis-dashboard_start.sh

#生成codis-fe的配置文件
# cd /data/redis/conf
# /usr/local/codis/codis-admin --dashboard-list --zookeeper=192.168.3.77:2181 >codis.json
#运行启动脚本
# vim /data/redis/script/codis-fe_start.sh
#!/bin/bash
/usr/local/codis/codis-fe --ncpu=1 --log=/data/redis/logs/codis-fe.log --log-level=WARN --dashboard-list=/data/redis/conf/codis.json --listen=0.0.0.0:65190 &

# 启动
# sh /data/redis/script/codis-fe_start.sh

7、访问

url:http://192.168.3.74:65190
例如:


image.png
7.1、添加proxy
image.png
7.1、添加Group,即redis

例如


image.png
7.1、添加sentinels
image.png

你可能感兴趣的:(Codis集群部署)