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.org https: //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.conf port 6379 pidfile /var/run/redis6379 .pid dbfilename dump6379.rdb appendfilename "appendonly-6379.aof" cluster-config- file nodes-6379.conf cluster-node-timeout 15000 cluster-enabled yes appendonly yes dir /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-server Rediscli= /usr/local/bin/redis-cli Redisconf= /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 start start redis-server...runing [root@redis1 ~] # netstat -tunlp |grep redis tcp 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-server Rediscli= /usr/local/bin/redis-cli Redisconf= /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 start start redis-server...runing [root@redis1 ~] # netstat -tunlp |grep redis tcp 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 cluster Connecting to node 172.16.1.46:6379: OK Connecting to node 172.16.1.46:6380: OK Connecting to node 172.16.1.47:6379: OK Connecting to node 172.16.1.47:6380: OK Connecting to node 172.16.1.48:6379: OK Connecting to node 172.16.1.48:6380: OK >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 172.16.1.46:6379 172.16.1.47:6379 172.16.1.48:6379 Adding replica 172.16.1.47:6380 to 172.16.1.46:6379 Adding replica 172.16.1.46:6380 to 172.16.1.47:6379 Adding replica 172.16.1.48:6380 to 172.16.1.48:6379 M: 3c2279ff6333b98a233ebf541e2b75981d27751f 172.16.1.46:6379 slots:0-5460 (5461 slots) master S: eb0b79b22797c14172c8f0f117a4839d6825ea1f 172.16.1.46:6380 replicates dd122d63def65b8bc62719cabbb468f7976b1b73 M: dd122d63def65b8bc62719cabbb468f7976b1b73 172.16.1.47:6379 slots:5461-10922 (5462 slots) master S: c8136c436cec8146dbbbd1ff2e5468d1dd5dd195 172.16.1.47:6380 replicates 3c2279ff6333b98a233ebf541e2b75981d27751f M: a0cf20f0ea29760dfdb3e4748417efaefc0c37f0 172.16.1.48:6379 slots:10923-16383 (5461 slots) master S: c6df03cde4424b2b09752c89d236ee1cd4834709 172.16.1.48:6380 replicates a0cf20f0ea29760dfdb3e4748417efaefc0c37f0 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 172.16.1.46:6379) M: 3c2279ff6333b98a233ebf541e2b75981d27751f 172.16.1.46:6379 slots:0-5460 (5461 slots) master M: eb0b79b22797c14172c8f0f117a4839d6825ea1f 172.16.1.46:6380 slots: (0 slots) master replicates dd122d63def65b8bc62719cabbb468f7976b1b73 M: dd122d63def65b8bc62719cabbb468f7976b1b73 172.16.1.47:6379 slots:5461-10922 (5462 slots) master M: c8136c436cec8146dbbbd1ff2e5468d1dd5dd195 172.16.1.47:6380 slots: (0 slots) master replicates 3c2279ff6333b98a233ebf541e2b75981d27751f M: a0cf20f0ea29760dfdb3e4748417efaefc0c37f0 172.16.1.48:6379 slots:10923-16383 (5461 slots) master M: 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:6379 Connecting to node 127.0.0.1:6379: OK Connecting to node 172.16.1.48:6379: OK Connecting to node 172.16.1.48:6380: OK Connecting to node 172.16.1.47:6379: OK Connecting to node 172.16.1.47:6380: OK Connecting 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 3c2279ff6333b98a233ebf541e2b75981d27751f S: 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 6379 127.0.0.1:6379> set a a -> Redirected to slot [15495] located at 172.16.1.48:6379 #可以看到值添加到了172.16.1.48:6379这个节点上 OK 172.16.1.48:6379> get a "a" #关闭172.16.1.48:6379这个节点 [root@redis3 redis] # /etc/init.d/redis6379 stop stop redis-server...stop [root@redis3 redis] # netstat -tunlp |grep 6379 #再次连接到集群上 [root@redis1 ~] # /usr/local/bin/redis-cli -c -p 6379 127.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 ...
随机推荐
- 【转】31个实用的find命令
find . -name "*.sql" -exec md5sum {} \; 一.主要内容 ====================================== . 用文 ...
- linux nexus bulid
1. 将下载好的nexus-2.5.1-bundle.tar.gz包,用FTP工具传至服务器上. 2. 解压安装包 解压命令: ? 1 tar -zvxf nexus-2.5.1-bundle ...
- RGB与CMYK以及加色与减色
转载自:http://blog.csdn.net/tohmin/article/details/4761930 黑白色配色与RGB.CMYK 1. 光学三原色与印刷三原色 光学与印刷三原色, 相信大家 ...
- 微服务之springCloud-docker-feign-hystrix(六)
简介 上一节我们讨论feign的配置,这节我们讨论一下,feign+hystrix调用生产者时,进行容错处理 一.创建模块(microservice-consumer-movie-feign-with ...
- 《5天学会卡西欧fx-5800p之实操视频教程(初级)》目录和我的工作室现场曝光
很多人给我讲,想让我录制一份卡西欧fx-5800p的视频教程,我也一直在准备,准备了半年,录制视频真的不是件容易的事,条件有限,而且工作也很忙,中途还会有想放弃的念头,真的是花费了我很多的心血,但不管 ...
- 【Unity】制作简易定时器(Timer)
最近开始学习Unity,也想开始学习写一些简单的博客. 在网上学习了一些关于定时器的写法,在此简单总结一下,方便自己以后用到时查阅. 需求:制作定时器,运行3秒后执行第一次,之后每隔3秒执行一次操作. ...
- C#中的索引器
在Java中,一般会这样使用get,set方法: class Person{ private String name; public void setName(String name){ this.n ...
- gSoap的“error LNK2001: 无法解析的外部符号 _namespaces”解决方法
错误 2 error LNK2001: 无法解析的外部符号 _namespaces 解决方法: 1. 在工程中定义 WITH_NONAMESPACES 宏 2.尝试 "#include &q ...
- Java通过ssh连接到Linxu和Windos服务器远程启动Tomcat
一.Linxu服务器远程启动tomcat 1.首先确保linxu服务器上的tomcat jdk等必要软件正确安装,并且可以正常启动. 2.编写Java SSH工具类. 相关jar包: <depe ...
- MacBook如何用Parallels Desktop安装windows7/8
虽然MacBook真的很好用,不过在天朝的国情下,有很多软件还是仅支持IE和windows系统下才有.所以有必要为自己的MacBook装一个windows版本的系统,之前试过用Boot Camp来建立 ...