codis环境搭建
1.docker环境准备
1.2 docker 准备
1.2.1 无对外暴露端口
# centos环境
$ docker run -dit --name codis centos
# 查看镜像
$ docker ps -a
# 进入容器
$ docker attach ${容器id}
1.2.2 对外暴露端口
# 对外暴露8080端口
$ docker run -dit -p8080:8080 --name codis2 centos
94a1fd93a54481414c745122f493eaccb6c845fc7114cf97aeb9f3dd995687f4
# 查看暴露的端口
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
94a1fd93a544 centos "/bin/bash" 11 seconds ago Up 9 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp codis2
1.2 centos环境软件包
# 更新yum
$ yum update -y
# 安装包
$ yum install -y vim wget tree lrzsz git make gcc
2.安装Go环境
考虑到codis是3.0版本,基于go的1.8版本开发的
2.1 下载安装
# 下载 Go 安装包
$ wget https://studygolang.com/dl/golang/go1.8.7.linux-amd64.tar.gz
# 解压
$ tar -zxf go1.8.7.linux-amd64.tar.gz /usr/local/
# 查看安装路径
$ pwd
/usr/local/go
2.2 环境配置
vim ~/.bashrc
export GOROOT=/usr/local/go
export GOPATH=/home/apps/devgo
export GOBIN=/home/apps/devgo/bin
export PATH=$PATH:$GOROOT/bin
2.3 Go环境检查
# 版本
[root@f67a5365a626 go]# go version
go version go1.8.7 linux/amd64
3.安装godep
3.1 安装
$ go get -u github.com/tools/godep
3.2 检查
[root@f67a5365a626 devgo]# which godep
which: no godep in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin)
# 如果输入which godep 报命令command not found的错误,可以这样解决
[root@f67a5365a626 devgo]# cp $GOPATH/bin/godep /usr/local/bin/
[root@f67a5365a626 devgo]# which godep
/usr/local/bin/godep
4.安装codis
4.1 下载
$ mkdir -p $GOPATH/src/github.com/CodisLabs
# 下载codis 源代码
$ cd $GOPATH/src/github.com/CodisLabs && git clone https://github.com/CodisLabs/codis.git -b release3.0
4.2 安装
$ cd $GOPATH/src/github.com/CodisLabs/codis
$
.....
In file included from adlist.c:34:
zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory
#include <jemalloc/jemalloc.h>
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [Makefile:197: adlist.o] Error 1
make[2]: *** Waiting for unfinished jobs....
# 出现异常情况
$ make MALLOC=libc LDFLAGS+=-ldl
make -j -C extern/redis-2.8.21/
... ...
make[2]: Leaving directory '/home/apps/devgo/src/github.com/CodisLabs/codis/extern/redis-2.8.21/src'
make[1]: Leaving directory '/home/apps/devgo/src/github.com/CodisLabs/codis/extern/redis-2.8.21'
go build -i -o bin/codis-dashboard ./cmd/dashboard
go build -i -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
4.3 编译后的效果
# 编译的路径文件
[root@f67a5365a626 codis]# ll
total 80
drwxr-xr-x 12 root root 4096 Jul 4 03:24 .
drwxr-xr-x 3 root root 4096 Jul 4 03:21 ..
drwxr-xr-x 3 root root 4096 Jul 4 03:31 bin
drwxr-xr-x 7 root root 4096 Jul 4 03:20 cmd
drwxr-xr-x 5 root root 4096 Jul 4 03:20 deploy
drwxr-xr-x 5 root root 4096 Jul 4 03:20 doc
-rw-r--r-- 1 root root 251 Jul 4 03:20 Dockerfile
drwxr-xr-x 5 root root 4096 Jul 4 03:20 extern
drwxr-xr-x 8 root root 4096 Jul 4 03:26 .git
-rw-r--r-- 1 root root 98 Jul 4 03:20 .gitignore
drwxr-xr-x 2 root root 4096 Jul 4 03:20 Godeps
-rw-r--r-- 1 root root 1040 Jul 4 03:20 Makefile
-rw-r--r-- 1 root root 1076 Jul 4 03:20 MIT-LICENSE.txt
drwxr-xr-x 6 root root 4096 Jul 4 03:20 pkg
-rw-r--r-- 1 root root 3121 Jul 4 03:20 README.md
drwxr-xr-x 2 root root 4096 Jul 4 03:20 scripts
-rw-r--r-- 1 root root 106 Jul 4 03:20 .travis.yml
drwxr-xr-x 4 root root 4096 Jul 4 03:20 vendor
-rwxr-xr-x 1 root root 418 Jul 4 03:20 version
-rw-r--r-- 1 root root 1081 Jul 4 03:20 wandoujia_license.txt
# 查看编译的效果
root@f67a5365a626 bin]# cat version
version = 2016-09-30 15:29:48 +0800 @a99a681a95b2eacbbcdb71ff8a6ee95fc36d3577
compile = 2021-07-04 03:30:58 +0000 by go version go1.8.7 linux/amd64
# 接下来,我们需要处理一下 bin/ 下的命令工具
$ cp codis-* /usr/local/bin
$ cp redis-* /usr/local/bin
5.安装etcd
# 下载 etcd
$ wget https://github.com/coreos/etcd/releases/download/v2.3.7/etcd-v2.3.7-linux-amd64.tar.gz
# 解压
$ tar -zxf etcd-v2.3.7-linux-amd64.tar.gz
# etcd路径文件
$ cd etcd-v2.3.7-linux-amd64 && cp etcd /usr/local/bin/ && cp etcdctl /usr/local/bin/
# 验证是否正常
[root@f67a5365a626 local]# etcd --version
etcd Version: 2.3.7
Git SHA: fd17c91
Go Version: go1.6.2
Go OS/Arch: linux/amd64
6.codis demo 运行
6.1 运行demo
# 运行目录
[root@f67a5365a626 codis]# pwd
/home/apps/devgo/src/github.com/CodisLabs/codis
# demo命令运行
$ cd scripts/demo.sh
/home/apps/devgo/src/github.com/CodisLabs/codis/scripts/tmp /home/apps/devgo/src/github.com/CodisLabs/codis/scripts
etcd.pid=1741
codis-server-16379.pid=1742
codis-server-16380.pid=1743
codis-server-16381.pid=1744
codis-server-16382.pid=1745
codis-server-16383.pid=1747
codis-server-16384.pid=1750
codis-server-16385.pid=1751
codis-server-16386.pid=1752
proxy-11080x19000.pid=1756
proxy-11081x19001.pid=1771
proxy-11082x19002.pid=1782
proxy-11083x19003.pid=1798
dashboard.pid=1800
fe.pid=1815
migrate slot-[ 768,1023] to group-4
migrate slot-[ 0, 255] to group-1
migrate slot-[ 256, 511] to group-2
migrate slot-[ 512, 767] to group-3
done
done
Mon Jul 5 07:53:16 CST 2021
6.2 界面效果