forked from IT-xzy/NEW-JAVA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20181201-A-java-6.html
230 lines (197 loc) · 10.3 KB
/
20181201-A-java-6.html
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>葡萄藤PPT</title>
<link rel="stylesheet" href="https://ptteng.github.io/PPT/css/reveal/reveal.css">
<!-- PPT主题,可以在/css/reveal/theme/中选择其他主题,目前暂时只能使用该模板 -->
<link rel="stylesheet" href="https://ptteng.github.io/PPT/css/reveal/theme/ptt.css">
<!-- syntax highlighting 代码高亮主题 -->
<link rel="stylesheet" href="https://ptteng.github.io/PPT/lib/reveal/css/zenburn.css">
<!-- 打印和PDF输出样式 -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'https://ptteng.github.io/PPT/css/reveal/print/pdf.css' : '../css/reveal/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<img src="https://ptteng.github.io/PPT/img/demo/logo.png" alt="" usemap="#pttmap" class="base-logo">
<map name="pttmap">
<area shape="rect" coords="0,0,276,58" href="http://www.jnshu.com" alt="" target="_blank"/>
</map>
<div class="reveal">
<div class="slides">
<section>
<h2>redis缓存集群介绍</h2>
<p>分享人:鲁伯良</p>
</section>
<section>
<p>目录</p>
<p>1.背景介绍</p>
<p>2.知识剖析</p>
<p>3.常见问题</p>
<p>4.解决方案</p>
<p>5.编码实战</p>
<p>6.扩展思考</p>
<p>7.参考文献</p>
<p>8.更多讨论</p>
</section>
<section>
<section>
<h3>1.背景介绍</h3>
</section>
<section style="text-align: left;">
<br style="text-align: left">
<h4>redis</h4>
redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash(哈希类型)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,redis支持各种不同方式的排序。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步。
</p>
</section>
</section>
<section>
<h3>2.知识剖析</h3>
</section>
<section style="text-align: left;">
<h3><strong>redis性能</strong></h3>
<p><br>
如下图所示
我们在碰到需要执行耗时特别久,且结果不频繁变动的SQL,就特别适合将运行结果放入缓存。这样,后面的请求就去缓存中读取,使得请求能够迅速响应br>
<img src="https://images.cnblogs.com/cnblogs_com/rjzheng/1202350/o_redis1.png">
</p>
</section>
<section style="text-align: left;">
<p>(二)并发
如下图所示,在大并发的情况下,所有的请求直接访问数据库,数据库会出现
连接异常。这个时候,就需要使用redis做一个缓冲操作,让请求先访问到
redis,而不是直接访问数据库。
<img src="https://images.cnblogs.com/cnblogs_com/rjzheng/1202350/o_redis2.png">
<br>
</section>
<section style="text-align: left;">
集群方案比较<br>
哨兵模式
在redis3.0以前的版本要实现集群一般是借助哨兵sentinel工具来监控master节点的状态,如果master节点异常,则会做主从切换,将某一台slave作为master,哨兵的配置略微复杂,并且性能和高可用性等各方面表现一般,特别是在主从切换的瞬间存在访问瞬断的情况
<br>
<img src="https://img-blog.csdn.net/20180514095854736?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RvbWNhdEFuZE9yYWNsZQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
</section>
<section style="text-align: left;">
<h3><strong>高可用集群</strong></h3>
<p>
redis集群是一个由多个主从节点群组成的分布式服务器群,它具有复制、高可用和分片特性。Redis集群不需要sentinel哨兵也能完成节点移除和故障转移的功能。需要将每个节点设置成集群模式,这种集群模式没有中心节点,可水平扩展,据官方文档称可以线性扩展到1000节点。redis集群的性能和高可用性均优于之前版本的哨兵模式,且集群配置非常简单<br>
<img src="https://img-blog.csdn.net/2018051409595112?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RvbWNhdEFuZE9yYWNsZQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70">
</section>
<section style="text-align: left;">
<h3><strong>集群搭建</strong></h3>
<p>1.安装好redis3.0以上版本<br>
2.新建六个文件夹,名字是每个实例代表的端口号<br>
3.将redis.conf,和 redis.server拷贝到刚才新建的文件夹下<br>
4.修改redis.conf配置,<br>
daemonize yes<br>
port 端口号<br>
cluster-enabled yes 启动集群模式<br>
cluster-node-timeout 5000<br>
appendonly yes<br>
5.cd 到新建文件夹 依次启动redis实例
6.安装ruby 和一些 其他的包,还有rubygems
7.进入redis安装目录cd 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
建立集群成功
</section>
</section>
</section>
<section>
<section>
<h3>3.常见问题</h3>
</section>
<section style="text-align: left;">
<p>单线程的redis为什么这么快<br>
</section>
</section>
<section>
<section>
<h3>4.解决方案</h3>
</section>
<section>
<p class="text-l">
(一)纯内存操作
(二)单线程操作,避免了频繁的上下文切换
(三)采用了非阻塞I/O多路复用机制<br>
</p>
</section>
</section>
<section>
<section>
<h3>5.编码实战</h3>
</section>
</section>
<section>
<section>
<h3>6.扩展思考</h3>
</section>
<section class="text-l">
<h4>槽(slot)的基本概念</h4>
</section>
<section style="text-align: left;">
<p>
redis存取key的时候,都要定位相应的槽(slot)。<br>
Redis 集群键分布算法使用数据分片(sharding)而非一致性哈希(consistency hashing)来实现: 一个 Redis 集群包含 16384 个哈希槽(hash slot), 它们的编号为0、1、2、3……16382、16383,这个槽是一个逻辑意义上的槽,实际上并不存在。redis中的每个key都属于这 16384 个哈希槽的其中一个,存取key时都要进行key->slot的映射计算。 </p>
</section>
</section>
<section>
<section>
<h3>7.参考文献</h3>
</section>
<section>
<p style="text-align: left">参考:<br>
<br>
https://www.cnblogs.com/hjwublog/p/5681700.html#autoid-2-8-0<br>
https://blog.csdn.net/tomcatAndOracle/article/details/80305947<br>
https://www.cnblogs.com/rjzheng/p/9096228.html<br>
</p>
</section>
</section>
<section>
<section>
<h3>8.更多讨论</h3>
</section>
</section>
<section>
<!--<h4>鸣谢</h4>-->
<p>感谢大家观看</p>
<p>
<small>BY : 鲁伯良</small>
</p>
</section>
</div>
</div>
<script src="https://ptteng.github.io/PPT/lib/reveal/js/head.min.js "></script>
<script src="https://ptteng.github.io/PPT/lib/reveal/reveal.js "></script>
<script>
// 以下为常见配置属性的默认值
// {
// controls: true, // 是否在右下角展示控制条
// progress: true, // 是否显示演示的进度条
// slideNumber: false, // 是否显示当前幻灯片的页数编号,也可以使用代码slideNumber: 'c / t' ,表示当前页/总页数。
// history: false, // 是否将每个幻灯片改变加入到浏览器的历史记录中去
// keyboard: true, // 是否启用键盘快捷键来导航
// overview: true, // 是否启用幻灯片的概览模式,可使用"Esc "或"o "键来切换概览模式
// center: true, // 是否将幻灯片垂直居中
// touch: true, // 是否在触屏设备上启用触
Reveal.initialize({
history: true,
dependencies: [
{src: 'https://ptteng.github.io/PPT/plugin/markdown/marked.js'},
{src: 'https://ptteng.github.io/PPT/plugin/markdown/markdown.js'},
{src: 'https://ptteng.github.io/PPT/plugin/notes/notes.js', async: true},
{
src: 'https://ptteng.github.io/PPT/plugin/highlight/highlight.js', async: true, callback: function () {
hljs.initHighlightingOnLoad();
}
}
]
});
</script>
</body>
</html>