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 [will@weiguoyuan 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的配置文件相同) 在尾部加上节点信息 (节点之前通信),

  将dataDir=/tmp/zookeeper 修改为dataDir=/data/zookeeper 因为tmp目录在机器重启后会清空,所有权限的用户都可以修改

  [will@weiguoyuan 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=/data/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会自动生成/data/zookeeper文件夹
再设置节点的myid myid对应的zoo.cfg的server.ID比如192.168.253.128机器上的myid文件内容为1(3个机器分别生成123
    echo "1" >/data/zookeeper/myid #3个机器上分别执行
echo "2" >/data/zookeeper/myid
echo "3" >/data/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 [will@weiguoyuan 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 [will@weiguoyuan 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 [will@weiguoyuan 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 [will@weiguoyuan 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 [will@weiguoyuan 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 [will@weiguoyuan 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

Codis 集群搭建的更多相关文章

  1. codis集群搭建笔记

    一.安装Linux虚拟机 二.安装go运行环境 https://www.cnblogs.com/xmzncc/p/6218694.html wget http://mirrors.flysnow.or ...

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

    导读 Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有明显的区别 (不支持的命令列表), 上层应用可 ...

  3. 基于.NetCore的Redis5.0.3(最新版)快速入门、源码解析、集群搭建与SDK使用【原创】

    1.[基础]redis能带给我们什么福利 Redis(Remote Dictionary Server)官网:https://redis.io/ Redis命令:https://redis.io/co ...

  4. Codis集群的搭建与使用

    一.简介 Codis是一个分布式的Redis解决方案,对于上层的应用来说,连接Codis Proxy和连接原生的Redis Server没有明显的区别(不支持的命令列表),上层应用可以像使用单机的Re ...

  5. Codis集群的搭建

    Codis集群的搭建与使用   一.简介 Codis是一个分布式的Redis解决方案,对于上层的应用来说,连接Codis Proxy和连接原生的Redis Server没有明显的区别(不支持的命令列表 ...

  6. 使用codis-admin搭建codis集群

    目的 在Redis Codis 部署安装的文章中,介绍了通过fe在web上搭建codis的基本步骤和方法,也介绍了codis-admin的相关说明,为了更好的熟悉codis-admin的使用,本文将使 ...

  7. [Big Data - Codis] Codis集群的搭建与使用

    一.简介 Codis是一个分布式的Redis解决方案,对于上层的应用来说,连接Codis Proxy和连接原生的Redis Server没有明显的区别(不支持的命令列表),上层应用可以像使用单机的Re ...

  8. codis+redis 集群搭建管理

    Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有明显的区别 (不支持的命令列表), 上层应用可以像使 ...

  9. Linux服务器上搭建codis集群之——安装前环境准备

    codis是redis的分布式集群模式,由豌豆荚开源,本文简单记录一下它的集群搭建方法. 首先介绍一下我的实验环境.三台配置相同的虚拟机, [root@test ~]# ip a|grep -w &q ...

随机推荐

  1. 449. Serialize and Deserialize BST——几乎所有树的面试题目都会回到BFS或者DFS,使用BFS,None节点存#

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  2. Jquery 表格操作,记录分页情况下,每一页中被用户勾选的信息

    如下图,一个分页列表,用户可以随意勾选一条或多条信息,然后进行某种操作,如“提交”.但是有个问题:如果勾选了一条信息之后,点[下一页],那么上一页 勾选的条目被刷新掉了. 问题:如果用户需要在第1页, ...

  3. 测试JdbcTemplate执行SQL语句和存储过程

    我在项目中需要使用到oracle的语句片段和存储过程.下面就是我的测试案例: public class DbTest extends BaseTestCase { @Resource JdbcUtil ...

  4. ionicModal中的监听事件

    //添加监听事件angular.module('MyApp').directive('gotTapped', ['$ionicGesture', function($ionicGesture) { r ...

  5. c++ 普通高精除高精

    //codevs3118 高精度练习之除法 //打出了高精除高精,内心有点小激动. //还记得已开始学的时候非常难打 #include<cstdio>#include<cstring ...

  6. Python 条件判断 循环

    age = 20 if age >= 18: print('your age is', age) print('adult') 根据Python的缩进规则,如果if语句判断是True,就把缩进的 ...

  7. FFT快速傅立叶变换的工作原理

    实数DFT,复数DFT,FFTFFT是计算DFT的快速算法,但是它是基于复数的,所以计算实数DFT的时候需要将其转换为复数的格式,下图展示了实数DFT和虚数DFT的情况,实数DFT将时域中N点信号转换 ...

  8. PL/SQL : Procedural Language / Structual Query Language and it is an exrension to SQL.

    SQL is not very flexible and it cannot be made to react differently to differing sutuations easily. ...

  9. Android VersionedGestureDetector手势事件

    今天研究了一下PhotoView,发现里面的自定义的手势事件可以支持所有的SDK版本,该事件可以实现拖拽.滑动.缩放功能.下面直接上代码: public abstract class Versione ...

  10. android Xutils dbutils 注解

    xUtils DbUtils 关于实体类注解 汇总 RockyZhang 发布于 1年前,共有 0 条评论 先来官方demo DbUtils db = DbUtils.create(this);    ...