Redis集群的搭建

来源:互联网 发布:怎么样加入淘宝 编辑:程序博客网 时间:2024/06/06 03:53

**前话:**Redis集群中至少应该有三个节点,要保证集群的高可用,需要每个节点有一个备份机。
集群搭建环境
1、使用ruby脚本搭建集群,安装ruby的运行环境
yum install ruby
yum install rubygems

2、安装ruby脚本运行使用的包
[root@localhost ~]# gem install redis-3.0.0.gem
图在图在
[root@localhost ~]# cd redis-3.0.0/src
[root@localhost src]# ll *.rb
-rwxrwxr-x. 1 root root 48141 Apr 1 2015 redis-trib.rb

搭建步骤
需要6台redis服务器
搭建伪分布式,需要6个redis实例,需要运行在不同的端口7001-7006

第一步:创建6个redis实例,需要修改redis.conf配置文件,让每个实例在不同的端口
还需要把cluster-enabled yes前的注释放开
这是图啦

第二步:启动每个redis实例

第三步:使用ruby脚本搭建集群
./redis-trib.rb create –replicas 1 虚拟机地址:7001 虚拟机地址:7002 …..虚拟机地址:7006

集群的使用方法
Redis-cli连接集群。
[root@localhost redis-cluster]# redis01/redis-cli -p 7002 -c
-c:代表连接的是redis集群

创建关闭集群的脚本:
[root@localhost redis-cluster]# vim shutdow-all.sh

[root@localhost redis-cluster]# chmod u+x shutdow-all.sh

[root@localhost redis-cluster]# ./redis-trib.rb create –replicas 1 虚拟机地址:7001 虚拟机地址:7002 …..虚拟机地址:7006
上图
中图
下图

ok!!!结束!! 希望给各位猿友带来帮助吧!!! 偷偷告诉你们!!!这是我刚写的日记!!

原创粉丝点击