Codis单机部署
前提准备
redis版本:3.2.8
系统版本:CentOS Linux release 7.3.1611 (Core)
内核版本:3.10.0-514.2.2.el7.x86_64
安装目标:codis-3.2
go版本:go version go1.7.3 linux/amd64
$GOPATH:/data0/gowork
安装步骤
下载 Codis 源代码
[root@hk-fa ~]# mkdir -p $GOPATH/src/github.com/CodisLabs
[root@hk-fa ~]# cd $_ && git clone https://github.com/CodisLabs/codis.git -b release3.2
编译 Codis 源代码
[root@hk-fa CodisLabs]# cd $GOPATH/src/github.com/CodisLabs/codis
[root@hk-fa codis]# make
...
===============================================================================
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@hk-fa codis]# ls bin/
assets codis-admin codis-dashboard codis-fe codis-ha codis-proxy codis-server redis-benchmark redis-cli version
[root@hk-fa codis]# cat bin/version
version = 2017-07-27 11:11:41 +0800 @3e69191beb07821ad5f948986ac02ce4330d0624 @3.2.0-9-g3e69191
compile = 2017-07-31 11:51:44 +0800 by go version go1.7.3 linux/amd64
快速启动
启动codis-dashboard
# 使用 codis-dashboard-admin.sh 脚本启动 dashboard
[root@hk-fa codis]# ./admin/codis-dashboard-admin.sh start
/data0/gowork/src/github.com/CodisLabs/codis/admin/../config/dashboard.toml
starting codis-dashboard ...
# 日志确认,快速启动集群元数据存储使用 filesystem,默认数据路径保存在 /tmp/codis,若启动失败,请检查当前用户是否对该路径拥有读写权限。
[root@hk-fa codis]# tail -100 ./log/codis-dashboard.log.2017-07-31
...
coordinator_name = "filesystem"
coordinator_addr = "/tmp/codis"
...
2017/07/31 11:54:59 fsclient.go:195: [INFO] fsclient - create /codis3/codis-demo/topom OK
...
2017/07/31 11:54:59 main.go:179: [WARN] [0xc4202770e0] dashboard is working ...
2017/07/31 11:54:59 topom.go:429: [WARN] admin start service on [::]:18080
启动codis-proxy
# 使用 codis-proxy-admin.sh 脚本启动 codis-proxy
[root@hk-fa codis]# ./admin/codis-proxy-admin.sh start
/data0/gowork/src/github.com/CodisLabs/codis/admin/../config/proxy.toml
starting codis-proxy ...
# 查看 proxy 日志确认启动是否有异常
[root@hk-fa codis]# tail -100 ./log/codis-proxy.log.2017-07-31
...
2017/07/31 11:59:39 proxy.go:293: [WARN] [0xc4200df340] set sentinels = []
2017/07/31 11:59:39 main.go:336: [WARN] rpc online proxy seems OK
2017/07/31 11:59:40 main.go:226: [WARN] [0xc4200df340] proxy is working ...
启动codis-server
# 使用 codis-server-admin.sh 脚本启动 codis-server
[root@hk-fa codis]# ./admin/codis-server-admin.sh start
/data0/gowork/src/github.com/CodisLabs/codis/admin/../config/redis.conf
starting codis-server ...
# 查看 redis 日志确认启动是否有异常
[root@hk-fa codis]# tail -100 /tmp/redis_6379.log
[root@hk-fa codis]# tail -100 /tmp/redis_6379.log
23395:M 31 Jul 12:02:02.447 # Creating Server TCP listening socket 127.0.0.1:6379: bind: Address already in use
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.9 (3e69191b/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 24342
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
24342:M 31 Jul 14:55:00.024 # Server started, Redis version 3.2.9
24342:M 31 Jul 14:55:00.024 # 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.
24342:M 31 Jul 14:55:00.024 # 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.
24342:M 31 Jul 14:55:00.024 * The server is now ready to accept connections on port 6379
启动codis-fe
# 使用 codis-fe-admin.sh 脚本启动 codis-fe
[root@hk-fa codis]# ./admin/codis-fe-admin.sh start
starting codis-fe ...
already running as process 23410.
# 看 fe 日志确认启动是否有异常
[root@hk-fa codis]# tail -100 ./log/codis-fe.log.2017-07-31
2017/07/31 12:03:46 main.go:101: [WARN] set ncpu = 1
2017/07/31 12:03:46 main.go:104: [WARN] set listen = 0.0.0.0:9090
2017/07/31 12:03:46 main.go:120: [WARN] set assets = /data0/gowork/src/github.com/CodisLabs/codis/bin/assets
2017/07/31 12:03:46 main.go:155: [WARN] set --filesystem = /tmp/codis
2017/07/31 12:03:46 main.go:209: [WARN] option --pidfile = /data0/gowork/src/github.com/CodisLabs/codis/bin/codis-fe.pid
通过fe添加group
通过反向代理模式访问集群管理页面
图1
NEW GROUP 行输入 1,再点击 NEW GROUP 即可 添加 Codis Server,
Add Server 行输入我们刚刚启动的 codis-server 地址,
添加到我们刚新建的 Group,然后再点击 Add Server 按钮即可
图2
通过fe初始化slot
新增的集群 slot 状态是 offline,因此我们需要对它进行初始化(将 1024 个 slot 分配到各个 group),而初始化最快的方法可通过 fe 提供的 rebalance all slots 按钮来做
图3
图4
相关参考
Codis 使用文档
CodisLabs/codis
网友评论