LVS

172.18.8.7

172.18.8.138

vip 172.18.8.123

codis-proxy

172.18.8.210

172.18.8.191

codis-config condis-ha

172.18.9.15

zookeeper

172.18.8.147

172.18.8.30

172.18.8.245

172.18.8.7

172.18.8.138

codis-server

172.18.9.43  46379 46380

172.18.9.66  46379 46380

172.18.9.76  46379 46380

172.18.8.7   46379 46380

172.18.8.138  46379 46380

一、安装jdk

此步骤正常安装jdk即可,过程略过

二、安装zookeeper

wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz

tar zxvf zookeeper-3.4.6.tar.gz 

mv zookeeper-3.4.6 /opt/zookeeper/

mkdir -p /data/zookeeper/{data,logs}

    vim /opt/zookeeper/conf/zoo.cfg  内容如下:

tickTime=2000

initLimit=5

syncLimit=2

dataDir=/data/zookeeper/data

clientPort=2181

server.1=172.18.8.147:2888:3888

server.2=172.18.8.30:2888:3888

server.3=172.18.8.245:2888:3888

server.4=172.18.8.7:2888:3888

server.5=172.18.8.138:2888:3888     

截止

echo 1 > /data/zookeeper/data/myid   此配置每台机数值不能相同,其他机器一次为2 3 4 5,对照zoo.cfg的server配置

/opt/zookeeper/bin/zkServer.sh start  启动zk

/opt/zookeeper/bin/zkServer.sh status  查看zk状态,多台zk启动后可以看到角色多个follower一个leader

三、安装go(codis是用go语言写的)

wget http://172.16.150.181:88/shell/go1.4.1.linux-amd64.tar.gz

tar zxvf go1.4.1.linux-amd64.tar.gz  

mv go /opt/

export GOROOT=/opt/go 

export PATH=$GOROOT/bin:$PATH

可以将这两行加到/etc/profile最下面了,source /etc/profile

执行  go version看是否ok

四、下载编译codis

mkdir /data/go

export GOPATH=/data/go

go get github.com/wandoulabs/codis

cd  /data/go/src/github.com/wandoulabs/codis/

./bootstrap.sh

make gotest

    由于国内访问国外的github容易超时,一次编译之后可以把codis文件复制使用

五、配置服务

1、codis-config

配置文件:

cat  /opt/codis/config/config.ini 

zk=172.18.8.147:2181,172.18.8.30:2181,172.18.8.245:2181,172.18.8.7:2181,172.18.8.138:2181

product=acc   #集群标识,同一codis集群此处一样

proxy_id=config1   #id唯一,proxy更改成不一样的

net_timeout=5000

proto=tcp4

dashboard_addr=172.18.9.15:18087  #codis后台,如果没有公网IP可以在nginx配置转发访问,最好做认证访问

coordinator=zookeeper

    启动dashboard  

mkdir -p /data/codis/log/

cat start_dashboard.sh 

#!/bin/sh

nohup /opt/codis/bin/codis-config -c /opt/codis/config/config.ini -L /data/codis/log/dashboard.log dashboard --addr=:18087 --http-log=/data/codis/log/requests.log &

./start_dashboard.sh

初始化slot

/opt/codis/bin/codis-config -c /opt/codis/config/config.ini slot init

2、启动codis-server ,启动方式跟redis一样

mkdir -p /data/codis/logs/

启动命令   /opt/codis/bin/codis-server /opt/codis/config/46380.conf

cat  /opt/codis/config/46380.conf 

daemonize yes

pidfile /var/run/redis_46380.pid

port 46380

tcp-backlog 511

timeout 0

tcp-keepalive 0

loglevel notice

logfile "/data/codis/logs/46380.log"

databases 16

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename 46380.rdb

dir /data/codis/

slave-serve-stale-data yes

slave-read-only yes

repl-disable-tcp-nodelay no

slave-priority 100

maxclients 10000

maxmemory 3gb

maxmemory-policy allkeys-lru

appendonly yes

appendfilename "appendonly_46380.aof"

appendfsync everysec

no-appendfsync-on-rewrite yes

auto-aof-rewrite-percentage 50

auto-aof-rewrite-min-size 256mb

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

latency-monitor-threshold 0

notify-keyspace-events ""

hash-max-ziplist-entries 512

hash-max-ziplist-value 64

list-max-ziplist-entries 512

list-max-ziplist-value 64

set-max-intset-entries 512

zset-max-ziplist-entries 128

zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

activerehashing yes

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

mkdir -p /data/codis/logs/

3、添加redis server group

/opt/codis/bin/codis-config -c /opt/codis/config/config.ini server add 1 172.18.9.43:46379  master

     /opt/codis/bin/codis-config -c /opt/codis/config/config.ini server add 1 172.18.9.43:46379  master

     /opt/codis/bin/codis-config -c /opt/codis/config/config.ini server add 1 172.18.9.66:46379  master

     /opt/codis/bin/codis-config -c /opt/codis/config/config.ini server add 2 172.18.9.66:46379  master

     /opt/codis/bin/codis-config -c /opt/codis/config/config.ini server add 3 172.18.9.76:46379  master

4、设定slot范围

/opt/codis/bin/codis-config -c /opt/codis/config/config.ini server add 1 172.18.9.43:46379  master

     /opt/codis/bin/codis-config -c /opt/codis/config/config.ini server add 1 172.18.9.66:46380  slave

     /opt/codis/bin/codis-config -c /opt/codis/config/config.ini server add 1 172.18.9.43:46379  master

     /opt/codis/bin/codis-config -c /opt/codis/config/config.ini server add 1 172.18.9.66:46379  master

     /opt/codis/bin/codis-config -c /opt/codis/config/config.ini server add 2 172.18.9.66:46379  master

     /opt/codis/bin/codis-config -c /opt/codis/config/config.ini server add 3 172.18.9.76:46379  master

5、启动proxy

mkdir -p /data/codis/log/

cat start_proxy.sh

#!/bin/sh

echo "shut down proxy1..."

/opt/codis/bin/codis-config -c /opt/codis/config/config.ini proxy offline proxy1

echo "done"

echo "start new proxy..."

nohup /opt/codis/bin/codis-proxy -c /opt/codis/config/config.ini -L /data/codis/log/proxy.log  --cpu=4 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &

echo "done"

sleep 1

./start_proxy.sh