Codis 集群搭建

Codis 集群搭建

1 安装go1.3.1 CentOS 7.0 安装go 1.3.1

1.1 下载go安装包 golang中国上下载 下载到Downloads下

1.2 解压 tar -zxf go1.3.1.linux-amd64.tar.gz -C /usr/local/

1.3 修改 etc/profile 文件在文件后加入 export的几行,在unset下面直接加,不要有空行

   unset i
   unset -f pathmunge
   export GOROOT=/usr/local/go
   export PATH=$GOROOT/bin:$PATH
   export GOPATH=/data/gopkg

1.4 然后执行 source /etc/profile 刷新配置文件

1.5 运行命令 go 测试go是否安装成功

1.6 在usr/local/go/test 下 运行 go run helloworld.go 测试

2 安装git yum -y install git

3 配置hosts文件 3个机器都是相同的配置

   cd /etc
   vi hosts

   [[email protected] etc]$ more hosts
   127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
   ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
   10.64.4.57  weiguoyuan
   10.64.4.95  weiguoyuan2
   10.64.4.99  hemy
还需要配置windows下的hosts文件 否则在windows下的jodis客户端访问codis集群机器找不到主机名对应的ip
   C:\Windows\System32\drivers\etc 

   # Copyright (c) 1993-2009 Microsoft Corp.
   #
   # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
   #
   # This file contains the mappings of IP addresses to host names. Each
   # entry should be kept on an individual line. The IP address should
   # be placed in the first column followed by the corresponding host name.
   # The IP address and the host name should be separated by at least one
   # space.
   #
   # Additionally, comments (such as these) may be inserted on individual
   # lines or following the machine name denoted by a ‘#‘ symbol.
   #
   # For example:
   #
   #      102.54.94.97     rhino.acme.com          # source server
   #       38.25.63.10     x.acme.com              # x client host

   # localhost name resolution is handled within DNS itself.
   #    127.0.0.1       localhost
   #    ::1             localhost

   10.64.4.57   weiguoyuan
   10.64.4.95   weiguoyuan2
   10.64.4.99   hemy

4 安装zookeeper 集群 3个机器上每个机器上都安装一个zookeeper

4.1 官网下载 下载到Downloads下

4.2 tar -xzf zookeeper.**.tar.gz -C /usr/local

4.3 cd /usr/local/zookeeper*/conf

4.4 cp zookeeper.cfg zoo.cfg

4.5 vi zoo.cfg(三个zookeeper的配置文件相同) 在尾部加上节点信息 (节点之前通信)

  [[email protected] conf]$ more zoo.cfg
  # The number of milliseconds of each tick
  tickTime=2000
  # The number of ticks that the initial
  # synchronization phase can take
  initLimit=10
  # The number of ticks that can pass between
  # sending a request and getting an acknowledgement
  syncLimit=5
  # the directory where the snapshot is stored.
  # do not use /tmp for storage, /tmp here is just
  # example sakes.
  dataDir=/tmp/zookeeper
  # the port at which the clients will connect
  clientPort=2181
  # the maximum number of client connections.
  # increase this if you need to handle more clients
  #maxClientCnxns=60
  #
  # Be sure to read the maintenance section of the
  # administrator guide before turning on autopurge.
  #
  # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
  #
  # The number of snapshots to retain in dataDir
  #autopurge.snapRetainCount=3
  # Purge task interval in hours
  # Set to "0" to disable auto purge feature
  #autopurge.purgeInterval=1
  server.1=10.64.4.57:2888:3888
  server.2=10.64.4.95:2888:3888
  server.3=10.64.4.99:2888:3888

4.6 配置zookeeper节点id

先启动3个机器的zookeeper zookeeper会自动生成/tmp/zookeeper文件夹
再设置节点的myid myid对应的zoo.cfg的server.ID比如192.168.253.128机器上的myid文件内容为1(3个机器分别生成123
    echo "1" >/tmp/zookeeper/myid #3个机器上分别执行
    echo "2" >/tmp/zookeeper/myid
    echo "3" >/tmp/zookeeper/myid

4.7 启动zookeeper

    cd /usr/local/zookeeper/bin
   ./zkServer.sh start
   ./zkServer.sh stop
   ./zkServer.sh status 查看节点状态有 leader,fellower

5 安装codis 编译 3个机器上都需安装

    go get -d github.com/wandoulabs/codis

    cd $GOPATH/src/github.com/wandoulabs/codis

    ./bootstrap.sh (这步比较慢 失败了可以重试)

    make gotest

Codis 配置

1 官方文档 命令方式配置 https://github.com/wandoulabs/codis/blob/master/doc/tutorial_zh.md

2 编写脚本 脚本方式配置

2.1 配置config.ini 3个机器都得配置

   cd /data/gopkg/src/github.com/wandoulabs/codis/sample
   vi config.ini

   [[email protected] sample]$ more config.ini
   zk=10.64.4.57:2181,10.64.4.95:2181,10.64.4.99:2181 #zookeeper列表
   product=test
   proxy_id=proxy_1 #3个机器上分别是 proxy_1 proxy_2 proxy_3
   net_timeout=5
   dashboard_addr=weiguoyuan:18087
   coordinator=zookeeper

2.2 配置 start_redis.sh 3个机器都要配置

   cd /data/gopkg/src/github.com/wandoulabs/codis/sample
   vi start_redis.sh

   [[email protected] sample]$ more start_redis.sh
   #!/bin/sh
   nohup ../bin/codis-server ./redis_conf/6380.conf &> ./log/redis_6380.log &
   nohup ../bin/codis-server ./redis_conf/6381.conf &> ./log/redis_6381.log &
   nohup ../bin/codis-server ./redis_conf/6382.conf &> ./log/redis_6382.log &
   nohup ../bin/codis-server ./redis_conf/6383.conf &> ./log/redis_6383.log &

   echo "sleep 3s"
   sleep 3
   tail -n 30 ./log/redis_6380.log
   tail -n 30 ./log/redis_6381.log
   tail -n 30 ./log/redis_6382.log
   tail -n 30 ./log/redis_6383.log

2.3 配置 add_group.sh 只需一个机器配置

    cd /data/gopkg/src/github.com/wandoulabs/codis/sample
    vi start_redis.sh

    [[email protected] sample]$ more add_group.sh
    #!/bin/sh

    echo "add group 1 with a master(localhost:6381), Notice: do not use localhost when in produciton"
    ../bin/codis-config -c config.ini -L ./log/cconfig.log server add 1 10.64.4.57:6380 master
    ../bin/codis-config -c config.ini -L ./log/cconfig.log server add 1 10.64.4.95:6380 slave
    ../bin/codis-config -c config.ini -L ./log/cconfig.log server add 1 10.64.4.99:6380 slave
    ../bin/codis-config -c config.ini -L ./log/cconfig.log server add 2 10.64.4.57:6381 master
    ../bin/codis-config -c config.ini -L ./log/cconfig.log server add 2 10.64.4.95:6381 slave
    ../bin/codis-config -c config.ini -L ./log/cconfig.log server add 2 10.64.4.99:6381 slave

    echo "add group 2 with a master(localhost:6382), Notice: do not use localhost when in produciton"
    ../bin/codis-config -c config.ini -L ./log/cconfig.log server add 3 10.64.4.95:6382 master
    ../bin/codis-config -c config.ini -L ./log/cconfig.log server add 3 10.64.4.57:6382 slave
    ../bin/codis-config -c config.ini -L ./log/cconfig.log server add 3 10.64.4.99:6382 slave
    ../bin/codis-config -c config.ini -L ./log/cconfig.log server add 4 10.64.4.99:6383 master
    ../bin/codis-config -c config.ini -L ./log/cconfig.log server add 4 10.64.4.95:6383 slave
    ../bin/codis-config -c config.ini -L ./log/cconfig.log server add 4 10.64.4.57:6383 slave

2.4 配置 initslot.sh 只需一个机器配置

    cd /data/gopkg/src/github.com/wandoulabs/codis/sample
       vi initslot.sh

       [[email protected] sample]$ more initslot.sh
       #!/bin/sh
       echo "slots initializing..."
       ../bin/codis-config -c config.ini slot init -f
       echo "done"

       echo "set slot ranges to server groups..."
       ../bin/codis-config -c  config.ini slot range-set 0 255 1 online
       ../bin/codis-config -c  config.ini slot range-set 256 511 2 online
       ../bin/codis-config -c  config.ini slot range-set 512 767 3 online
       ../bin/codis-config -c  config.ini slot range-set 768 1023 4 online
       echo "done"

2.5 修改 start_proxy.sh 机器1 不用修改另外两个机器修改

       cd /data/gopkg/src/github.com/wandoulabs/codis/sample
       vi start_proxy.sh

       [[email protected] sample]$ more start_proxy.sh
       #!/bin/sh
       echo "shut down proxy_1..."
       ../bin/codis-config -c config.ini proxy offline proxy_1 //修改这里
       echo "done"

       echo "start new proxy..."
       nohup ../bin/codis-proxy --log-level info -c config.ini -L ./log/proxy.log  --cpu=8 --addr=0.0.0.0:190
       00 --http-addr=0.0.0.0:11000 &
       echo "done"

       echo "sleep 3s"
       sleep 3
       tail -n 30 ./log/proxy.log

2.6 修改 set_proxy_online.sh 机器1 不用修改另外两个机器修改

  cd /data/gopkg/src/github.com/wandoulabs/codis/sample
  vi set_proxy_online.sh

  [[email protected] sample]$ more set_proxy_online.sh
  #!/bin/sh
  echo "set proxy_1 online"
  ../bin/codis-config -c config.ini proxy online proxy_1 #修改这里
  echo "done"

Codis 集群启动

1 启动3个机器

2 关闭3个机器防火墙

CentOS防火墙分为2中 firewalld 和 iptables
如果是firewalld systemctl stop firewalld.service
如果是iptables  systemctl stop iptables.service

3 启动3个机器的zookeeper

cd /usr/local/zookeeper/bin ./zkServer.sh start

4 在没有配置add_group.sh的两个机器上(机器2和3)

cd /data/gopkg/src/github.com/wandoulabs/codis/sample ./start_redis.sh

5 在配置add_group.sh的机器上(机器1) 上

cd /data/gopkg/src/github.com/wandoulabs/codis/sample ./startall.sh

6 在机器1上打开火狐浏览器 打开网址 http://localhost:18087/admin 可以看到节点 代理信息

7 在机器2和3上分别启动代理

cd /data/gopkg/src/github.com/wandoulabs/codis/sample ./start_proxy.sh

8 在机器1上浏览器http://localhost:18087/admin的代理信息中 设置proxy_2 proxy_3 online

9 可以通过windows上的jodis客户端访问Codis集群了

利用Asis2生成 Webservice服务

http://www.cnblogs.com/weixiaole/p/4372319.html

codis-ha

官方文档 https://github.com/ngaut/codis-ha

go get github.com/ngaut/codis-ha

cd codis-ha

go build

codis-ha --codis-config=localhost:18087 --productName=test

参考

   http://navyaijm.blog.51cto.com/4647068/1637688
   https://github.com/wandoulabs/codis/blob/master/doc/tutorial_zh.md
时间: 2024-08-30 02:07:32

Codis 集群搭建的相关文章

codis集群搭建

Codis简介(来自开源中国社区) Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 CodisProxy 和连接原生的 Redis Server 没有明显的区别 (不支持的命令列表), 上层应用可以像使用单机的 Redis 一样使用, Codis 底层会处理请求的转发, 不停机的数据迁移等工作, 所有后边的一切事情, 对于前面的客户端来说是透明的, 可以简单的认为后边连接的是一个内存无限大的 Redis 服务. Codis 由四部分组成: Codis Proxy

实战Centos系统部署Codis集群服务

导读 Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有明显的区别 (不支持的命令列表), 上层应用可以像使用单机的 Redis 一样使用, Codis 底层会处理请求的转发, 不停机的数据迁移等工作, 所有后边的一切事情, 对于前面的客户端来说是透明的, 可以简单的认为后边连接的是一个内存无限大的 Redis 服务. 一.Codis简介 Codis 是 Wandoujia Infrastructu

Codis集群的搭建与使用

一.简介 Codis是一个分布式的Redis解决方案,对于上层的应用来说,连接Codis Proxy和连接原生的Redis Server没有明显的区别(不支持的命令列表),上层应用可以像使用单机的Redis一样使用,Codis底层会处理请求的转发,不停机的数据迁移等工作,所有后边的一切事情,对于前面客户端来说是透明的,可以简单的认为后边连接是一个内存无限大的Redis服务. Codis架构图: 以上我们可以看到codis-proxy是单个节点的,因为我们可以通过结合keepalived来实现高可

codis+redis 集群搭建管理

Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有明显的区别 (不支持的命令列表), 上层应用可以像使用单机的 Redis 一样使用, Codis 底层会处理请求的转发, 不停机的数据迁移等工作, 所有后边的一切事情, 对于前面的客户端来说是透明的, 可以简单的认为后边连接的是一个内存无限大的 Redis 服务. Codis 由四部分组成: Codis Proxy (codis-proxy) Cod

codis集群部署实战

一.概要 1.折腾codis集群已经快两个月了,感谢一直以来codis的作者刘奇和黄东旭的耐心支持,在这里给你们点个赞,现在我司已经有一个业务跑在了codis集群上,目前只是切了整个业务的10%的量,预计下周会全量切到codis上,这个时候大家肯定特别想知道codis稳定吗?有没有什么bug啊,你想知道的也是我想知道的,搞起吧,用了才知道,反正目前我们这没发现啥问题,一些小的问题已经及时联系作者改掉了,好吧,不扯淡了,写这篇文章的目的是帮助想了解codis的初学者快速部署(官方的部署文档对应运维

redis3.0集群搭建

Redis集群搭建 redis cluster介绍 节点自动发现.集群容错slave选举.Cluster管理.集群配置管理. 集群中的每个Redis节点需要2个TCP连接端口,如6379端口用于Client连接,16379端口用于集群数据通信 集群采用Hash Slot方案,而不是一致性哈希,共16384个Hashslot.如果有3台机器,那么NodeA在0-5500,NodeB 在5501-11000,NodeC在11001-16384.这种设计下,添加,删除新Node比较方便. 由于Hash

rabbitmq集群搭建(centos6.5)

一:rabbitmq的安装: 参考:http://www.blogjava.net/hellxoul/archive/2014/06/25/415135.html http://blog.haohtml.com/archives/15249 说明:修改机器名字后再安装(为后面集群做准备) vi /etc/sysconfig/network 修改名字 vi /etc/hosts 修改地址映射表,如192.168.1.112   rabbitmq-node1.com rabbitmq-node1 #

linux 下heartbeat简单高可用集群搭建

Heartbeat 项目是 Linux-HA 工程的一个组成部分,它实现了一个高可用集群系统.通过Heartbeat我们可以实现双机热备,以实现服务的持续性. linux下基于heartbeat的简单web服务的高可用集群搭建 首先规划好两台主机作为heartbeat的双机热备,命名为node1.lvni.cc(主) ;node2.lvni.cc, node1的eth0IP :192.168.157.148  Vip eth0:0:192.168.157.149 node2的eth0IP :19

mysql5.7 MGR集群搭建

mysql5.7 MGR集群搭建部署 此文章由队员(谆谆)拟写 此文章来自 乌龟运维 官网 wuguiyunwei.com QQ群 602183872 最近看了一下mysql5.7的MGR集群挺不错的,有单主和多主模式,于是乎搭建测试了一下效果还不错,我指的不错是搭建和维护方面都比较简单.网上绝大多数都是单主模式,当然我这里也是,为了加深印象,特意记录一下搭建过程,等以后再去尝试多主模式,相信大家现在数据库的瓶颈基本都是在写,读写分离虽然是一种可行的解决方案,但是如果数据量很大,写一样会有问题,