redis集群搭建 Installing Redis Cluster

打印 上一主题 下一主题

主题 786|帖子 786|积分 2358

简介:

Redis的集群模式实现了数据的分布式存储,每个节点存储不同的数据,实现数据动态扩容。
优点:无中心节点架构,数据按照slot分布在多个节点上
缺点:不支持多数据库
 
1、安装包准备
  1、redis-4.0.1.tar.gz  redis源文件
     下载地址:https://download.redis.io/releases/redis-4.0.1.tar.gz
  2、ruby-2.5.9.tar.gz  ruby安装包
2、安装机器准备
  三台机器:192.168.43.120  192.168.43.130  192.168.43.140   3主3从,每台机器两个节点
 
3、目录创建和redis编译
  a、在120机器上创建目录:/opt/soft
  b、进入soft目录,执行 wget https://download.redis.io/releases/redis-4.0.1.tar.gz 下载redis源文件
  c、执行 tar -zxvf redis-4.0.1.tar.gz 解压源文件包,解压后得到redis-4.0.1目录
  d、cd redis-4.0.1 目录,编译源文件,执行命令:make
  如果出现以下错误:
  
 
  说明没有gcc,运行 yum install  gcc
  再执行make命令,如果出现以下错误:
  
  则执行命令:make MALLOC=libc
4、节点创建
  每台机器配置两个节点 7000和7001
  创建目录  mkdir cluster
  
   进入cluster目录,分别创建7000和7001目录
  
   复制配置文件,把redis.conf分别复制到7000和7001下
  
    增加配置:
  分别在7000和7001下的redis.conf添加如下配置
  
  
  1. bind 192.168.43.140
  2. port 7000
  3. #masterauth 123456
  4. #requirepass 123456
  5. cluster-enabled yes
  6. cluster-config-file nodes-7000.conf
  7. cluster-node-timeout 5000
  8. appendonly yes
复制代码
    保存退出
5、启动节点
  执行命令分别启动7000和7001节点:
  ./src/redis-server /opt/soft/redis-4.0.1/cluster/7000/redis.conf &
  ./src/redis-server /opt/soft/redis-4.0.1/cluster/7001/redis.conf &
  启动成功如下:
  
       其它两台机器一样操作
 6、创建集群(只需要在一台机器上执行)
  a、安装ruby
  tar -zxvf ruby-2.5.9.tar.gz
  cd ruby-2.5.9/
  ./configure --prefix=/usr/local/ruby
  make && make install
  查看安装后的版本
  /usr/local/ruby/bin/ruby -v
  设置环境变量
  vi /etc/profile
  export PATH=$PATH:/usr/local/ruby/bin:
  source /etc/profile
 
    b、安装gem
  运行命令gem install redis
  
 
    出现如下错误说明确实zlib库
  yum install zlib-devel
  集成zlib库到ruby环境
  cd /opt/soft/ruby-2.5.9/ext/zlib/
  ruby extconf.rb
  
    操作之前修改Makefile里的文件
  vi Makefile
  在文件最后找到:zlib.o: $(top_srcdir)/include/ruby.h   修改为  zlib.o: ../../include/ruby.h  保存退出
  执行命令 make && make install
  执行命令gem install redis 如果报一下错误
  
 
    安装 openssl-devel
  yum install openssl-devel
  集成openssl库到ruby
  cd /opt/soft/ruby-2.5.9/ext/openssl/
  ruby extconf.rb
  修改Makefile 里面的    
  ossl.o: $(top_srcdir)/include/ruby.h  修改为 ossl.o: ../../include/ruby.h  
  ossl_asn1.o: $(top_srcdir)/include/ruby.h 修改为 ossl_asn1.o: ../../include/ruby.h
  ossl_bio.o: $(top_srcdir)/include/ruby.h   
  ossl_bn.o: $(top_srcdir)/include/ruby.h
  ossl_cipher.o: $(top_srcdir)/include/ruby.h
  等等全部修改
  保存退出
  执行命令 make && make install
  最后 运行命令gem install redis 
  如果卡死 执行  gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
  
 
 
  c、创建集群
  ./redis-trib.rb create --replicas 1 192.168.43.120:7000 192.168.43.120:7001 192.168.43.130:7000  192.168.43.130:7001 192.168.43.140:7000 192.168.43.140:7001
   
  1. [root@centos3 src]# ./redis-trib.rb create --replicas 1 192.168.43.120:7000 192.168.43.120:7001 192.168.43.130:7000  192.168.43.130:7001 192.168.43.140:7000 192.168.43.140:7001
  2. >>> Creating cluster
  3. >>> Performing hash slots allocation on 6 nodes...
  4. Using 3 masters:
  5. 192.168.43.120:7000
  6. 192.168.43.130:7000
  7. 192.168.43.140:7000
  8. Adding replica 192.168.43.130:7001 to 192.168.43.120:7000
  9. Adding replica 192.168.43.120:7001 to 192.168.43.130:7000
  10. Adding replica 192.168.43.140:7001 to 192.168.43.140:7000
  11. M: 5b341137f0fa22573b34a14206b3b4c625986f42 192.168.43.120:7000
  12.    slots:0-5460 (5461 slots) master
  13. S: 5e162d8d5dad7e6e4fa9ecefac9b3d27e8659e33 192.168.43.120:7001
  14.    replicates 6cbcdc0f773f5c1d895aeb33b29da449890e3064
  15. M: 6cbcdc0f773f5c1d895aeb33b29da449890e3064 192.168.43.130:7000
  16.    slots:5461-10922 (5462 slots) master
  17. S: 6ac36c5449c77caca707b67c8d01dcc9efe3f0fa 192.168.43.130:7001
  18.    replicates 5b341137f0fa22573b34a14206b3b4c625986f42
  19. M: f8c1c69d67ebecb3e6092e901fe1ca66bd097381 192.168.43.140:7000
  20.    slots:10923-16383 (5461 slots) master
  21. S: 4e632fd278a48016c62255746f5128c121a71dfe 192.168.43.140:7001
  22.    replicates f8c1c69d67ebecb3e6092e901fe1ca66bd097381
  23. Can I set the above configuration? (type 'yes' to accept): yes
  24. >>> Nodes configuration updated
  25. >>> Assign a different config epoch to each node
  26. >>> Sending CLUSTER MEET messages to join the cluster
  27. Waiting for the cluster to join...
  28. >>> Performing Cluster Check (using node 192.168.43.120:7000)
  29. M: 5b341137f0fa22573b34a14206b3b4c625986f42 192.168.43.120:7000
  30.    slots:0-5460 (5461 slots) master
  31.    1 additional replica(s)
  32. S: 6ac36c5449c77caca707b67c8d01dcc9efe3f0fa 192.168.43.130:7001
  33.    slots: (0 slots) slave
  34.    replicates 5b341137f0fa22573b34a14206b3b4c625986f42
  35. M: 6cbcdc0f773f5c1d895aeb33b29da449890e3064 192.168.43.130:7000
  36.    slots:5461-10922 (5462 slots) master
  37.    1 additional replica(s)
  38. M: f8c1c69d67ebecb3e6092e901fe1ca66bd097381 192.168.43.140:7000
  39.    slots:10923-16383 (5461 slots) master
  40.    1 additional replica(s)
  41. S: 4e632fd278a48016c62255746f5128c121a71dfe 192.168.43.140:7001
  42.    slots: (0 slots) slave
  43.    replicates f8c1c69d67ebecb3e6092e901fe1ca66bd097381
  44. S: 5e162d8d5dad7e6e4fa9ecefac9b3d27e8659e33 192.168.43.120:7001
  45.    slots: (0 slots) slave
  46.    replicates 6cbcdc0f773f5c1d895aeb33b29da449890e3064
  47. [OK] All nodes agree about slots configuration.
  48. >>> Check for open slots...
  49. >>> Check slots coverage...
  50. [OK] All 16384 slots covered.
复制代码
  
  最后客户端测试
  
 
 
  
 
  
  
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

卖不甜枣

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表