Codis2.0搭建部署

Codis搭建部署

codis1 10.111.32.51    codis-proxy,redis master,redis slave
codis2 10.111.32.52    codis-proxy,redis master,redis slave
codis3 10.111.32.53    redis master,redis slave

部署codis集群

1.安装go语言(在3台服务器上)
tar -zxvf go1.4.linux-amd64.tar.gz -C /usr/local/

2.添加go环境变量(在3台服务器上)
vim /etc/profile  
#go
export PATH=$PATH:/usr/local/go/bin:/usr/local/codis/bin
export GOPATH=/usr/local/codis

source /etc/profile

yum install git

#go get github.com/wandoulabs/codis
package github.com/wandoulabs/codis
        imports github.com/wandoulabs/codis
        imports github.com/wandoulabs/codis: no buildable Go source files in /usr/local/codis/src/github.com/wandoulabs/codis
        正常

        
cd $GOPATH/src/github.com/wandoulabs/codis

目录执行make命令编译代码, (此处可能有失败的情况,因为需要从国外网站下载文件,多尝试几次

表示成功:
Hint: It's a good idea to run 'make test' ;)
make[2]: Leaving directory `/usr/local/codis/src/github.com/wandoulabs/codis/extern/redis-2.8.21/src'
make[1]: Leaving directory `/usr/local/codis/src/github.com/wandoulabs/codis/extern/redis-2.8.21'

并执行make gotest来跑测试


建议只通过go get命令来下载codis,除非你非常熟悉go语言的目录引用形式从而不会导致代码放错地方。
该命令会下载master分支的最新版,我们会确保master分支的稳定。

执行全部指令后,会在 bin 文件夹内生成 codis-config、codis-proxy、codis-server三个可执行文件。
另外, bin/assets 文件夹是 codis-config 的 dashboard http 服务需要的前端资源, 需要和 codis-config 放置在同一文件夹下)

[root@testserver2 bin]# pwd
/usr/local/codis/src/github.com/wandoulabs/codis/bin
[root@testserver2 bin]# ll
total 35636
drwxr-xr-x. 4 root root     4096 Dec 28 09:41 assets
-rwxr-xr-x. 1 root root 15164600 Dec 28 09:41 codis-config
-rwxr-xr-x. 1 root root 15007240 Dec 28 09:40 codis-proxy
-rwxr-xr-x. 1 root root  6311171 Dec 28 09:41 codis-server

[root@testserver2 codis]# pwd
/usr/local/codis/src/github.com/wandoulabs/codis
[root@testserver2 codis]# ll
total 140
drwxr-xr-x. 3 root root  4096 Dec 28 09:41 bin
drwxr-xr-x. 4 root root  4096 Dec 26 20:53 cmd
-rw-r--r--. 1 root root  1793 Dec 28 17:15 config.ini
drwxr-xr-x. 5 root root  4096 Dec 26 20:53 doc
drwxr-xr-x. 2 root root  4096 Dec 26 20:53 docker
-rw-r--r--. 1 root root   352 Dec 26 20:53 Dockerfile
drwxr-xr-x. 5 root root  4096 Dec 26 20:53 extern
-rwxr-xr-x. 1 root root   293 Dec 26 20:53 genver.sh
drwxr-xr-x. 3 root root  4096 Dec 26 21:35 Godeps
drwxr-xr-x. 2 root root  4096 Dec 28 18:12 logs
-rw-r--r--. 1 root root   909 Dec 26 20:53 Makefile
-rw-r--r--. 1 root root  1081 Dec 26 20:53 MIT-LICENSE.txt
-rw-------. 1 root root   205 Dec 28 17:16 nohup.out
drwxr-xr-x. 5 root root  4096 Dec 26 20:53 pkg
-rw-r--r--. 1 root root  3265 Dec 26 20:53 README.md
drwxr-xr-x. 4 root root  4096 Dec 28 16:56 sample
-rw-r--r--. 1 root root 66032 Dec 28 16:30 sample.tar.gz
drwxr-xr-x. 2 root root  4096 Dec 26 20:53 test
-rw-r--r--. 1 root root  1475 Dec 26 20:53 vitess_license
[root@testserver2 codis]#


配置codis-proxy(在3台服务器上)

#10.111.32.51
cd /usr/local/codis/src/github.com/wandoulabs/codis
vim config.ini
/配置zookeeper连接
zk=codis1:2181,codis2:2181,codis3:2181
/配置redis集群名称
product=codis  
#此处配置图形化界面的dashboard,注意codis集群只要一个即可,因此全部指向10.111.32.52:18087
dashboard_addr=10.111.32.52:18087
coordinator=zookeeper
backend_ping_period=5
session_max_timeout=1800
session_max_bufsize=131072
session_max_pipeline=128
/配置redis集群proxy名称
proxy_id=codis_proxy_1


#10.111.32.52
cd /usr/local/codis/src/github.com/wandoulabs/codis
vim config.ini
zk=codis1:2181,codis2:2181,codis3:2181
product=codis
#此处配置图形化界面的dashboard,注意codis集群只要一个即可,因此全部指向10.111.32.52:18087  
dashboard_addr=10.111.32.52:18087
coordinator=zookeeper
backend_ping_period=5
session_max_timeout=1800
session_max_bufsize=131072
session_max_pipeline=128
proxy_id=codis_proxy_2


#10.111.32.53
cd /usr/local/codis/src/github.com/wandoulabs/codis
vim config.ini
zk=codis1:2181,codis2:2181,codis3:2181
product=codis
#此处配置图形化界面的dashboard,注意codis集群只要一个即可,因此全部指向10.111.32.52:18087
dashboard_addr=10.111.32.52:18087
coordinator=zookeeper
backend_ping_period=5
session_max_timeout=1800
session_max_bufsize=131072
session_max_pipeline=128
proxy_id=codis_proxy_3


[root@testserver2 sample]# pwd
/usr/local/codis/src/github.com/wandoulabs/codis/sample
[root@testserver2 sample]# ll
total 56
-rwxr-x---. 1 root root  389 Sep 10 14:47 add_group.sh
-rw-r-----. 1 root root  136 Sep 10 15:25 config.ini
-rwxr-x---. 1 root root  288 Sep 10 14:42 initslot.sh
drwxr-xr-x. 2 root root 4096 Dec 28 16:57 log
-rw-------. 1 root root 4998 Nov 27 22:44 nohup.out
drwxr-xr-x. 2 root root 4096 Dec 28 16:57 redis_conf
-rw-r-----. 1 root root  696 Sep 10 14:42 request.log
-rwxr-x---. 1 root root  104 Nov 10 20:06 set_proxy_online.sh
-rwxr-x---. 1 root root  106 Sep 10 14:42 startall.sh
-rwxr-x---. 1 root root  142 Sep 10 14:42 start_dashboard.sh
-rwxr-x---. 1 root root  331 Sep 10 15:25 start_proxy.sh
-rwxr-x---. 1 root root  716 Sep 10 14:42 start_redis.sh
-rw-r-----. 1 root root  229 Sep 10 14:47 usage.md


redis服务为主从,,从为备份,每2个做为一组,每组的主备不在同一台主机上。
Redis配置文件

主redis配置
/usr/local/go/bin/src/github.com/wandoulabs/codis/sample/redis_conf/6379_master.conf
port 6379 /配置redis端口
daemonize yes
dir /usr/local/go/bin/src/github.com/wandoulabs/codis/logs   /配置redis日志位置
maxmemory 50gb  /配置redis最大可用内存;
dbfilename 6379.rdb
 
备redis配置
/usr/local/go/bin/src/github.com/wandoulabs/codis/sample/redis_conf/6380_slave.conf
port 6380 /配置redis端口
daemonize yes
dir /usr/local/go/bin/src/github.com/wandoulabs/codis/logs   /配置redis日志位置
maxmemory 50gb  /配置redis最大可用内存;
slaveof 10.111.32.52 6379 /配置同步的主redis端口
dbfilename 6380.rdb



启动流程:
0. start zookeeper
1. change config items in config.ini
2. ./start_redis.sh
3. ./add_group.sh
4. ./initslot.sh
5. ./start_proxy.sh
6. ./set_proxy_online.sh
7. ./start_dashboard.sh
8. open browser to http://localhost:18087/admin


以下脚本根据实际情况调整:

mkdir sample

启动redis
[root@testserver2 sample]# cat start_redis.sh
#!/bin/sh

nohup ../bin/codis-server ./redis_conf/6379_master.conf &> ./log/redis_6379.log &
nohup ../bin/codis-server ./redis_conf/6380_slave.conf &> ./log/redis_6380.log &

echo "sleep 3s"
sleep 3
tail -n 30 ./log/redis_6379.log
tail -n 30 ./log/redis_6380.log

说明:redis_conf/6379_master.conf文件根据实际情况调整


建立组
[root@testserver2 sample]# cat add_group.sh
#!/bin/sh
echo "add group 1 with a master(localhost:6381), Notice: do not use localhost when in produciton"
../bin/codis-config -c config.ini -L ./log/config.log server add 1 localhost:6381 master

echo "add group 2 with a master(localhost:6382), Notice: do not use localhost when in produciton"
../bin/codis-config -c config.ini -L ./log/config.log server add 2 localhost:6382 master


dashboard启动  (不启动这个初始化槽位会报错)
[root@testserver2 sample]# cat start_dashboard.sh
#!/bin/sh
nohup ../bin/codis-config -c config.ini -L ./log/dashboard.log dashboard --addr=:18087 --http-log=./log/requests.log &>/dev/null &

初始化槽位(注意需要将1024个槽位都分配才能正常启动proxy,槽位后期可以迁移调整)
[root@testserver2 sample]# cat initslot.sh
#!/bin/sh
echo "slots initializing..."
../bin/codis-config -c config.ini slot init -f
echo "done"

echo "set slot ranges to server groups..."
../bin/codis-config -c  config.ini slot range-set 0 511 1 online
../bin/codis-config -c  config.ini slot range-set 512 1023 2 online
echo "done"

说明:将0-511槽位分配给组1,将512-1023槽位分配给组2


开始proxy
[root@testserver2 sample]# cat start_proxy.sh
#!/bin/sh
echo "shut down proxy_5..."
../bin/codis-config -c config.ini proxy offline proxy_5
echo "done"

echo "start new proxy..."
nohup ../bin/codis-proxy --log-level info -c config.ini -L ./log/proxy.log  --cpu=8 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &
echo "done"

echo "sleep 3s"
sleep 3
tail -n 30 ./log/proxy.log

说明:需要先行创建log/proxy.log 文件,--cpu=8根据服务器cpu核数调整。

proxy服务上线
[root@testserver2 sample]# cat set_proxy_online.sh
#!/bin/sh
echo "set proxy_1 online"
../bin/codis-config -c config.ini proxy online proxy_1
echo "done"
说明:config.ini文件路径根据实际情况调整


/usr/local/codis/src/github.com/wandoulabs/codis/extern/redis-2.8.21/src/redis-cli -p 6379
/usr/local/codis/src/github.com/wandoulabs/codis/extern/redis-2.8.21/src/redis-cli -h 10.111.32.52 -p 19000

如果你将codis整个文件夹移动到其他目录下:/usr/local/codis/extern/redis-2.8.21/src/redis-cli -h 10.111.32.52 -p 19000

删除zookeeper中内容: delete /zk 将创建的 znode 删除
递归删除 rmr /zk

设置下/etc/sysctl.conf文件,不然启动codis会报:
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

vi编辑
#vi /etc/sysctl.conf
vm.overcommit_memory = 1

#sysctl -p 生效

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
解决方法:
sysctl vm.overcommit_memory=1

WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue 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. Redis must be restarted after THP is disabled.
解决方法:
echo never > /sys/kernel/mm/transparent_hugepage/enabled


WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128
解决方法:
echo 511 > /proc/sys/net/core/somaxconn



参考:
http://blog.csdn.net/dc_726/article/details/47052607
https://github.com/wandoulabs/codis/blob/master/doc/tutorial_zh.md
http://blog.csdn.net/yanggd1987/article/details/46825895
http://hugnew.com/codis%E9%9B%86%E7%BE%A4%E6%90%AD%E5%BB%BA%E5%AE%9E%E8%B7%B5/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值