码迷,mamicode.com
首页 > 其他好文 > 详细

redis离线集群安装

时间:2019-04-22 22:42:49      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:poc   add   方法   改名   open   dev   export   节点   size   

用一个叫redis-trib.rb的ruby脚本。redis-trib.rb是redis官方推出的管理redis集群的工具,集成在redis的源码src目录下(redis-xxx/src/)。是基于redis提供的集群命令封装成简单、便捷、实用的操作工具。redis-trib.rb是redis作者用ruby完成的。所以redis集群需要先安装ruby环境。

这是在线安装步骤

Redis-cluster集群需要使redis-trib.rb脚本来管理集群,redis-trib.rb脚本是使用ruby语言编写的。

 

搭建集群同时需要搭建6redis服务器,其中3台主机、3台从机。端口分别为7001~7006。

 

第一步:搭建ruby环境

[root@bogon bin]# yum install -y ruby

[root@bogon bin]# yum install -y rubygems

 

第二步:上传rubyredis的接口程序

 

 

第三步:安装rubyredis的接口

[root@bogon ~]# gem install redis-3.0.0.gem

 

第四步:复制redis-trib.rb脚本到/usr/local/redis-cluster目录下

[root@bogon ~]# mkdir /usr/local/redis-cluster

[root@bogon ~]# cp /root/redis-3.0.0/src/redis-trib.rb /usr/local/redis-cluster/

 

第五步:复制/usr/local/redis/bin/usr/local/redis-cluster/并改名为7001

[root@bogon redis-cluster]# cp /usr/local/redis/bin ./7001 –r

 

第六步修改7001目录下的redis.conf文件,主要修改端口和集群配置。

port 7001

cluster-enabled yes

 

 

 

第七步复制7001目录为7002~7006,然后修改端口

Cp 7001/ 7002 -r

Cp 7001/ 7003 -r

......

第八步启动7001~70066redis服务器

编辑启动脚本

cd 7001/

./redis-server redis.conf

cd ..

cd 7002/

./redis-server redis.conf

cd ..

cd 7003/

./redis-server redis.conf

cd ..

cd 7004/

./redis-server redis.conf

cd ..

cd 7005/

./redis-server redis.conf

cd ..

cd 7006/

./redis-server redis.conf

cd ..

 

第九步:创建集群

[root@bogon redis-cluster]# ./redis-trib.rb create --replicas 1 192.168.242.129:7001 192.168.242.129:7002 192.168.242.129:7003 192.168.242.129:7004 192.168.242.129:7005  192.168.242.129:7006

>>> Creating cluster

Connecting to node 192.168.242.129:7001: OK

Connecting to node 192.168.242.129:7002: OK

Connecting to node 192.168.242.129:7003: OK

Connecting to node 192.168.242.129:7004: OK

Connecting to node 192.168.242.129:7005: OK

Connecting to node 192.168.242.129:7006: OK

>>> Performing hash slots allocation on 6 nodes...

Using 3 masters:

192.168.242.129:7001

192.168.242.129:7002

192.168.242.129:7003

Adding replica 192.168.242.129:7004 to 192.168.242.129:7001

Adding replica 192.168.242.129:7005 to 192.168.242.129:7002

Adding replica 192.168.242.129:7006 to 192.168.242.129:7003

M: e6e324f6e07a8791bb4680e6d9a43a8c8521d071 192.168.242.129:7001

   slots:0-5460 (5461 slots) master

M: 4734ef2831cc50f6ed2a311ef6e69cd7ac3e98ab 192.168.242.129:7002

   slots:5461-10922 (5462 slots) master

M: 7bb03b2f0f2bed96b367d4a5ec1886e63f5b4a37 192.168.242.129:7003

   slots:10923-16383 (5461 slots) master

S: 4679464174bb13ab556b9caf89085b9ae6e322a3 192.168.242.129:7004

   replicates e6e324f6e07a8791bb4680e6d9a43a8c8521d071

S: 3dd4692316cba5b3ab458cbcf93d85ff1de4cfbe 192.168.242.129:7005

   replicates 4734ef2831cc50f6ed2a311ef6e69cd7ac3e98ab

S: 2285d1dbbe3f5c54b3ffeffcedd534866d8953b5 192.168.242.129:7006

   replicates 7bb03b2f0f2bed96b367d4a5ec1886e63f5b4a37

Can I set the above configuration? (type ‘yes‘ to accept): yes

>>> Nodes configuration updated

>>> Assign a different config epoch to each node

>>> Sending CLUSTER MEET messages to join the cluster

Waiting for the cluster to join......

>>> Performing Cluster Check (using node 192.168.242.129:7001)

M: e6e324f6e07a8791bb4680e6d9a43a8c8521d071 192.168.242.129:7001

   slots:0-5460 (5461 slots) master

M: 4734ef2831cc50f6ed2a311ef6e69cd7ac3e98ab 192.168.242.129:7002

   slots:5461-10922 (5462 slots) master

M: 7bb03b2f0f2bed96b367d4a5ec1886e63f5b4a37 192.168.242.129:7003

   slots:10923-16383 (5461 slots) master

M: 4679464174bb13ab556b9caf89085b9ae6e322a3 192.168.242.129:7004

   slots: (0 slots) master

   replicates e6e324f6e07a8791bb4680e6d9a43a8c8521d071

M: 3dd4692316cba5b3ab458cbcf93d85ff1de4cfbe 192.168.242.129:7005

   slots: (0 slots) master

   replicates 4734ef2831cc50f6ed2a311ef6e69cd7ac3e98ab

M: 2285d1dbbe3f5c54b3ffeffcedd534866d8953b5 192.168.242.129:7006

   slots: (0 slots) master

   replicates 7bb03b2f0f2bed96b367d4a5ec1886e63f5b4a37

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

 

 

1.1 连接集群

命令:./redis-cli –h 127.0.0.1 –p 7001 –c

注意-c 连接redis集群

[root@localhost-0723 redis]# ./redis-cli -p 7006 -c

127.0.0.1:7006> set key1 123

-> Redirected to slot [9189] located at 127.0.0.1:7002

OK

127.0.0.1:7002>

 

1.2 查看集群的命令

  • 查看集群状态

127.0.0.1:7003> cluster info

cluster_state:ok

cluster_slots_assigned:16384

cluster_slots_ok:16384

cluster_slots_pfail:0

cluster_slots_fail:0

cluster_known_nodes:6

cluster_size:3

cluster_current_epoch:6

cluster_my_epoch:3

cluster_stats_messages_sent:926

cluster_stats_messages_received:926

 

  • 查看集群中的节点:

 

127.0.0.1:7003> cluster nodes

7a12bc730ddc939c84a156f276c446c28acf798c 127.0.0.1:7002 master - 0 1443601739754 2 connected 5461-10922

93f73d2424a796657948c660928b71edd3db881f 127.0.0.1:7003 myself,master - 0 0 3 connected 10923-16383

d8f6a0e3192c905f0aad411946f3ef9305350420 127.0.0.1:7001 master - 0 1443601741267 1 connected 0-5460

4170a68ba6b7757e914056e2857bb84c5e10950e 127.0.0.1:7006 slave 93f73d2424a796657948c660928b71edd3db881f 0 1443601739250 6 connected

f79802d3da6b58ef6f9f30c903db7b2f79664e61 127.0.0.1:7004 slave d8f6a0e3192c905f0aad411946f3ef9305350420 0 1443601742277 4 connected

0bc78702413eb88eb6d7982833a6e040c6af05be 127.0.0.1:7005 slave 7a12bc730ddc939c84a156f276c446c28acf798c 0 1443601740259 5 connected

127.0.0.1:7003>

 

这是离线安装

离线步骤和在线相差不大只是,需要离线安装,ruby,rubygems,openssl,zlib-devel

安装redis集群的环境,环境安装完了,集群安装是一样的

依赖包 redis-3.2.1.gem

      openssl-1.0.1s.tar.gz

   rubygems-2.4.2.tgz

           ruby-2.3.0.tar.gz

安装ruby: 

   tar -zxvf ruby-2.3.0.tar.gz

   ./configure --prefix=/home/hadoop/opt/ruby

  make

     make install
配置环境变量
  vim .bash_profile
  export PATH=$JAVA_HOME/bin:$PATH:/home/hadoop/software/ruby/bin
  source .bash_profile
查看版本
  ruby -v

安装rubygens

  tar -zxvf rubygems-2.4.2.tgz
  cd rubygems-2.4.2
  ruby setup.rb

安装 redis与ruby接口

gem install redis-3.2.1.gem

出现报错

ERROR: Loading command: install (LoadError)
 cannot load such file -- zlib
ERROR: While executing gem ... (NoMethodError)
    undefined method `invoke_with_build_args‘ for nil:NilClass

需先安装 zlib-devel 不然下面的make不能编译

yum -y install zlib-devel(离线安装这个包也要离线安装 ,暂且在线安装 zlib-debel)
 
进入ruby源码文件夹,安装ruby自身提供的zlib包
 
cd ruby-2.3.0/ext/zlib
ruby ./extconf.rb
make
make install
安装zlib包成功
 
在次安装

gem install redis-3.2.1.gem 

报错:

 

ERROR: While executing gem ... (Gem::Exception)  

Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources  

 

查看解决方法 https://www.cnblogs.com/a-du/p/7767810.html 完美解决

环境安装好 集群安装和在线安装一样

redis离线集群安装

标签:poc   add   方法   改名   open   dev   export   节点   size   

原文地址:https://www.cnblogs.com/zhoufly-blog/p/10753427.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!