redis 集群管理工具codis的安装

 

摘要:无意间在github上看到的一个redis集群管理工具,对于我这种手残党来说是莫大的福音,毕竟自己搭建的集群会出现各种各样的问题,有这个统一管理的工具还是很不错的。codis有两种安装方式一种是直接下载编译好的,另一种是自己手动编译。我推荐用直接编译好的,毕竟自己编译可能会出现各种各样的玄学bug

 

编译好的下载地址 请对应下载  下载地址

编译安装,由于我是直接下载的编译好的没有编译安装,所以直接照搬的文档上的过程,手动狗头保命

1. 安装 Go 运行环境 

安装完成后可以运行下列命令进行检测:

$ go version
go version go1.7.3 linux/amd64

 

2. 设置编译环境

注意 $GOPATH 是本机所有第三方库 go 项目所在目录,Codis 仅是其中之一。

添加 $GOPATH/bin 到 $PATH,例如:PATH=$PATH:$GOPATH/bin

$ go env GOPATH
/home/codis/gopath

 

3. 下载 Codis 源代码

Codis 源代码需要下载到 $GOPATH/src/github.com/CodisLabs/codis

$ mkdir -p $GOPATH/src/github.com/CodisLabs
$ cd $_ && git clone https://github.com/CodisLabs/codis.git -b release3.2

 

4. 编译 Codis 源代码

  • 直接通过 make 进行编译,会看到如下输出:
    $ cd $GOPATH/src/github.com/CodisLabs/codis
    $ make
    make -j -C extern/redis-3.2.8/
    ... ...
    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-fe ./cmd/fe
    
    $ ls bin/
    total 69124
    drwxr-xr-x 4 codis codis     4096 Jan  4 14:55 assets
    -rwxr-xr-x 1 codis codis 17600752 Jan  4 14:55 codis-admin
    -rwxr-xr-x 1 codis codis 18416320 Jan  4 14:55 codis-dashboard
    -rwxr-xr-x 1 codis codis  9498040 Jan  4 14:55 codis-fe
    -rwxr-xr-x 1 codis codis 11057280 Jan  4 14:55 codis-proxy
    -rwxr-xr-x 1 codis codis  4234432 Jan  4 14:55 codis-server
    -rw-r--r-- 1 codis codis      148 Jan  4 14:55 version
    ... ...
    
    $ cat bin/version
    version = 2016-01-03 14:53:22 +0800 @51f06ae3b58a256a58f857f590430977638846a3
    compile = 2016-01-04 15:00:17 +0800 by go version go1.5.2 linux/amd64

       

    1. 快速启动

    2分钟快速构建一个单机版测试 codis 集群,无任何外部组件依赖.

    源码中 admin 文件夹提供了一系列脚本以便快速启动、停止各个组件,提高运维效率。

    启动codis-dashboard

    使用 codis-dashboard-admin.sh 脚本启动 dashboard,并查看 dashboard 日志确认启动是否有异常。

    ./admin/codis-dashboard-admin.sh start
     tail -100 ./log/codis-dashboard.log.2017-04-08
    
    2017/04/08 15:16:57 fsclient.go:197: [INFO] fsclient - create /codis3/codis-demo/topom OK
    2017/04/08 15:16:57 main.go:140: [WARN] [0xc42025f7a0] dashboard is working ...
    2017/04/08 15:16:57 topom.go:424: [WARN] admin start service on [::]:18080
    

    快速启动集群元数据存储使用 filesystem,默认数据路径保存在 /tmp/codis,若启动失败,请检查当前用户是否对该路径拥有读写权限。

    启动codis-proxy

    使用 codis-proxy-admin.sh 脚本启动 codis-proxy,并查看 proxy 日志确认启动是否有异常。

    ./admin/codis-proxy-admin.sh start
    tail -100 ./log/codis-proxy.log.2017-04-08
    
    2017/04/08 15:39:37 proxy.go:293: [WARN] [0xc4200df760] set sentinels = []
    2017/04/08 15:39:37 main.go:320: [WARN] rpc online proxy seems OK
    2017/04/08 15:39:38 main.go:210: [WARN] [0xc4200df760] proxy is working ...
    

    启动codis-server

    使用 codis-server-admin.sh 脚本启动 codis-server,并查看 redis 日志确认启动是否有异常。

    ./admin/codis-server-admin.sh start
    tail -100 /tmp/redis_6379.log 
    
    5706:M 08 Apr 16:04:11.748 * DB loaded from disk: 0.000 seconds
    5706:M 08 Apr 16:04:11.748 * The server is now ready to accept connections on port 6379
    

    redis.conf 配置中 pidfile、logfile 默认保存在 /tmp 目录,若启动失败,请检查当前用户是否有该目录的读写权限。

    启动codis-fe

    使用 codis-fe-admin.sh 脚本启动 codis-fe,并查看 fe 日志确认启动是否有异常。

    ./admin/codis-fe-admin.sh start
    tail -100 ./log/codis-fe.log.2017-04-08
    
    2017/04/08 16:12:13 main.go:100: [WARN] set ncpu = 1
    2017/04/08 16:12:13 main.go:103: [WARN] set listen = 0.0.0.0:9090
    2017/04/08 16:12:13 main.go:115: [WARN] set assets = /home/codis/go/src/github.com/CodisLabs/codis/admin/../bin/assets
    2017/04/08 16:12:13 main.go:153: [WARN] set --filesystem = /tmp/codis
    

     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
redis-cluster-tool 是一个非常便利的 Redis 集群管理工具。help        Usage: redis-cluster-tool [-?hVds] [-v verbosity level] [-o output file]                  [-c conf file] [-a addr] [-i interval]                  [-p pid file] [-C command] [-r redis role]                  [-t thread number] [-b buffer size]    Options:      -h, --help             : this help      -V, --version          : show version and exit      -d, --daemonize        : run as a daemon      -s, --simple           : show the output not in detail      -v, --verbosity=N      : set logging level (default: 5, min: 0, max: 11)      -o, --output=S         : set logging file (default: stderr)      -c, --conf-file=S      : set configuration file (default: conf/rct.yml)      -a, --addr=S           : set redis cluster address (default: 127.0.0.1:6379)      -i, --interval=N       : set interval in msec (default: 1000 msec)      -p, --pid-file=S       : set pid file (default: off)      -C, --command=S        : set command to execute (default: cluster_state)      -r, --role=S           : set the role of the nodes that command to execute on (default: all, you can input: all, master or slave)      -t, --thread=N         : set how many threads to run the job(default: 8)      -b, --buffer=S         : set buffer size to run the job (default: 1048576 byte, unit:G/M/K)        Commands:        cluster_state                 :Show the cluster state.        cluster_used_memory           :Show the cluster used memory.        cluster_keys_num              :Show the cluster holds keys num.        slots_state                   :Show the slots state.        node_slot_num                 :Show the node hold slots number.        new_nodes_name                :Show the new nodes name that not covered slots.        cluster_rebalance             :Show the cluster how to rebalance.        flushall                      :Flush all the cluster.        cluster_config_get            :Get config from every node in the cluster and check consistency.        cluster_config_set            :Set config to every node in the cluster.        cluster_config_rewrite        :Rewrite every node config to echo node for the cluster.        node_list                     :List the nodes            del_keys                      :Delete keys in the cluster. The keys must match a given glob-style pattern.(This command not block the redis)ExampleGet the cluster state:        $redis-cluster-tool -a 127.0.0.1:34501 -C cluster_state -r master    master[127.0.0.1:34504] cluster_state is ok     master[127.0.0.1:34501] cluster_state is ok     master[127.0.0.1:34502] cluster_state is ok     master[127.0.0.1:34503] cluster_state is ok     all nodes cluster_state is ok    Get the cluster used memory:    $redis-cluster-tool -a 127.0.0.1:34501 -C cluster_used_memory -r master    master[127.0.0.1:34504] used 195 M 25%    master[127.0.0.1:34501] used 195 M 25%    master[127.0.0.1:34502] used 195 M 25%    master[127.0.0.1:34503] used 195 M 25%    cluster used 780 MRebalance the cluster slots:    $redis-cluster-tool -a 127.0.0.1:34501 -C cluster_rebalance    --from e1a4ba9922555bfc961f987213e3d4e6659c9316 --to 785862477453bc6b91765ffba0b5bc803052d70a --slots 2048    --from 437c719f50dc9d0745032f3b280ce7ecc40792ac --to cb8299390ce53cefb2352db34976dd768708bf64 --slots 2048    --from a497fc619d4f6c93bd4afb85f3f8a148a3f35adb --to a0cf6c1f12d295cd80f5811afab713cdc858ea30 --slots 2048    --from 0bdef694d08cb3daab9aac518d3ad6f8035ec896 --to 471eaf98ff43ba9a0aadd9579f5af1609239c5b7 --slots 2048Then you can use "redis-trib.rb reshard --yes --from e1a4ba9922555bfc961f987213e3d4e6659c9316 --to 785862477453bc6b91765ffba0b5bc803052d70a --slots 2048 127.0.0.1:34501" to rebalance the cluster slots     Flushall the cluster:    $redis-cluster-tool -a 127.0.0.1:34501 -C flushall -s    Do you really want to execute the "flushall"?    please input "yes" or "no" :        yes    OKGet a config from every node in cluster:    $redis-cluster-tool -a 127.0.0.1:34501 -C "cluster_config_get maxmemory" -r master    master[127.0.0.1:34501] config maxmemory is 1048576000 (1000MB)    master[127.0.0.1:34502] config maxmemory is 1048576000 (1000MB)    master[127.0.0.1:34503] config maxmemory is 1048576000 (1000MB)    master[127.0.0.1:34504] config maxmemory is 1048576000 (1000MB)    All nodes config are Consistent    cluster total maxmemory: 4194304000 (4000MB)Set a config from every node in cluster:    $redis-cluster-tool -a 127.0.0.1:34501 -C "cluster_config_set maxmemory 10000000" -s    Do you really want to execute the "cluster_config_set"?    please input "yes" or "no" :    yes        OKDelete keys in the cluster:    $redis-cluster-tool -a 127.0.0.1:34501 -C "del_keys abc*"    Do you really want to execute the "del_keys"?    please input "yes" or "no" :    yes    delete keys job is running...    delete keys job finished, deleted: 999999 keys, used: 4 s 标签:redis

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值