1.1 系统配置
IP |
MEM |
CPU |
DISK |
Description |
192.168.16.11 |
4G |
4C |
50G |
Redis-g1-m; codis-proxy1 |
192.168.16.13 |
4G |
4C |
50G |
Redis-g1-s; codis-proxy2 |
192.168.16.14 |
4G |
4C |
50G |
Redis-g2-m;zk1;sentinel |
192.168.16.15 |
4G |
4C |
50G |
Redis-g2-s;zk2;sentinel |
192.168.16.16 |
4G |
4C |
50G |
Redis-g3-m;zk3;sentinel |
192.168.16.17 |
4G |
4C |
50G |
Redis-g3-s;codis-dashborad:18080;codis-fe:18090 |
1.1 系统依赖配置
Zookeeper-3.4.14(stable release)
https://www.apache.org/dist/zookeeper/
Codis3.2
https://github.com/CodisLabs/codis
集群中每台主机可解析对方hostname,当前配置为修改/etc/hosts
2.1 总体说明
Golang依赖安装使用yum安装。
Codis及zookeeper使用源码安装,
Zookeeper-3.4.14(stable release)
https://www.apache.org/dist/zookeeper/
Codis3.2
https://github.com/CodisLabs/codis
2.2 系统安装部署步骤
2.2.1 基础环境
全部节点执行:
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
sed "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config -i
设置编译环境
注意 $GOPATH 是本机所有第三方库 go 项目所在目录,Codis 仅是其中之一。
添加 $GOPATH/bin 到 $PATH,例如:PATH=$PATH:$GOPATH/bin。
cat ~/.bash_profile
export JAVA_HOME=/home/app/jdk1.8.0_73
export GOROOT=/usr/lib/golang
export GOPATH=/home/app/godir
export PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$GOPATH/bin:$GOROOT/bin
下载 Codis 源代码
Codis 源代码需要下载到 $GOPATH/src/github.com/CodisLabs/codis:
mkdir -p $GOPATH/src/github.com/CodisLabs
cd $_ && git clone https://github.com/CodisLabs/codis.git -b release3.2
编译 Codis 源代码
直接通过 make 进行编译,会看到如下输出:
cd $GOPATH/src/github.com/CodisLabs/codis
make
ll bin/ 查看编译后的命令
cat bin/version
完成编译后,将会在bin目录中看到codis-admin、codis-dashboard、codis-fe、codis-ha、codis-proxy、codis-server六个可执行文件。另外,bin/assert文件夹是codis-dashboard的http服务需要的前端资源,其需要和codis-dashboard放置在同一个文件夹中。
补充:在目录./extern/redis-3.2.11/src/中可以找到redis-sentinel可执行文件,其将会用于集群主从的切换。
mkdir -p ~/codis/bin
mkdir -p ~/codis/config
mkdir -p ~/codis/admin
cp -a $GOPATH/src/github.com/CodisLabs/codis/bin/* ~/codis/bin/
cp -a $GOPATH/src/github.com/CodisLabs/codis/config/* ~/codis/config/
cp –a $GOPATH/src/github.com/CodisLabs/codis/admin ~/codis/
2.2.2 安装zookeeper
IP |
MEM |
CPU |
DISK |
Description |
192.168.16.14 |
4G |
4C |
50G |
Zk1 |
192.168.16.15 |
4G |
4C |
50G |
Zk2 |
192.168.16.16 |
4G |
4C |
50G |
Zk3 |
cat ~/zookeeper-3.4.14/conf/zoo.cfg
配置如下:
=============================================
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/app/zookeeper-3.4.14/dataDir/zookeeper
clientPort=2181
server.1=192.168.16.14:2888:3888
server.2=192.168.16.15:2888:3888
server.3=192.168.16.16:2888:3888
===============================================
2.2.3 Codis-server
作用:基于 redis-3.2.11 分支开发。增加了额外的数据结构,以支持 slot 有关的操作以及数据迁移指令。具体的修改可以参考文档 redis 的修改。
按照部署规划,将在如下机器上部署该程序
IP |
MEM |
CPU |
DISK |
Description |
192.168.16.11 |
4G |
4C |
50G |
Redis-g1-master |
192.168.16.13 |
4G |
4C |
50G |
Redis-g1-slave |
192.168.16.14 |
4G |
4C |
50G |
Redis-g2-master |
192.168.16.15 |
4G |
4C |
50G |
Redis-g2-slave |
192.168.16.16 |
4G |
4C |
50G |
Redis-g3-master |
192.168.16.17 |
4G |
4C |
50G |
Redis-g3-slave |
cat ~/codis/config/redis.conf
修改以下参数。其余保持默认。
timeout 86400
pidfile /home/app/codis/run/redis_6379.pid
logfile "/home/app/codis/log/redis_6379.log"
dir /home/app/codis/data/
maxmemory 3gb //内存大小
warning提示:
add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1'
run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot.
修正warning信息:
echo "'vm.overcommit_memory = 1" >>/etc/sysctl.d/codis.conf
sysctl -a
sysctl vm.overcommit_memory=1
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >>/etc/rc.local
启动:
sh admin/codis-server-admin.sh start
关闭:
sh admin/codis-server-admin.sh stop
2.2.4 dashboard
部署节点:192.168.16.17
./codis-dashboard - -default-conifg | tee ../config/dashboard.conf #生成配置
启动:
nohup ./codis-dashboard --ncpu=4 --config="/home/app/codis/config/dashboard.conf" --log=~/codis/log/dashboard.log --log-level=WARN &
关闭:
./codis-admin --dashboard=192.168.16.17:18080 --shutdown
./codis-admin --dashboard=192.168.16.17:18080 -auth=123456 –shutdown //如配置了密码,需加认证。
2.2.5 Proxy:
192.168.16.11 192.168.16.13 2台
./bin/codis-proxy --default-config | tee ./config/proxy.conf //生成配置文件
启动
nohup ./codis-proxy --ncpu=4 --config=../config/proxy.conf --log=../log/proxy.log --log-level=WARN &
关闭:
Kill -15 $pid
2.2.6 Sentinel
作用:Redis官方推荐的高可用性(HA)解决方案。它可以实现对Redis的监控、通知、自动故障转移。如果Master不能工作,则会自动启动故障转移进程,将其中的一个Slave提升为Master,其他的Slave重新设置新的Master服务。
部署:按照部署规划,将在如下机器上部署该程序。
192.168.16.14 192.168.16.15 192.168.16.16
1. 拷贝程序
# cp -a $GOPATH/src/github.com/CodisLabs/codis/extern/redis-3.2.11/src/redis-sentinel ~/codis/bin/
2. 拷贝配置
#cp -a $GOPATH/src/github.com/CodisLabs/codis/extern/redis-3.2.11/sentinel.conf ~/codis/config/
3. 修改配置
#vim ./config/sentinel.conf
修改以下配置:
删除所有sentinel开头的配置。
sed "/^sentinel/d" sentinel.conf -i
sed "/^dir/d" sentinel.conf -i
新增以下配置
bind 0.0.0.0
protected-mode no
port 26379
dir “/home/app/codis/data_sentinel/” #dir按需更改(默认dir /tmp)
备注:其余配置保持默认,其他结点的配置与此一致。
4. 启动程序
cd ~/codis/bin/
nohup ./redis-sentinel ../config/sentinel.conf &
2.2.7 codis-fe
192.168.16.17
作用:集群管理界面。
1.多个集群实例共享可以共享同一个前端展示页面;
2.通过配置文件管理后端codis-dashboard列表,配置文件可自动更新。
安装:
1. 生成配置
#./codis-admin --dashboard-list --zookeeper=192.168.16.14:2181 | tee ../config/codis.json
2. 启动程序
#nohup ./codis-fe --ncpu=4 --log=../log/fe.log --log-level=WARN --dashboard-list=../config/codis.json --listen=0.0.0.0:18090 &
2.3 集群配置
2.3.1 概览
打开浏览器,输入http://192.168.16.17:18090便可看到codis集群的监控界面。如下图所示:
2.3.2 加入集群配置:
步骤:
1. Codis-proxy
在proxy栏的输入框中输入相应ip和端口可将proxy添加到集群中,如下图所示:
2.Codis-Server
3. 配置Slots
4. Sentinel
3.1 故障排查
待续
3.2 Q&A
待续