一、环境
系统 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 ...
随机推荐
-
MySQL zabbix
http://liqingbiao.blog.51cto.com/3044896/1712080
-
centos5.4下mysql主从复制
centos5.4下mysql主从复制配置分享. 本文转自:http://www.jbxue.com/article/771.html 安装环境:centos 5.4 mysql版本:mysql 5. ...
-
.net+easyui--combobox
一:预定义结构的 select 元素创建组合框(combobox)值固定写死 <select class="easyui-combobox" name="state ...
-
前端上将字符串用语音读出来只能在IE上运行 其他不行 代码极少
先保存保存自己的笔记 有高手看到求指点 <script type="text/javascript"> var VoiceObj; try { VoiceObj = n ...
-
Cannot retrieve metalink for repository: epel.
Error: Cannot retrieve metalink for repository: epel. Please verify its path and ...
-
android 垂直 SeekBar 源代码(VerticalSeekBar)[转]
主要是继承 AbsSeekBar 然后修改下面这些方法 onProgressRefresh() //当进度条数据更新的时候,例如我们拖动滑动条的时候,这个方法被调用 setThumbPos() //这 ...
-
WARNING: &#39;aclocal-1.14&#39; is missing on your system.
源码安装zabbix agent时进行到make install时报如下错误: WARNING: 'aclocal-1.14' is missing on your system. You shoul ...
-
cPanel中添加设置附加域(Addon domain)
本文介绍cPanel设置附加域(addon domain)来实现一个空间做多个网站的方法. 附加域(addon domain) 作用:通过它可以实现添加 新的*域名绑定到主机,从而创建新的站点.例如 ...
-
idea插件actiBPM源码
actiBPM https://github.com/Activiti/Activiti
-
MySQL的冷备份和热备份概念理解(转)
一.冷备份(off, 慢, 时间点上恢复) 冷备份发生在数据库已经正常关闭的情况下,当正常关闭时会提供给我们一个完整的数据库.冷备份是将关键性文件拷贝到另外位置的一种说法.对于备份数据库信息而言,冷备 ...