IP前端 |
MEMlinux |
CPUgit |
DISKgithub |
Descriptiongolang |
192.168.16.11redis |
4Gapache |
4Cjson |
50Gvim |
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 |
Zookeeper-3.4.14(stable release)
https://www.apache.org/dist/zookeeper/
Codis3.2
https://github.com/CodisLabs/codis
集羣中每臺主機可解析對方hostname,當前配置爲修改/etc/hosts
Golang依賴安裝使用yum安裝。
Codis及zookeeper使用源碼安裝,
Zookeeper-3.4.14(stable release)
https://www.apache.org/dist/zookeeper/
Codis3.2
https://github.com/CodisLabs/codis
所有節點執行:
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/
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
===============================================
做用:基於 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
部署節點: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 //如配置了密碼,需加認證。
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
做用: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 &
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 &
打開瀏覽器,輸入http://192.168.16.17:18090即可看到codis集羣的監控界面。以下圖所示:
步驟:
1. Codis-proxy
在proxy欄的輸入框中輸入相應ip和端口可將proxy添加到集羣中,以下圖所示:
2.Codis-Server
3. 配置Slots
4. Sentinel
待續
待續