• codis 部署和测试



    git clone https://github.com/CodisLabs/codis.git

    1:下载go环境 官网:https://golang.org/doc/install
    wget https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz

    tar -C /usr/local -xzf go1.6.2.linux-amd64.tar.gz

    cd /usr/local/go

    cat >> /etc/profile <<EOF
    export GOROOT=/usr/local/go
    export GOPATH=/workspace/golang
    export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
    export CODIS_HOME=$GOPATH/src/github.com/CodisLabs/codis
    export GO15VENDOREXPERIMENT=0
    EOF



    source /etc/profile



    2:下载安装codis 官网:https://github.com/CodisLabs/codis/blob/master/doc/tutorial_zh.md  根据官网推荐采用这种方式,而不是git clone ...codis
    go get -u -d github.com/CodisLabs/codis
    go get github.com/tools/godep

    cd $GOPATH/src/github.com/CodisLabs/codis
    make
    make gotest
    #mkdir -p /usr/local/codis/{logs,conf,scripts}
    #mkdir -p /data/codis_server/{logs,conf,data}

    cd $GOPATH/src/github.com/CodisLabs/codis/bin


    3:安装zookeeper
    wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz  -P /opt
    tar -C /opt -xvf /opt/zookeeper-3.4.6.tar.gz  
    cd /opt/zookeeper-3.4.6/conf
    cp zoo_sample.cfg zoo.cfg
    /opt/zookeeper-3.4.6/bin/zkServer.sh start

    read -p "请输入zookeeper的地址: " zookeeper-ip

    sed -i  's/192.168.0.123/$zookeeper-ip/g' config.ini


    ###assets //dashboard的静态文件目录
    ###codis-config codis命令式配置管理组件
    ###codis-proxy codis 代理也就是核心组件
    ###codis-server codis基于redis2.8.21定制版redis


    mkdir /workspace/golang/src/github.com/CodisLabs/codis/wk
    cp /workspace/golang/src/github.com/CodisLabs/codis/config.ini  /workspace/golang/src/github.com/CodisLabs/codis/wk/

    4:启动 dashboard(codis-config上操作)
    cd $CODIS_HOME && ./bin/codis-config -c $CODIS_HOME/wk/config.ini dashboard &

    可以从浏览器打开http://192.168.16.239:18087/admin/

    5:初始化 slot,该命令会在zookeeper上创建slot相关信息
    cd $CODIS_HOME &&  ./bin/codis-config -c $CODIS_HOME/wk/config.ini slot init &

    6:启动 Codis Redis , 和官方的Redis Server参数一样(codis-server上操作)
    cp extern/redis-2.8.21/redis.conf wk/
    cd $CODIS_HOME && ./codis-server ../extern/redis-2.8.21/redis.conf                    (端口6379)作为16.241的6380的master
                      ./codis-server ../extern/redis-2.8.21/redis6380.conf                   (端口6380)作为16.241的6379的slave

    7:添加 Redis Server Group , 每一个 Server Group 作为一个 Redis 服务器组存在, 只允许有一个 master,
         可以有多个 slave, group id 仅支持大于等于1的整数(codis-config上操作)
        ./codis-config -c ../wk/config.ini server add 1 192.168.16.239:6379 master
        ./codis-config -c ../wk/config.ini server add 1 192.168.16.241:6380 slave
        
        
        ./codis-config -c ../wk/config.ini server add 2 192.168.16.241:6379 master
        ./codis-config -c ../wk/config.ini server add 2 192.168.16.239:6380 slave
        

    8: 启动241上面的redis服务,作为slave
    /codis-server ../extern/redis-2.8.21/redis.conf                作为16.239的6380 的master
    /codis-server ../extern/redis-2.8.21/redis6380.conf              作为16.239的6379 的slave

    ****************注意,不需要从redis.conf 去配置slave,必须用codis-server 去启动redis***************







    [root@shell bin]# 2016/04/28 14:16:48 dashboard.go:160: [INFO] dashboard listening on addr: :18087
    2016/04/28 14:16:49 dashboard.go:234: [PANIC] create zk node failed
    [error]: dashboard already exists: {"addr": "192.168.16.239:18087", "pid": 2280}
    [stack]:
        3   /workspace/golang/src/github.com/CodisLabs/codis/cmd/cconfig/dashboard.go:234
                main.runDashboard
        2   /workspace/golang/src/github.com/CodisLabs/codis/cmd/cconfig/dashboard.go:54
                main.cmdDashboard
        1   /workspace/golang/src/github.com/CodisLabs/codis/cmd/cconfig/main.go:85
                main.runCommand
        0   /workspace/golang/src/github.com/CodisLabs/codis/cmd/cconfig/main.go:152
                main.main
            ... ...
            
    解决:
    ./zkCli.sh
    [zk: localhost:2181(CONNECTED) 11] rmr  /zk/codis

    原因:
    2016/04/28 14:52:44 dashboard.go:143: [INFO] dashboard node created: /zk/codis/db_wk/dashboard, {"addr": "192.168.16.239:18087", "pid": 8578}
    2016/04/28 14:52:44 dashboard.go:144: [WARN] ********** Attention **********
    2016/04/28 14:52:44 dashboard.go:145: [WARN] You should use `kill {pid}` rather than `kill -9 {pid}` to stop me,
    2016/04/28 14:52:44 dashboard.go:146: [WARN] or the node resisted on zk will not be cleaned when I'm quiting and you must remove it manually


    9:设置 server group 服务的 slot 范围

    Codis 采用 Pre-sharding 的技术来实现数据的分片, 默认分成 1024 个 slots (0-1023), 对于每个key来说, 通过以下公式确定所属的
    Slot Id : SlotId = crc32(key) % 1024 每一个 slot 都会有一个且必须有一个特定的 server group id 来表示这个 slot 的数据由哪个 server group 来提供

    [root@shell bin]# ./codis-config  -c ../wk/config.ini slot -h
    usage:
            codis-config slot init [-f]
            codis-config slot info <slot_id>
            codis-config slot set <slot_id> <group_id> <status>
            codis-config slot range-set <slot_from> <slot_to> <group_id> <status>
            codis-config slot migrate <slot_from> <slot_to> <group_id> [--delay=<delay_time_in_ms>]
            codis-config slot rebalance [--delay=<delay_time_in_ms>]
            
    [root@shell bin]# ./codis-config  -c ../wk/config.ini slot  range-set 0 511 1 online
    {
      "msg": "OK",
      "ret": 0
    }

    到浏览器上看看效果

    或者
    [root@shell bin]# ./codis-config  -c ../wk/config.ini slot  info 1
    {
      "group_id": 1,
      "id": 1,
      "product_name": "wk",
      "state": {
        "last_op_ts": "0",
        "migrate_status": {
          "from": -1,
          "to": -1
        },
        "status": "online"
      }
     
    10:启动 codis-proxy

    [root@shell bin]# ./codis-proxy -c ../wk/config.ini -L ./log/proxy.log  --cpu=4 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &

      _____  ____    ____/ /  (_)  _____
     / ___/ / __   / __  /  / /  / ___/
    / /__  / /_/ / / /_/ /  / /  (__  )
    \___/  \____/  \__,_/  /_/  /____/


    在241上启动第二个代理服务器
     ./codis-proxy -c ../wk/config.ini -L ./log/proxy.log  --cpu=4 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &
     
     在浏览器上看到proxy_2是offile状态,如果用命令去启动proxy_2 online状态,则提示下面错误,需要去启动dashboard,我们直接在界面上启动为online状态

    [root@zabbix bin]# ./codis-config -c ../wk/config.ini proxy online proxy_2
    2016/05/03 13:43:12 utils.go:49: [ERROR] can't connect to dashboard, please check 'dashboard_addr' is corrent in config file
    [stack]:


  • 相关阅读:
    docker 容器与主机之间的数据copy
    vim 中如何快速注释和取消注释
    java查找字符中的某个内容并替换
    linux正则表达式
    数据流重定向与管道命令
    linux杂七杂八
    linux变量
    redis常用命令操作
    redis基本操作介绍
    redis数据结构
  • 原文地址:https://www.cnblogs.com/liangsky/p/5546129.html
Copyright © 2020-2023  润新知