一:Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有明显的区别 (不支持的命令列表https://github.com/CodisLabs/codis/blob/release3.1/doc/unsupported_cmds.md), 上层应用可以像使用单机的 Redis 一样使用, Codis 底层会处理请求的转发, 不停机的数据迁移等工作, 所有后边的一切事情, 对于前面的客户端来说是透明的, 可以简单的认为后边连接的是一个内存无限大的 Redis 服务:
Codis是豌豆荚的开源方案,目前在redis集群实现方式对比,codis集群比较稳定的方案,并且客户端不需要做任何修改,相对redis cluster兼容性更强,可节约大量开发成本并减少大量后期维护成本,豌豆荚gitlab地址https://github.com/pingcap,豌豆荚codis项目官方github地址https://github.com/CodisLabs/codis,codis 主要由以下特点:
可以无缝迁移到codis,自带迁移工具,并且案例较多
可以动态扩容和缩容
多业务完全透明,业务不知道运行的是codis
支持多核心CPU,twemproxy只能单核
codis是中心基于proxy的设计,是客户端像连接单机一样操作proxy
有部分命令不能支持,比如keys *等
支持group划分,组内可以设置一个主多个从,通过sentinel 监控redis主从,当主down了自动将从切换为主
设置的进程要最大等于CPU的核心,不能超过CPU的核心数
其依赖于zookeeper,里面保存的是key保存的redis主机位置,因此zookeeper要做高可用
监控可以使用接口和dashboard
1.1:安装go环境,codis基于go开发:
1.1.1:架构环境:
codis-proxy相当于redis,即连接codis-proxy和连接redis是没有任何区别的,codis-proxy无状态,不负责记录是否在哪保存,数据在zookeeper记录,即codis proxy向zookeeper查询key的记录位置,proxy 将请求转发到一个组进行处理,一个组里面有一个master和一个或者多个slave组成,默认有1024个槽位,redis cluster 默认有16384个槽位,其把不同的槽位的内容放在不通的group。
部署环境:3台服务器
1.1.2:codis是基于go语言编写的,因此要安装go语言环境:
# cd /usr/local/src [[email protected] src]# yum install -y gcc glibc gcc-c++ make git [[email protected] src]# wget https://storage.googleapis.com/golang/go1.7.3.linux-amd64.tar.gz [[email protected] src]# tar zxf go1.7.3.linux-amd64.tar.gz [[email protected] src]# mv go /usr/local/ [[email protected] src]# mkdir /usr/local/go/work [[email protected] src]# vim /root/.bash_profile export PATH=$PATH:/usr/local/go/bin export GOROOT=/usr/local/go export GOPATH=/usr/local/go/work path=$PATH:$HOME/bin:$GOROOT/bin:$GOPATH/bin [[email protected] src]# source /root/.bash_profile [[email protected] src]# echo $GOPATH /usr/local/go/work [[email protected] ~]# go version go version go1.7.3 linux/amd64
1.1.3:每台服务器安装java环境和zookeeper,zookeeper集群最少需要3台服务器,推荐5台,因为zookeeper是基于java开发的:
# tar zxf jdk-8u131-linux-x64.gz # mv jdk1.8.0_131 /usr/local/
加入脚本
# vim /etc/profile export JAVA_HOME=/usr/local/jdk1.8.0_131 export PATH=$JAVA_HOME/bin:$PATH [[email protected] jdk1.8.0_131]# source /etc/profile [[email protected] jdk1.8.0_131]# java -version java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode) [[email protected] jdk1.8.0_131]# echo $JAVA_HOME /usr/local/jdk1.8.0_131 # tar zxf zookeeper-3.4.6.tar.gz # mv zookeeper-3.4.6 /usr/local/ [[email protected] src]# ln -sv /usr/local/zookeeper-3.4.6/ /usr/local/zookeeper ‘/usr/local/zookeeper’ -> ‘/usr/local/zookeeper-3.4.6/’ [[email protected] src]# cd /opt [[email protected] opt]# mkdir zk1 zk2 zk3 #准备zookeeper 服务ID,每个服务器的ID是不同的 [[email protected] opt]# echo 1 > zk1/myid [[email protected] opt]# echo 2 > zk2/myid [[email protected] opt]# echo 3 > zk3/myid [[email protected] opt]# cp /usr/local/zookeeper-3.4.6/conf/zoo_sample.cfg /opt/zk1/zk1.cfg
#准备配置文件
#第一个zookeeper的配置文件:
[[email protected] opt]# grep "^[a-Z]" /opt/zk1/zk1.cfg tickTime=6000 #服务器和客户端的心跳维持间隔,间隔多久发送心跳 ,6000微秒等于6毫秒 initLimit=10 #选举的时候的时间间隔是10次,10次 * 6000微秒 即60秒 syncLimit=10 # Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度 dataDir=/opt/zk1 # 数据保存目录 clientPort=2181 # 客户端连接的端口 # 集群端口和ID配置 server.1=192.168.3.198:2887:3887 server.2=192.168.3.198:2888:3888 server.3=192.168.3.198:2889:3889
1.1.4:配置第二个zookeeper服务:
#配置第二个zookeeper服务,每个服务对应不用的配置文件和数据目录:
[[email protected] opt]# cp /opt/zk1/zk1.cfg /opt/zk2/zk2.cfg
[[email protected] opt]# grep "^[a-Z]" /opt/zk2/zk2.cfg
tickTime=6000 initLimit=20 syncLimit=10 dataDir=/opt/zk2 # 需要修改配置 clientPort=2182 # 需要修改监听端口 server.1=192.168.3.198:2887:3887 server.2=192.168.3.198:2888:3888 server.3=192.168.3.198:2889:3889
1.1.5:配置第三个zookeeper服务:
#配置第三个zookeeper服务,每个服务对应不用的配置文件和数据目录:
[[email protected] opt]# cp /opt/zk1/zk1.cfg /opt/zk3/zk3.cfg [[email protected] opt]# vim /opt/zk3/zk3.cfg [[email protected] opt]# grep "^[a-Z]" /opt/zk3/zk3.cfg tickTime=6000 initLimit=20 syncLimit=10 dataDir=/opt/zk3 # 需要修改配置 clientPort=2183 # 需要修改监听端口 server.1=192.168.3.198:2887:3887 server.2=192.168.3.198:2888:3888 server.3=192.168.3.198:2889:3889
1.1.6:参数详解:
详细解释:
tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
initLimit:这个配置项是用来配置 Zookeeper 接受客户端(这里所说的客户端不是用户连接 Zookeeper 服务器的客户端,而是 Zookeeper 服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 5个心跳的时间(也就是 tickTime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 10*6000=60 秒
syncLimit:这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 5*6000=30 秒
server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的 ip 地址;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。
1.1.7:分别启动各zookeeper服务:
[[email protected] opt]# /usr/local/zookeeper/bin/zkServer.sh start /opt/zk1/zk1.cfg [[email protected] opt]# /usr/local/zookeeper/bin/zkServer.sh start /opt/zk2/zk2.cfg [[email protected] opt]# /usr/local/zookeeper/bin/zkServer.sh start /opt/zk3/zk3.cfg [[email protected] opt]# ss -tnlp|grep 218* LISTEN 0 50 :::2181 :::* users:(("java",pid=2893,fd=24)) LISTEN 0 50 :::2182 :::* users:(("java",pid=3055,fd=24)) LISTEN 0 50 :::2183 :::* users:(("java",pid=3099,fd=24))
1.1.9:查看各个zookeeper节点的状态:
[[email protected] opt]# /usr/local/zookeeper/bin/zkServer.sh status /opt/zk1/zk1.cfg JMX enabled by default Using config: /opt/zk1/zk1.cfg Mode: follower # 备用节点 [[email protected] opt]# /usr/local/zookeeper/bin/zkServer.sh status /opt/zk2/zk2.cfg JMX enabled by default Using config: /opt/zk2/zk2.cfg Mode: leader # 主节点 [[email protected] opt]# /usr/local/zookeeper/bin/zkServer.sh status /opt/zk3/zk3.cfg JMX enabled by default Using config: /opt/zk3/zk3.cfg Mode: follower # 备用节点
1.1.10:测试连接到zookeeper节点:
[[email protected] opt]# /usr/local/zookeeper/bin/zkCli.sh -server 192.168.10.101:2181 Connecting to 192.168.10.101:2181 2017-05-12 17:27:41,481 [myid:] - INFO [main:[email protected]100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT 2017-05-12 17:27:41,485 [myid:] - INFO [main:[email protected]100] - Client environment:host.name=www.chinasoft.com 2017-05-12 17:27:41,485 [myid:] - INFO [main:[email protected]100] - Client environment:java.version=1.8.0_131 2017-05-12 17:27:41,488 [myid:] - INFO [main:[email protected]100] - Client environment:java.vendor=Oracle Corporation 2017-05-12 17:27:41,488 [myid:] - INFO [main:[email protected]100] - Client environment:java.home=/usr/local/jdk1.8.0_131/jre 2017-05-12 17:27:41,488 [myid:] - INFO [main:[email protected]100] - Client environment:java.class.path=/usr/local/zookeeper/bin/../build/classes:/usr/local/zookeeper/bin/../build/lib/*.jar:/usr/local/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/bin/../zookeeper-3.4.6.jar:/usr/local/zookeeper/bin/../src/java/lib/*.jar:/usr/local/zookeeper/bin/../conf:..:/usr/local/jdk/lib:/usr/local/jdk/jre/lib:/usr/local/jdk/lib/tools.jar:/usr/local/jdk/lib:/usr/local/jdk/jre/lib:/usr/local/jdk/lib/tools.jar 2017-05-12 17:27:41,489 [myid:] - INFO [main:[email protected]] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2017-05-12 17:27:41,489 [myid:] - INFO [main:[email protected]] - Client environment:java.io.tmpdir=/tmp 2017-05-12 17:27:41,489 [myid:] - INFO [main:[email protected]] - Client environment:java.compiler=<NA> 2017-05-12 17:27:41,489 [myid:] - INFO [main:[email protected]] - Client environment:os.name=Linux 2017-05-12 17:27:41,489 [myid:] - INFO [main:[email protected]] - Client environment:os.arch=amd64 2017-05-12 17:27:41,489 [myid:] - INFO [main:[email protected]] - Client environment:os.version=3.10.0-514.el7.x86_64 2017-05-12 17:27:41,489 [myid:] - INFO [main:[email protected]] - Client environment:user.name=root 2017-05-12 17:27:41,490 [myid:] - INFO [main:[email protected]] - Client environment:user.home=/root 2017-05-12 17:27:41,490 [myid:] - INFO [main:[email protected]] - Client environment:user.dir=/opt 2017-05-12 17:27:41,491 [myid:] - INFO [main:[email protected]] - Initiating client connection, connectString=192.168.10.101:2181 sessionTimeout=30000 [email protected] Welcome to ZooKeeper! 2017-05-12 17:27:41,534 [myid:] - INFO [main-SendThread(192.168.10.101:2181):[email protected]] - Opening socket connection to server 192.168.10.101/192.168.10.101:2181. Will not attempt to authenticate using SASL (unknown error) JLine support is enabled [zk: 192.168.10.101:2181(CONNECTING) 0] 1.1.11:获取zookeeper命令行帮助: [zk: 192.168.10.101:2181(CONNECTING) 0] help ZooKeeper -server host:port cmd args stat path [watch] set path data [version] ls path [watch] delquota [-n|-b] path ls2 path [watch] setAcl path acl setquota -n|-b val path history redo cmdno printwatches on|off delete path [version] sync path listquota path rmr path get path [watch] create [-s] [-e] path data acl addauth scheme auth quit getAcl path close connect host:port [zk: 192.168.10.101:2181(CONNECTING) 1]
1.2.12:下载codis 3.2版本:
# mkdir -p $GOPATH/src/github.com/CodisLabs [[email protected] work]# cd /usr/local/go/work/src/github.com/CodisLabs [[email protected] CodisLabs]# git clone https://github.com/CodisLabs/codis.git -b release3.2 [[email protected] CodisLabs]# cd $GOPATH/src/github.com/CodisLabs/codis [[email protected] codis]# pwd /usr/local/go/work/src/github.com/CodisLabs/codis
1.1.13:执行make进行编译:
安装依赖
[[email protected] codis]# yum install autoconf automake libtool -y [[email protected] codis]# make make -j4 -C extern/redis-3.2.8/ make[1]: Entering directory `/usr/local/go/work/src/github.com/CodisLabs/codis/extern/redis-3.2.8‘ cd src && make all make[2]: Entering directory `/usr/local/go/work/src/github.com/CodisLabs/codis/extern/redis-3.2.8/src‘ ... lazy_lock : 0 tls : 1 cache-oblivious : 1 =============================================================================== go build -i -o bin/codis-dashboard ./cmd/dashboard go build -i -tags "cgo_jemalloc" -o bin/codis-proxy ./cmd/proxy go build -i -o bin/codis-admin ./cmd/admin go build -i -o bin/codis-fe ./cmd/fe
1.1.14:执行测试:
[[email protected] codis]# make gotest go test ./cmd/... ./pkg/... ? github.com/CodisLabs/codis/cmd/admin [no test files] ? github.com/CodisLabs/codis/cmd/dashboard [no test files] ? github.com/CodisLabs/codis/cmd/fe [no test files] ? github.com/CodisLabs/codis/cmd/proxy [no test files] ? github.com/CodisLabs/codis/pkg/models [no test files] ? github.com/CodisLabs/codis/pkg/models/etcd [no test files] ? github.com/CodisLabs/codis/pkg/models/fs [no test files] ? github.com/CodisLabs/codis/pkg/models/zk [no test files] ok github.com/CodisLabs/codis/pkg/proxy 2.525s ok github.com/CodisLabs/codis/pkg/proxy/redis 0.530s ok github.com/CodisLabs/codis/pkg/topom 6.560s ok github.com/CodisLabs/codis/pkg/utils 0.009s ? github.com/CodisLabs/codis/pkg/utils/assert [no test files] ok github.com/CodisLabs/codis/pkg/utils/bufio2 0.006s ok github.com/CodisLabs/codis/pkg/utils/bytesize 0.004s ? github.com/CodisLabs/codis/pkg/utils/errors [no test files] ? github.com/CodisLabs/codis/pkg/utils/log [no test files] ok github.com/CodisLabs/codis/pkg/utils/math2 0.002s ? github.com/CodisLabs/codis/pkg/utils/redis [no test files] ? github.com/CodisLabs/codis/pkg/utils/rpc [no test files] ? github.com/CodisLabs/codis/pkg/utils/sync2 [no test files] ? github.com/CodisLabs/codis/pkg/utils/sync2/atomic2 [no test files] ok github.com/CodisLabs/codis/pkg/utils/timesize 0.009s ? github.com/CodisLabs/codis/pkg/utils/trace [no test files] ok github.com/CodisLabs/codis/pkg/utils/unsafe2 0.003s
1.1.15:执行全部指令后,会在 bin 文件夹内生成 codis-proxy、codis-server三个可执行文件。另外, bin/assets 文件夹是 dashboard http 服务需要的前端资源)
[[email protected] codis]# ll bin total 75680 drwxr-xr-x 4 root root 117 May 12 18:00 assets -rwxr-xr-x 1 root root 15474864 May 12 18:00 codis-admin -rwxr-xr-x 1 root root 17093776 May 12 18:00 codis-dashboard -rwxr-xr-x 1 root root 15365824 May 12 18:00 codis-fe -rwxr-xr-x 1 root root 19167944 May 12 18:00 codis-proxy # 代理 -rwxr-xr-x 1 root root 5357008 May 12 18:00 codis-server # codis 开发的codis server -rwxr-xr-x 1 root root 2431984 May 12 18:00 redis-benchmark -rwxr-xr-x 1 root root 2586040 May 12 18:00 redis-cli -rw-r--r-- 1 root root 169 May 12 18:00 version [[email protected] codis]# cat bin/version version = 2017-05-12 17:22:43 +0800 @07352186632fafd45ca31b0cbde4a541862d46fe @3.2-rc1-32-g0735218 compile = 2017-05-12 18:00:10 +0800 by go version go1.7.3 linux/amd64
编译codis3.2错误记录:
make[2]: Leaving directory `/usr/local/go/work/src/github.com/CodisLabs/codis/extern/redis-3.2.8/src‘ make[1]: Leaving directory `/usr/local/go/work/src/github.com/CodisLabs/codis/extern/redis-3.2.8‘ autoconf ./autogen.sh: line 5: autoconf: command not found Error 0 in autoconf make[2]: *** [config] Error 1 make[1]: *** [build] Error 2 make: *** [codis-deps] Error 2
解决:
安装依赖
[[email protected] codis]# yum install autoconf automake libtool -y
1.2:默认启动的会读取config目录的dashboard.toml文件,编辑如下:
1.2.1:dashboard 的配置文件:
vim /usr/local/go/work/src/github.com/CodisLabs/codis/config/dashboard.toml
主要配置信息如下:
coordinator_name = "zookeeper" coordinator_addr = "192.168.3.198:2181,192.168.3.198:2182,192.168.3.198:2183" product_name = "codis-chinasoft"
启动dashboard:
[[email protected] codis]# nohup ./bin/codis-dashboard --ncpu=1 --config=config/dashboard.toml --log=dashboard.log --log-level=WARN >> /var/log/codis_dashboard.log &
# 默认配置文件获取方式:./bin/codis-dashboard --default-config | tee dashboard.toml
启动代理
[[email protected] codis]# nohup ./bin/codis-proxy --ncpu=1 --config=config/proxy.toml --log=proxy.log --log-level=WARN >> /var/log/codis_proxy.log &
主要配置信息如下:
product_name = "codis-chinasoft" product_auth = "123456" jodis_name = "zookeeper" jodis_addr = "192.168.3.198:2181,192.168.3.198:2182,192.168.3.198:2183" jodis_timeout = "20s" jodis_compatible = true
./bin/codis-admin --dashboard=127.0.0.1:18080 --create-proxy -x 127.0.0.1:11080 其中 127.0.0.1:18080 以及 127.0.0.1:11080 分别为 dashboard 和 proxy 的 admin_addr 地址; ./bin/codis-admin --dashboard=127.0.0.1:18080 --create-proxy -x 127.0.0.1:11080 ./bin/codis-admin --dashboard=192.168.3.198:18080 --create-proxy -x 192.168.3.198:11080
启动codis-server,即创建redis实例(此处我们创建4个redis实例,给予codis修改过的redis-3.2.8非原生redis)
[[email protected] codis]# mkdir -pv /var/lib/redis_638{1..4}
mkdir: created directory ??/var/lib/redis_6381?ˉ
mkdir: created directory ??/var/lib/redis_6382?ˉ
mkdir: created directory ??/var/lib/redis_6383?ˉ
mkdir: created directory ??/var/lib/redis_6384?ˉ
[[email protected] redis-3.2.8]# pwd
/usr/local/go/work/src/github.com/CodisLabs/codis/extern/redis-3.2.8
[[email protected] redis-3.2.8]# cp redis.conf /usr/local/go/work/src/github.com/CodisLabs/codis/
[[email protected] redis-3.2.8]# cd /usr/local/go/work/src/github.com/CodisLabs/codis/
修改redis.conf
pidfile /var/run/redis_6381.pid
port 6381
dbfilename dump_6381.rdb
dir /var/lib/redis_6381
logfile "/tmp/redis_6381.log"
maxmemory 1g #一定要设置最大内存,否则后面的codis无法使用
[[email protected] codis]# cp redis.conf redis_6381.conf
[[email protected] codis]# cp redis_6381.conf redis_6382.conf
[[email protected] codis]# cp redis_6381.conf redis_6383.conf
[[email protected] codis]# cp redis_6381.conf redis_6384.conf
[[email protected] codis]# sed -i ‘s/6381/6382/g‘ redis_6382.conf
[[email protected] codis]# sed -i ‘s/6381/6383/g‘ redis_6383.conf
[[email protected] codis]# sed -i ‘s/6381/6384/g‘ redis_6384.conf
1.2.3:通过codis-server指定redis.conf文件启动redis服务,不能通过redis命令启动redis服务,通过redis启动的redis 服务加到codis集群无法正常使用:
[[email protected] codis]# ./bin/codis-server ./redis_6381.conf
[[email protected] codis]# ./bin/codis-server ./redis_6382.conf
[[email protected] codis]# ./bin/codis-server ./redis_6383.conf
[[email protected] codis]# ./bin/codis-server ./redis_6384.conf
1.2.4:验证通过codis启动redis 服务成功:
[[email protected] codis]# ss -tnlp|grep 638*
LISTEN 0 128 127.0.0.1:6381 *:* users:(("codis-server",pid=11726,fd=4))
LISTEN 0 128 127.0.0.1:6382 *:* users:(("codis-server",pid=11733,fd=4))
LISTEN 0 128 127.0.0.1:6383 *:* users:(("codis-server",pid=11738,fd=4))
LISTEN 0 128 127.0.0.1:6384 *:* users:(("codis-server",pid=11743,fd=4))
启动codis-fe,Listen监听端口不要为8080,指定8090
nohup ./bin/codis-fe --ncpu=1 --log=fe.log --log-level=WARN --zookeeper=192.168.3.198:2181 --listen=192.168.3.198:8090 &
通过网页访问:http://192.168.3.198:8090 可以看到codis的管理页面
管理界面的配置实用:
1、通过fe添加group
通过web浏览器访问集群管理页面(fe地址:192.168.3.198:8090) 选择我们刚搭建的集群 codis-chinasoft,在 Proxy 栏可看到我们已经启动的 Proxy, 但是 Group 栏为空,因为我们启动的 codis-server 并未加入到集群 添加 NEW GROUP,NEW GROUP 行输入 1,再点击 NEW GROUP 即可 添加 Codis Server,
2、添加实例(即添加后端的redis服务器)
Add Server 行输入我们刚刚启动的 codis-server 地址,添加到我们刚新建的 Group,然后再点击 Add Server 按钮即可,如下图所示
删除实例
3、对slots进行分组
如下图所示,输入所要分组的slots的起和止的范围,然后输入组ID,点击后面按钮即可。
4、添加管理proxy
如下图所示,在框内输入proxy所对应的ip地址和端口号点击Add proxy即可。
5、通过codis-proxy连接redis进行测试
[[email protected] ~]# redis-cli -h 192.168.3.198 -p 19000
192.168.3.198:19000> info
# Server
redis_version:3.2.8
redis_git_sha1:07352186
redis_git_dirty:0
redis_build_id:ff8148d434e43f05
redis_mode:standalone
os:Linux 3.10.0-514.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:11726
run_id:5832460909b887822ce81723b33e1e6ecd84e203
tcp_port:6381
uptime_in_seconds:5015
uptime_in_days:0
hz:10
lru_clock:1664676
executable:/usr/local/go/work/src/github.com/CodisLabs/codis/./bin/codis-server
config_file:/usr/local/go/work/src/github.com/CodisLabs/codis/./redis_6381.conf
# Clients
connected_clients:17
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
# Memory
used_memory:4630728
used_memory_human:4.42M
used_memory_rss:14225408
used_memory_rss_human:13.57M
used_memory_peak:4671664
used_memory_peak_human:4.46M
total_system_memory:1912111104
total_system_memory_human:1.78G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:50000000
maxmemory_human:47.68M
maxmemory_policy:noeviction
mem_fragmentation_ratio:3.07
mem_allocator:jemalloc-4.0.3
# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1494834582
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
# Stats
total_connections_received:70
total_commands_processed:13563
instantaneous_ops_per_sec:3
total_net_input_bytes:369067
total_net_output_bytes:17298971
instantaneous_input_kbps:0.09
instantaneous_output_kbps:4722.65
rejected_connections:0
sync_full:1
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:948
migrate_cached_sockets:0
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=6382,state=online,offset=5468,lag=0
master_repl_offset:5468
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:937
repl_backlog_histlen:4532
# CPU
used_cpu_sys:3.93
used_cpu_user:1.91
used_cpu_sys_children:0.02
used_cpu_user_children:0.00
# Cluster
cluster_enabled:0
# Keyspace
192.168.3.198:19000> set name jack
OK
192.168.3.198:19000> get name
"jack"
192.168.3.198:19000> set address shenzhen
OK
192.168.3.198:19000> get address
"shenzhen"
web界面验证key是否添加完成,可以看到已经添加到了group2中:
连接zookeeper,可以看到codis的group,slots,proxy等信息都记录在zook中
/usr/local/zookeeper/bin/zkCli.sh -server
*************************************
codis3.2安装报错dashboard.go:369: [PANIC] call rpc create-proxy to dashboard 127.0.0.1:18080 failed的处理
执行以下命令时报错:
# pwd
/usr/local/go/work/src/github.com/CodisLabs/codis
# ./bin/codis-admin --dashboard=192.168.3.198:18080 --create-proxy -x 192.168.3.198:11080
[[email protected] codis]# ./bin/codis-admin --dashboard=127.0.0.1:18080 --create-proxy -x 127.0.0.1:11080
2017/05/12 19:13:51 dashboard.go:369: [PANIC] call rpc create-proxy to dashboard 127.0.0.1:18080 failed
[error]: [Remote Error] [email protected]:11080 fetch model failed, Get http://127.0.0.1:11080/api/proxy/model: dial tcp 127.0.0.1:11080: getsockopt: connection refused
2 /usr/local/go/work/src/github.com/CodisLabs/codis/pkg/topom/topom_proxy.go:24
github.com/CodisLabs/codis/pkg/topom.(*Topom).CreateProxy
1 /usr/local/go/work/src/github.com/CodisLabs/codis/pkg/topom/topom_api.go:244
github.com/CodisLabs/codis/pkg/topom.(*apiServer).CreateProxy
0 /usr/local/go/work/src/github.com/CodisLabs/codis/pkg/topom/topom_api.go:81
github.com/CodisLabs/codis/pkg/topom.(*apiServer).CreateProxy-fm
... ...
[stack]:
2 /usr/local/go/work/src/github.com/CodisLabs/codis/cmd/admin/dashboard.go:369
main.(*cmdDashboard).handleProxyCommand
1 /usr/local/go/work/src/github.com/CodisLabs/codis/cmd/admin/dashboard.go:52
main.(*cmdDashboard).Main
0 /usr/local/go/work/src/github.com/CodisLabs/codis/cmd/admin/main.go:82
main.main
... ...
知乎上的答案:https://www.zhihu.com/question/52519151,感觉没有说清楚问题和解决办法
实际上经过看前面的启动dashboard命令:
官方文档是这样启动dashboard的
nohup ./bin/codis-dashboard --ncpu=4 --config=dashboard.toml \
--log=dashboard.log --log-level=WARN &
问题出在--config=dashboard.toml上,没有显示指定config文件,就用默认的,而实际上我们需要启动自己的配置文件
加上config即可,如下:
[[email protected] codis]# nohup ./bin/codis-dashboard --ncpu=1 --config=config/dashboard.toml --log=dashboard.log --log-level=WARN >> /var/log/codis_dashboard.log &