什么是Codis?
Codis是一个基于代理的高性能的分布式Redis解决方案,对于上层应用来说,连接到Codis Proxy和连接原生的Redis Server没有显著区别(只是不支持部分命令)。使用go语言开发。
Codis的GitHub地址:https://github.com/CodisLabs/codis
Codis官方架构图:
Codis 3.x 由以下组件组成:
Codis Dashboard、Codis Proxy、Codis Server、Codis Admin、Codis FE、Storage
1、安装jdk、zookeeper
下载、解压
tar -zxvf jdk-8u181-linux-x64.tar.gz
tar -zxvf zookeeper-3.4.12.tar.gz
2、安装go运行环境(codis用go语言写的)
下载地址:https://studygolang.com/dl/golang/go1.9.1.linux-amd64.tar.gz
解压:
tar -zxvf go1.9.1.linux-amd64.tar.gz
3、配置环境变量:
vim /etc/profile
在/etc/profile文件末尾添加:
export GOROOT=/apps/go #go根目录,根据自己实际安装目录配
export GOPATH=/apps/codis #go项目所在目录,因为现在我们要安装Codis,所以这里配codis
export JAVA_HOME=/usr/local/jdk
export CLASS_PATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.6
export PATH=$PATH:$GOROOT/bin:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin
#查看环境变量
[root@iZwz977ogd6jecq7rowvtsZ apps]# env |egrep -i "GOPATH|JAVA_HOME"
JAVA_HOME=/apps/jdk1.8.0_181
GOPATH=/apps/gopath
验证go环境是否安装成功:
[root@iZwz977ogd6jecq7rowvtsZ apps]# go version
go version go1.9.1 linux/amd64
验证go是否能正常运行:
创建hello.go文件,
[root@iZwz977ogd6jecq7rowvtsZ apps]# cat > hello.go
package main
import "fmt"
func main(){
fmt.Printf("hello,world\n")
}
运行hello.go成功说明go能正常使用了:
[root@iZwz977ogd6jecq7rowvtsZ apps]# go run hello.go
hello,world
4、安装Codis
安装git:
[root@iZwz977ogd6jecq7rowvtsZ apps]# yum install -y git
下载Codis源码:
Codis源码需要下载到:$GOPATH/src/github.com/CodisLabs
[root@iZwz977ogd6jecq7rowvtsZ codis]# mkdir -p $GOPATH/src/github.com/CodisLabs
[root@iZwz977ogd6jecq7rowvtsZ codis]# cd src/github.com/CodisLabs/
[root@iZwz977ogd6jecq7rowvtsZ codis]# git clone https://github.com/CodisLabs/codis.git -b release3.2
编译Codis源码:
进入下载目录执行make命令进行编译,它会搜索Makefile文件并执行其中的指令
[root@iZwz977ogd6jecq7rowvtsZ wandoulabs]# cd codis/
[root@iZwz977ogd6jecq7rowvtsZ codis]# ls
admin cmd deploy Dockerfile extern kubernetes MIT-LICENSE.txt README.md vendor wandoujia_license.txt
ansible config doc example Godeps Makefile pkg scripts version
[root@iZwz977ogd6jecq7rowvtsZ codis]# pwd
/apps/codis/src/github.com/wandoulabs/codis
[root@iZwz977ogd6jecq7rowvtsZ codis]# make
.....
make[2]: Leaving directory `/apps/codis/src/github.com/wandoulabs/codis/extern/redis-3.2.11/src'
make[1]: Leaving directory `/apps/codis/src/github.com/wandoulabs/codis/extern/redis-3.2.11'
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
[root@iZwz977ogd6jecq7rowvtsZ codis]#
编译过程中报错:找不到autoconf命令,解决办法:安装autoconf,然后重新编译
[root@iZwz977ogd6jecq7rowvtsZ codis]# yum install autoconf
重新编译又报下面的错误,原因是由于安装的go版本太低,重新安装高版本即可解决
go build -i -o bin/codis-dashboard ./cmd/dashboard
pkg/topom/config.go:9:2: cannot find package "github.com/BurntSushi/toml" in any of:
/root/tools/go/src/github.com/BurntSushi/toml (from $GOROOT)
/root/tools/gopkg/src/github.com/BurntSushi/toml (from $GOPATH)
...
make: *** [codis-dashboard] Error 1
成功编译结果如下,在Codis的bin目录下可以看到Codis的几个核心组件:
[root@iZwz977ogd6jecq7rowvtsZ codis]# make
make -j4 -C extern/redis-3.2.11/
make[1]: Entering directory `/apps/codis/src/github.com/CodisLabs/codis/extern/redis-3.2.11'
cd src && make all
make[2]: Entering directory `/apps/codis/src/github.com/CodisLabs/codis/extern/redis-3.2.11/src'
Hint: It's a good idea to run 'make test' ;)
make[2]: Leaving directory `/apps/codis/src/github.com/CodisLabs/codis/extern/redis-3.2.11/src'
make[1]: Leaving directory `/apps/codis/src/github.com/CodisLabs/codis/extern/redis-3.2.11'
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-ha ./cmd/ha
go build -i -o bin/codis-fe ./cmd/fe
[root@iZwz977ogd6jecq7rowvtsZ codis]# ls bin/
assets codis-dashboard codis-ha codis-server redis-cli version
codis-admin codis-fe codis-proxy redis-benchmark redis-sentinel