codis配置实例

3.13.10.1架构图及环境

1、架构图

     wKiom1kas9aT0HRDAAMriaNo4r4726.png-wh_50                       

2、软件版本

(1)zookeeper-3.5.2-alpha.tar.gz

(2)go1.8.1.linux-amd64.tar.gz

(3)codis3.2

 

3.13.10.2 zookeeper集群安装

1、安装jdk 1.8(这一步不作详解)


2、下载zookeeper3.5.2安装

192.168.2.122, 192.168.2.123, 192.168.2.124执行以下安装

 

(1)准备安装目录和数据存放目录,并建立id文件

#Mkdir /apps/

#Mkdir -p /var/zookeeperdata/

 

(2)安装zookeeper

# tar -xvf zookeeper-3.5.2-alpha.tar.gz -C/apps/

 

(3)配置zook.cfg

/apps/zookeeper目录下的conf目录下配置zoo.cfg如下:

 

clientPort=2181

dataDir=/var/zookeeperdata            //主要改这一项。

syncLimit=5

initLimit=10

tickTime=2000

server.1=192.168.2.122:2888:3888//后面一定不能有空格,否则启动出错。

server.2=192.168.2.123:2888:3888 

server.3=192.168.2.124:2888:3888

 

(1)   zookeeper服务器创建ID

192.168.2.122服务器执行:

Echo “1”>>/var/zookeeperdata/myid

192.168.2.123服务器执行:

Echo “2”>>/var/zookeeperdata/myid

192.168.2.124服务器执行:

Echo “3”>>/var/zookeeperdata/myid

 

(5)启动并验证

./bin/zkServer.sh start

./bin/zkServer.sh status    //查看状态

可以查看状态:(谁先启动谁为leader)

192.168.2.123leader

wKiom1katDXSMd-6AAB5uGXPEk0460.png-wh_50

 

192.168.2.122192.168.2.124follower

wKiom1katELzts92AABnPWQLXoU449.png-wh_50

 

3.13.10.3安装codis-proxycodis-server

192.168.2.122,192.168.2.123,192.168.9.124上执行下列相同操作。

1、安装gcc  gcc-c++ git  autoconf

Yum -y install gcc gcc-c++  git autoconf

2、安装 go

go的官网下载go.tar.gz包到/apps/目录下:

#Tar -xvf go1.8.1.linux-amd64.tar.gz -C /apps/

 

Vi /etc/profile.d/go.sh

Export GOROOT=/apps/go

EXPORT GOPATH=apps/codis

Export PATH=$PATH:$GOROOT:$GOPATH

 

Source go.sh

 

3、  安装codis

下载codis

#go get -u -d github.com/CodisLabs/codis

Codis会下载到/apps/codis目录下。 

(2)编译codis

#Cd /apps/codis/src/github.com/codislabs/codis

#make

 

编译成功会在/apps/codis/src/github.com/codislabs/codis

bin/目录下生成如下文件:

wKioL1katGnigyC9AAAWwE5ywaE095.png-wh_50

 

4、  创建并复制主要目录到/apps/codis/目录下

#mkdir-p /apps/codis/{bin,logs,data}/

#cp -rf$GOPATH/src/github.com/CodisLabs/codis/bin/* /opt/local/codis/bin

#cp -rf$GOPATH/src/github.com/CodisLabs/codis/config /opt/local/codis/

 

3.13.10.4启动codis-dishboard

1、配置codis-dishboard

Vi /apps/codis/config/ dashboard.toml

 

coordinator_name = "zookeeper"       

coordinator_addr = "192.168.2.123:2181,192.168.2.122:2181,192.168.2.124:2181"

product_name = "codis-loready"

product_auth = ""      

admin_addr = "0.0.0.0:18080"  

 

2、启动 codis-dishboard

#./bin/codis-dashboard --config=./config/dashboard.toml--log=./logs/dashboard.log --log-level=WARN &

3.13.10.5 启动codis-proxy

192.168.2.122,192.168.2.123上启动codis-proxy

1、  配置codis-proxy

vi proxy.toml:

 

product_name ="codis-loready"           //关键配置

product_auth = ""               

session_auth = ""              

admin_addr = "0.0.0.0:11080"     

proto_type = "tcp4"             

proxy_addr = "0.0.0.0:19000"     

jodis_name = "Zookeeper"               //关键配置            

jodis_addr = "192.168.2.123:2181,192.168.2.122:2181,192.168.2.124:2181"    //关键配置            

jodis_timeout = "20s"          

jodis_compatible = false

proxy_datacenter = ""

proxy_max_clients = 1000      

proxy_max_offheap_size = "1024mb"

proxy_heap_placeholder = "256mb"

backend_ping_period = "5s"  

backend_number_databases = 16  

 

2、启动codis-proxy

#./bin/codis-proxy  --config=./config/proxy.toml  --log=./logs/proxy.log --log-level=WARN &

 

 

3.13.10.5配置codis-server-group

192.168.2.123192.168.2.124上配置redis.conf,并启动codis-server,并把192.168.2.124作为master,192.128.2.123作为slave

 

1、  配置redis.conf

(1)192.168.2.124(master)的配置

Vi /apps/codis/config/redis.conf

 

bind 127.0.0.1

bind 192.168.2.124

logfile"/apps/codis/logs/redis_6379.log"

#save 900 1                           //关闭快照持久化。

#save 300 10

#save 60 10000

 

appendonly yes                       //开启aof持久化

appendfilename "appendonly.aof"

appendfsync everysec

 

 

(2)192.168.2.123(slave配置)

Vi /apps/codis/config/redis.conf

 

bind 127.0.0.1

bind 192.168.2.123

logfile"/apps/codis/logs/redis_6379.log"

#save 900 1                           //关闭快照持久化。

#save 300 10

#save 60 10000

 

slaveof 192.168.2.124 6379             //设定master的地址

slave-serve-stale-data yes

slave-read-only yes

 

 

appendonly yes                       //开启aof持久化

appendfilename "appendonly.aof"

appendfsync everysec

 

2、  启动redis

192.168.2.123192.168.2.124

Cd  /apps/codis

# ./bin/codis-server ./config/redis.conf  &

3.13.10.6配置CODIS-FE管理codis

1、生成codis.json文件

./bin/codis-admin--dashboard-list --zookeeper=192.168.2.123:2181,192.168.2.122:2181,192.168.2.124:2181|tee ./config/codis.json

2、启动codis-fe

./bin/codis-fe --log=./logs/fe.log--log-level=WARN --zookeeper=192.168.2.123:2181 --listen=192.168.2.122:8089&

 

3、  访问192.168.2.122:8089配置集群

 

wKioL1katJyBiNxDAABJDTyD-3o980.png-wh_50

 

(1)      添加codis-proxy

依次添加192.168.2.122:11080, 192.168.2.123:11080


 wKiom1katN3DlObdAABmM8-PcLI221.png-wh_50

(2)      添加codis-server-group

wKiom1katPCiFV0dAACU1cn0eM0511.png-wh_50

 

(3)      初始化solts

可以把不同的solt分配到不同的codis-server-group,因为我这里只创建了一个codis-group,所以把1024solt全分配到group1.

wKioL1katP_D4LR_AABEMkDTmVI158.png-wh_50

 

 

 

至此codis集群部署完毕。