文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

CentOS6.6如何安装Redis3.0.3集群

2024-04-02 19:55

关注

这篇文章主要介绍CentOS6.6如何安装Redis3.0.3集群,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

一个Redis集群,至少需要6个节点,3个为主,3个为从。

IP

端口

节点

127.0.0.1

7000

Master

127.0.0.1

7001

Master

127.0.0.1

7002

Master

127.0.0.1

7003

Slave

127.0.0.1

7004

Slave

127.0.0.1

7005

Slave

安装步骤:

一、下载redis3.0.3

# cd /usr/local

# wget http://download.redis.io/releases/redis-3.0.3.tar.gz

二、解压并编译

# tar -zxvf redis-3.0.3.tar.gz

# cd redis-3.0.3

# make

# make test

# make install

执行make install后,在/usr/local/bin目录下可看到生成了一些文件:

# ls /usr/local/bin/

redis-benchmark  redis-check-dump  redis-sentinel

redis-check-aof  redis-cli         redis-server

三、创建集群需要的目录并拷贝redis

# mkdir -p /usr/local/cluster

# mkdir -p /usr/local/cluster/7000

# mkdir -p /usr/local/cluster/7001

# mkdir -p /usr/local/cluster/7002

# mkdir -p /usr/local/cluster/7003

# mkdir -p /usr/local/cluster/7004

# mkdir -p /usr/local/cluster/7005

# cp -rf /usr/local/redis-3.0.3/* /usr/local/cluster/7000/

# cp -rf /usr/local/redis-3.0.3/* /usr/local/cluster/7001/

# cp -rf /usr/local/redis-3.0.3/* /usr/local/cluster/7002/

# cp -rf /usr/local/redis-3.0.3/* /usr/local/cluster/7003/

# cp -rf /usr/local/redis-3.0.3/* /usr/local/cluster/7004/

# cp -rf /usr/local/redis-3.0.3/* /usr/local/cluster/7005/

四、修改配置文件redis.conf

# vi /usr/local/cluster/7000/redis.conf

修改配置文件中的下面选项

daemonize yes

port 7000

appendonly yes

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

用7000/redis.conf覆盖7001,7002,7003,7004,7005目录下的redis.conf

# cp /usr/local/cluster/7001/redis.conf /usr/local/cluster/7001

# cp /usr/local/cluster/7001/redis.conf /usr/local/cluster/7002

# cp /usr/local/cluster/7001/redis.conf /usr/local/cluster/7003

# cp /usr/local/cluster/7001/redis.conf /usr/local/cluster/7004

# cp /usr/local/cluster/7001/redis.conf /usr/local/cluster/7005

再修改7001,7002,7003,7004,7005目录下的redis.conf中的port,使得redis.conf中的port与其父目录名称一致,比如7001/redis.conf中的port为7001,7002/redis.conf中的port为7002

五、启动6个redis

# cd /usr/local/cluster/7000/src

# redis-server ../redis.conf

# cd /usr/local/cluster/7001/src

# redis-server ../redis.conf

# cd /usr/local/cluster/7002/src

# redis-server ../redis.conf

# cd /usr/local/cluster/7003/src

# redis-server ../redis.conf

# cd /usr/local/cluster/7004/src

# redis-server ../redis.conf

# cd /usr/local/cluster/7005/src

# redis-server ../redis.conf

启动之后使用命令查看redis的启动情况

# ps -ef | grep redis

root       9656      1  0 20:35 ?        00:00:00 redis-server *:7000 [cluster]                 

root       9684      1  0 20:37 ?        00:00:00 redis-server *:7001 [cluster]

root       9725      1  0 20:43 ?        00:00:00 redis-server *:7002 [cluster]

root       9730      1  0 20:43 ?        00:00:00 redis-server *:7003 [cluster]

root       9734      1  0 20:43 ?        00:00:00 redis-server *:7004 [cluster]

root       9739      1  0 20:43 ?        00:00:00 redis-server *:7005 [cluster]

root       9743   3288  0 20:43 pts/0    00:00:00 grep redis

六、创建redis集群

1 执行创建redis集群的命令会报错,提示找不到ruby

# cd /usr/local/redis-3.0.3/src

# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

/usr/bin/env: ruby: 没有那个文件或目录

解决此错误需要安装ruby,这里推荐使用yum install ruby

# yum install ruby

2 再执行创建集群的命令,还会报错,提示缺少rubygems组件

# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

./redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)

         from ./redis-trib.rb:24

解决此错误需要安装rubygems

# yum install rubygems

3 再次执行创建集群的命令,还会报错,提示不能加载redis,是因为缺少redis的接口

# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- redis (LoadError)

         from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'

         from ./redis-trib.rb:25

解决此错误需要安装redis

# gem install redis

Successfully installed redis-3.3.3

1 gem installed

Installing ri documentation for redis-3.3.3...

Installing RDoc documentation for redis-3.3.3...

注意,有时候碰到无法安装的情况,需要手工下载并安装:

# wget https://rubygems.global.ssl.fastly.net/gems/redis-3.3.3.gem

# gem install -l ./redis-3.3.3.gem

4 再次执行安装集群的命令,正常执行

# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

>>> Creating cluster

Connecting to node 127.0.0.1:7000: OK

Connecting to node 127.0.0.1:7001: OK

Connecting to node 127.0.0.1:7002: OK

Connecting to node 127.0.0.1:7003: OK

Connecting to node 127.0.0.1:7004: OK

Connecting to node 127.0.0.1:7005: OK

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

Using 3 masters:

127.0.0.1:7000

127.0.0.1:7001

127.0.0.1:7002

Adding replica 127.0.0.1:7003 to 127.0.0.1:7000

Adding replica 127.0.0.1:7004 to 127.0.0.1:7001

Adding replica 127.0.0.1:7005 to 127.0.0.1:7002

M: 747467b5f2e2a472afad96de6c88dc2f3bf5b426 127.0.0.1:7000

   slots:0-5460 (5461 slots) master

M: 4e4d8ba07d743c4e69fcd5df8867b996084ca4d9 127.0.0.1:7001

   slots:5461-10922 (5462 slots) master

M: a6fe3c0a16bcb465a23147de8a3e242deb87e800 127.0.0.1:7002

   slots:10923-16383 (5461 slots) master

S: 827ca514f4289dc4ac4d51308721f90851ae6180 127.0.0.1:7003

   replicates 747467b5f2e2a472afad96de6c88dc2f3bf5b426

S: be77a6f99e905109150ceaaa50d357ed86803a4c 127.0.0.1:7004

   replicates 4e4d8ba07d743c4e69fcd5df8867b996084ca4d9

S: 1285a04f3628c3e76f14d1036c59aef1cb36258d 127.0.0.1:7005

   replicates a6fe3c0a16bcb465a23147de8a3e242deb87e800

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 127.0.0.1:7000)

M: 747467b5f2e2a472afad96de6c88dc2f3bf5b426 127.0.0.1:7000

   slots:0-5460 (5461 slots) master

M: 4e4d8ba07d743c4e69fcd5df8867b996084ca4d9 127.0.0.1:7001

   slots:5461-10922 (5462 slots) master

M: a6fe3c0a16bcb465a23147de8a3e242deb87e800 127.0.0.1:7002

   slots:10923-16383 (5461 slots) master

M: 827ca514f4289dc4ac4d51308721f90851ae6180 127.0.0.1:7003

   slots: (0 slots) master

   replicates 747467b5f2e2a472afad96de6c88dc2f3bf5b426

M: be77a6f99e905109150ceaaa50d357ed86803a4c 127.0.0.1:7004

   slots: (0 slots) master

   replicates 4e4d8ba07d743c4e69fcd5df8867b996084ca4d9

M: 1285a04f3628c3e76f14d1036c59aef1cb36258d 127.0.0.1:7005

   slots: (0 slots) master

   replicates a6fe3c0a16bcb465a23147de8a3e242deb87e800

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

至此redis集群即搭建成功!

七、执行redis-cli命令进入集群环境

# redis-cli -c -p 7000

127.0.0.1:7000> quit;

#

以上是“CentOS6.6如何安装Redis3.0.3集群”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯