redis集群【转】
一、环境
系统 CentOS7.0 64位最小化安装
redis1 172.16.1.46 6379,6380
redis2 172.16.1.47 6379,6380
redis3 172.16.1.47 6379,6380
二、基础软件安装
|
1
2
|
[root@redis1 ~]# yum install vim wget tree ntp net-tools lsof gcc* -y[root@redis1 ~]# yum -y install gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel gcc-c++ automake autoconf libxml2* rubygem-nokogiri |
三、安装ruby
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@redis1 ~]# yum install ruby rubygems ruby-devel -y#删除ruby的默认源[root@redis1 ~]# gem source --remove https://rubygems.org/https://rubygems.org/ removed from sources#添加源[root@redis1 ~]# gem sources -a https://ruby.taobao.orghttps://ruby.taobao.org added to sources#安装rails[root@redis1 ~]# gem install rails#安装redis和ruby的接口[root@redis1 ~]# gem install redis |
四、安装redis
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
#下载redis[root@redis1 ~]# wget http://download.redis.io/releases/redis-3.0.1.tar.gz[root@redis1 ~]# tar xf redis-3.0.1.tar.gz -C /usr/local/[root@redis1 ~]# ln -sv /usr/local/redis-3.0.1 /usr/local/redis‘/usr/local/redis’ -> ‘/usr/local/redis-3.0.1’[root@redis1 ~]# cd /usr/local/redis[root@redis1 redis]# make[root@redis1 redis]# make install[root@redis1 ~]# cp /usr/local/redis/redis.conf /usr/local/redis6379.conf#编辑6379的配置文件[root@redis1 ~]# vim /usr/local/redis/redis6379.confport 6379pidfile /var/run/redis6379.piddbfilename dump6379.rdbappendfilename "appendonly-6379.aof"cluster-config-file nodes-6379.confcluster-node-timeout 15000cluster-enabled yesappendonly yesdir /usr/local/redis/data/6379#编辑6380的配置文件[root@redis1 ~]# cp /usr/local/redis/redis6379.conf /usr/local/redis/redis6380.conf[root@redis1 ~]# sed -i 's#6379#6380#g' /usr/local/redis/redis6380.conf#创建相应的目录[root@redis1 ~]# mkdir -p /usr/local/redis/data/{6379,6380}#创建6379的启动脚本[root@redis1 ~]# cat /etc/init.d/redis6379#!/bin/bash# chkconfig: 2345 50 30## description: Redis service##Script:Redis command Redisserver=/usr/local/bin/redis-serverRediscli=/usr/local/bin/redis-cliRedisconf=/usr/local/redis/redis6379.conf function_start(){ printf "start redis-server..." $Redisserver $Redisconf &>/dev/null & if [ $? -eq 0 ];then echo "runing" fi} function_stop(){ printf "stop redis-server..." $Rediscli -p 6379 shutdown if [ $? -eq 0 ];then echo "stop" fi} function_restart(){ function_start function_stop} function_kill(){ killall redis-server} function_status(){ a=`ps -A|grep "redis-server\>" -c` if [ $a -ge 1 ];then echo -e "The Redis is [\e[0;32;5m runing \e[0m]" else echo -e "The Redis is [\e[0;31;5m not run \e[0m]" fi} case "$1" in start) function_start ;; stop) function_stop ;; restart) function_stop function_start ;; kill) function_kill ;; status) function_status ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|kill|status}" esac exit#赋予执行权限[root@redis1 ~]# chmod +x /etc/init.d/redis6379[root@redis1 ~]# /etc/init.d/redis6379 startstart redis-server...runing[root@redis1 ~]# netstat -tunlp |grep redistcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 5631/redis-server * #创建6380的启动脚本[root@redis1 ~]# cat /etc/init.d/redis6380 #!/bin/bash# chkconfig: 2345 50 30## description: Redis service##Script:Redis command Redisserver=/usr/local/bin/redis-serverRediscli=/usr/local/bin/redis-cliRedisconf=/usr/local/redis/redis6380.conf function_start(){ printf "start redis-server..." $Redisserver $Redisconf &>/dev/null & if [ $? -eq 0 ];then echo "runing" fi} function_stop(){ printf "stop redis-server..." $Rediscli -p 6380 shutdown if [ $? -eq 0 ];then echo "stop" fi} function_restart(){ function_start function_stop} function_kill(){ killall redis-server} function_status(){ a=`ps -A|grep "redis-server\>" -c` if [ $a -ge 1 ];then echo -e "The Redis is [\e[0;32;5m runing \e[0m]" else echo -e "The Redis is [\e[0;31;5m not run \e[0m]" fi} case "$1" in start) function_start ;; stop) function_stop ;; restart) function_stop function_start ;; kill) function_kill ;; status) function_status ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|kill|status}" esac exit#赋予执行权限并启动6380[root@redis1 ~]# chmod +x /etc/init.d/redis6380 [root@redis1 ~]# /etc/init.d/redis6380 startstart redis-server...runing[root@redis1 ~]# netstat -tunlp |grep redistcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 5646/redis-server * tcp 0 0 0.0.0.0:6380 0.0.0.0:* LISTEN 5652/redis-server * #其余2台执行同样的操作 |
五、配置集群
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#在任意一台机器上操作[root@redis1 ~]# /usr/local/redis/src/redis-trib.rb create --replicas 1 172.16.1.46:6379 172.16.1.46:6380 172.16.1.47:6379 172.16.1.47:6380 172.16.1.48:6379 172.16.1.48:6380>>> Creating clusterConnecting to node 172.16.1.46:6379: OKConnecting to node 172.16.1.46:6380: OKConnecting to node 172.16.1.47:6379: OKConnecting to node 172.16.1.47:6380: OKConnecting to node 172.16.1.48:6379: OKConnecting to node 172.16.1.48:6380: OK>>> Performing hash slots allocation on 6 nodes...Using 3 masters:172.16.1.46:6379172.16.1.47:6379172.16.1.48:6379Adding replica 172.16.1.47:6380 to 172.16.1.46:6379Adding replica 172.16.1.46:6380 to 172.16.1.47:6379Adding replica 172.16.1.48:6380 to 172.16.1.48:6379M: 3c2279ff6333b98a233ebf541e2b75981d27751f 172.16.1.46:6379 slots:0-5460 (5461 slots) masterS: eb0b79b22797c14172c8f0f117a4839d6825ea1f 172.16.1.46:6380 replicates dd122d63def65b8bc62719cabbb468f7976b1b73M: dd122d63def65b8bc62719cabbb468f7976b1b73 172.16.1.47:6379 slots:5461-10922 (5462 slots) masterS: c8136c436cec8146dbbbd1ff2e5468d1dd5dd195 172.16.1.47:6380 replicates 3c2279ff6333b98a233ebf541e2b75981d27751fM: a0cf20f0ea29760dfdb3e4748417efaefc0c37f0 172.16.1.48:6379 slots:10923-16383 (5461 slots) masterS: c6df03cde4424b2b09752c89d236ee1cd4834709 172.16.1.48:6380 replicates a0cf20f0ea29760dfdb3e4748417efaefc0c37f0Can 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 clusterWaiting for the cluster to join....>>> Performing Cluster Check (using node 172.16.1.46:6379)M: 3c2279ff6333b98a233ebf541e2b75981d27751f 172.16.1.46:6379 slots:0-5460 (5461 slots) masterM: eb0b79b22797c14172c8f0f117a4839d6825ea1f 172.16.1.46:6380 slots: (0 slots) master replicates dd122d63def65b8bc62719cabbb468f7976b1b73M: dd122d63def65b8bc62719cabbb468f7976b1b73 172.16.1.47:6379 slots:5461-10922 (5462 slots) masterM: c8136c436cec8146dbbbd1ff2e5468d1dd5dd195 172.16.1.47:6380 slots: (0 slots) master replicates 3c2279ff6333b98a233ebf541e2b75981d27751fM: a0cf20f0ea29760dfdb3e4748417efaefc0c37f0 172.16.1.48:6379 slots:10923-16383 (5461 slots) masterM: c6df03cde4424b2b09752c89d236ee1cd4834709 172.16.1.48:6380 slots: (0 slots) master replicates a0cf20f0ea29760dfdb3e4748417efaefc0c37f0[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.#检查集群状态[root@redis1 ~]# /usr/local/redis/src/redis-trib.rb check 127.0.0.1:6379Connecting to node 127.0.0.1:6379: OKConnecting to node 172.16.1.48:6379: OKConnecting to node 172.16.1.48:6380: OKConnecting to node 172.16.1.47:6379: OKConnecting to node 172.16.1.47:6380: OKConnecting to node 172.16.1.46:6380: OK>>> Performing Cluster Check (using node 127.0.0.1:6379)M: 3c2279ff6333b98a233ebf541e2b75981d27751f 127.0.0.1:6379 slots:0-5460 (5461 slots) master 1 additional replica(s)M: a0cf20f0ea29760dfdb3e4748417efaefc0c37f0 172.16.1.48:6379 slots:10923-16383 (5461 slots) master 1 additional replica(s)S: c6df03cde4424b2b09752c89d236ee1cd4834709 172.16.1.48:6380 slots: (0 slots) slave replicates a0cf20f0ea29760dfdb3e4748417efaefc0c37f0 M: dd122d63def65b8bc62719cabbb468f7976b1b73 172.16.1.47:6379 slots:5461-10922 (5462 slots) master 1 additional replica(s)S: c8136c436cec8146dbbbd1ff2e5468d1dd5dd195 172.16.1.47:6380 slots: (0 slots) slave replicates 3c2279ff6333b98a233ebf541e2b75981d27751fS: eb0b79b22797c14172c8f0f117a4839d6825ea1f 172.16.1.46:6380 slots: (0 slots) slave replicates dd122d63def65b8bc62719cabbb468f7976b1b73[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.#测试集群,添加一个值[root@redis1 ~]# /usr/local/bin/redis-cli -c -p 6379127.0.0.1:6379> set a a-> Redirected to slot [15495] located at 172.16.1.48:6379 #可以看到值添加到了172.16.1.48:6379这个节点上OK172.16.1.48:6379> get a"a"#关闭172.16.1.48:6379这个节点[root@redis3 redis]# /etc/init.d/redis6379 stopstop redis-server...stop[root@redis3 redis]# netstat -tunlp |grep 6379#再次连接到集群上[root@redis1 ~]# /usr/local/bin/redis-cli -c -p 6379127.0.0.1:6379> get a-> Redirected to slot [15495] located at 172.16.1.48:6380"a" #这里能看到之前设置的值,从172.16.1.48:6380拿到结果了#集群配置到此结束 |
http://blog.51cto.com/ly36843/1771628
redis集群【转】的更多相关文章
- Redis集群案例与场景分析
1.背景 Redis的出现确实大大地提高系统大并发能力支撑的可能性,转眼间Redis的最新版本已经是3.X版本了,但我们的系统依然继续跑着2.8,并很好地支撑着我们当前每天5亿访问量的应用系统.想当年 ...
- Java Spring mvc 操作 Redis 及 Redis 集群
本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5941953.html 关于 Redis 集群搭建可以参考我的另一篇文章 Redis集群搭建与简单使用 R ...
- Redis集群搭建与简单使用
介绍安装环境与版本 用两台虚拟机模拟6个节点,一台机器3个节点,创建出3 master.3 salve 环境. redis 采用 redis-3.2.4 版本. 两台虚拟机都是 CentOS ,一台 ...
- window下使用Redis Cluster部署Redis集群
日常的项目很多时候都需要用到缓存.redis算是一个比较好的选择.一般情况下做一个主从就可以满足一些比较小的项目需要.在一些并发量比较大的项目可能就需要用到集群了,redis在Windows下做集群可 ...
- Redis集群~windows下搭建Sentinel环境及它对主从模式的实际意义
回到目录 关于redis-sentinel出现的原因 Redis集群的主从模式有个最大的弊端,就是当主master挂了之前,它的slave从服务器无法提升为主,而在redis-sentinel出现之后 ...
- [个人翻译]Redis 集群教程(中)
上一篇:http://www.cnblogs.com/li-peng/p/6143709.html 官方原文地址:https://redis.io/topics/cluster-tutorial 水 ...
- [个人翻译]Redis 集群教程(上)
官方原文地址:https://redis.io/topics/cluster-tutorial 水平有限,如果您在阅读过程中发现有翻译的不合理的地方,请留言,我会尽快修改,谢谢. 这是 ...
- Redis集群(九):Redis Sharding集群Redis节点主从切换后客户端自动重新连接
上文介绍了Redis Sharding集群的使用,点击阅读 本文介绍当某个Redis节点的Master节点发生问题,发生主从切换时,Jedis怎样自动重连新的Master节点 一.步骤如下: 1.配 ...
- Redis集群(八):Redis Sharding集群
一.Redis目前的集群方案主要有两种:Redis Sharding和Redis Cluster 1.Redis Sharding:3.0以前基本上使用分片实现集群,目前主流方案,客户端实现 2.Re ...
- Redis-Sentinel(Redis集群监控管理)
Redis的高可用方案的实现:主从切换以及虚拟IP或客户端 从Redis 2.8开始加入对Sentinel机制从而实现了服务器端的主从切换,但目前尚未发现实现虚拟IP或客户端切换方案 Redis-Se ...
随机推荐
- idea 实现热部署
Idea实现热部署需要以下几步 1.open module setting,设置path,使output path指向存放实时编译class的文件夹 2.设置Artifacts,选择exploded选 ...
- JIRA python篇之统计产品尚未解决的bugs
[本文出自天外归云的博客园] 通过python中的jira类我们可以方便的操作jira,获取一些我们想要再加工的信息. 一些通过JIRA的JTL查询语句不方便直接搜索的过滤条件可以通过JIRA的pyt ...
- js如何获取到本周的第一天和最后一天,本月的第一天和最后一天以及本季度的第一天和最后一天
1.首先来一个自己公司项目的源码: 项目需求描述: 从20150712日开始, , 需求①:根据当前时间返回每一周 .周一~周日的日期(需返回2种格式 格式1:7月13日,格式2:2015-07-13 ...
- java你可能不知道的事(2)--堆和栈<转>
在java语言的学习和使用当中你可能已经了解或者知道堆和栈,但是你可能没有完全的理解它们.今天我们就一起来学习堆.栈的特点以及它们的区别.认识了这个之后,你可能对java有更深的理解. Java堆内存 ...
- 小米手机刷机工具MiFlash怎么用
刷机包的获取:直接登陆MIUI系统官网(miui.com),在其“下载”栏目中根据手机类型找到对应的刷机包进行下载. 接下来就需要下载“小米手机刷机工具MiFlash”程序,可以直接从以下地址中获 ...
- [算法]谷歌笔试题:Beautiful Numbers
题目描述 思路 这道题就是在说,由多个1组成的数是beautiful的,现在想求出r进制中的r,使得给出的数字转换成r进制,得到beautiful的数字,如果有多种方式转换,那么取1的个数最多的那种情 ...
- Hibernate注解方式一对多自关联关系映射
MySQL版数据库表结构 DROP TABLE IF EXISTS SYS_DICT_ITEM; CREATE TABLE SYS_DICT_ITEM( ITEM_CODE ) NOT NULL, ...
- Nodejs中export的作用
在上一节,我们编写了一个hello.js文件,这个hello.js文件就是一个模块,模块的名字就是文件名(去掉.js后缀),所以hello.js文件就是名为hello的模块. 我们把hello.js改 ...
- OpenResty最佳实践
https://moonbingbing.gitbooks.io/openresty-best-practices/content/
- Java设计模式(15)备忘录模式(Memento模式)
Memento定义:memento是一个保存另外一个对象内部状态拷贝的对象,这样以后就可以将该对象恢复到原先保存的状态. Memento模式相对也比较好理解,我们看下列代码: public class ...