-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
583 lines (280 loc) · 330 KB
/
search.xml
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>FastDFS分布式部署</title>
<link href="/2020/12/09/fastdfs-fen-bu-shi-bu-shu/"/>
<url>/2020/12/09/fastdfs-fen-bu-shi-bu-shu/</url>
<content type="html"><![CDATA[<h1 id="环境准备"><a href="#环境准备" class="headerlink" title="环境准备"></a>环境准备</h1><h2 id="使用的系统软件"><a href="#使用的系统软件" class="headerlink" title="使用的系统软件"></a>使用的系统软件</h2><table><thead><tr><th align="left">名称</th><th>说明</th></tr></thead><tbody><tr><td align="left">Redhat</td><td>7.x</td></tr><tr><td align="left">libfastcommon</td><td>FastDFS分离出的一些公用函数包</td></tr><tr><td align="left">FastDFS</td><td>FastDFS本体</td></tr><tr><td align="left">fastdfs-nginx-module</td><td>FastDFS和nginx的关联模块</td></tr><tr><td align="left">nginx</td><td>nginx1.18.0</td></tr></tbody></table><h2 id="编译环境"><a href="#编译环境" class="headerlink" title="编译环境"></a>编译环境</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y</span><br></pre></td></tr></tbody></table></figure><h2 id="磁盘目录"><a href="#磁盘目录" class="headerlink" title="磁盘目录"></a>磁盘目录</h2><table><thead><tr><th>说明</th><th>位置</th></tr></thead><tbody><tr><td>所有安装包</td><td>/home/dfs/soft</td></tr><tr><td>数据存储位置</td><td>/home/dfs/</td></tr></tbody></table><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mkdir /home/dfs #创建数据存储目录</span><br><span class="line">cd /usr/local/src #切换到安装目录准备下载安装包</span><br></pre></td></tr></tbody></table></figure><h2 id="安装libfastcommon"><a href="#安装libfastcommon" class="headerlink" title="安装libfastcommon"></a>安装libfastcommon</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz -O libfastcommon.tar.gz</span><br><span class="line">tar -xzvf libfastcommon.tar.gz</span><br><span class="line">cd libfastcommon-1.0.43</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">编译安装</span></span><br><span class="line">./make.sh && ./make.sh install </span><br></pre></td></tr></tbody></table></figure><h2 id="安装FastDFS"><a href="#安装FastDFS" class="headerlink" title="安装FastDFS"></a>安装FastDFS</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">cd ../ #返回上一级目录</span><br><span class="line">wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz -O fastdfs.tar.gz</span><br><span class="line">tar -xzvf fastdfs.tar.gz</span><br><span class="line">cd fastdfs-6.06/</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">编译安装</span></span><br><span class="line">./make.sh && ./make.sh install </span><br></pre></td></tr></tbody></table></figure><p>安装完成/etc/fdfs存放配置文件</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ls /etc/fdfs</span><br><span class="line">client.conf.sample storage.conf.sample storage_ids.conf.sample tracker.conf.sample</span><br></pre></td></tr></tbody></table></figure><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">#配置文件准备</span><br><span class="line">cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf</span><br><span class="line">cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf</span><br><span class="line">cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf</span><br><span class="line"> #客户端文件,测试用</span><br><span class="line">#供nginx访问使用</span><br><span class="line">cp conf/http.conf conf/mime.types /etc/fdfs/ </span><br></pre></td></tr></tbody></table></figure><h2 id="安装fastdfs-nginx-module"><a href="#安装fastdfs-nginx-module" class="headerlink" title="安装fastdfs-nginx-module"></a>安装fastdfs-nginx-module</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">cd ../ #返回上一级目录</span><br><span class="line">wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz -O fastdfs-nginx-module.tar.gz</span><br><span class="line">tar -xzvf fastdfs-nginx-module.tar.gz</span><br><span class="line">cd fastdfs-nginx-module-1.22/</span><br><span class="line">cp src/mod_fastdfs.conf /etc/fdfs/</span><br></pre></td></tr></tbody></table></figure><h2 id="安装nginx"><a href="#安装nginx" class="headerlink" title="安装nginx"></a>安装nginx</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">wget https://nginx.org/download/nginx-1.18.0.tar.gz #下载nginx压缩包</span><br><span class="line">tar -xzvf nginx-1.18.0.tar.gz #解压</span><br><span class="line">cd nginx-1.18.0/</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">添加fastdfs-nginx-module模块</span></span><br><span class="line">./configure --add-module=/home/dfs/soft/fastdfs-nginx-module-1.22/src/ </span><br><span class="line">make && make install #编译安装</span><br></pre></td></tr></tbody></table></figure><h1 id="单机部署"><a href="#单机部署" class="headerlink" title="单机部署"></a>单机部署</h1><h2 id="tracker配置"><a href="#tracker配置" class="headerlink" title="tracker配置"></a>tracker配置</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">服务器ip为 192.168.81.76</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">我建议用ftp下载下来这些文件 本地修改</span></span><br><span class="line">vim /etc/fdfs/tracker.conf</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">需要修改的内容如下</span></span><br><span class="line">port=22122 # tracker服务器端口(默认22122,一般不修改)</span><br><span class="line">base_path=/home/dfs # 存储日志和数据的根目录</span><br></pre></td></tr></tbody></table></figure><h2 id="storage配置"><a href="#storage配置" class="headerlink" title="storage配置"></a>storage配置</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/fdfs/storage.conf</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">需要修改的内容如下</span></span><br><span class="line">port=23000 # storage服务端口(默认23000,一般不修改)</span><br><span class="line">base_path=/home/dfs # 数据和日志文件存储根目录</span><br><span class="line">store_path0=/home/dfs # 第一个存储目录</span><br><span class="line">tracker_server=192.168.81.76:22122 # tracker服务器IP和端口</span><br><span class="line">http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)</span><br></pre></td></tr></tbody></table></figure><h2 id="client测试"><a href="#client测试" class="headerlink" title="client测试"></a>client测试</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/fdfs/client.conf</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">需要修改的内容如下</span></span><br><span class="line">base_path=/home/dfs</span><br><span class="line">tracker_server=192.168.81.76:22122 #tracker服务器IP和端口</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">保存后测试,返回ID表示成功 如:group1/M00/00/00/wKhRTF-RUImAXsvzAA_cqj_P4TU.tar.gz</span></span><br><span class="line">fdfs_upload_file /etc/fdfs/client.conf /home/dfs/soft/nginx-1.18.0.tar.gz</span><br></pre></td></tr></tbody></table></figure><h2 id="配置nginx访问"><a href="#配置nginx访问" class="headerlink" title="配置nginx访问"></a>配置nginx访问</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/fdfs/mod_fastdfs.conf</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">需要修改的内容如下</span></span><br><span class="line">tracker_server=192.168.81.76:22122 #tracker服务器IP和端口</span><br><span class="line">url_have_group_name=true</span><br><span class="line">store_path0=/home/dfs</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">配置nginx.config</span></span><br><span class="line">vim /usr/local/nginx/conf/nginx.conf</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">添加如下配置</span></span><br><span class="line">server {</span><br><span class="line"> listen 8888; ## 该端口为storage.conf中的http.server_port相同</span><br><span class="line"> server_name localhost;</span><br><span class="line"> location ~/group[0-9]/ {</span><br><span class="line"> ngx_fastdfs_module;</span><br><span class="line"> }</span><br><span class="line"> error_page 500 502 503 504 /50x.html;</span><br><span class="line"> location = /50x.html {</span><br><span class="line"> root html;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">测试下载,用外部浏览器访问刚才已传过的nginx安装包,引用返回的ID</span></span><br><span class="line">http://192.168.81.76:8888/group1/M00/00/00/wKhRTF-RUImAXsvzAA_cqj_P4TU.tar.gz</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">弹出下载,单机部署全部跑通</span></span><br></pre></td></tr></tbody></table></figure><h1 id="分布式部署"><a href="#分布式部署" class="headerlink" title="分布式部署"></a>分布式部署</h1><h2 id="tracker配置-1"><a href="#tracker配置-1" class="headerlink" title="tracker配置"></a>tracker配置</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">服务器ip为 192.168.81.74,192.168.81.75,192.168.81.76</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">我建议用ftp下载下来这些文件 本地修改</span></span><br><span class="line">vim /etc/fdfs/tracker.conf</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">需要修改的内容如下</span></span><br><span class="line">port=22122 # tracker服务器端口(默认22122,一般不修改)</span><br><span class="line">base_path=/home/dfs # 存储日志和数据的根目录</span><br></pre></td></tr></tbody></table></figure><h2 id="storage配置-1"><a href="#storage配置-1" class="headerlink" title="storage配置"></a>storage配置</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/fdfs/storage.conf</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">需要修改的内容如下</span></span><br><span class="line">port=23000 # storage服务端口(默认23000,一般不修改)</span><br><span class="line">base_path=/home/dfs # 数据和日志文件存储根目录</span><br><span class="line">store_path0=/home/dfs # 第一个存储目录</span><br><span class="line">tracker_server=192.168.81.74:22122 # 服务器1</span><br><span class="line">tracker_server=192.168.81.75:22122 # 服务器2</span><br><span class="line">tracker_server=192.168.81.76:22122 # 服务器3</span><br><span class="line">http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)</span><br></pre></td></tr></tbody></table></figure><h2 id="client测试-1"><a href="#client测试-1" class="headerlink" title="client测试"></a>client测试</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/fdfs/client.conf</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">需要修改的内容如下</span></span><br><span class="line">base_path=/home/moe/dfs</span><br><span class="line">tracker_server=192.168.81.74:22122 # 服务器1</span><br><span class="line">tracker_server=192.168.81.75:22122 # 服务器2</span><br><span class="line">tracker_server=192.168.81.76:22122 # 服务器3</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">保存后测试,返回ID表示成功 如:group1/M00/00/00/wKhRTF-SSf2AO6VIAAxZcPR00vw.tar.gz</span></span><br><span class="line">fdfs_upload_file /etc/fdfs/client.conf /home/dfs/soft/nginx-1.18.0.tar.gz</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h2 id="配置nginx访问-1"><a href="#配置nginx访问-1" class="headerlink" title="配置nginx访问"></a>配置nginx访问</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/fdfs/mod_fastdfs.conf</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">需要修改的内容如下</span></span><br><span class="line">tracker_server=192.168.81.74:22122 # 服务器1</span><br><span class="line">tracker_server=192.168.81.75:22122 # 服务器2</span><br><span class="line">tracker_server=192.168.81.76:22122 # 服务器3</span><br><span class="line">url_have_group_name=true</span><br><span class="line">store_path0=/home/dfs</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">配置nginx.config</span></span><br><span class="line">vim /usr/local/nginx/conf/nginx.conf</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">添加如下配置</span></span><br><span class="line">server {</span><br><span class="line"> listen 8888; ## 该端口为storage.conf中的http.server_port相同</span><br><span class="line"> server_name localhost;</span><br><span class="line"> location ~/group[0-9]/ {</span><br><span class="line"> ngx_fastdfs_module;</span><br><span class="line"> }</span><br><span class="line"> error_page 500 502 503 504 /50x.html;</span><br><span class="line"> location = /50x.html {</span><br><span class="line"> root html;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>服务器启动后分别访问<code>192.168.81.74:8888/group1/M00/00/00/wKhRTF-SSf2AO6VIAAxZcPR00vw.tar.gz</code>和<code>192.168.81.76:8888/group1/M00/00/00/wKhRTF-SSf2AO6VIAAxZcPR00vw.tar.gz</code>,弹出文件下载,则分布式服务部署成功。</p><h1 id="启动"><a href="#启动" class="headerlink" title="启动"></a>启动</h1><h2 id="防火墙"><a href="#防火墙" class="headerlink" title="防火墙"></a>防火墙</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">不关闭防火墙的话无法使用</span></span><br><span class="line">systemctl stop firewalld.service #关闭</span><br><span class="line">systemctl restart firewalld.service #重启</span><br></pre></td></tr></tbody></table></figure><h2 id="tracker"><a href="#tracker" class="headerlink" title="tracker"></a>tracker</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">/etc/init.d/fdfs_trackerd start #启动tracker服务</span><br><span class="line">/etc/init.d/fdfs_trackerd restart #重启动tracker服务</span><br><span class="line">/etc/init.d/fdfs_trackerd stop #停止tracker服务</span><br><span class="line">chkconfig fdfs_trackerd on #自启动tracker服务</span><br></pre></td></tr></tbody></table></figure><h2 id="storage"><a href="#storage" class="headerlink" title="storage"></a>storage</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">/etc/init.d/fdfs_storaged start #启动storage服务</span><br><span class="line">/etc/init.d/fdfs_storaged restart #重动storage服务</span><br><span class="line">/etc/init.d/fdfs_storaged stop #停止动storage服务</span><br><span class="line">chkconfig fdfs_storaged on #自启动storage服务</span><br></pre></td></tr></tbody></table></figure><h2 id="nginx"><a href="#nginx" class="headerlink" title="nginx"></a>nginx</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">/usr/local/nginx/sbin/nginx #启动nginx</span><br><span class="line">/usr/local/nginx/sbin/nginx -s reload #重启nginx</span><br><span class="line">/usr/local/nginx/sbin/nginx -s stop #停止nginx</span><br></pre></td></tr></tbody></table></figure><h2 id="检测集群"><a href="#检测集群" class="headerlink" title="检测集群"></a>检测集群</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">/usr/bin/fdfs_monitor /etc/fdfs/storage.conf</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">会显示会有几台服务器 有3台就会 显示 Storage 1-Storage 3的详细信息</span></span><br></pre></td></tr></tbody></table></figure><h1 id="说明"><a href="#说明" class="headerlink" title="说明"></a>说明</h1><h2 id="配置文件"><a href="#配置文件" class="headerlink" title="配置文件"></a>配置文件</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">tracker_server #有几台服务器写几个</span><br><span class="line">group_name #地址的名称的命名</span><br><span class="line">bind_addr #服务器ip绑定</span><br><span class="line">store_path_count #store_path(数字)有几个写几个</span><br><span class="line">store_path(数字) #设置几个储存地址写几个 从0开始</span><br></pre></td></tr></tbody></table></figure><h2 id="可能遇到的问题"><a href="#可能遇到的问题" class="headerlink" title="可能遇到的问题"></a>可能遇到的问题</h2><figure class="highlight shell"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">如果不是root 用户 你必须在除了cd的命令之外 全部加sudo</span><br><span class="line">如果不是root 用户 编译和安装分开进行 先编译再安装</span><br><span class="line">如果上传成功 但是nginx报错404 先检查mod_fastdfs.conf文件中的store_path0是否一致</span><br><span class="line">如果nginx无法访问 先检查防火墙 和 mod_fastdfs.conf文件tracker_server是否一致</span><br><span class="line">如果 unknown directive "ngx_fastdfs_module" in /usr/local/nginx/conf/nginx.conf:151,可能是nginx一直是启动的,必须要重启nginx才可以,`nginx -s reload`无效。</span><br></pre></td></tr></tbody></table></figure>]]></content>
<categories>
<category> Linux </category>
</categories>
<tags>
<tag> nginx </tag>
<tag> Linux </tag>
<tag> FastDFS </tag>
</tags>
</entry>
<entry>
<title>Linux安全加固</title>
<link href="/2020/10/15/linux-an-quan-jia-gu/"/>
<url>/2020/10/15/linux-an-quan-jia-gu/</url>
<content type="html"><![CDATA[<h2 id="Linux加固"><a href="#Linux加固" class="headerlink" title="Linux加固"></a>Linux加固</h2><h3 id="检查口令最小长度"><a href="#检查口令最小长度" class="headerlink" title="检查口令最小长度"></a>检查口令最小长度</h3><p>vim /etc/login.defs</p><p>设置 PASS_MIN_LEN 8</p><h3 id="检查是否设置口令生存周期"><a href="#检查是否设置口令生存周期" class="headerlink" title="检查是否设置口令生存周期"></a>检查是否设置口令生存周期</h3><p>vim /etc/login.defs</p><p>设置PASS_MAX_DAYS 90</p><h3 id="检查设备密码复杂度策略"><a href="#检查设备密码复杂度策略" class="headerlink" title="检查设备密码复杂度策略"></a>检查设备密码复杂度策略</h3><p>vim /etc/pam.d/system-auth</p><p>追加到password requisite pam_cracklib.so后面(ucredit=-1 lcredit=-1 dcredit=-1)</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">password requisite pam_cracklib.so ucredit=-1 lcredit=-1 dcredit=-1</span><br></pre></td></tr></tbody></table></figure><h3 id="检查是否限制用户su到root"><a href="#检查是否限制用户su到root" class="headerlink" title="检查是否限制用户su到root"></a>检查是否限制用户su到root</h3><p>vim /etc/pam.d/su<br>在开头添加下面两行:</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">auth sufficient pam_rootok.so</span><br><span class="line">auth required pam_wheel.so group=wheel </span><br><span class="line"># 将用户添加组</span><br><span class="line">usermod -G wheel gcs</span><br></pre></td></tr></tbody></table></figure><h3 id="检查是否设置文件与目录缺省权限"><a href="#检查是否设置文件与目录缺省权限" class="headerlink" title="检查是否设置文件与目录缺省权限"></a>检查是否设置文件与目录缺省权限</h3><p>vim /etc/profile</p><p>在文件/etc/profile中设置umask 027或UMASK 027,</p><p>如果文件中含有umask参数,则需要在最前面设置该参数</p><h3 id="检查是否设置命令行界面超时退出"><a href="#检查是否设置命令行界面超时退出" class="headerlink" title="检查是否设置命令行界面超时退出"></a>检查是否设置命令行界面超时退出</h3><p>vim /etc/profile,增加 </p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">export TMOUT=300</span><br></pre></td></tr></tbody></table></figure><p>source /etc/profile</p><h3 id="检查是否限制root用户远程登录"><a href="#检查是否限制root用户远程登录" class="headerlink" title="检查是否限制root用户远程登录"></a>检查是否限制root用户远程登录</h3><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">cat /etc/ssh/sshd_config|grep PermitRootLogin</span><br><span class="line">vim /etc/ssh/sshd_config</span><br><span class="line"># 配置</span><br><span class="line">PermitRootLogin no</span><br><span class="line">service sshd restart</span><br></pre></td></tr></tbody></table></figure><h3 id="检查是否配置远程日志功能"><a href="#检查是否配置远程日志功能" class="headerlink" title="检查是否配置远程日志功能"></a>检查是否配置远程日志功能</h3><p>指定具体服务器ip</p><p>vim /etc/rsyslog.conf</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rsyslog.*@192.168.212.1</span><br></pre></td></tr></tbody></table></figure><h3 id="检查FTP用户上传的文件所具有的权限"><a href="#检查FTP用户上传的文件所具有的权限" class="headerlink" title="检查FTP用户上传的文件所具有的权限"></a>检查FTP用户上传的文件所具有的权限</h3><p>如果系统使用vsftp:</p><p>修改/etc/vsftpd.conf(或者为/etc/vsftpd/vsftpd.conf)</p><p>vi /etc/vsftpd.conf</p><p>确保以下行未被注释掉,如果没有该行,请添加:</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">write_enable=YES //允许上传。如果不需要上传权限,此项可不进行更改。</span><br><span class="line">ls_recurse_enable=YES</span><br><span class="line">local_umask=022 //设置用户上传文件的属性为755</span><br><span class="line">anon_umask=022 //匿名用户上传文件(包括目录)的 umask</span><br></pre></td></tr></tbody></table></figure><p>重启网络服务</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/etc/init.d/vsftpd restart</span><br></pre></td></tr></tbody></table></figure><p>如果系统使用pure-ftp<br>修改/etc/pure-ftpd/pure-ftpd.conf</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vi /etc/pure-ftpd/pure-ftpd.conf</span><br></pre></td></tr></tbody></table></figure><p>确保以下行未被注释掉,如果没有该行,请添加:</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">umask 177:077</span><br></pre></td></tr></tbody></table></figure><p>重启ftp服务</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/etc/init.d/pure-ftpd restart</span><br></pre></td></tr></tbody></table></figure><h3 id="检查是否修改系统banner"><a href="#检查是否修改系统banner" class="headerlink" title="检查是否修改系统banner"></a>检查是否修改系统banner</h3><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mv /etc/issue /etc/issue.bak</span><br><span class="line">mv /etc/issue.net /etc/issue.net.bak</span><br></pre></td></tr></tbody></table></figure><h3 id="检查FTP-Banner设置"><a href="#检查FTP-Banner设置" class="headerlink" title="检查FTP Banner设置"></a>检查FTP Banner设置</h3><p>修改vsftp回显信息<br>vi /etc/vsftpd.conf(或/etc/vsftpd/vsftpd.conf)</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ftpd_banner=Authorized users only. All activity will be monitored and reported.”</span><br></pre></td></tr></tbody></table></figure><p>可根据实际需要修改该文件内容。<br>重启服务:</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/etc/init.d/vsftpd restart 或者service vsftpd restart</span><br></pre></td></tr></tbody></table></figure><h3 id="检查是否启用SSH协议,禁用telnet协议"><a href="#检查是否启用SSH协议,禁用telnet协议" class="headerlink" title="检查是否启用SSH协议,禁用telnet协议"></a>检查是否启用SSH协议,禁用telnet协议</h3><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">cat /etc/xinetd.d/telnet|grep disable</span><br><span class="line">vim /etc/xinetd.d/telnet</span><br><span class="line">#修改 </span><br><span class="line">disable = yes</span><br><span class="line">service xinetd restart</span><br></pre></td></tr></tbody></table></figure>]]></content>
<categories>
<category> Linux </category>
</categories>
<tags>
<tag> Linux </tag>
<tag> 漏洞修复 </tag>
</tags>
</entry>
<entry>
<title>openssh8.4p1升级</title>
<link href="/2020/10/15/openssh8-4p1-sheng-ji/"/>
<url>/2020/10/15/openssh8-4p1-sheng-ji/</url>
<content type="html"><![CDATA[<h1 id="准备工作"><a href="#准备工作" class="headerlink" title="准备工作"></a>准备工作</h1><h2 id="开启telnet"><a href="#开启telnet" class="headerlink" title="开启telnet"></a>开启telnet</h2><p>以防服务器升级ssh失败,造成服务器无法连接</p><h3 id="安装telnet"><a href="#安装telnet" class="headerlink" title="安装telnet"></a>安装telnet</h3><p><strong>redhat 7.x版本安装</strong></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">yum install telnet-server.x86_64</span><br><span class="line">yum install telnet.x86_64</span><br><span class="line">yum install xinetd.x86_64 </span><br></pre></td></tr></tbody></table></figure><p>启动服务</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">systemctl start xinetd</span><br><span class="line">systemctl start telnet.socket</span><br></pre></td></tr></tbody></table></figure><p><strong>redhat 6.x版本安装</strong></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">yum install xinetd</span><br><span class="line">yum install telnet</span><br><span class="line">yum install telnet-server</span><br></pre></td></tr></tbody></table></figure><p>启动服务</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">service xinetd start</span><br></pre></td></tr></tbody></table></figure><p>telnet激活需要更改以下文件</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/xinetd.d/telnet 将disabled 改成no</span><br><span class="line">vim /etc/pam.d/remote 将第二行屏蔽掉</span><br><span class="line">#auth required pam_securetty.so</span><br><span class="line"># 重启</span><br><span class="line">service xinetd restart</span><br></pre></td></tr></tbody></table></figure><h2 id="安装依赖"><a href="#安装依赖" class="headerlink" title="安装依赖"></a>安装依赖</h2><p>安装以下依赖</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel</span><br></pre></td></tr></tbody></table></figure><h1 id="开始安装"><a href="#开始安装" class="headerlink" title="开始安装"></a>开始安装</h1><p>以下操作全部在root用户下</p><h2 id="1、备份openssh的配置文件"><a href="#1、备份openssh的配置文件" class="headerlink" title="1、备份openssh的配置文件"></a>1、备份openssh的配置文件</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cp -r /etc/ssh/ /etc/ssh_bak_2 </span><br><span class="line">cp /etc/init.d/sshd /etc/init.d/sshd_bak_2</span><br><span class="line">cp /usr/sbin/sshd /usr/sbin/sshd_bak_2</span><br></pre></td></tr></tbody></table></figure><h2 id="2、解压文件"><a href="#2、解压文件" class="headerlink" title="2、解压文件"></a>2、解压文件</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">tar -xzvf openssh-8.4p1.tar.gz</span><br><span class="line">tar -xzvf openssl-1.1.1h.tar.gz</span><br><span class="line">tar -xzvf zlib-1.2.11.tar.gz</span><br></pre></td></tr></tbody></table></figure><h2 id="3、安装openssl"><a href="#3、安装openssl" class="headerlink" title="3、安装openssl"></a>3、安装openssl</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">cd openssl-1.1.1h </span><br><span class="line">./config --prefix=/usr --shared</span><br><span class="line"># 编译&安装</span><br><span class="line">make && make install</span><br></pre></td></tr></tbody></table></figure><h2 id="4、安装zlib"><a href="#4、安装zlib" class="headerlink" title="4、安装zlib"></a>4、安装zlib</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd ../zlib-1.2.11</span><br><span class="line"> ./configure && make && make install</span><br></pre></td></tr></tbody></table></figure><h2 id="5、安装openssh"><a href="#5、安装openssh" class="headerlink" title="5、安装openssh"></a>5、安装openssh</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd ../openssh-8.4p1 </span><br><span class="line">./configure && make && make install</span><br></pre></td></tr></tbody></table></figure><h2 id="6、以上编译安装完成,下面替换文件"><a href="#6、以上编译安装完成,下面替换文件" class="headerlink" title="6、以上编译安装完成,下面替换文件"></a>6、以上编译安装完成,下面替换文件</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">cp contrib/redhat/sshd.init /etc/init.d/sshd</span><br><span class="line">chkconfig sshd --add</span><br><span class="line">cp ssh scp sftp ssh-keygen ssh-add ssh-agent ssh-keyscan /usr/bin/</span><br><span class="line">rm -rf /usr/sbin/sshd</span><br><span class="line">cp sshd /usr/sbin/</span><br><span class="line">ln -s /usr/lib64/libssl.so /usr/lib64/libssl.so.10</span><br><span class="line">ln -s /usr/lib64/libcrypto.so.1.0.0 /usr/lib64/libcrypto.so.10</span><br><span class="line">cp ssh_config sshd_config /etc/ssh/</span><br><span class="line">cp sftp-server ssh-keysign ssh-pkcs11-helper /usr/libexec/</span><br><span class="line">cp scp.1 ssh-add.1 sftp.1 ssh-keyscan.1 ssh-agent.1 /usr/share/man/man1/</span><br><span class="line">cp sshd.8 sftp-server.8 ssh-keysign.8 ssh-pkcs11-helper.8 /usr/share/man/man8/</span><br><span class="line">touch /etc/ssh/ssh_host_ecdsa_key.pub</span><br></pre></td></tr></tbody></table></figure><p>修改ssh配置</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">vi /etc/ssh/sshd_config</span><br><span class="line">PermitRootLogin yes #禁止root登录,8.4p1默认禁止root用户登录,如有需要,改为yes </span><br><span class="line">PubkeyAuthentication yes</span><br><span class="line">PasswordAuthentication yes</span><br></pre></td></tr></tbody></table></figure><h2 id="7、启动ssh"><a href="#7、启动ssh" class="headerlink" title="7、启动ssh"></a>7、启动ssh</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">service sshd restart</span><br></pre></td></tr></tbody></table></figure><h2 id="8、验证"><a href="#8、验证" class="headerlink" title="8、验证"></a>8、验证</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ssh -V</span><br><span class="line">提示:OpenSSH_8.4p1, OpenSSL 1.1.1h </span><br><span class="line">表示升级成功!</span><br></pre></td></tr></tbody></table></figure><h2 id="9、恢复telnet配置"><a href="#9、恢复telnet配置" class="headerlink" title="9、恢复telnet配置"></a>9、恢复telnet配置</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/xinetd.d/telnet 将disabled 改成no</span><br><span class="line">vim /etc/pam.d/remote </span><br><span class="line">auth required pam_securetty.so</span><br><span class="line">#重启</span><br><span class="line">service xinetd restart</span><br></pre></td></tr></tbody></table></figure><p><a href="https://download.csdn.net/download/haha_201510/12928276">openssh升级文件</a></p>]]></content>
<categories>
<category> Linux </category>
</categories>
<tags>
<tag> openssh </tag>
</tags>
</entry>
<entry>
<title>Spring Cache缓存</title>
<link href="/2020/09/15/spring-cache-huan-cun/"/>
<url>/2020/09/15/spring-cache-huan-cun/</url>
<content type="html"><![CDATA[<h1 id="缓存介绍"><a href="#缓存介绍" class="headerlink" title="缓存介绍"></a>缓存介绍</h1><blockquote><p>Spring3.1之后引入了基于注释(annotation)的缓存(cache)技术,它本质上不是一个具体的缓存实现方案(如EHCache 或者Redis),而是一个对缓存使用的抽象,通过在既有代码中添加少量它定义的各种annotation,即能够达到缓存方法的返回对象的效果。</p></blockquote><blockquote><p>Spring的缓存技术还具备相当的灵活性,不仅能够使用 SpEL(Spring Expression Language)来定义缓存的key和各种condition,还提供开箱即用的缓存临时存储方案,也支持和主流的专业缓存,例如Redis、EHCache集成。</p></blockquote><p>Spring Cache位于spring-content中,如下图<br><img src="http://img.xujn.xyz/20200914154543.png?!"></p><h1 id="Spring-Cache涉及主要类"><a href="#Spring-Cache涉及主要类" class="headerlink" title="Spring Cache涉及主要类"></a>Spring Cache涉及主要类</h1><p>Spring定义了Cache和CacheManager两个基础接口类。</p><h2 id="Cache"><a href="#Cache" class="headerlink" title="Cache"></a>Cache</h2><p><code>Cache</code>接口提供了其他缓存技术实现的规范,包括缓存的各种操作,增加、删除、获取缓存等。Cache默认实现缓存如下,其中<code>Ehcache</code>、<code>RedisCache</code>都为流行的Cache实现方法。</p><p><img src="http://img.xujn.xyz/20200914160019.png?!"></p><h2 id="CacheManager"><a href="#CacheManager" class="headerlink" title="CacheManager"></a>CacheManager</h2><p><code>CacheManager</code>是Spring提供的各种缓存技术抽象接口,通过它管理Spring框架内部默认实现的CacheManager,Spring框架内部默认实现的CacheManager如下</p><p><img src="http://img.xujn.xyz/20200914160901.png?!"></p><h2 id="CacheResolver"><a href="#CacheResolver" class="headerlink" title="CacheResolver"></a>CacheResolver</h2><p><code>CacheResolver</code>解析器,用于根据实际情况来动态解析使用哪个Cache。</p><p><img src="http://img.xujn.xyz/20200914161331.png?!"></p><h2 id="KeyGenerator"><a href="#KeyGenerator" class="headerlink" title="KeyGenerator"></a>KeyGenerator</h2><p><code>KeyGenerator</code>当使用注解时,默认key的生成规则。</p><p><img src="http://img.xujn.xyz/20200914161527.png?!"></p><h1 id="Spring-Cache主要的注解"><a href="#Spring-Cache主要的注解" class="headerlink" title="Spring Cache主要的注解"></a>Spring Cache主要的注解</h1><h2 id="Cacheable"><a href="#Cacheable" class="headerlink" title="@Cacheable"></a>@Cacheable</h2><p>用于读取缓存的方法上,先从缓存中读取数据,如果没有再调用具体方法获取数据,然后将数据添加到缓存中。</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Target({ElementType.TYPE, ElementType.METHOD})</span></span><br><span class="line"><span class="meta">@Retention(RetentionPolicy.RUNTIME)</span></span><br><span class="line"><span class="meta">@Inherited</span></span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> Cacheable {</span><br><span class="line"><span class="comment">//cacheNames的别名</span></span><br><span class="line"> <span class="meta">@AliasFor("cacheNames")</span></span><br><span class="line"> String[] value() <span class="keyword">default</span> {};</span><br><span class="line"><span class="comment">//方法调用的结果存储时的cache名字</span></span><br><span class="line"> <span class="meta">@AliasFor("value")</span></span><br><span class="line"> String[] cacheNames() <span class="keyword">default</span> {};</span><br><span class="line"><span class="comment">//缓存的键值名称,支持SpEL</span></span><br><span class="line"> String <span class="title function_">key</span><span class="params">()</span> <span class="keyword">default</span> <span class="string">""</span>;</span><br><span class="line"><span class="comment">//key的生成策略</span></span><br><span class="line"> String <span class="title function_">keyGenerator</span><span class="params">()</span> <span class="keyword">default</span> <span class="string">""</span>;</span><br><span class="line"><span class="comment">//cache管理器,不指定使用默认</span></span><br><span class="line"> String <span class="title function_">cacheManager</span><span class="params">()</span> <span class="keyword">default</span> <span class="string">""</span>;</span><br><span class="line"><span class="comment">//cache解析器,不指定使用默认</span></span><br><span class="line"> String <span class="title function_">cacheResolver</span><span class="params">()</span> <span class="keyword">default</span> <span class="string">""</span>;</span><br><span class="line"><span class="comment">//满足何种条件才能被缓存,支持SpEL</span></span><br><span class="line"> String <span class="title function_">condition</span><span class="params">()</span> <span class="keyword">default</span> <span class="string">""</span>;</span><br><span class="line"><span class="comment">//满足哪些结果不加入缓存</span></span><br><span class="line"> String <span class="title function_">unless</span><span class="params">()</span> <span class="keyword">default</span> <span class="string">""</span>;</span><br><span class="line"><span class="comment">//是否同步读取缓存,更新缓存</span></span><br><span class="line"> <span class="type">boolean</span> <span class="title function_">sync</span><span class="params">()</span> <span class="keyword">default</span> <span class="literal">false</span>;</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>例子:</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Cacheable(value = "user", key = "#id",condition = "#id.length()>0",unless = "#id==null")</span></span><br><span class="line"> <span class="keyword">public</span> User <span class="title function_">findById</span><span class="params">(String id)</span> {</span><br><span class="line"> <span class="keyword">return</span> userDao.findById(id).orElseGet(User::<span class="keyword">new</span>);</span><br><span class="line"> }</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h2 id="CachePut"><a href="#CachePut" class="headerlink" title="@CachePut"></a>@CachePut</h2><p>用于保存或者更新方法上,调用方法时将相应数据存入缓存中。</p><p>例子:</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@CachePut(value = "user", key = "#user.id")</span></span><br><span class="line"> <span class="meta">@Transactional</span></span><br><span class="line"> <span class="keyword">public</span> User <span class="title function_">update</span><span class="params">(User user)</span> {</span><br><span class="line"> <span class="keyword">return</span> userDao.save(user);</span><br><span class="line"> }</span><br></pre></td></tr></tbody></table></figure><h2 id="CacheEvict"><a href="#CacheEvict" class="headerlink" title="@CacheEvict"></a>@CacheEvict</h2><p>用于删除方法上,删除对应缓存。</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Target({ElementType.TYPE, ElementType.METHOD})</span></span><br><span class="line"><span class="meta">@Retention(RetentionPolicy.RUNTIME)</span></span><br><span class="line"><span class="meta">@Inherited</span></span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> CacheEvict {</span><br><span class="line"> ...</span><br><span class="line"><span class="comment">//是否删除所有实体对象</span></span><br><span class="line"><span class="type">boolean</span> <span class="title function_">allEntries</span><span class="params">()</span> <span class="keyword">default</span> <span class="literal">false</span>;</span><br><span class="line"><span class="comment">//是否在方法调用之前执行,默认在调用方法执行成功后删除缓存。</span></span><br><span class="line"><span class="type">boolean</span> <span class="title function_">beforeInvocation</span><span class="params">()</span> <span class="keyword">default</span> <span class="literal">false</span>;</span><br></pre></td></tr></tbody></table></figure><p>例子:</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@CacheEvict(value = "user")</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">delete</span><span class="params">()</span> {</span><br><span class="line"> ...</span><br><span class="line"> }</span><br></pre></td></tr></tbody></table></figure><h2 id="Caching"><a href="#Caching" class="headerlink" title="@Caching"></a>@Caching</h2><p>组合使用Cache注解</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Target({ElementType.TYPE, ElementType.METHOD})</span></span><br><span class="line"><span class="meta">@Retention(RetentionPolicy.RUNTIME)</span></span><br><span class="line"><span class="meta">@Inherited</span></span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> Caching {</span><br><span class="line"></span><br><span class="line">Cacheable[] cacheable() <span class="keyword">default</span> {};</span><br><span class="line"></span><br><span class="line">CachePut[] put() <span class="keyword">default</span> {};</span><br><span class="line"></span><br><span class="line">CacheEvict[] evict() <span class="keyword">default</span> {};</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h2 id="CacheConfig"><a href="#CacheConfig" class="headerlink" title="@CacheConfig"></a>@CacheConfig</h2><p>全局Cache配置,自定义cache时需在方法上指定此注解。</p><h2 id="EnableCaching"><a href="#EnableCaching" class="headerlink" title="@EnableCaching"></a>@EnableCaching</h2><p>开启Spring Cache的默认配置,启动缓存需要在项目中添加此注解。</p><h1 id="Spring-Boot集成"><a href="#Spring-Boot集成" class="headerlink" title="Spring Boot集成"></a>Spring Boot集成</h1><h2 id="redis"><a href="#redis" class="headerlink" title="redis"></a>redis</h2><p>支持分布式缓存,默认使用Luttuce客户端,也可采用Jedis。</p><h3 id="引入依赖"><a href="#引入依赖" class="headerlink" title="引入依赖"></a>引入依赖</h3><p>pom.xml</p><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><!--缓存--></span></span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-cache<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"><span class="comment"><!--redis实现--></span></span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-data-redis<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure><h3 id="配置文件"><a href="#配置文件" class="headerlink" title="配置文件"></a>配置文件</h3><p>application.yml</p><p><strong>单机模式配置</strong></p><figure class="highlight yml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">application:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">coding-cache-redis</span></span><br><span class="line"><span class="comment"># redis配置 </span></span><br><span class="line"> <span class="attr">redis:</span></span><br><span class="line"> <span class="attr">host:</span> <span class="string">localhost</span></span><br><span class="line"> <span class="attr">port:</span> <span class="number">6379</span></span><br><span class="line"> <span class="attr">password:</span> <span class="number">1111</span></span><br><span class="line"> <span class="attr">database:</span> <span class="number">0</span></span><br><span class="line"><span class="comment"># 启动缓存类型 </span></span><br><span class="line"> <span class="attr">cache:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">redis</span></span><br></pre></td></tr></tbody></table></figure><p><strong>哨兵模式配置</strong></p><figure class="highlight yml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">application:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">coding-cache-redis</span></span><br><span class="line"> <span class="attr">redis:</span></span><br><span class="line"> <span class="attr">sentinel:</span></span><br><span class="line"> <span class="attr">master:</span> <span class="string">mymaster</span></span><br><span class="line"> <span class="attr">nodes:</span> <span class="number">192.168</span><span class="number">.81</span><span class="number">.10</span><span class="string">:26375,192.168.81.11:26376,192.168.81.12:26377</span></span><br><span class="line"> <span class="attr">database:</span> <span class="number">3</span></span><br><span class="line"> <span class="attr">password:</span> <span class="number">1111</span> </span><br><span class="line"> <span class="comment"># 启动缓存类型</span></span><br><span class="line"> <span class="attr">cache:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">redis</span></span><br></pre></td></tr></tbody></table></figure><p><strong>集群模式配置</strong></p><figure class="highlight yml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">application:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">coding-cache-redis</span></span><br><span class="line"> <span class="attr">redis:</span></span><br><span class="line"> <span class="attr">database:</span> <span class="number">3</span></span><br><span class="line"> <span class="attr">password:</span> <span class="number">1111</span></span><br><span class="line"> <span class="attr">cluster:</span></span><br><span class="line"> <span class="comment">#代表redis多个节点的ip与端口号,多个节点需要使用“,”隔开。</span></span><br><span class="line"> <span class="attr">nodes:</span> <span class="number">192.168</span><span class="number">.81</span><span class="number">.10</span><span class="string">:26375,192.168.81.11:26376,192.168.81.12:26377</span></span><br><span class="line"> <span class="comment">#最大重定向次数</span></span><br><span class="line"> <span class="attr">max-redirects:</span> <span class="number">2</span></span><br><span class="line"> <span class="comment"># 启动缓存类型</span></span><br><span class="line"> <span class="attr">cache:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">redis</span></span><br></pre></td></tr></tbody></table></figure><h3 id="启动缓存"><a href="#启动缓存" class="headerlink" title="启动缓存"></a>启动缓存</h3><p>在Application启动类中使用<code>@EnableCaching</code>注解启用缓存</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@EnableCaching</span></span><br><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">CodingCacheRedisApplication</span> {</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line"> SpringApplication.run(CodingCacheRedisApplication.class, args);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h3 id="具体操作"><a href="#具体操作" class="headerlink" title="具体操作"></a>具体操作</h3><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Service</span></span><br><span class="line"><span class="meta">@CacheConfig(cacheNames = "user")</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UserService</span> {</span><br><span class="line"> <span class="meta">@Autowired</span></span><br><span class="line"> <span class="keyword">private</span> UserDao userDao;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Cacheable</span></span><br><span class="line"> <span class="meta">@Transactional</span></span><br><span class="line"> <span class="keyword">public</span> User <span class="title function_">save</span><span class="params">(User user)</span> {</span><br><span class="line"> <span class="keyword">return</span> userDao.save(user);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 缓存更新</span></span><br><span class="line"> <span class="meta">@CachePut(key = "#user.id")</span></span><br><span class="line"> <span class="meta">@Transactional</span></span><br><span class="line"> <span class="keyword">public</span> User <span class="title function_">update</span><span class="params">(User user)</span> {</span><br><span class="line"> <span class="keyword">return</span> userDao.save(user);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 缓存保存</span></span><br><span class="line"> <span class="meta">@Cacheable(key = "#id", condition = "#id.length()>0", unless = "#id==null")</span></span><br><span class="line"> <span class="keyword">public</span> User <span class="title function_">findById</span><span class="params">(String id)</span> {</span><br><span class="line"> <span class="keyword">return</span> userDao.findById(id).orElseGet(User::<span class="keyword">new</span>);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">//缓存删除</span></span><br><span class="line"> <span class="meta">@CacheEvict</span></span><br><span class="line"> <span class="meta">@Transactional</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">delete</span><span class="params">(String id)</span> {</span><br><span class="line"> userDao.deleteById(id);</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h2 id="Ehcache"><a href="#Ehcache" class="headerlink" title="Ehcache"></a>Ehcache</h2><blockquote><p>EhCache 是一个纯 Java 的进程内缓存框架,具有快速、精干等特点,是 Hibernate 中默认的 CacheProvider 。</p></blockquote><h3 id="引入依赖-1"><a href="#引入依赖-1" class="headerlink" title="引入依赖"></a>引入依赖</h3><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>net.sf.ehcache<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>ehcache<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br><span class="line"><span class="tag"><<span class="name">dependency</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">groupId</span>></span>org.springframework.boot<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-boot-starter-cache<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br></pre></td></tr></tbody></table></figure><h3 id="配置文件-1"><a href="#配置文件-1" class="headerlink" title="配置文件"></a>配置文件</h3><p>application.yml</p><figure class="highlight yml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line"> <span class="attr">application:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">coding-cache-redis</span></span><br><span class="line"><span class="comment"># redis配置 </span></span><br><span class="line"> <span class="attr">redis:</span></span><br><span class="line"> <span class="attr">host:</span> <span class="string">localhost</span></span><br><span class="line"> <span class="attr">port:</span> <span class="number">6379</span></span><br><span class="line"> <span class="attr">password:</span> <span class="number">1111</span></span><br><span class="line"> <span class="attr">database:</span> <span class="number">0</span></span><br><span class="line"><span class="comment"># 启动缓存类型 </span></span><br><span class="line"> <span class="attr">cache:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">ehcache</span></span><br></pre></td></tr></tbody></table></figure><p>在resources下添加ehcache.xml</p><figure class="highlight xml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"><?xml version=<span class="string">"1.0"</span> encoding=<span class="string">"UTF-8"</span>?></span> </span><br><span class="line"><span class="tag"><<span class="name">ehcache</span> <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span> </span></span><br><span class="line"><span class="tag"><span class="attr">xsi:noNamespaceSchemaLocation</span>=<span class="string">"ehcache.xsd"</span>></span></span><br><span class="line"><span class="tag"><<span class="name">diskStore</span> <span class="attr">path</span>=<span class="string">"java.io.tmpdir"</span>/></span></span><br><span class="line"><span class="comment"><!--硬盘上缓存存储位置 --></span></span><br><span class="line"><span class="comment"><!--user.home 用户home目录 --></span></span><br><span class="line"><span class="comment"><!--user.dir 用户当前工作目录--></span></span><br><span class="line"><span class="comment"><!--java.io.tmpdir默认临时目录--></span></span><br><span class="line"><span class="tag"><<span class="name">defaultCache</span></span></span><br><span class="line"><span class="tag"> <span class="attr">eternal</span>=<span class="string">"false"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">maxEntriesLocalHeap</span>=<span class="string">"2000"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">timeToIdleSeconds</span>=<span class="string">"120"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">timeToLiveSeconds</span>=<span class="string">"120"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">overflowToDisk</span>=<span class="string">"false"</span> /></span></span><br><span class="line"> <span class="comment"><!-- user 缓存 --></span></span><br><span class="line"> <span class="comment"><!-- name:缓存名 --></span></span><br><span class="line"> <span class="comment"><!-- maxElementsInMemory:最大缓存 key 数量 --></span></span><br><span class="line"> <span class="comment"><!-- timeToLiveSeconds:缓存过期时长,单位:秒 --></span></span><br><span class="line"> <span class="comment"><!-- memoryStoreEvictionPolicy:缓存淘汰策略 --></span></span><br><span class="line"> <span class="tag"><<span class="name">cache</span> <span class="attr">name</span>=<span class="string">"user"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">maxElementsInMemory</span>=<span class="string">"1000"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">timeToLiveSeconds</span>=<span class="string">"60"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">memoryStoreEvictionPolicy</span>=<span class="string">"LRU"</span>/></span> </span><br><span class="line"><span class="tag"></<span class="name">cache</span>></span></span><br><span class="line"></span><br><span class="line"><span class="tag"></<span class="name">ehcache</span>></span></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h3 id="启动缓存-1"><a href="#启动缓存-1" class="headerlink" title="启动缓存"></a>启动缓存</h3><p>在Application启动类中使用<code>@EnableCaching</code>注解启用缓存</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@EnableCaching</span></span><br><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">CodingCacheRedisApplication</span> {</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line"> SpringApplication.run(CodingCacheRedisApplication.class, args);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><h3 id="具体操作-1"><a href="#具体操作-1" class="headerlink" title="具体操作"></a>具体操作</h3><p>同redis</p>]]></content>
<categories>
<category> Spring Boot </category>
</categories>
<tags>
<tag> 缓存 </tag>
<tag> Spring Boot </tag>
<tag> Redis </tag>
<tag> Ehcache </tag>
</tags>
</entry>
<entry>
<title>Spring Boot Mail发送邮件</title>
<link href="/2020/08/11/pring-boot-mail-fa-song-you-jian/"/>
<url>/2020/08/11/pring-boot-mail-fa-song-you-jian/</url>
<content type="html"><![CDATA[<h1 id="邮件协议"><a href="#邮件协议" class="headerlink" title="邮件协议"></a>邮件协议</h1><blockquote><p>示例引用于网易邮箱,不同邮箱<code>服务器地址</code>不同</p></blockquote><p><img src="http://img.xujn.xyz/20200713173053.png?!"></p><blockquote><p>IMAP和POP3区别</p></blockquote><p><img src="http://img.xujn.xyz/20200713173655.png?!"></p><h2 id="POP3-接收邮件服务器"><a href="#POP3-接收邮件服务器" class="headerlink" title="POP3 接收邮件服务器"></a>POP3 接收邮件服务器</h2><blockquote><p> <strong>POP3</strong>是Post Office Protocol 3的简称,即邮局协议的第3个版本,它规定怎样将个人计算机连接到Internet的邮件服务器和下载电子邮件的电子协议。它是因特网电子邮件的第一个离线协议标准,POP3允许用户从服务器上把邮件存储到本地主机(即自己的计算机)上,同时删除保存在邮件服务器上的邮件,而POP3服务器则是遵循POP3协议的接收邮件服务器,用来接收电子邮件的。</p></blockquote><h2 id="IMAP-接收邮件服务器"><a href="#IMAP-接收邮件服务器" class="headerlink" title="IMAP 接收邮件服务器"></a>IMAP 接收邮件服务器</h2><blockquote><p> <strong>IMAP</strong>全称是Internet Mail Access Protocol,即交互式邮件存取协议,它是跟POP3类似邮件访问标准协议之一。不同的是,开启了IMAP后,您在电子邮件客户端收取的邮件仍然保留在服务器上,同时在客户端上的操作都会反馈到服务器上,如:删除邮件,标记已读等,服务器上的邮件也会做相应的动作。所以无论从浏览器登录邮箱或者客户端软件登录邮箱,看到的邮件以及状态都是一致的。</p></blockquote><h2 id="SMTP-发送邮件服务器"><a href="#SMTP-发送邮件服务器" class="headerlink" title="SMTP 发送邮件服务器"></a>SMTP 发送邮件服务器</h2><blockquote><p><strong>SMTP</strong> 的全称是“Simple Mail Transfer Protocol”,即简单邮件传输协议。它是一组用于从源地址到目的地址传输邮件的规范,通过它来控制邮件的中转方式。SMTP 协议属于 TCP/IP 协议簇,它帮助每台计算机在发送或中转信件时找到下一个目的地。SMTP 服务器就是遵循 SMTP 协议的发送邮件服务器。SMTP 认证,简单地说就是要求必须在提供了账户名和密码之后才可以登录 SMTP 服务器,这就使得那些垃圾邮件的散播者无可乘之机。增加 SMTP 认证的目的是为了使用户避免受到垃圾邮件的侵扰。 </p></blockquote><h1 id="项目依赖"><a href="#项目依赖" class="headerlink" title="项目依赖"></a>项目依赖</h1><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><dependency></span><br><span class="line"> <groupId>org.springframework.boot</groupId></span><br><span class="line"> <artifactId>spring-boot-starter-mail</artifactId></span><br><span class="line"></dependency></span><br></pre></td></tr></tbody></table></figure><h1 id="项目配置"><a href="#项目配置" class="headerlink" title="项目配置"></a>项目配置</h1><p>aplication.yml</p><p><strong>启用ssl</strong></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">server:</span><br><span class="line"> port: 9010</span><br><span class="line"></span><br><span class="line">spring:</span><br><span class="line"> mail:</span><br><span class="line"># 发送邮件服务器地址</span><br><span class="line"> host: smtp.xxx.com</span><br><span class="line"># 用户名</span><br><span class="line"> username: xxx@xxx.com</span><br><span class="line"># 密码,对于QQ邮箱、163邮箱等填写授权码</span><br><span class="line"> password: 123456</span><br><span class="line"># ssl 加密端口,无ssl加密为25端口</span><br><span class="line"> port: 465</span><br><span class="line"># 采用协议</span><br><span class="line"> protocol: smtp</span><br><span class="line"># ssl配置参数</span><br><span class="line"> properties:</span><br><span class="line"> mail:</span><br><span class="line"> smtp:</span><br><span class="line"> ssl:</span><br><span class="line"> enable: true</span><br><span class="line"> socketFactory:</span><br><span class="line"> fallback: false</span><br><span class="line"> class: javax.net.ssl.SSLSocketFactory</span><br><span class="line"> auth: true</span><br><span class="line"> starttls:</span><br><span class="line"> enable: true</span><br><span class="line"> required: true</span><br><span class="line"># freemarker模板配置</span><br><span class="line"> freemarker:</span><br><span class="line"># 指定文件后缀</span><br><span class="line"> suffix: .html</span><br></pre></td></tr></tbody></table></figure><p><strong>不启用ssl</strong></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">server:</span><br><span class="line"> port: 9010</span><br><span class="line"></span><br><span class="line">spring:</span><br><span class="line"> mail:</span><br><span class="line"># 发送邮件服务器地址</span><br><span class="line"> host: smtp.xxx.com</span><br><span class="line"># 用户名</span><br><span class="line"> username: xxx@xxx.com</span><br><span class="line"># 密码,对于QQ邮箱、163邮箱等填写授权码</span><br><span class="line"> password: 123456</span><br><span class="line"># ssl 加密端口,无ssl加密为25端口</span><br><span class="line"> port: 25</span><br><span class="line"># 采用协议</span><br><span class="line"> protocol: smtp</span><br><span class="line"># freemarker模板配置</span><br><span class="line"> freemarker:</span><br><span class="line"># 指定文件后缀</span><br><span class="line"> suffix: .html</span><br></pre></td></tr></tbody></table></figure><h1 id="发送邮件"><a href="#发送邮件" class="headerlink" title="发送邮件"></a>发送邮件</h1><h2 id="简易邮件"><a href="#简易邮件" class="headerlink" title="简易邮件"></a>简易邮件</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"> @Autowired</span><br><span class="line"> private JavaMailSender javaMailSender;</span><br><span class="line"> </span><br><span class="line"> public void sendSimpleMail() {</span><br><span class="line">// 创建消息体</span><br><span class="line"> SimpleMailMessage simpleMailMessage = new SimpleMailMessage();</span><br><span class="line"> simpleMailMessage.setFrom("xxxxx@xxx.com");//发件人</span><br><span class="line"> simpleMailMessage.setTo("1111@qq.com");//收件人</span><br><span class="line"> simpleMailMessage.setSubject("测试邮件");//主题</span><br><span class="line"> simpleMailMessage.setCc("156@163.com");//抄送,可添多个</span><br><span class="line"> simpleMailMessage.setText("邮件内容");//邮件内容(只能文本)</span><br><span class="line">// simpleMailMessage.setBcc();//密送</span><br><span class="line"> javaMailSender.send(simpleMailMessage);</span><br><span class="line"> log.info("发送成功");</span><br><span class="line"> }</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h2 id="附件邮件"><a href="#附件邮件" class="headerlink" title="附件邮件"></a>附件邮件</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"> @Autowired</span><br><span class="line"> private JavaMailSender javaMailSender;</span><br><span class="line"> public void sendAttachmentMail() throws MessagingException {</span><br><span class="line">// 创建消息体</span><br><span class="line"> MimeMessage mimeMessage = javaMailSender.createMimeMessage();</span><br><span class="line"> MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);</span><br><span class="line"> helper.setFrom("xxxxx@xxx.com");//发件人</span><br><span class="line"> helper.setTo("1111@qq.com");//收件人</span><br><span class="line"> helper.setSubject("测试邮件");//主题</span><br><span class="line"> helper.setCc("156@163.com");//抄送,可添多个</span><br><span class="line"> helper.setText("<html><body><b>邮件内容</b></body></html>", true);//邮件内容(文本或者html)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> File file = new File("C:\\home\\logs\\log.2019-08-01.log");</span><br><span class="line">// 添加附件</span><br><span class="line"> helper.addAttachment("测试附加", file);</span><br><span class="line"> javaMailSender.send(mimeMessage);</span><br><span class="line"> }</span><br></pre></td></tr></tbody></table></figure><h2 id="模板邮件"><a href="#模板邮件" class="headerlink" title="模板邮件"></a>模板邮件</h2><p>添加freemarker依赖,也可以采用其他模板语言velocity、themeleaf等,用法类似</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework.boot</groupId></span><br><span class="line"> <artifactId>spring-boot-starter-freemarker</artifactId></span><br><span class="line"></dependency></span><br></pre></td></tr></tbody></table></figure><p>创建freemarker模板,新建vm.html模板文件</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><!DOCTYPE html></span><br><span class="line"><html lang="en"></span><br><span class="line"><head></span><br><span class="line"> <meta charset="UTF-8"></span><br><span class="line"> <title>邮件模板</title></span><br><span class="line"></head></span><br><span class="line"><body></span><br><span class="line">${username}您好:</span><br><span class="line"> 欢迎使用xxx系统</span><br><span class="line"></body></span><br><span class="line"></html></span><br></pre></td></tr></tbody></table></figure><p>发送邮件</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"> Autowired</span><br><span class="line"> private JavaMailSender javaMailSender;</span><br><span class="line"> public void sendTemplateMail() {</span><br><span class="line">// 创建消息体</span><br><span class="line"> MimeMessage mimeMessage = javaMailSender.createMimeMessage();</span><br><span class="line"> MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);</span><br><span class="line"> helper.setFrom("xxxxx@xxx.com");//发件人</span><br><span class="line"> helper.setTo("1111@qq.com");//收件人</span><br><span class="line"> helper.setSubject("测试邮件");//主题</span><br><span class="line"> helper.setCc("156@163.com");//抄送,可添多个</span><br><span class="line"></span><br><span class="line"> Map<String, Object> model = new HashMap<>();</span><br><span class="line"> model.put("username", "Joe");</span><br><span class="line">// 获取模板文件</span><br><span class="line"> Template template = freeMarkerConfigurer.getConfiguration().getTemplate("vm.html");</span><br><span class="line">// 根据模型转换模板内容</span><br><span class="line"> String text = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);</span><br><span class="line"> helper.setText(text, true);//邮件内容</span><br><span class="line"></span><br><span class="line"> javaMailSender.send(mimeMessage);</span><br><span class="line"> }</span><br></pre></td></tr></tbody></table></figure>]]></content>
<categories>
<category> Spring Boot </category>
</categories>
<tags>
<tag> Spring Boot </tag>
<tag> Mail </tag>
</tags>
</entry>
<entry>
<title>elasticsearch安装</title>
<link href="/2020/08/11/elasticsearch-an-zhuang/"/>
<url>/2020/08/11/elasticsearch-an-zhuang/</url>
<content type="html"><![CDATA[<h2 id="环境说明"><a href="#环境说明" class="headerlink" title="环境说明"></a>环境说明</h2><ul><li>redhat</li><li>java 8</li></ul><h2 id="安装elasticsearch"><a href="#安装elasticsearch" class="headerlink" title="安装elasticsearch"></a>安装elasticsearch</h2><p><em>es安装默认不支持使用root用户安装,否则会提示java.lang.RuntimeException: can not run elasticsearch as root</em></p><h3 id="新建用户组"><a href="#新建用户组" class="headerlink" title="新建用户组"></a>新建用户组</h3><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">groupadd es</span><br><span class="line">useradd es -g es</span><br><span class="line">passwd es</span><br><span class="line">es2020</span><br><span class="line">chown -R es:es elasticsearch-7.6.1 </span><br><span class="line">su - es</span><br></pre></td></tr></tbody></table></figure><p>从官网下载<a href="https://www.elastic.co/cn/downloads/elasticsearch">elasticsearch</a>,然后执行以下命令。</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-linux-x86_64.tar.gz</span><br><span class="line">//解压</span><br><span class="line">tar-xzvf elasticsearch-7.6.2-linux-x86_64.tar.gz</span><br><span class="line">//进入解压目录</span><br><span class="line">./bin/elasticsearch</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>执行成功后,es会使用9200端口运行</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">curl localhost:9200</span><br><span class="line">//返回一个 JSON 对象,包含当前节点、集群、版本等信息。</span><br><span class="line">{</span><br><span class="line"> "name" : "node74",</span><br><span class="line"> "cluster_name" : "elasticsearch",</span><br><span class="line"> "cluster_uuid" : "OUU4f0tiQnazkiQOlExfFw",</span><br><span class="line"> "version" : {</span><br><span class="line"> "number" : "7.6.1",</span><br><span class="line"> "build_flavor" : "default",</span><br><span class="line"> "build_type" : "tar",</span><br><span class="line"> "build_hash" : "aa751e09be0a5072e8570670309b1f12348f023b",</span><br><span class="line"> "build_date" : "2020-03-01T00:15:25.529771Z",</span><br><span class="line"> "build_snapshot" : false,</span><br><span class="line"> "lucene_version" : "8.4.0",</span><br><span class="line"> "minimum_wire_compatibility_version" : "6.8.0",</span><br><span class="line"> "minimum_index_compatibility_version" : "6.0.0-beta1"</span><br><span class="line"> },</span><br><span class="line"> "tagline" : "You Know, for Search"</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><table><thead><tr><th>参数</th><th>说明</th></tr></thead><tbody><tr><td>cluster.name</td><td>集群名称,相同名称为一个集群</td></tr><tr><td>node.name</td><td>节点名称,集群模式下每个节点名称唯一</td></tr><tr><td>node.master</td><td>当前节点是否可以被选举为master节点,是:true、否:false</td></tr><tr><td>node.data</td><td>当前节点是否用于存储数据,是:true、否:false</td></tr><tr><td>path.data</td><td>索引数据存放的位置</td></tr><tr><td>path.logs</td><td>日志文件存放的位置</td></tr><tr><td>bootstrap.memory_lock</td><td>需求锁住物理内存,是:true、否:false</td></tr><tr><td>network.host</td><td>监听地址,用于访问该es, 0.0.0.0允许任务服务器访问</td></tr><tr><td>network.publish_host</td><td>可设置成内网ip,用于集群内各机器间通信</td></tr><tr><td>http.port</td><td>es对外提供的http端口,默认 9200</td></tr><tr><td>transport.tcp.port</td><td>TCP的默认监听端口,默认 9300</td></tr><tr><td>discovery.seed_hosts</td><td>es7.x 之后新增的配置,写入候选主节点的设备地址,在开启服务后可以被选为主节点</td></tr><tr><td>cluster.initial_master_nodes</td><td>es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举master</td></tr><tr><td>http.cors.enabled</td><td>是否支持跨域,是:true,在使用head插件时需要此配置</td></tr><tr><td>http.cors.allow-origin</td><td>“*” 表示支持所有域名</td></tr></tbody></table>]]></content>
<categories>
<category> Linux </category>
</categories>
<tags>
<tag> elasticsearch </tag>
</tags>
</entry>
<entry>
<title>Spring Boot集成Tinymce富文本编辑器</title>
<link href="/2020/07/02/sping-boot-ji-cheng-tinymce-fu-wen-ben-bian-ji/"/>
<url>/2020/07/02/sping-boot-ji-cheng-tinymce-fu-wen-ben-bian-ji/</url>
<content type="html"><![CDATA[<h1 id="基础环境"><a href="#基础环境" class="headerlink" title="基础环境"></a>基础环境</h1><ul><li>IDEA</li><li>Spring Boot 2.2.1</li><li>Freemarker</li></ul><h1 id="tinymce简介"><a href="#tinymce简介" class="headerlink" title="tinymce简介"></a>tinymce简介</h1><blockquote><p>TinyMCE是一款易用、且功能强大的所见即所得的富文本编辑器。同类程序有:UEditor、Kindeditor、Simditor、CKEditor、wangEditor、Suneditor、froala等。</p></blockquote><p>经过多番对比(<del>界面好看</del>),认定Tinymce功能更加完善,并且具备可扩展特性,功能完善,遂采用。</p><h1 id="小例子"><a href="#小例子" class="headerlink" title="小例子"></a>小例子</h1><p>下面是tinymce实例化的例子,通过id绑定,渲染页面。tinymce可以嵌入到任意web项目中。编辑内容的保存可以通过post表单的形式提交,也可以自己获取内容提交。</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><!DOCTYPE html></span><br><span class="line"><html></span><br><span class="line"><head></span><br><span class="line"></span><br><span class="line"></head></span><br><span class="line"></span><br><span class="line"><body></span><br><span class="line"><h1>TinyMCE快速开始示例</h1></span><br><span class="line"> <form method="post"></span><br><span class="line"> <textarea id="demo">Hello, World!</textarea></span><br><span class="line"> </form></span><br><span class="line"></body</span><br><span class="line"> <script src='tinymce.min.js'></script></span><br><span class="line"> <script></span><br><span class="line"> tinymce.init({</span><br><span class="line"> selector: '#demo'//ID绑定</span><br><span class="line"> //此处可添加更多特性</span><br><span class="line"> });</span><br><span class="line"> </script></span><br><span class="line"></html></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h1 id="正式开始"><a href="#正式开始" class="headerlink" title="正式开始"></a>正式开始</h1><h2 id="引入Tinymce脚本"><a href="#引入Tinymce脚本" class="headerlink" title="引入Tinymce脚本"></a>引入Tinymce脚本</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><script src="/complaints/tinymce/tinymce.min.js"></script></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h2 id="渲染区域"><a href="#渲染区域" class="headerlink" title="渲染区域"></a>渲染区域</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><div class="layui-form-item"></span><br><span class="line"> <textarea id="content" name="content"></textarea></span><br><span class="line"></div></span><br></pre></td></tr></tbody></table></figure><h2 id="实例化"><a href="#实例化" class="headerlink" title="实例化"></a>实例化</h2><p>支持图片、视频</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br></pre></td><td class="code"><pre><span class="line">tinymce.init({</span><br><span class="line"> selector: '#content',//绑定渲染区</span><br><span class="line"> height: 600,</span><br><span class="line"> plugins: 'paste importcss code table advlist fullscreen imagetools textcolor colorpicker hr autolink link image lists preview media wordcount',</span><br><span class="line"> toolbar: 'styleselect | formatselect | fontsizeselect | forecolor backcolor | bold italic underline strikethrough | image media | table | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | preview removeformat hr | paste code link | undo redo | fullscreen',</span><br><span class="line"> skin: 'oxide',</span><br><span class="line"> language: 'zh_CN',//汉化</span><br><span class="line"> convert_urls: false,</span><br><span class="line"> // relative_urls : true,</span><br><span class="line"> images_upload_url: '../tmmedia/upload',//图片上传地址</span><br><span class="line"> images_upload_credentials: true,</span><br><span class="line"> image_dimensions: false,</span><br><span class="line"> image_class_list: [</span><br><span class="line"> {title: '无', value: ''},</span><br><span class="line"> {title: '预览', value: 'preview'},</span><br><span class="line"> ],</span><br><span class="line"> // images_upload_base_path: '/',</span><br><span class="line"> forced_root_block: 'p',</span><br><span class="line"> force_p_newlines: true,</span><br><span class="line"> importcss_append: true,</span><br><span class="line"> content_style: `</span><br><span class="line"> * { padding:0; margin:0; }</span><br><span class="line"> html, body { height:100%; }</span><br><span class="line"> img { max-width:100%; display:block;height:auto; }</span><br><span class="line"> a { text-decoration: none; }</span><br><span class="line"> iframe { width: 100%; }</span><br><span class="line"> p { line-height:1.6; margin: 0px; }</span><br><span class="line"> table { word-wrap:break-word; word-break:break-all; max-width:100%; border:none; border-color:#999; }</span><br><span class="line"> .mce-object-iframe { width:100%; box-sizing:border-box; margin:0; padding:0; }</span><br><span class="line"> ul,ol { list-style-position:inside; }</span><br><span class="line"> `,</span><br><span class="line"> insert_button_items: 'image link | inserttable',</span><br><span class="line"> // CONFIG: Paste</span><br><span class="line"> paste_retain_style_properties: 'all',</span><br><span class="line"> paste_word_valid_elements: '*[*]', // word需要它</span><br><span class="line"> paste_data_images: true, // 粘贴的同时能把内容里的图片自动上传</span><br><span class="line"> paste_convert_word_fake_lists: false, // 插入word文档需要该属性</span><br><span class="line"> paste_webkit_styles: 'all',</span><br><span class="line"> paste_merge_formats: true,</span><br><span class="line"> nonbreaking_force_tab: false,</span><br><span class="line"> paste_auto_cleanup_on_paste: false,</span><br><span class="line"></span><br><span class="line"> // CONFIG: Font</span><br><span class="line"> fontsize_formats: '10px 11px 12px 14px 16px 18px 20px 24px',</span><br><span class="line"></span><br><span class="line"> // CONFIG: StyleSelect</span><br><span class="line"> style_formats: [</span><br><span class="line"> {</span><br><span class="line"> title: '首行缩进',</span><br><span class="line"> block: 'p',</span><br><span class="line"> styles: {'text-indent': '2em'}</span><br><span class="line"> },</span><br><span class="line"> {</span><br><span class="line"> title: '行高',</span><br><span class="line"> items: [</span><br><span class="line"> {title: '1', styles: {'line-height': '1'}, inline: 'span'},</span><br><span class="line"> {title: '1.5', styles: {'line-height': '1.5'}, inline: 'span'},</span><br><span class="line"> {title: '2', styles: {'line-height': '2'}, inline: 'span'},</span><br><span class="line"> {title: '2.5', styles: {'line-height': '2.5'}, inline: 'span'},</span><br><span class="line"> {title: '3', styles: {'line-height': '3'}, inline: 'span'}</span><br><span class="line"> ]</span><br><span class="line"> }</span><br><span class="line"> ],</span><br><span class="line"> // Tab</span><br><span class="line"> tabfocus_elements: ':prev,:next',</span><br><span class="line"> object_resizing: true,</span><br><span class="line"></span><br><span class="line"> // Image</span><br><span class="line"> imagetools_toolbar: 'rotateleft rotateright | flipv fliph | editimage imageoptions',</span><br><span class="line"> file_picker_types: 'media',</span><br><span class="line"> media_live_embeds: true,</span><br><span class="line"> //be used to add custom file picker to those dialogs that have it.</span><br><span class="line"> file_picker_callback: function (cb, value, meta) {</span><br><span class="line"> if (meta.filetype == 'media') {</span><br><span class="line"> //创建一个隐藏的type=file的文件选择input</span><br><span class="line"> let input = document.createElement('input');</span><br><span class="line"> input.setAttribute('type', 'file');</span><br><span class="line"> input.onchange = function(){</span><br><span class="line"> let file = this.files[0];//只选取第一个文件。如果要选取全部,后面注意做修改</span><br><span class="line"> let xhr, formData;</span><br><span class="line"> xhr = new XMLHttpRequest();</span><br><span class="line"> xhr.open('POST', '../tmmedia/upload');//自定义文件上传</span><br><span class="line"> xhr.withCredentials = true;</span><br><span class="line"> xhr.upload.onprogress = function (e) {</span><br><span class="line"> // 进度(e.loaded / e.total * 100)</span><br><span class="line"> };</span><br><span class="line"> xhr.onerror = function () {</span><br><span class="line"> console.log(xhr.status);</span><br><span class="line"> return;</span><br><span class="line"> };</span><br><span class="line"> xhr.onload = function () {</span><br><span class="line"> let json;</span><br><span class="line"> if (xhr.status < 200 || xhr.status >= 300) {</span><br><span class="line"> console.log('HTTP 错误: ' + xhr.status);</span><br><span class="line"> return;</span><br><span class="line"> }</span><br><span class="line"> json = JSON.parse(xhr.responseText);</span><br><span class="line"> console.log(json)</span><br><span class="line"> //接口返回的文件保存地址</span><br><span class="line"> let mediaLocation=json.location;</span><br><span class="line"> //cb()回调函数,将mediaLocation显示在弹框输入框中</span><br><span class="line"> cb(mediaLocation, { title: file.name });</span><br><span class="line"></span><br><span class="line"> };</span><br><span class="line"> formData = new FormData();</span><br><span class="line"> //假设接口接收参数为file,值为选中的文件</span><br><span class="line"> formData.append('file', file);</span><br><span class="line"> //正式使用将下面被注释的内容恢复</span><br><span class="line"> xhr.send(formData);</span><br><span class="line"> }</span><br><span class="line"> //触发点击</span><br><span class="line"> input.click();</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> });</span><br></pre></td></tr></tbody></table></figure><p>实现效果<br><img src="http://img.xujn.xyz/20200702182102.png?!"></p><h2 id="保存功能"><a href="#保存功能" class="headerlink" title="保存功能"></a>保存功能</h2><p>通过 <code>tinymce.activeEditor.getContent()</code>获取编辑区内容,内容为html代码。</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">form.on('submit(save)', function (data) {</span><br><span class="line"> var field = data.field;</span><br><span class="line"> //获取内容核心</span><br><span class="line"> field.content = tinymce.activeEditor.getContent()</span><br><span class="line"></span><br><span class="line"> var loadIndex;</span><br><span class="line"> loadIndex = layer.load(2);</span><br><span class="line"> $.post("../tmknowledgebase/saveOrUpdate", field, function (data) {</span><br><span class="line"> if (data.code === 200) {</span><br><span class="line"> tools.success("保存成功!");</span><br><span class="line"> layer.msg("成功!", {time: 1000}, function () {</span><br><span class="line"> layer.close(loadIndex);</span><br><span class="line"> //传给上个页面,刷新table用</span><br><span class="line"> tools.putTempData('submitOK', true);</span><br><span class="line"> //关掉对话框</span><br><span class="line"> tools.closeThisDialog();</span><br><span class="line"> });</span><br><span class="line"> } else {</span><br><span class="line"> layer.close(loadIndex)</span><br><span class="line"> tools.error(data.msg);</span><br><span class="line"> }</span><br><span class="line"> })</span><br><span class="line"> })</span><br></pre></td></tr></tbody></table></figure><h2 id="内容回显"><a href="#内容回显" class="headerlink" title="内容回显"></a>内容回显</h2><p>在保存编辑内容后,如果我们想要再次编辑,需要对以保存内容进行回显,之前提到,保存的内容实际是html片段,因此采用html渲染即可。在此项目中采用Freemarker框架,渲染代码如下:</p><p><code>${data.content!""}</code>为后台返回的编辑区内容</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"> <div class="layui-card-body layui-form-item"></span><br><span class="line"> <textarea id="content" name="content">${data.content!""}</textarea></span><br><span class="line"></div></span><br></pre></td></tr></tbody></table></figure><p>实例化区域代码与上文相同</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">tinymce.init({</span><br><span class="line"> selector: '#content',</span><br><span class="line"> height: 600,</span><br><span class="line"> ...</span><br></pre></td></tr></tbody></table></figure><h2 id="汉化"><a href="#汉化" class="headerlink" title="汉化"></a>汉化</h2><p>tinymce默认是英文的,需要引入汉化包zh_CN.js到langs目录下,在<code>language</code>属性下添加<code>zh_CN</code>.</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">tinymce.init({</span><br><span class="line"> selector: '#content',</span><br><span class="line"> language:'zh_CN',//注意大小写</span><br><span class="line">});</span><br></pre></td></tr></tbody></table></figure><h2 id="图片上传"><a href="#图片上传" class="headerlink" title="图片上传"></a>图片上传</h2><p>首先后台自定义文件上传接口</p><p><strong>注意</strong>:需要指定具体的下载地址,否则上传后文件无法回显<code> map.put("location", "当前文件实际下载地址");</code></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">@PostMapping(value = "/tmmedia/upload")</span><br><span class="line"> public Object downloadFile(@RequestParam MultipartFile file) {</span><br><span class="line"> Map<String, String> map = new HashMap<>();</span><br><span class="line"> try {</span><br><span class="line"> String fileName = file.getOriginalFilename();</span><br><span class="line"> String extension = StringUtils.getFilenameExtension(fileName);</span><br><span class="line"> String name = IdUtil.fastUUID() + "." + extension;</span><br><span class="line"> ftpUtils.upload(dir, name, file);</span><br><span class="line">// 文件下载,供前台回显</span><br><span class="line"> map.put("location", downloadUrl + dir + "/" + name);</span><br><span class="line"> } catch (Exception e) {</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> map.put("location", "");</span><br><span class="line"> }</span><br><span class="line"> return map;</span><br><span class="line"> }</span><br></pre></td></tr></tbody></table></figure><p>渲染区配置</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">tinymce.init({</span><br><span class="line"> selector: '#content',</span><br><span class="line"> language:'zh_CN',//注意大小写</span><br><span class="line"> plugins: image ',</span><br><span class="line"> images_upload_url: '../tmmedia/upload',//图片上传地址</span><br><span class="line"> images_upload_credentials: true,</span><br><span class="line"> image_dimensions: false,</span><br><span class="line"> image_class_list: [</span><br><span class="line"> {title: '无', value: ''},</span><br><span class="line"> {title: '预览', value: 'preview'},</span><br><span class="line"> ],</span><br><span class="line">});</span><br></pre></td></tr></tbody></table></figure><h2 id="视频播放"><a href="#视频播放" class="headerlink" title="视频播放"></a>视频播放</h2><p>首先后台自定义文件上传接口</p><p>==注意==:需要指定具体的下载地址,否则上传后文件无法回显<code> map.put("location", "当前文件实际下载地址");</code></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">@PostMapping(value = "/tmmedia/upload")</span><br><span class="line"> public Object downloadFile(@RequestParam MultipartFile file) {</span><br><span class="line"> Map<String, String> map = new HashMap<>();</span><br><span class="line"> try {</span><br><span class="line"> String fileName = file.getOriginalFilename();</span><br><span class="line"> String extension = StringUtils.getFilenameExtension(fileName);</span><br><span class="line"> String name = IdUtil.fastUUID() + "." + extension;</span><br><span class="line"> ftpUtils.upload(dir, name, file);</span><br><span class="line">// 文件下载,供前台回显</span><br><span class="line"> map.put("location", downloadUrl + dir + "/" + name);</span><br><span class="line"> } catch (Exception e) {</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> map.put("location", "");</span><br><span class="line"> }</span><br><span class="line"> return map;</span><br><span class="line"> }</span><br></pre></td></tr></tbody></table></figure><p>渲染区配置</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line">tinymce.init({</span><br><span class="line"> selector: '#content',</span><br><span class="line"> language:'zh_CN',//注意大小写</span><br><span class="line"> plugins: media ',</span><br><span class="line"> file_picker_types: 'media',</span><br><span class="line"> media_live_embeds: true,</span><br><span class="line"> //be used to add custom file picker to those dialogs that have it.</span><br><span class="line"> file_picker_callback: function (cb, value, meta) {</span><br><span class="line"> if (meta.filetype == 'media') {</span><br><span class="line"> //创建一个隐藏的type=file的文件选择input</span><br><span class="line"> let input = document.createElement('input');</span><br><span class="line"> input.setAttribute('type', 'file');</span><br><span class="line"> input.onchange = function(){</span><br><span class="line"> let file = this.files[0];//只选取第一个文件。如果要选取全部,后面注意做修改</span><br><span class="line"> let xhr, formData;</span><br><span class="line"> xhr = new XMLHttpRequest();</span><br><span class="line"> xhr.open('POST', '../tmmedia/upload');//自定义文件上传</span><br><span class="line"> xhr.withCredentials = true;</span><br><span class="line"> xhr.upload.onprogress = function (e) {</span><br><span class="line"> // 进度(e.loaded / e.total * 100)</span><br><span class="line"> };</span><br><span class="line"> xhr.onerror = function () {</span><br><span class="line"> console.log(xhr.status);</span><br><span class="line"> return;</span><br><span class="line"> };</span><br><span class="line"> xhr.onload = function () {</span><br><span class="line"> let json;</span><br><span class="line"> if (xhr.status < 200 || xhr.status >= 300) {</span><br><span class="line"> console.log('HTTP 错误: ' + xhr.status);</span><br><span class="line"> return;</span><br><span class="line"> }</span><br><span class="line"> json = JSON.parse(xhr.responseText);</span><br><span class="line"> console.log(json)</span><br><span class="line"> //接口返回的文件保存地址</span><br><span class="line"> let mediaLocation=json.location;</span><br><span class="line"> //cb()回调函数,将mediaLocation显示在弹框输入框中</span><br><span class="line"> cb(mediaLocation, { title: file.name });</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> };</span><br><span class="line"> formData = new FormData();</span><br><span class="line"> //假设接口接收参数为file,值为选中的文件</span><br><span class="line"> formData.append('file', file);</span><br><span class="line"> //正式使用将下面被注释的内容恢复</span><br><span class="line"> xhr.send(formData);</span><br><span class="line"> }</span><br><span class="line"> //触发点击</span><br><span class="line"> input.click();</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">});</span><br></pre></td></tr></tbody></table></figure>]]></content>
<categories>
<category> Spring Boot </category>
</categories>
<tags>
<tag> Spring Boot </tag>
<tag> Tinymce </tag>
</tags>
</entry>
<entry>
<title>Nginx常用场景</title>
<link href="/2020/06/12/nginx-chang-yong-chang-jing/"/>
<url>/2020/06/12/nginx-chang-yong-chang-jing/</url>
<content type="html"><![CDATA[<h1 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h1><p>Nginx是一款轻量级的Web服务器、反向代理服务器,由于它的内存占用少,启动极快,高并发能力强,在互联网项目中广泛应用。</p><h1 id="应用场景"><a href="#应用场景" class="headerlink" title="应用场景"></a>应用场景</h1><h2 id="负载均衡"><a href="#负载均衡" class="headerlink" title="负载均衡"></a>负载均衡</h2><p><strong>轮询</strong></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">upstream test {</span><br><span class="line"> server 10.200.100.3:8080;</span><br><span class="line"> server 10.200.100.4:8081;</span><br><span class="line">}</span><br><span class="line">upstream admin {</span><br><span class="line"> server 10.200.100.3:9080;</span><br><span class="line"> server 10.200.100.4:9081;</span><br><span class="line">}</span><br><span class="line">server {</span><br><span class="line"> listen 81; </span><br><span class="line"> server_name localhost; </span><br><span class="line">#映射地址</span><br><span class="line"> location / {</span><br><span class="line"> ssi on;</span><br><span class="line"> ssi_silent_errors on;</span><br><span class="line"> proxy_read_timeout 300;</span><br><span class="line"> proxy_set_header Host $host:$server_port;</span><br><span class="line"> proxy_set_header X-Real-IP $remote_addr;</span><br><span class="line"> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</span><br><span class="line"> # proxy_pass内容与upstream对应</span><br><span class="line"> proxy_pass http://test;</span><br><span class="line"> proxy_redirect default;</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> #映射地址指定多个,根据访问路径匹配不同地址`location`</span><br><span class="line"> location /admin {</span><br><span class="line"> ssi on;</span><br><span class="line"> ssi_silent_errors on;</span><br><span class="line"> proxy_read_timeout 300;</span><br><span class="line"> proxy_set_header Host $host:$server_port;</span><br><span class="line"> proxy_set_header X-Real-IP $remote_addr;</span><br><span class="line"> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</span><br><span class="line"> # proxy_pass内容与upstream对应</span><br><span class="line"> proxy_pass http://admin;</span><br><span class="line"> proxy_redirect default;</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p><strong>设置权重</strong></p><p>通过weight指定访问服务器权重,权重越高代表服务器被访问的几率的越大。</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">upstream test {</span><br><span class="line"> server localhost:8080 weight=9;</span><br><span class="line"> server localhost:8081 weight=1;</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p><strong>iphash</strong></p><p>iphash的每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。(分布式session同步可采用redis解决)</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">upstream test {</span><br><span class="line"> ip_hash;</span><br><span class="line"> server localhost:8080;</span><br><span class="line"> server localhost:8081;</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h2 id="反正代理"><a href="#反正代理" class="headerlink" title="反正代理"></a>反正代理</h2><blockquote><p>反向代理隐藏了真实的服务端,例如访问<code>http://www.baidu.com</code>,可能有成千上万的程序为我们服务。代理对象为服务端。</p></blockquote><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">server { </span><br><span class="line"> listen 80; </span><br><span class="line"> server_name localhost; </span><br><span class="line"> </span><br><span class="line"> location / {</span><br><span class="line"> proxy_pass http://10.200.100.2:8080;</span><br><span class="line"> proxy_set_header Host $host:$server_port;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><blockquote><p>正向代理: 它隐藏了真实的请求客户端,服务端不知道真实的客户端是谁,客户端请求的服务都被代理服务器代替来请求.代理对象为客户端。</p></blockquote><h2 id="HTTP服务器"><a href="#HTTP服务器" class="headerlink" title="HTTP服务器"></a>HTTP服务器</h2><p>Nginx本身也是一个静态资源的服务器,当只有静态资源的时候,就可以使用Nginx来做服务器。</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">server {</span><br><span class="line"> listen 80; </span><br><span class="line"> server_name localhost; </span><br><span class="line"></span><br><span class="line"> location / {</span><br><span class="line"> #指定静态文件位置</span><br><span class="line"> root /opt/dist;</span><br><span class="line"> #访问首页</span><br><span class="line"> index index.html;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h1 id="常用操作"><a href="#常用操作" class="headerlink" title="常用操作"></a>常用操作</h1><p><strong>解压安装常用</strong></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">查看nginx安装位置:</span><br><span class="line">whereis nginx</span><br><span class="line"></span><br><span class="line">启动:</span><br><span class="line">$ /usr/local/nginx/sbin/nginx</span><br><span class="line"></span><br><span class="line">热重启:</span><br><span class="line">$ /usr/local/nginx/sbin/nginx –s reload</span><br><span class="line"></span><br><span class="line">停止:</span><br><span class="line">$ /usr/local/nginx/sbin/nginx –s stop</span><br><span class="line"></span><br><span class="line">测试配置文件是否正常:</span><br><span class="line">$ /usr/local/nginx/sbin/nginx –t</span><br><span class="line"></span><br><span class="line">强制关闭:</span><br><span class="line">$ pkill nginx</span><br></pre></td></tr></tbody></table></figure><p><strong>yum安装常用</strong></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">systemctl enable nginx # 设置开机启动 Nginx</span><br><span class="line">systemctl disable nginx # 关闭开机启动 Nginx</span><br><span class="line">systemctl start nginx # 启动 Nginx</span><br><span class="line">systemctl stop nginx # 停止 Nginx</span><br><span class="line">systemctl restart nginx # 重启 Nginx</span><br><span class="line">systemctl reload nginx # 重新加载 Nginx</span><br><span class="line">systemctl status nginx # 查看 Nginx 运行状态</span><br></pre></td></tr></tbody></table></figure>]]></content>
<categories>
<category> Linux </category>
</categories>
<tags>
<tag> nginx </tag>
</tags>
</entry>
<entry>
<title>nginx解压版平滑升级</title>
<link href="/2020/03/25/nginx-jie-ya-ban-ping-hua-sheng-ji/"/>
<url>/2020/03/25/nginx-jie-ya-ban-ping-hua-sheng-ji/</url>
<content type="html"><![CDATA[<h1 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h1><ul><li>nginx 1.16.1</li><li>redhat</li></ul><h1 id="操作过程"><a href="#操作过程" class="headerlink" title="操作过程"></a>操作过程</h1><p><em><strong>做好配置备份</strong></em></p><p>下载<a href="http://nginx.org/download/nginx-1.16.1.tar.gz">nginx1.16.1</a>,进行解压操作。</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">wget http://nginx.org/download/nginx-1.16.1.tar.gz</span><br><span class="line">tar -xzvf nginx-1.16.1.tar.gz</span><br></pre></td></tr></tbody></table></figure><p>进入解压后的文件夹,进行编译,不进行安装操作</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd nginx-1.16.1</span><br><span class="line">./configure && make</span><br></pre></td></tr></tbody></table></figure><p>备份旧版本nginx</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx114.old</span><br></pre></td></tr></tbody></table></figure><p>将刚编译后的文件替换原有文件,编译后的文件在<code>objs</code>目录下<br> </p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp objs/nginx /usr/local/nginx/sbin/</span><br></pre></td></tr></tbody></table></figure><br>平滑升级,旧的Nginx主进程会变为<code>xxx.oldbin</code>,然后执行新版 nginx。两个版本会同时存在,共同处理请求。<p></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`</span><br></pre></td></tr></tbody></table></figure><p>关闭旧版本nginx</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`</span><br></pre></td></tr></tbody></table></figure><p>查看升级后版本</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">/usr/local/nginx/sbin/nginx -v</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>操作过程</p><p><img src="http://img.xujn.xyz/20200325175159.png?!"></p>]]></content>
<categories>
<category> 软件安装 </category>
</categories>
<tags>
<tag> nginx </tag>
</tags>
</entry>
<entry>
<title>redis 4.14单机\哨兵模式搭建</title>
<link href="/2020/03/11/redis-4.14-shao-bing-mo-shi-da-jian/"/>
<url>/2020/03/11/redis-4.14-shao-bing-mo-shi-da-jian/</url>
<content type="html"><![CDATA[<h1 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h1><ul><li>redis:4.0.14</li><li>linux</li><li>1主2从</li></ul><h1 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h1><h2 id="下载redis"><a href="#下载redis" class="headerlink" title="下载redis"></a>下载redis</h2><p><a href="http://download.redis.io/releases/redis-4.0.14.tar.gz">redis-4.0.14.tar.gz</a></p><h2 id="配置redis"><a href="#配置redis" class="headerlink" title="配置redis"></a>配置redis</h2><p>解压 <code>tar -xzvf redis-4.0.14.tar.gz</code></p><p>编译<br><code>cd redis-4.0.14/</code></p><p>执行<code>make</code></p><p>结束后,在<code>redis-4.0.14</code>新建config文件夹<br><code>mkdir config</code></p><p>拷贝redis配置文件</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cp redis.conf ../config/redis-6301.conf</span><br><span class="line">cp redis.conf ../config/redis-6302.conf</span><br><span class="line">cp redis.conf ../config/redis-6303.conf</span><br></pre></td></tr></tbody></table></figure><p>配置三个redis.conf</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim redis-6301.conf</span><br></pre></td></tr></tbody></table></figure><p>主节点</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">//服务器ip</span><br><span class="line">#bind 192.168.18.128</span><br><span class="line">protected-mode no</span><br><span class="line">port 6301</span><br><span class="line"><!--后台启动--></span><br><span class="line">daemonize yes</span><br><span class="line">supervised no</span><br><span class="line">pidfile "/var/run/redis_6301.pid"</span><br><span class="line">dbfilename "6301dump.rdb"</span><br><span class="line">masterauth "redis"</span><br><span class="line"></span><br><span class="line">slave-read-only no # 从节点不仅可以读,也可以写,yes为从节点只读</span><br></pre></td></tr></tbody></table></figure><p>从节点添加</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">//主节点ip port</span><br><span class="line">slaveof 192.168.18.128 6301</span><br></pre></td></tr></tbody></table></figure><p>另外修改对应端口</p><p>启动</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">./redis-server ../config/redis-6301.conf</span><br><span class="line">./redis-server ../config/redis-6302.conf </span><br><span class="line">./redis-server ../config/redis-6303.conf </span><br></pre></td></tr></tbody></table></figure><p>查看</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">./redis-cli -h 192.168.18.128 -p 6301</span><br><span class="line"></span><br><span class="line"><!--验证--></span><br><span class="line">auth redis</span><br><span class="line"><!--显示信息--></span><br><span class="line">info</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>显示主从信息</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"># Replication</span><br><span class="line">role:master //主节点</span><br><span class="line">connected_slaves:2</span><br><span class="line">slave0:ip=192.168.18.128,port=6301,state=online,offset=6359422,lag=1</span><br><span class="line">slave1:ip=192.168.18.128,port=6302,state=online,offset=6359279,lag=1</span><br><span class="line">master_replid:82dd642ad60846cd858cfa20e86cda7c4a043881</span><br><span class="line">master_replid2:0000000000000000000000000000000000000000</span><br><span class="line">master_repl_offset:6359565</span><br><span class="line">second_repl_offset:-1</span><br><span class="line">repl_backlog_active:1</span><br><span class="line">repl_backlog_size:1048576</span><br><span class="line">repl_backlog_first_byte_offset:5310990</span><br><span class="line">repl_backlog_histlen:1048576</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h1 id="哨兵模式配置"><a href="#哨兵模式配置" class="headerlink" title="哨兵模式配置"></a>哨兵模式配置</h1><p>配置项</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">port 26301</span><br><span class="line">sentinel monitor mymaster 192.168.18.128 6301 2</span><br><span class="line">sentinel auth-pass mymaster redis</span><br><span class="line">sentinel down-after-milliseconds mymaster 15000</span><br><span class="line">sentinel parallel-syncs mymaster 1</span><br><span class="line">sentinel failover-timeout mymaster 80000</span><br><span class="line">bind 192.168.18.128</span><br><span class="line">protected-mode no</span><br><span class="line">daemonize yes //允许后台启动</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>向config文件夹中拷贝三个配置文件</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cp sentinel.conf ../config/sentinel-6301.conf</span><br><span class="line">cp sentinel.conf ../config/sentinel-6302.conf</span><br><span class="line">cp sentinel.conf ../config/sentinel-6303.conf</span><br></pre></td></tr></tbody></table></figure><p>从节点修改端口26302,26303</p><p>启动</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">./redis-sentinel ../config/sentinel-26301.conf</span><br><span class="line">./redis-sentinel ../config/sentinel-26302.conf</span><br><span class="line">./redis-sentinel ../config/sentinel-26303.conf</span><br></pre></td></tr></tbody></table></figure><h2 id="结果验证"><a href="#结果验证" class="headerlink" title="结果验证"></a>结果验证</h2><p>查看进程<br><code>ps -ef|grep redis</code></p><p><img src="http://img.xujn.xyz/20190403162358.png?!"></p><p>验证下主从同步</p><p><code>kill -9 13028</code><br>查看主节点变更情况</p><h2 id="spring-boot集成"><a href="#spring-boot集成" class="headerlink" title="spring boot集成"></a>spring boot集成</h2><p>配置文件application.yml</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">spring:</span><br><span class="line"> redis:</span><br><span class="line"> # url: 127.0.0.1 // 单机使用</span><br><span class="line"> # host: localhost</span><br><span class="line"> # port: 6379</span><br><span class="line"> timeout: 3600</span><br><span class="line"> password: redis</span><br><span class="line"> sentinel:</span><br><span class="line"> nodes: 192.168.18.128:26301,192.168.18.128:26302,192.168.18.128:26303</span><br><span class="line"> master: mymaster</span><br></pre></td></tr></tbody></table></figure><p>WebMvcConfigurer配置</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">@Configuration</span><br><span class="line">public class WebConfig implements WebMvcConfigurer {</span><br><span class="line"> @Value("#{'${spring.redis.sentinel.nodes}'.split(',')}")</span><br><span class="line"> private List<String> nodes;</span><br><span class="line"> @Value("${spring.redis.password}")</span><br><span class="line"> private String redisPassword;</span><br><span class="line"> @Value("${spring.redis.sentinel.master}")</span><br><span class="line"> private String redisMaster;</span><br><span class="line"> @Autowired</span><br><span class="line"> private FastJsonHttpMessageConverter fastJsonHttpMessageConverter;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> @Bean</span><br><span class="line"> public RestTemplateBuilder restTemplateBuilder() {</span><br><span class="line"> RestTemplateBuilder builder = new RestTemplateBuilder();</span><br><span class="line"> return builder.messageConverters(fastJsonHttpMessageConverter);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> @Bean</span><br><span class="line"> public RestTemplate restTemplate() {</span><br><span class="line"> return restTemplateBuilder().build();</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> @Bean</span><br><span class="line"> JedisConnectionFactory jedisConnectionFactory() {</span><br><span class="line"> return new JedisConnectionFactory(sentinelConfiguration());</span><br><span class="line"> }</span><br><span class="line"> @Bean</span><br><span class="line"> public RedisSentinelConfiguration sentinelConfiguration(){</span><br><span class="line"> RedisSentinelConfiguration redisSentinelConfiguration = new RedisSentinelConfiguration();</span><br><span class="line"> //配置matser的名称</span><br><span class="line"> redisSentinelConfiguration.master(redisMaster);</span><br><span class="line"> //配置redis的哨兵sentinel</span><br><span class="line"> Set<RedisNode> redisNodeSet = new HashSet<>();</span><br><span class="line"> nodes.forEach(x->{</span><br><span class="line"> redisNodeSet.add(new RedisNode(x.split(":")[0],Integer.parseInt(x.split(":")[1])));</span><br><span class="line"> });</span><br><span class="line"> log.info("\nredisNodeSet -->{}",redisNodeSet);</span><br><span class="line"> redisSentinelConfiguration.setSentinels(redisNodeSet);</span><br><span class="line"> redisSentinelConfiguration.setPassword(RedisPassword.of(redisPassword));</span><br><span class="line"> return redisSentinelConfiguration;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> @Bean</span><br><span class="line"> public RedisTemplate<String, Object> redisTemplate() {</span><br><span class="line"> RedisTemplate<String, Object> template = new RedisTemplate<>();</span><br><span class="line"> template.setConnectionFactory(jedisConnectionFactory());</span><br><span class="line"> return template;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>启动,连接成功会显示具体信息</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">redis.clients.jedis.JedisSentinelPool : Trying to find master from available Sentinels...</span><br><span class="line">redis.clients.jedis.JedisSentinelPool : Redis master running at 192.168.18.128:6303, starting Sentinel listeners...</span><br><span class="line">redis.clients.jedis.JedisSentinelPool : Created JedisPool to master at 192.168.18.128:6303</span><br></pre></td></tr></tbody></table></figure><p>连接异常情况</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">2019-04-04 09:55:44.961 INFO 24056 --- [ main] redis.clients.jedis.JedisSentinelPool : Trying to find master from available Sentinels...</span><br><span class="line">2019-04-04 09:55:44.973 WARN 24056 --- [ main] redis.clients.jedis.JedisSentinelPool : Cannot get master address from sentinel running @ 192.168.18.1281:26302. Reason: redis.clients.jedis.exceptions.JedisConnectionException: java.net.UnknownHostException: 192.168.18.1281. Trying next one.</span><br><span class="line">2019-04-04 09:55:44.973 WARN 24056 --- [ main] redis.clients.jedis.JedisSentinelPool : Cannot get master address from sentinel running @ 192.168.18.1281:26301. Reason: redis.clients.jedis.exceptions.JedisConnectionException: java.net.UnknownHostException: 192.168.18.1281. Trying next one.</span><br><span class="line">2019-04-04 09:55:44.973 WARN 24056 --- [ main] redis.clients.jedis.JedisSentinelPool : Cannot get master address from sentinel running @ 192.168.18.1281:26303. Reason: redis.clients.jedis.exceptions.JedisConnectionException: java.net.UnknownHostException: 192.168.18.1281. Trying next one.</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h2 id="注意事项"><a href="#注意事项" class="headerlink" title="注意事项"></a>注意事项</h2><p>防火墙端口开启</p>]]></content>
<categories>
<category> 软件安装 </category>
</categories>
<tags>
<tag> redis </tag>
</tags>
</entry>
<entry>
<title>nginx 1.14.2解压版安装</title>
<link href="/2020/03/11/nginx-1.14.2-jie-ya-ban-an-zhuang/"/>
<url>/2020/03/11/nginx-1.14.2-jie-ya-ban-an-zhuang/</url>
<content type="html"><![CDATA[<h2 id="安装包"><a href="#安装包" class="headerlink" title="安装包"></a>安装包</h2><ul><li>nginx-1.14.2.tar.gz</li><li>openssl-fips-2.0.16.tar.gz</li><li>zlib-1.2.11.tar.gz</li><li>pcre-8.43.tar.gz</li></ul><h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><p>先安装依赖,然后安装nginx</p><p>openssl</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">tar -xzvf openssl-fips-2.0.16.tar.gz</span><br><span class="line">cd openssl-fips-2.0.16/</span><br><span class="line">./config && make && make install</span><br></pre></td></tr></tbody></table></figure><p>pcre</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">tar -xzvf pcre-8.43.tar.gz </span><br><span class="line">cd pcre-8.43/</span><br><span class="line">./configure && make && make install</span><br></pre></td></tr></tbody></table></figure><p>zlib</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">tar -zxvf zlib-1.2.11.tar.gz</span><br><span class="line"> cd zlib-1.2.11</span><br><span class="line"> ./configure && make && make install</span><br></pre></td></tr></tbody></table></figure><p>最后nginx</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">tar -zxvf nginx-1.14.2.tar.gz </span><br><span class="line">cd nginx-1.14.2</span><br><span class="line"> ./configure && make && make install</span><br></pre></td></tr></tbody></table></figure><h2 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h2><p><img src="http://img.xujn.xyz/20190404144507.png?!"></p><h2 id="操作"><a href="#操作" class="headerlink" title="操作"></a>操作</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><!---启动-></span><br><span class="line">/usr/local/nginx/sbin/nginx</span><br><span class="line"></span><br><span class="line"><!--重启--></span><br><span class="line">/usr/local/nginx/sbin/nginx -s reload</span><br><span class="line"></span><br><span class="line"><!--停止--></span><br><span class="line">/usr/local/nginx/sbin/nginx -s stop</span><br><span class="line"></span><br><span class="line"><!--查看nginx安装位置--></span><br><span class="line">whereis nginx</span><br><span class="line"></span><br><span class="line"><!---配置文件-></span><br><span class="line">cd /usr/local/nginx/conf</span><br><span class="line">vim nginx.conf</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure>]]></content>
<categories>
<category> 软件安装 </category>
</categories>
<tags>
<tag> nginx </tag>
</tags>
</entry>
<entry>
<title>Docker安装oracle 11g</title>
<link href="/2020/03/11/docker-an-zhuang-oracle/"/>
<url>/2020/03/11/docker-an-zhuang-oracle/</url>
<content type="html"><![CDATA[<h2 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h2><ul><li>主机win10,宿主机 Ubuntu 18.04</li><li>Docker version 18.09.2</li><li>oracle 11g</li><li>Vmware Workstaion 15 Pro</li></ul><h2 id="安装docker"><a href="#安装docker" class="headerlink" title="安装docker"></a>安装docker</h2><p>安装docker有两种方式,一种从Ubuntu的存储库安装,这种安装方式docker版本不是最新的。第二种从Docker存储库安装。这里我选用的是第一种。</p><p><strong>安装</strong></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt install docker.io</span><br></pre></td></tr></tbody></table></figure><p><strong>启动,并添加开机启动</strong></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">systemctl start docker //启动</span><br><span class="line">systemctl enable docker //开机启动</span><br></pre></td></tr></tbody></table></figure><p><strong>查看安装版本</strong></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker --version</span><br></pre></td></tr></tbody></table></figure><h2 id="docker常用命令"><a href="#docker常用命令" class="headerlink" title="docker常用命令"></a>docker常用命令</h2><p><strong>搜索镜像</strong></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">//搜索oracle镜像</span><br><span class="line">docker search oracle </span><br></pre></td></tr></tbody></table></figure><p><strong>下载镜像</strong></p><p>pull命令将从指定Docker Register上下载镜像</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull oracle </span><br></pre></td></tr></tbody></table></figure><p><strong>列出镜像</strong></p><p>images命令将列出已下载镜像</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker images</span><br></pre></td></tr></tbody></table></figure><p><strong>删除镜像</strong></p><p>rmi命令可删除指定镜像</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker rmi hello-world</span><br></pre></td></tr></tbody></table></figure><h2 id="安装oracle"><a href="#安装oracle" class="headerlink" title="安装oracle"></a>安装oracle</h2><p><strong>下载镜像</strong></p><p>文件有点大,建议先将Ubuntu的下载源更改为国内的。</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p><strong>新建镜像并启动</strong></p><p>使用root用户操作</p><p>docker run命令 <code>-d</code>后台启动,<code>-p</code>指定端口映射 </p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d -p 1521:1521 --name oracle_11g registry.aliyuncs.com/helowin/oracle_11g</span><br></pre></td></tr></tbody></table></figure><p>如果容器停止使用docker start 命令启动</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker start oracle_11g</span><br></pre></td></tr></tbody></table></figure><p>查看容器状态</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker ps</span><br></pre></td></tr></tbody></table></figure><h2 id="修改用户信息"><a href="#修改用户信息" class="headerlink" title="修改用户信息"></a>修改用户信息</h2><ol><li>进入镜像内,修改信息</li></ol><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it oracle_11g bash</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><ol start="2"><li>root用户操作,root用户密码<code>helowin</code></li></ol><p>编辑<code>/etc/profile</code></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2</span><br><span class="line">export ORACLE_SID=helowin</span><br><span class="line">export PATH=$ORACLE_HOME/bin:$PATH</span><br></pre></td></tr></tbody></table></figure><p>使文件生效<code>source /etc/profile</code></p><ol start="3"><li>添加软链接</li></ol><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ln -s $ORACLE_HOME/bin/sqlplus /usr/bin</span><br></pre></td></tr></tbody></table></figure><ol start="4"><li>切换oracle用户,修改密码</li></ol><p><code>su - oracle</code></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">alter user system identified by 密码;</span><br><span class="line">alter user sys identified by 密码;</span><br><span class="line">ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;</span><br></pre></td></tr></tbody></table></figure><h2 id="测试一下"><a href="#测试一下" class="headerlink" title="测试一下"></a>测试一下</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">ip:宿主机ip</span><br><span class="line">端口:1521</span><br><span class="line">SID: helowin</span><br><span class="line">用户名:****</span><br><span class="line">密码:****</span><br></pre></td></tr></tbody></table></figure><h2 id="结束了么?"><a href="#结束了么?" class="headerlink" title="结束了么?"></a>结束了么?</h2><p>并没有,我的最终目的是让其他同事也访问我的oracle,所以需要做一步端口转发,将虚拟机1521端口映射到主机的某个端口上,然后通过主机暴露出的ip:port访问。</p><h3 id="选择编辑,打开虚拟网络编辑器"><a href="#选择编辑,打开虚拟网络编辑器" class="headerlink" title="选择编辑,打开虚拟网络编辑器"></a>选择编辑,打开虚拟网络编辑器</h3><p>1.前提虚拟机已关机<br>2.选择更改设置<br>3.选择NAT设置</p><p><img src="http://img.xujn.xyz/EB5F7A58E52B7087FFF188704B0EFC2F.png?!"></p><p>4.选择添加</p><p>我选择1522端口作为映射</p><p>222为远程访问虚拟机的端口(如果需要,现在虚拟机安装<code>openssh-server</code>)</p><p><img src="http://img.xujn.xyz/4C9D950D53CE966D298E7818EA869429.png?!"></p><p><strong>参考文章</strong></p><p><a href="https://www.howtoing.com/ubuntu-docker">Docker:Ubuntu 18.04 LTS上的安装和基本使用</a></p>]]></content>
<categories>
<category> 数据库 </category>
</categories>
<tags>
<tag> Oracle </tag>
<tag> Docker </tag>
</tags>
</entry>
<entry>
<title>Oracle笔记</title>
<link href="/2020/03/11/oracle-bi-ji/"/>
<url>/2020/03/11/oracle-bi-ji/</url>
<content type="html"><![CDATA[<h1 id="Oracle权限赋予和新建序列"><a href="#Oracle权限赋予和新建序列" class="headerlink" title="Oracle权限赋予和新建序列"></a>Oracle权限赋予和新建序列</h1><h2 id="赋予表和序列权限"><a href="#赋予表和序列权限" class="headerlink" title="赋予表和序列权限"></a>赋予表和序列权限</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">grant select,insert,update on res.plan_task to ishare</span><br><span class="line">grant select,insert,update on res.plan_task_instance to ishare</span><br><span class="line">grant select,insert,update on res.plan_task_object to ishare</span><br><span class="line">grant select,insert,update on res.plan_task_photo to ishare</span><br><span class="line"></span><br><span class="line">grant select,alter on res.seq_plan_task to ishare</span><br><span class="line">grant select,alter on res.seq_plan_task_instance to ishare</span><br><span class="line">grant select,alter on res.seq_plan_task_object to ishare</span><br><span class="line">grant select,alter on res.seq_plan_task_photo to ishare</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h2 id="新建序列"><a href="#新建序列" class="headerlink" title="新建序列"></a>新建序列</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">CREATE SEQUENCE RES.seq_plan_task_photo</span><br><span class="line">INCREMENT BY 1 </span><br><span class="line">START WITH 1 </span><br><span class="line">MINVALUE 1</span><br><span class="line">MAXVALUE 99999999999999</span><br><span class="line">NOCYCLE </span><br><span class="line">CACHE 2;</span><br></pre></td></tr></tbody></table></figure><p>序列说明<br><img src="http://img.xujn.xyz/image20181015113548.png" alt="序列说明"></p><h2 id="索引"><a href="#索引" class="headerlink" title="索引"></a>索引</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">--在数据库中查找表名</span><br><span class="line">select * from user_tables where table_name like 'tablename%';</span><br><span class="line"></span><br><span class="line">--查看该表的所有索引</span><br><span class="line">select * from all_indexes where table_name = 'MANAGEDELEMENT';</span><br><span class="line"></span><br><span class="line">--查看该表的所有索引列</span><br><span class="line">select* from all_ind_columns where table_name = 'MANAGEDELEMENT';</span><br><span class="line">--创建索引</span><br><span class="line">create index INDEX_MANAGEDELEMENT on MANAGEDELEMENT(EMS);</span><br></pre></td></tr></tbody></table></figure><h1 id="新建表空间-用户授权"><a href="#新建表空间-用户授权" class="headerlink" title="新建表空间/用户授权"></a>新建表空间/用户授权</h1><ul><li>查询数据表空间位置<figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select name from v$datafile;</span><br></pre></td></tr></tbody></table></figure></li><li>创建表空间 <figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">CREATE tablespace etl_space datafile '/opt/oracle/oradata/orcl/etl01.dbf'</span><br><span class="line">size 500m autoextend on next 5M maxsize unlimited;</span><br></pre></td></tr></tbody></table></figure></li><li>创建用户 <figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">CREATE USER tomcat_etl IDENTIFIED BY tomcat_etl</span><br><span class="line">DEFAULT tablespace etl_space </span><br><span class="line">temporary tablespace temp</span><br><span class="line">profile DEFAULT ;</span><br></pre></td></tr></tbody></table></figure></li><li>用户授权 <figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grant connect,resource,dba to tomcat_etl;</span><br></pre></td></tr></tbody></table></figure></li></ul><h1 id="修改字符集"><a href="#修改字符集" class="headerlink" title="修改字符集"></a>修改字符集</h1><p>进入sqlplus</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sqlplus / as sysdba</span><br></pre></td></tr></tbody></table></figure><p>修改字符集</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">SQL>SHUTDOWN IMMEDIATE</span><br><span class="line">SQL>STARTUP MOUNT</span><br><span class="line">SQL>ALTER SYSTEM ENABLE RESTRICTED SESSION;</span><br><span class="line">SQL>ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;</span><br><span class="line">SQL>ALTER SYSTEM SET AQ_TM_PROCESSES=0;</span><br><span class="line">SQL>ALTER DATABASE OPEN;</span><br><span class="line">//ZHS16GBK、AL32UTF8</span><br><span class="line">SQL>ALTER DATABASE CHARACTER SET INTERNAL_USE ZHS16GBK;</span><br><span class="line">SQL>SHUTDOWN IMMEDIATE;</span><br><span class="line">//启动数据库</span><br><span class="line">SQL>STARTUP;</span><br><span class="line">//查看字符集</span><br><span class="line">SQL>select userenv('language') from dual;</span><br></pre></td></tr></tbody></table></figure><h1 id="卸载oracle"><a href="#卸载oracle" class="headerlink" title="卸载oracle"></a>卸载oracle</h1><p>进入sqlplus</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sqlplus / as sysdba</span><br></pre></td></tr></tbody></table></figure><p>停止Oracle数据库服务</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">shutdown immediate;</span><br></pre></td></tr></tbody></table></figure><p>停止监听服务</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">lsnrctl stop</span><br></pre></td></tr></tbody></table></figure><p>删除/usr/local/bin下的文件</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">coraenv dbhome oraenv</span><br></pre></td></tr></tbody></table></figure><p>删除/etc下的文件</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">oraInst.loc oratab</span><br></pre></td></tr></tbody></table></figure><p>删除/opt下ORCLfmap</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rm –rf ORCLfmap</span><br></pre></td></tr></tbody></table></figure><p>删除oracle安装目录<code>ORACLE_HOME</code></p><p>删除用户和组</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">userdel –r oracle</span><br><span class="line">groupdel oinstall</span><br><span class="line">groupdel dba</span><br></pre></td></tr></tbody></table></figure><h1 id="密码过期"><a href="#密码过期" class="headerlink" title="密码过期"></a>密码过期</h1><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">-- 查询用户</span><br><span class="line">select username,profile from dba_users</span><br><span class="line">--查看密码有效期</span><br><span class="line">Select * FROM dba_profiles s Where s.profile='DEFAULT' AND resource_name='PASSWORD_LIFE_TIME'</span><br><span class="line"></span><br><span class="line">-- 设置密码永久有效</span><br><span class="line"> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED</span><br><span class="line">--修改密码</span><br><span class="line">alter user ishare identified by 111111</span><br></pre></td></tr></tbody></table></figure><h1 id="常见问题"><a href="#常见问题" class="headerlink" title="常见问题"></a>常见问题</h1><h2 id="ORA-00054:资源正忙,要求指定NOWAIT"><a href="#ORA-00054:资源正忙,要求指定NOWAIT" class="headerlink" title="ORA-00054:资源正忙,要求指定NOWAIT"></a>ORA-00054:资源正忙,要求指定NOWAIT</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">select session_id from v$locked_object;</span><br><span class="line"> SELECT sid, serial#, username, osuser FROM v$session where sid = 39;</span><br><span class="line"> </span><br><span class="line"> ALTER SYSTEM KILL SESSION '39,1290';</span><br></pre></td></tr></tbody></table></figure>]]></content>
<categories>
<category> 数据库 </category>
</categories>
<tags>
<tag> ORACLE </tag>
</tags>
</entry>
<entry>
<title>Layui动态表格的增删改查</title>
<link href="/2019/01/23/layui-dong-tai-biao-ge-de-zeng-shan-gai-cha/"/>
<url>/2019/01/23/layui-dong-tai-biao-ge-de-zeng-shan-gai-cha/</url>
<content type="html"><![CDATA[<h2 id="表格"><a href="#表格" class="headerlink" title="表格"></a>表格</h2><p>查询按钮</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><button class="layui-btn" lay-submit lay-filter="lay-index-search"></span><br><span class="line"> <i class="layui-icon layui-icon-search"></i></span><br><span class="line"></button></span><br></pre></td></tr></tbody></table></figure><p>表格主体</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><table id="lay-index-list" lay-filter="lay-index-list-filter"></table></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>工具栏(表格外)</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><script type="text/html" id="toolbarindex"></span><br><span class="line"> <div style="padding-bottom: 10px;"></span><br><span class="line"> <button class="layui-btn layuiadmin-btn-list" data-type="addindex">新增</button></span><br><span class="line"> <button class="layui-btn layuiadmin-btn-list" data-type="batchdelindex">删除</button></span><br><span class="line"> </div></span><br><span class="line"></script></span><br></pre></td></tr></tbody></table></figure><p>工具栏(表格内)</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><script type="text/html" id="table-tool-list"></span><br><span class="line"> <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i</span><br><span class="line"> class="layui-icon layui-icon-edit"></i>修改</a></span><br><span class="line"></script></span><br></pre></td></tr></tbody></table></figure><h2 id="查询"><a href="#查询" class="headerlink" title="查询"></a>查询</h2><p>监听查询按钮</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">//监听搜索</span><br><span class="line"> form.on('submit(lay-index-search)', function (data) {</span><br><span class="line"> var field = data.field;</span><br><span class="line"></span><br><span class="line"> //执行重载</span><br><span class="line"> table.reload('lay-index-list', {</span><br><span class="line"> where: field</span><br><span class="line"> });</span><br><span class="line"> });</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>表格部分</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">//表格初始化</span><br><span class="line"> table.render({</span><br><span class="line"> elem: '#lay-index-list'//绑定表格id</span><br><span class="line"> , url: '/abcefg' //表格接口</span><br><span class="line"> , method: 'post' //请求方式</span><br><span class="line"> , toolbar: '#toolbarindex' //自定义工具栏</span><br><span class="line"> , defaultToolbar: []</span><br><span class="line"> , title: '数据表'</span><br><span class="line"> , totalRow: false</span><br><span class="line"> , where: { //查询参数</span><br><span class="line"> "name1": '12',</span><br><span class="line"> "name2": '34'</span><br><span class="line"> }</span><br><span class="line"> , cols: [[</span><br><span class="line"> {type: 'checkbox', fixed: 'left'}</span><br><span class="line"> , {field: 'kpiName', title: '指标名称', width: 260}</span><br><span class="line"> , {</span><br><span class="line"> field: 'kpiCode', title: '指标编码', width: 180, templet: function (res) {</span><br><span class="line"> return '<em>' + res.kpiCode + '</em>'</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> , {field: 'kpiDevType', title: '设备类型', width: 100}</span><br><span class="line"> , {field: 'kpiUnits', title: '指标单位', width: 100}</span><br><span class="line"> , {</span><br><span class="line"> field: 'kpiLevel', title: '指标级别', width: 100, templet: function (res) {</span><br><span class="line"> if (res.kpiLevel === "2") {</span><br><span class="line"> return '网元'} else if (res.kpiLevel === "3") {</span><br><span class="line"> return '板卡'} else if (res.kpiLevel === "4") {</span><br><span class="line"> return '端口'}}}</span><br><span class="line"> , {field: 'kpiDesc', title: '描述', width: 150}</span><br><span class="line"> , {fixed: 'right', title: '操作', toolbar: '#table-tool-list', width: 150} //绑定操作</span><br><span class="line"> ]]</span><br><span class="line"> , page: true</span><br><span class="line"> , limit: 10</span><br><span class="line"> , limits: [10, 20, 50]</span><br><span class="line"> });</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h2 id="修改"><a href="#修改" class="headerlink" title="修改"></a>修改</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line">table.on('tool(lay-index-list-filter)', function (obj) {</span><br><span class="line"> var value = obj.value //得到修改后的值</span><br><span class="line"> , data = obj.data //得到所在行所有键值</span><br><span class="line"> , field = obj.field; //得到字段</span><br><span class="line"> var layEvent = obj.event;</span><br><span class="line"> if (layEvent === 'edit') {</span><br><span class="line"> layer.open({</span><br><span class="line"> type: 1,</span><br><span class="line"> title: '修改指标',</span><br><span class="line"> area: ['100%','100%'],</span><br><span class="line"> btn: ['确认', '取消'],</span><br><span class="line"> btnAlign: 'c', // 按钮居中</span><br><span class="line"> content: $('#edit').html(),</span><br><span class="line"> yes: function (index, layero) {</span><br><span class="line"> var id = $("#id").val();</span><br><span class="line"> var kpiName = $("#kpiNameEdit").val();</span><br><span class="line"> var kpiCode = $("#kpiCodeEdit").val();</span><br><span class="line"> var devType = $("#devTypeEdit").val();</span><br><span class="line"> var kpiUnits = $("#kpiUnitsEdit").val();</span><br><span class="line"> var kpiLevel = $("#kpiLevelEdit").val();</span><br><span class="line"> var kpiDesc = $("#kpiDescEdit").val();</span><br><span class="line"></span><br><span class="line"> $.post('/modifykpi',</span><br><span class="line"> {</span><br><span class="line"> "id":id,</span><br><span class="line"> "kpiName":kpiName,</span><br><span class="line"> "kpiCode":kpiCode,</span><br><span class="line"> "devType":devType,</span><br><span class="line"> "kpiUnits":kpiUnits,</span><br><span class="line"> "kpiLevel":kpiLevel,</span><br><span class="line"> "kpiDesc":kpiDesc</span><br><span class="line"> }, function (data) {</span><br><span class="line"> if (data.code === 200) {</span><br><span class="line"> layer.msg('更新成功', {icon: 1});</span><br><span class="line"> // 同步更新表格数据</span><br><span class="line"> obj.update({</span><br><span class="line"> kpiName:kpiName,</span><br><span class="line"> kpiCode:kpiCode,</span><br><span class="line"> devType:devType,</span><br><span class="line"> kpiUnits:kpiUnits,</span><br><span class="line"> kpiLevel:kpiLevel,</span><br><span class="line"> kpiDesc:kpiDesc</span><br><span class="line"> })</span><br><span class="line"> } else {</span><br><span class="line"> layer.msg('更新失败', {icon: 5})</span><br><span class="line"> }</span><br><span class="line"> });</span><br><span class="line"> layer.close(index);//关闭弹出框</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> });</span><br><span class="line"> console.log('初始化表单之前'+JSON.stringify(data));</span><br><span class="line"> //初始化修改表单 "name":value</span><br><span class="line"> form.val("form-kpi-edit", {</span><br><span class="line"> "id": data.id</span><br><span class="line"> , "kpiNameEdit": data.kpiName</span><br><span class="line"> , "kpiCodeEdit": data.kpiCode</span><br><span class="line"> , "devTypeEdit": data.kpiDevType</span><br><span class="line"> , "kpiUnitsEdit": data.kpiUnits</span><br><span class="line"> , "kpiLevelEdit": data.kpiLevel</span><br><span class="line"> , "kpiDescEdit": data.kpiDesc</span><br><span class="line"> });</span><br><span class="line"> form.render(null, 'form-kpi-edit')</span><br><span class="line"> }</span><br><span class="line"> });</span><br></pre></td></tr></tbody></table></figure><h2 id="批量删除"><a href="#批量删除" class="headerlink" title="批量删除"></a>批量删除</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">var active = {</span><br><span class="line"> batchdelindex: function () {</span><br><span class="line"> var checkStatus = table.checkStatus('lay-index-list')</span><br><span class="line"> , checkData = checkStatus.data; //得到选中的数据</span><br><span class="line"></span><br><span class="line"> if (checkData.length === 0) {</span><br><span class="line"> return layer.msg('请选择数据');</span><br><span class="line"> } else {</span><br><span class="line"> var ids = [];</span><br><span class="line"> $.each(checkData, function (i, v) {</span><br><span class="line"> ids.push(v.id);</span><br><span class="line"> });</span><br><span class="line"> console.log(ids);</span><br><span class="line"> layer.confirm('确定删除吗?', function (index) {</span><br><span class="line"></span><br><span class="line"> //执行 Ajax 后重载</span><br><span class="line"> $.post('/batchdelkpi', {"ids": JSON.stringify(ids)}, function (data) {</span><br><span class="line"> if (data.code === 200) {</span><br><span class="line"> layer.close(index);</span><br><span class="line"> table.reload('lay-index-list');</span><br><span class="line"> layer.msg('已删除', {icon: 1});</span><br><span class="line"> } else {</span><br><span class="line"> layer.close(index);</span><br><span class="line"> layer.msg(data.msg, {icon: 5});</span><br><span class="line"> }</span><br><span class="line"> });</span><br><span class="line"> },function(index) {</span><br><span class="line"> layer.close(index);</span><br><span class="line"> });</span><br><span class="line"> }</span><br><span class="line"> },</span><br><span class="line"> edit:function{.....}</span><br><span class="line"> };</span><br></pre></td></tr></tbody></table></figure>]]></content>
<categories>
<category> Layui </category>
</categories>
<tags>
<tag> Layui </tag>
</tags>
</entry>
<entry>
<title>Spring MVC项目搭建过程说明</title>
<link href="/2018/09/06/spring-mvc-xiang-mu-da-jian-guo-cheng-shuo-ming/"/>
<url>/2018/09/06/spring-mvc-xiang-mu-da-jian-guo-cheng-shuo-ming/</url>
<content type="html"><![CDATA[<h2 id="基本的项目结构"><a href="#基本的项目结构" class="headerlink" title="基本的项目结构"></a>基本的项目结构</h2><p><img src="http://img.xujn.xyz/image20180906224906.png" alt="项目框架"></p><h2 id="pom-xml文件"><a href="#pom-xml文件" class="headerlink" title="pom.xml文件"></a>pom.xml文件</h2><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br></pre></td><td class="code"><pre><span class="line"><properties></span><br><span class="line"> <project.build.sourceEncoding>UTF-<span class="number">8</span></project.build.sourceEncoding></span><br><span class="line"> <!-- log4j日志包版本号 --></span><br><span class="line"> <slf4j.version><span class="number">1.7</span><span class="number">.18</span></slf4j.version></span><br><span class="line"> <log4j.version><span class="number">1.2</span><span class="number">.17</span></log4j.version></span><br><span class="line"> <spring-version><span class="number">4.3</span><span class="number">.12</span>.RELEASE</spring-version></span><br><span class="line"> </properties></span><br><span class="line"><dependencies></span><br><span class="line"> <!--spring security--></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework.security</groupId></span><br><span class="line"> <artifactId>spring-security-web</artifactId></span><br><span class="line"> <version><span class="number">4.2</span><span class="number">.6</span>.RELEASE</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework.security</groupId></span><br><span class="line"> <artifactId>spring-security-config</artifactId></span><br><span class="line"> <version><span class="number">4.2</span><span class="number">.6</span>.RELEASE</version></span><br><span class="line"> </dependency></span><br><span class="line"> <!-- test set--></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>junit</groupId></span><br><span class="line"> <artifactId>junit</artifactId></span><br><span class="line"> <version><span class="number">4.12</span></version></span><br><span class="line"> <scope>test</scope></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.mockito</groupId></span><br><span class="line"> <artifactId>mockito-all</artifactId></span><br><span class="line"> <version><span class="number">1.10</span><span class="number">.19</span></version></span><br><span class="line"> <scope>test</scope></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.hamcrest</groupId></span><br><span class="line"> <artifactId>hamcrest-all</artifactId></span><br><span class="line"> <version><span class="number">1.3</span></version></span><br><span class="line"> <scope>test</scope></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>javax</groupId></span><br><span class="line"> <artifactId>javaee-web-api</artifactId></span><br><span class="line"> <version><span class="number">7.0</span></version></span><br><span class="line"> <scope>provided</scope></span><br><span class="line"> </dependency></span><br><span class="line"> <!--spring--></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework</groupId></span><br><span class="line"> <artifactId>spring-beans</artifactId></span><br><span class="line"> <version>${spring-version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework</groupId></span><br><span class="line"> <artifactId>spring-core</artifactId></span><br><span class="line"> <version>${spring-version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework</groupId></span><br><span class="line"> <artifactId>spring-context</artifactId></span><br><span class="line"> <version>${spring-version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework</groupId></span><br><span class="line"> <artifactId>spring-context-support</artifactId></span><br><span class="line"> <version>${spring-version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework</groupId></span><br><span class="line"> <artifactId> spring-jdbc</artifactId></span><br><span class="line"> <version>${spring-version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework</groupId></span><br><span class="line"> <artifactId>spring-tx</artifactId></span><br><span class="line"> <version>${spring-version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework</groupId></span><br><span class="line"> <artifactId>spring-web</artifactId></span><br><span class="line"> <version>${spring-version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework</groupId></span><br><span class="line"> <artifactId>spring-webmvc</artifactId></span><br><span class="line"> <version>${spring-version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework</groupId></span><br><span class="line"> <artifactId>spring-expression</artifactId></span><br><span class="line"> <version>${spring-version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>commons-logging</groupId></span><br><span class="line"> <artifactId>commons-logging</artifactId></span><br><span class="line"> <version><span class="number">1.2</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.springframework</groupId></span><br><span class="line"> <artifactId>spring-test</artifactId></span><br><span class="line"> <version>${spring-version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <!--bean 验证--></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>javax.validation</groupId></span><br><span class="line"> <artifactId>validation-api</artifactId></span><br><span class="line"> <version><span class="number">2.0</span><span class="number">.1</span>.Final</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.hibernate.validator</groupId></span><br><span class="line"> <artifactId>hibernate-validator</artifactId></span><br><span class="line"> <version><span class="number">6.0</span><span class="number">.7</span>.Final</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.hibernate.validator</groupId></span><br><span class="line"> <artifactId>hibernate-validator-annotation-processor</artifactId></span><br><span class="line"> <version><span class="number">6.0</span><span class="number">.7</span>.Final</version></span><br><span class="line"> </dependency></span><br><span class="line"> <!-- 添加日志相关jar包 --></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>log4j</groupId></span><br><span class="line"> <artifactId>log4j</artifactId></span><br><span class="line"> <version>${log4j.version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.slf4j</groupId></span><br><span class="line"> <artifactId>slf4j-api</artifactId></span><br><span class="line"> <version>${slf4j.version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.slf4j</groupId></span><br><span class="line"> <artifactId>slf4j-log4j12</artifactId></span><br><span class="line"> <version>${slf4j.version}</version></span><br><span class="line"> </dependency></span><br><span class="line"> <!--mysql依赖--></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>mysql</groupId></span><br><span class="line"> <artifactId> mysql-connector-java</artifactId></span><br><span class="line"> <version><span class="number">5.1</span><span class="number">.44</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <!--<dependency>--></span><br><span class="line"> <!--<groupId>com.alibaba</groupId>--></span><br><span class="line"> <!--<artifactId>druid</artifactId>--></span><br><span class="line"> <!--<version><span class="number">1.1</span><span class="number">.6</span></version>--></span><br><span class="line"> <!--</dependency>--></span><br><span class="line"> <!-- https:<span class="comment">//mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 --></span></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.apache.commons</groupId></span><br><span class="line"> <artifactId>commons-dbcp2</artifactId></span><br><span class="line"> <version><span class="number">2.2</span><span class="number">.0</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.apache.commons</groupId></span><br><span class="line"> <artifactId>commons-pool2</artifactId></span><br><span class="line"> <version><span class="number">2.5</span><span class="number">.0</span></version></span><br><span class="line"> </dependency></span><br><span class="line"></span><br><span class="line"> <!--文件上传--></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>commons-fileupload</groupId></span><br><span class="line"> <artifactId>commons-fileupload</artifactId></span><br><span class="line"> <version><span class="number">1.3</span><span class="number">.3</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>commons-io</groupId></span><br><span class="line"> <artifactId>commons-io</artifactId></span><br><span class="line"> <version><span class="number">2.6</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.apache.commons</groupId></span><br><span class="line"> <artifactId>commons-lang3</artifactId></span><br><span class="line"> <version><span class="number">3.7</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <!--shiro配置--></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.apache.shiro</groupId></span><br><span class="line"> <artifactId>shiro-core</artifactId></span><br><span class="line"> <version><span class="number">1.2</span><span class="number">.2</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>javax.servlet</groupId></span><br><span class="line"> <artifactId>javax.servlet-api</artifactId></span><br><span class="line"> <version><span class="number">3.1</span><span class="number">.0</span></version></span><br><span class="line"> <scope>provided</scope></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>javax.servlet</groupId></span><br><span class="line"> <artifactId>jstl</artifactId></span><br><span class="line"> <version><span class="number">1.2</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <!-- https:<span class="comment">//mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core --></span></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>com.fasterxml.jackson.core</groupId></span><br><span class="line"> <artifactId>jackson-core</artifactId></span><br><span class="line"> <version><span class="number">2.9</span><span class="number">.4</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>com.fasterxml.jackson.core</groupId></span><br><span class="line"> <artifactId>jackson-databind</artifactId></span><br><span class="line"> <version><span class="number">2.9</span><span class="number">.4</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>com.fasterxml.jackson.core</groupId></span><br><span class="line"> <artifactId>jackson-annotations</artifactId></span><br><span class="line"> <version><span class="number">2.9</span><span class="number">.4</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>javax.servlet.jsp</groupId></span><br><span class="line"> <artifactId>jsp-api</artifactId></span><br><span class="line"> <version><span class="number">2.2</span></version></span><br><span class="line"> <scope>provided</scope></span><br><span class="line"> </dependency></span><br><span class="line"> <!--模版引擎--></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.freemarker</groupId></span><br><span class="line"> <artifactId>freemarker</artifactId></span><br><span class="line"> <version><span class="number">2.3</span><span class="number">.28</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <!--markdown-java parser--></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>com.atlassian.commonmark</groupId></span><br><span class="line"> <artifactId>commonmark</artifactId></span><br><span class="line"> <version><span class="number">0.11</span><span class="number">.0</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>com.atlassian.commonmark</groupId></span><br><span class="line"> <artifactId>commonmark-ext-gfm-tables</artifactId></span><br><span class="line"> <version><span class="number">0.11</span><span class="number">.0</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>com.atlassian.commonmark</groupId></span><br><span class="line"> <artifactId>commonmark-ext-gfm-strikethrough</artifactId></span><br><span class="line"> <version><span class="number">0.11</span><span class="number">.0</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>com.vladsch.flexmark</groupId></span><br><span class="line"> <artifactId>flexmark-all</artifactId></span><br><span class="line"> <version><span class="number">0.32</span><span class="number">.18</span></version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>org.projectlombok</groupId></span><br><span class="line"> <artifactId>lombok</artifactId></span><br><span class="line"> <version><span class="number">1.16</span><span class="number">.20</span></version></span><br><span class="line"> <scope>provided</scope></span><br><span class="line"> </dependency></span><br><span class="line"></dependencies></span><br><span class="line"> <build></span><br><span class="line"> <finalName>${artifactId}</finalName></span><br><span class="line"> <plugins></span><br><span class="line"> <plugin></span><br><span class="line"> <groupId>org.apache.maven.plugins</groupId></span><br><span class="line"> <artifactId>maven-compiler-plugin</artifactId></span><br><span class="line"> <configuration></span><br><span class="line"> <source><span class="number">1.8</span></source></span><br><span class="line"> <target><span class="number">1.8</span></target></span><br><span class="line"> </configuration></span><br><span class="line"> </plugin></span><br><span class="line"></span><br><span class="line"> </plugins></span><br><span class="line"> </build></span><br></pre></td></tr></tbody></table></figure><h2 id="Java配置-无XML配置"><a href="#Java配置-无XML配置" class="headerlink" title="Java配置(无XML配置)"></a>Java配置(无XML配置)</h2><p>RootConfig文件</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ComponentScan(basePackages = {"com.xxx"},</span></span><br><span class="line"><span class="meta"> excludeFilters = {</span></span><br><span class="line"><span class="meta"> @ComponentScan.Filter(type = FilterType.ANNOTATION,value = EnableWebMvc.class),</span></span><br><span class="line"><span class="meta"> @ComponentScan.Filter(type = FilterType.ANNOTATION,value = Controller.class)})</span></span><br><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">RootConfig</span> {</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>WebInitializer文件,代替web.xml文件</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WebInitializer</span> <span class="keyword">extends</span></span><br><span class="line"> <span class="title class_">AbstractAnnotationConfigDispatcherServletInitializer</span> {</span><br><span class="line"></span><br><span class="line"> <span class="keyword">protected</span> Class<?>[] getRootConfigClasses() {</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">Class</span>[]{RootConfig.class};</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">protected</span> Class<?>[] getServletConfigClasses() {</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">Class</span>[]{WebConfig.class};</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">protected</span> String[] getServletMappings() {</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">String</span>[]{<span class="string">"/"</span>};</span><br><span class="line"> }</span><br><span class="line"><span class="comment">//配置过滤器</span></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">protected</span> Filter[] getServletFilters() {</span><br><span class="line"> <span class="type">CharacterEncodingFilter</span> <span class="variable">characterEncodingFilter</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">CharacterEncodingFilter</span>();</span><br><span class="line"> characterEncodingFilter.setEncoding(<span class="string">"UTF-8"</span>);</span><br><span class="line"> characterEncodingFilter.setForceEncoding(<span class="literal">true</span>);</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">Filter</span>[]{characterEncodingFilter};</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>WebConfig文件,相当于前端控制器,替代dispatcher-servlet.xml文件 </p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@EnableWebMvc</span></span><br><span class="line"><span class="meta">@ComponentScan(basePackages = "com.xujn")</span></span><br><span class="line"><span class="meta">@PropertySource(value = "classpath:freemarker.properties",encoding = "UTF-8")</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">WebConfig</span> <span class="keyword">extends</span> <span class="title class_">WebMvcConfigurerAdapter</span> {</span><br><span class="line"></span><br><span class="line"><span class="meta">@Autowired</span></span><br><span class="line"> <span class="keyword">private</span> Environment env;</span><br><span class="line"> <span class="comment">// 视图解析器</span></span><br><span class="line"> <span class="meta">@Bean</span></span><br><span class="line"> <span class="keyword">public</span> ViewResolver <span class="title function_">viewResolver</span><span class="params">()</span>{</span><br><span class="line"> <span class="type">InternalResourceViewResolver</span> <span class="variable">resolver</span> <span class="operator">=</span></span><br><span class="line"> <span class="keyword">new</span> <span class="title class_">InternalResourceViewResolver</span>();</span><br><span class="line"> resolver.setViewClass(JstlView.class);</span><br><span class="line"> resolver.setPrefix(<span class="string">"/WEB-INF/views/"</span>);</span><br><span class="line"> resolver.setSuffix(<span class="string">".jsp"</span>);</span><br><span class="line"> resolver.setOrder(<span class="number">1</span>);</span><br><span class="line"> resolver.setExposeContextBeansAsAttributes(<span class="literal">true</span>);</span><br><span class="line"> <span class="keyword">return</span> resolver;</span><br><span class="line"> }</span><br><span class="line"><span class="comment">// freemarker解析器</span></span><br><span class="line"> <span class="meta">@Bean</span></span><br><span class="line"> <span class="keyword">public</span> FreeMarkerViewResolver <span class="title function_">FreeMarkerViewResolver</span><span class="params">()</span>{</span><br><span class="line"> <span class="type">FreeMarkerViewResolver</span> <span class="variable">resolver</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">FreeMarkerViewResolver</span>(<span class="string">""</span>,<span class="string">".ftl"</span>);</span><br><span class="line"> resolver.setCache(<span class="literal">true</span>);</span><br><span class="line"> resolver.setContentType(<span class="string">"text/html;charset=UTF-8"</span>);</span><br><span class="line"> resolver.setOrder(<span class="number">0</span>);</span><br><span class="line"> <span class="keyword">return</span> resolver;</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// 配置资源映射</span></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">addResourceHandlers</span><span class="params">(ResourceHandlerRegistry registry)</span> {</span><br><span class="line"><span class="comment">// SpringMVCBlog/src/main/resources</span></span><br><span class="line"> registry.addResourceHandler(<span class="string">"/resources/**"</span>).</span><br><span class="line"> addResourceLocations(<span class="string">"classpath:/resources/"</span>).setCachePeriod(<span class="number">2592000</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// json解析</span></span><br><span class="line"> <span class="meta">@Bean</span></span><br><span class="line"> <span class="keyword">public</span> MappingJackson2HttpMessageConverter <span class="title function_">mappingJackson2HttpMessageConverter</span><span class="params">()</span> {</span><br><span class="line"> <span class="type">MappingJackson2HttpMessageConverter</span> <span class="variable">converter</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MappingJackson2HttpMessageConverter</span>();</span><br><span class="line"> List<MediaType> supportedMediaTypes = <span class="keyword">new</span> <span class="title class_">ArrayList</span><>();</span><br><span class="line"> supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);</span><br><span class="line"> supportedMediaTypes.add(MediaType.TEXT_HTML);</span><br><span class="line"> converter.setSupportedMediaTypes(supportedMediaTypes);</span><br><span class="line"> <span class="comment">// converter.setObjectMapper(objectMapper());</span></span><br><span class="line"> <span class="keyword">return</span> converter;</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// 主题资源配置</span></span><br><span class="line"> <span class="meta">@Bean(name = "themeSource")</span></span><br><span class="line"> <span class="keyword">public</span> ThemeSource <span class="title function_">resourceBundleThemeSource</span><span class="params">()</span> {</span><br><span class="line"> <span class="type">ResourceBundleThemeSource</span> <span class="variable">source</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ResourceBundleThemeSource</span>();</span><br><span class="line"> source.setDefaultEncoding(<span class="string">"UTF-8"</span>);</span><br><span class="line"> source.setBasenamePrefix(<span class="string">"themes."</span>);</span><br><span class="line"> <span class="keyword">return</span> source;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Bean</span></span><br><span class="line"> <span class="keyword">public</span> CookieThemeResolver <span class="title function_">themeResolver</span><span class="params">()</span> {</span><br><span class="line"> <span class="type">CookieThemeResolver</span> <span class="variable">resolver</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">CookieThemeResolver</span>();</span><br><span class="line"> resolver.setDefaultThemeName(<span class="string">"anime"</span>);</span><br><span class="line"> resolver.setCookieName(<span class="string">"my-theme-cookie"</span>);</span><br><span class="line"> <span class="keyword">return</span> resolver;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Bean</span></span><br><span class="line"> <span class="keyword">public</span> ThemeChangeInterceptor <span class="title function_">themeChangeInterceptor</span><span class="params">()</span> {</span><br><span class="line"> <span class="type">ThemeChangeInterceptor</span> <span class="variable">interceptor</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ThemeChangeInterceptor</span>();</span><br><span class="line"> interceptor.setParamName(<span class="string">"theme"</span>);</span><br><span class="line"> <span class="keyword">return</span> interceptor;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">addInterceptors</span><span class="params">(InterceptorRegistry registry)</span> {</span><br><span class="line"> registry.addInterceptor(themeChangeInterceptor());</span><br><span class="line"> }</span><br><span class="line"> <span class="meta">@Bean(name = "multipartResolver")</span></span><br><span class="line"> <span class="keyword">public</span> CommonsMultipartResolver <span class="title function_">commonsMultipartResolver</span><span class="params">()</span>{</span><br><span class="line"> <span class="type">CommonsMultipartResolver</span> <span class="variable">resolver</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">CommonsMultipartResolver</span>();</span><br><span class="line"> resolver.setMaxUploadSize(<span class="number">5</span> * <span class="number">1024</span> * <span class="number">1024</span>);</span><br><span class="line"> resolver.setDefaultEncoding(<span class="string">"UTF-8"</span>);</span><br><span class="line"> <span class="keyword">return</span> resolver;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure><p>以下为基本配置</p><h2 id="数据源配置"><a href="#数据源配置" class="headerlink" title="数据源配置"></a>数据源配置</h2><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">DataSourceConfig</span> {</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Bean( name = "dataSource")</span></span><br><span class="line"> <span class="keyword">public</span> DataSource <span class="title function_">dataSource</span><span class="params">()</span>{</span><br><span class="line"> <span class="type">BasicDataSource</span> <span class="variable">ds</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">BasicDataSource</span>();</span><br><span class="line"> ds.setDriverClassName(<span class="string">"com.mysql.jdbc.Driver"</span>);</span><br><span class="line"> ds.setUrl(<span class="string">"jdbc:mysql://localhost:3306/blog?"</span> + <span class="string">"useUnicode=true&characterEncoding=UTF-8"</span>);</span><br><span class="line"> ds.setUsername(<span class="string">"username"</span>);</span><br><span class="line"> ds.setPassword(<span class="string">"password"</span>);</span><br><span class="line"> ds.setInitialSize(<span class="number">5</span>);</span><br><span class="line"> ds.setMaxTotal(<span class="number">10</span>);</span><br><span class="line"> <span class="keyword">return</span> ds;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 配置jdbcTemplate</span></span><br><span class="line"> <span class="meta">@Bean</span></span><br><span class="line"> <span class="keyword">public</span> JdbcTemplate <span class="title function_">jdbcTemplate</span><span class="params">(DataSource dataSource)</span>{</span><br><span class="line"> System.out.println(<span class="string">"bean"</span>+dataSource);</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">JdbcTemplate</span>(dataSource);</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// 命名参数模版</span></span><br><span class="line"> <span class="meta">@Bean</span></span><br><span class="line"> <span class="keyword">public</span> NamedParameterJdbcTemplate <span class="title function_">namedParameterJdbcTemplate</span><span class="params">(DataSource dataSource)</span>{</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">NamedParameterJdbcTemplate</span>(dataSource);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h2 id="log4j配置"><a href="#log4j配置" class="headerlink" title="log4j配置"></a>log4j配置</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">log4j.rootLogger=INFO,Console,File,ERROR,stdout</span><br><span class="line"></span><br><span class="line">log4j.appender.Console=org.apache.log4j.ConsoleAppender</span><br><span class="line">log4j.appender.Console.Target=System.out</span><br><span class="line">log4j.appender.Console.layout=org.apache.log4j.PatternLayout</span><br><span class="line">log4j.appender.Console.layout.ConversionPattern=[%p][%t][%d{yyyy-MM-dd HH\:mm\:ss}][%C] - %m%n</span><br><span class="line"></span><br><span class="line">log4j.logger.com.xujn.mapper=TRACE</span><br><span class="line">log4j.appender.File=org.apache.log4j.RollingFileAppender</span><br><span class="line">log4j.appender.File.File=logs/ssm.log</span><br><span class="line">log4j.appender.File.MaxFileSize=10MB</span><br><span class="line"></span><br><span class="line">log4j.appender.File.Threshold=ALL</span><br><span class="line">log4j.appender.File.layout=org.apache.log4j.PatternLayout</span><br><span class="line">log4j.appender.File.layout.ConversionPattern=[%p][%t][%d{yyyy-MM-dd HH\:mm\:ss}][%C] - %m%n</span><br></pre></td></tr></tbody></table></figure><h2 id="控制器Controller"><a href="#控制器Controller" class="headerlink" title="控制器Controller"></a>控制器Controller</h2><p><img src="http://img.xujn.xyz/image20180906231507.png"></p><p>新建index.jsp文件在WEB-INF/views下,在控制器中指定index.jsp文件。</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Controller</span></span><br><span class="line"><span class="meta">@RequestMapping(value = "/")</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestController</span> {</span><br><span class="line"></span><br><span class="line"> <span class="meta">@RequestMapping(value = "index",method = RequestMethod.GET)</span></span><br><span class="line"> <span class="keyword">public</span> String <span class="title function_">index</span><span class="params">()</span>{</span><br><span class="line"> <span class="keyword">return</span> <span class="string">"index"</span>;</span><br><span class="line"> }</span><br><span class="line"> </span><br></pre></td></tr></tbody></table></figure><p>运行项目吧!</p>]]></content>
<categories>
<category> Spring </category>
</categories>
<tags>
<tag> Spring MVC </tag>
<tag> Spring </tag>
</tags>
</entry>
<entry>
<title>Redhat7.1静默安装Oracle 11g</title>
<link href="/2018/09/02/redhat7-1-jing-mo-an-zhuang-oracle-11g/"/>
<url>/2018/09/02/redhat7-1-jing-mo-an-zhuang-oracle-11g/</url>
<content type="html"><![CDATA[<h2 id="安装前环境配置"><a href="#安装前环境配置" class="headerlink" title="安装前环境配置"></a>安装前环境配置</h2><p>以下配置在root用户下执行</p><h3 id="安装依赖"><a href="#安装依赖" class="headerlink" title="安装依赖"></a>安装依赖</h3><p>先将redhat自带yum源更换,然后安装下面依赖。</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">yum -y install binutils \</span><br><span class="line">compat-libstdc++-33 \</span><br><span class="line">elfutils-libelf \</span><br><span class="line">elfutils-libelf-devel \</span><br><span class="line">expat \</span><br><span class="line">gcc \</span><br><span class="line">gcc-c++ \</span><br><span class="line">glibc \</span><br><span class="line">glibc-common \</span><br><span class="line">glibc-devel \</span><br><span class="line">glibc-headers \</span><br><span class="line">libaio \</span><br><span class="line">libaio-devel \</span><br><span class="line">libgcc \</span><br><span class="line">libstdc++ \</span><br><span class="line">libstdc++-devel \</span><br><span class="line">make \</span><br><span class="line">pdksh \</span><br><span class="line">sysstat \</span><br><span class="line">unixODBC \</span><br><span class="line">unixODBC-devel</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h3 id="检查是否安装成功"><a href="#检查是否安装成功" class="headerlink" title="检查是否安装成功"></a>检查是否安装成功</h3><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">rpm -q \</span><br><span class="line">binutils \</span><br><span class="line">compat-libstdc++-33 \</span><br><span class="line">elfutils-libelf \</span><br><span class="line">elfutils-libelf-devel \</span><br><span class="line">expat \</span><br><span class="line">gcc \</span><br><span class="line">gcc-c++ \</span><br><span class="line">glibc \</span><br><span class="line">glibc-common \</span><br><span class="line">glibc-devel \</span><br><span class="line">glibc-headers \</span><br><span class="line">libaio \</span><br><span class="line">libaio-devel \</span><br><span class="line">libgcc \</span><br><span class="line">libstdc++ \</span><br><span class="line">libstdc++-devel \</span><br><span class="line">make \</span><br><span class="line">pdksh \</span><br><span class="line">sysstat \</span><br><span class="line">unixODBC \</span><br><span class="line">unixODBC-devel | grep "not installed"</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>提示pdksh没有安装,正常使用<code>yum -y install pdksh</code>安装不了,需要下载</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget -O pdksh-5.2.14-37.el5_8.1.x86_64.rpm http://vault.centos.org/5.11/os/x86_64/CentOS/pdksh-5.2.14-37.el5_8.1.x86_64.rpm</span><br></pre></td></tr></tbody></table></figure><p>下载完成,执行下面命令安装</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -ivh pdksh-5.2.14-37.el5_8.1.x86_64.rpm</span><br></pre></td></tr></tbody></table></figure><p>检查依赖包是否安装完成。</p><h3 id="修改kernel参数"><a href="#修改kernel参数" class="headerlink" title="修改kernel参数"></a>修改kernel参数</h3><p><code>vim /etc/sysctl.conf</code>打开文件</p><p>文件底部添加下面内容</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">net.ipv4.ip_local_port_range = 9000 65500</span><br><span class="line">fs.file-max = 6815744</span><br><span class="line">kernel.shmall = 10523004</span><br><span class="line">kernel.shmmax = 6465333657</span><br><span class="line">kernel.shmmni = 4096</span><br><span class="line">kernel.sem = 250 32000 100 128</span><br><span class="line">net.core.rmem_default=262144</span><br><span class="line">net.core.wmem_default=262144</span><br><span class="line">net.core.rmem_max=4194304</span><br><span class="line">net.core.wmem_max=1048576</span><br><span class="line">fs.aio-max-nr = 1048576</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>执行<code>sysctl –p</code>使内核生效</p><h3 id="创建用户和相应的组"><a href="#创建用户和相应的组" class="headerlink" title="创建用户和相应的组"></a>创建用户和相应的组</h3><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">groupadd –g 200 oinstall</span><br><span class="line">groupadd –g 201 dba</span><br><span class="line">useradd –u 440 –g oinstall –G dba –d /home/oracle oracle</span><br><span class="line">passwd oracle</span><br></pre></td></tr></tbody></table></figure><p><code>id oracle</code>可以检查创建的用户,oracle为创建的用户。</p><h3 id="修改登录系统参数"><a href="#修改登录系统参数" class="headerlink" title="修改登录系统参数"></a>修改登录系统参数</h3><p><code>vim /etc/pam.d/login</code>打开文件</p><p>文件底部添加</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">session required pam_limits.so</span><br></pre></td></tr></tbody></table></figure><h3 id="修改操作系统安全限制等参数"><a href="#修改操作系统安全限制等参数" class="headerlink" title="修改操作系统安全限制等参数"></a>修改操作系统安全限制等参数</h3><p><code>vim /etc/security/limits.conf</code>打开文件</p><p>底部添加</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">oracle soft nproc 2047</span><br><span class="line">oracle hard nproc 16384</span><br><span class="line">oracle soft nofile 1024</span><br><span class="line">oracle hard nofile 65536</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h3 id="修改环境变量"><a href="#修改环境变量" class="headerlink" title="修改环境变量"></a>修改环境变量</h3><p><code>vim /etc/profile</code>打开文件</p><p>底部添加</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">if [ $USER = "oracle" ]; then</span><br><span class="line">if [ $SHELL = "/bin/ksh" ]; then</span><br><span class="line">ulimit -p 16384</span><br><span class="line">ulimit -n 65536</span><br><span class="line">else</span><br><span class="line">ulimit -u 16384 -n 65536</span><br><span class="line">fi</span><br><span class="line">fi</span><br></pre></td></tr></tbody></table></figure><p>执行<code>source /etc/profile</code>使更改生效</p><h3 id="配置oracle安装目录"><a href="#配置oracle安装目录" class="headerlink" title="配置oracle安装目录"></a>配置oracle安装目录</h3><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">root@localhost opt]# mkdir -p /opt/oracle/product/oraHome #安装目录</span><br><span class="line">[root@localhost opt]# mkdir -p /opt/oracle/oradata </span><br><span class="line">[root@localhost opt]# mkdir -p /opt/inventory</span><br><span class="line">[root@localhost opt]# chown -R oracle:oinstall /opt/oracle</span><br><span class="line">[root@localhost opt]# chown -R 755 /opt/oracle</span><br></pre></td></tr></tbody></table></figure><h3 id="配置oracle用户环境变量"><a href="#配置oracle用户环境变量" class="headerlink" title="配置oracle用户环境变量"></a>配置oracle用户环境变量</h3><p>此部分需要切换到oracle用户执行,执行<code>su - oracle</code>切换用户。<code>su</code>为切换回root用户</p><p><code>vim ~/.bash_profile </code></p><p>在文件中添加</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">export ORACLE_BASE=/opt/oracle</span><br><span class="line">export ORACLE_HOME=$ORACLE_BASE/product/oraHome</span><br><span class="line">export ORACLE_SID=orcl</span><br><span class="line">export ORACLE_OWNER=oracle</span><br><span class="line">export ORACLE_TERM=vt100</span><br><span class="line">export PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin</span><br><span class="line">export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin:$PATH</span><br><span class="line">LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/local/lib</span><br><span class="line">export LD_LIBRARY_PATH</span><br><span class="line">CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib</span><br><span class="line">CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib</span><br><span class="line">export CLASSPATH</span><br><span class="line">export LC_ALL="en_US"</span><br><span class="line">export LANG="en_US"</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>配置生效<code>source ~/.bash_profile</code></p><hr><p>至此配置部分完成,开始安装oracle。</p><hr><h2 id="安装oracle"><a href="#安装oracle" class="headerlink" title="安装oracle"></a>安装oracle</h2><p>下面需要在root用户下执行</p><h3 id="下载安装包"><a href="#下载安装包" class="headerlink" title="下载安装包"></a>下载安装包</h3><p>下载<a href="http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html">oracle 11g</a>,官网需要登录。</p><p><img src="http://img.xujn.xyz/image20180902222159.png"><br>下载两个文件后,上传到linux服务器上。</p><h3 id="解压"><a href="#解压" class="headerlink" title="解压"></a>解压</h3><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">unzip linux.x64_11gR2_database_1of2.zip -d /opt</span><br><span class="line">unzip linux.x64_11gR2_database_2of2.zip -d /opt</span><br></pre></td></tr></tbody></table></figure><p>我是将其解压在/opt下,解压之后文件会在database目录下。</p><h3 id="静默安装文件配置"><a href="#静默安装文件配置" class="headerlink" title="静默安装文件配置"></a>静默安装文件配置</h3><p>拷贝<code>database/response/</code>下面的<code>dbca.rsp</code>、<code>db_install.rsp</code>及<code>netca.rsp</code>三个文件至<code>/opt/oracle</code>目录下。这三个文件很重要</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp response/* /opt/oracle</span><br></pre></td></tr></tbody></table></figure><p>编辑db_install.rsp文件 </p><p><code>vim /db/etc/db_install.rsp</code></p><p><code>hostname</code>查看自己的主机名</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">racle.install.option=INSTALL_DB_SWONLY</span><br><span class="line">DECLINE_SECURITY_UPDATES=true</span><br><span class="line">UNIX_GROUP_NAME=oinstall</span><br><span class="line">INVENTORY_LOCATION=/opt/inventory</span><br><span class="line">SELECTED_LANGUAGES=en,zh_CN</span><br><span class="line">ORACLE_HOSTNAME=node75 #node75为自己的主机名</span><br><span class="line">ORACLE_HOME=/opt/oracle/product/oraHome</span><br><span class="line">ORACLE_BASE=/opt/oracle</span><br><span class="line">oracle.install.db.InstallEdition=EE</span><br><span class="line">oracle.install.db.isCustomInstall=true</span><br><span class="line">oracle.install.db.DBA_GROUP=dba</span><br><span class="line">oracle.install.db.OPER_GROUP= oinstall</span><br><span class="line">Oracle.install.db.config.starterdb.type=GENERAL_PURPOSE</span><br><span class="line">Oracle.install.db.config.starterdb.globalDBName=orcl</span><br><span class="line">Oracle.install.db.config.starterdb.SID=orcl</span><br><span class="line">Oracle.install.db.config.starterdb.characterSet= AL32UTF8</span><br><span class="line">Oracle.install.db.config.starterdb.password.ALL=oracle</span><br><span class="line">DECLINE_SECURITY_UPDATES=true</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h3 id="静默安装"><a href="#静默安装" class="headerlink" title="静默安装"></a>静默安装</h3><p>切换至oracle 帐号<code>su – oracle</code></p><p>进入database目录</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./runInstaller -silent -ignorePrereq -responseFile /opt/oracle/db_install.rsp</span><br></pre></td></tr></tbody></table></figure><p>安装开始,时间会有点久,如果出现问题,查看控制台日志。运维第一步,会看日志。</p><p>安装完成,提示Successfully Setup Software.</p><p><img src="http://img.xujn.xyz/image20180902223914.png"></p><h3 id="执行脚本"><a href="#执行脚本" class="headerlink" title="执行脚本"></a>执行脚本</h3><p>切换回root用户,执行上图中提示的脚本。</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sh /opt/oracle/inventory/orainsRot.sh</span><br><span class="line">sh /opt/oracle/product/oraHome/root.sh</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><h3 id="配置监听"><a href="#配置监听" class="headerlink" title="配置监听"></a>配置监听</h3><p><code>netca /silent /responsefile /opt/oracle/netca.rsp</code><br><img src="http://img.xujn.xyz/image20180902224154.png"></p><h3 id="执行静默建库"><a href="#执行静默建库" class="headerlink" title="执行静默建库"></a>执行静默建库</h3><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dbca -silent -responseFile /opt/oracle/dbca.rsp -sysPassword oracle -systemPassword oracle</span><br></pre></td></tr></tbody></table></figure><p><code>-sysPassword oracle -systemPassword oracle</code>需要制定密码,不然报错</p><p><img src="http://img.xujn.xyz/image20180902224347.png"></p><p>如上图,安装成功。</p><h2 id="查看oracle"><a href="#查看oracle" class="headerlink" title="查看oracle"></a>查看oracle</h2><p>切换oracle用户</p><h3 id="查看实例进程"><a href="#查看实例进程" class="headerlink" title="查看实例进程"></a>查看实例进程</h3><p><code>ps -ef | grep ora_ | grep -v grep</code></p><p><img src="http://img.xujn.xyz/image20180902224540.png"></p><h3 id="查看监听状态"><a href="#查看监听状态" class="headerlink" title="查看监听状态"></a>查看监听状态</h3><p><code>lsnrctl status</code></p><p><img src="http://img.xujn.xyz/image20180902224703.png"></p><h3 id="其他操作"><a href="#其他操作" class="headerlink" title="其他操作"></a>其他操作</h3><p>登录sqlplus,查看实例状态</p><p><code>sqlplus / as sysdba</code></p><p>查看数据库编码</p><p><code>select userenv('language') from dual;</code></p><p>查看数据库版本信息</p><p><code>select * from v$version;</code></p>]]></content>
<categories>
<category> Oracle </category>
</categories>
<tags>
<tag> Oracle 11g </tag>
<tag> Redhat7 </tag>
</tags>
</entry>
<entry>
<title>Linux下解决TNS-12541 TNS no listener问题</title>
<link href="/2018/08/27/linux-xia-jie-jue-tns-12541-tns-no-listener-wen-ti/"/>
<url>/2018/08/27/linux-xia-jie-jue-tns-12541-tns-no-listener-wen-ti/</url>
<content type="html"><![CDATA[<h2 id="场景"><a href="#场景" class="headerlink" title="场景"></a>场景</h2><p>Navicat连接远程oracle数据库,数据库搭建在Redhat 7.1服务器上,莫名出现这个问题。</p><h2 id="解决办法"><a href="#解决办法" class="headerlink" title="解决办法"></a>解决办法</h2><ul><li>检查监听状态</li><li>无监听,则查看监听文件</li></ul><p>查看监听状态<code>lsnrctl status</code></p><p>如果有监听,则如下图,显示有服务orcl(服务名)监听。</p><p><img src="http://img.xujn.xyz/image20180827102215.png"></p><p>如果没有监听,查看监听文件</p><p><code>cd /opt/oracle/product/oraHome/network/admin</code><br><img src="http://img.xujn.xyz/image20180827101607.png"></p><p>tnsnames.ora:用于客户端,提示客户端从哪个监听实例连接。</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">ORCL =</span><br><span class="line"> (DESCRIPTION =</span><br><span class="line"> (ADDRESS = (PROTOCOL = TCP)(HOST = node75)(PORT = 1521))</span><br><span class="line"> (CONNECT_DATA =</span><br><span class="line"> (SERVER = DEDICATED)</span><br><span class="line"> (SERVICE_NAME = orcl)</span><br><span class="line"> )</span><br><span class="line"> )</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>listener.ora:用于服务端,用于提示服务端监听哪些实例。</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">LISTENER =</span><br><span class="line"> (DESCRIPTION_LIST =</span><br><span class="line"> (DESCRIPTION =</span><br><span class="line"> (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))</span><br><span class="line"> (ADDRESS = (PROTOCOL = TCP)(HOST =node75)(PORT = 1521))</span><br><span class="line"> )</span><br><span class="line"> )</span><br><span class="line"></span><br><span class="line">ADR_BASE_LISTENER = /opt/oracle</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>其中HOST为当前主机名,之前将主机名更改,忘记(<del>其实就是不知道</del>)修改oracle监听的主机名。</p><h2 id="开启oracle"><a href="#开启oracle" class="headerlink" title="开启oracle"></a>开启oracle</h2><p>配置完成,开启oracle</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">lsnrctl start #开启监听</span><br><span class="line">dbstart # 启动用户实例</span><br></pre></td></tr></tbody></table></figure>]]></content>
<categories>
<category> Oracle </category>
</categories>
<tags>
<tag> Linux </tag>
<tag> Oracle </tag>
</tags>
</entry>
<entry>
<title>Centos7下Nginx安装配置</title>
<link href="/2018/08/23/centos7-xia-nginx-an-zhuang-pei-zhi/"/>
<url>/2018/08/23/centos7-xia-nginx-an-zhuang-pei-zhi/</url>
<content type="html"><![CDATA[<h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><pre><code>yum install epel-releaseyum -y install nginxservice nginx startsystemctl enable nginx</code></pre><p>访问自己的地址<code>http://server_ip</code></p><p>记得开启80端口</p><p><img src="http://img.xujn.xyz/image20180823124919.png" alt="nginx默认界面"></p><p>firewalld支持动态更新和zone概念。firewalld有图形界面和命令行界面。</p><p>firewalld命令行管理工具是firewall-cmd,firewalld-cmd –help查看常用命令。</p><pre><code> firewalld默认有8个zone,都配置好了,只要切换就可以了 drop 默认丢弃所有包 block 拒绝所有外部链接,允许内部发起的连接 public 指定外部连接可以进入 external dmz 和硬件防火墙一样,受限制的公共连接可以进入 work 工作区,概念和workgroup一样,指定的外部链接允许 home 类似家庭组 internal 信任所有链接 centos7默认安装了firewalld,若没有安装,执行 yum install firewalld firewalld-config安装 systemctl start firewalld 启动 systemctl status firewalld或者firewall-cmd –state 查看状态 sytemctl disable firewalld 停止并禁用开机启动 systemctl enable firewalld 设置开机启动 systemctl stop firewalld 禁用 firewall-cmd –version 查看版本 firewall-cmd –help帮助信息 firewall-cmd –get-active-zones查看区域信息 firewall-cmd –get-zone-of-interface=eth0查看指定接口所属区域 firewall-cmd –panic-on 拒绝所有包 firewall-cmd –panic-off取消拒绝状态 firewall-cmd –query-panic查看是否拒绝 firewall-cmd –reload 更新防火墙规则 firewall-cmd –complete-reload 断开再连接 firewall-cmd –zone=public –add-interface=eth0 将接口添加到public区域 , 默认接口都在public。若加上–permanet则永久生效 firewall-cmd –set-default-zone=public 设置public为默认接口区域 firewall-cmd –zone=pulic –list-ports 查看所有打开的端口 firewall-cmd –zone=pulic –add-port=80/tcp 把tcp 80端口加入到区域 firewall-cmd –zone=public –add-service=http 把http服务加入到区域 firewall-cmd –zone=public –remove-service=http 移除http服务</code></pre>]]></content>
<categories>
<category> 软件安装 </category>
</categories>
<tags>
<tag> nginx </tag>
</tags>
</entry>
<entry>
<title>IntelliJ IDEA SSM框架整合</title>
<link href="/2018/08/23/intellij-idea-ssm-kuang-jia-zheng-he/"/>
<url>/2018/08/23/intellij-idea-ssm-kuang-jia-zheng-he/</url>
<content type="html"><![CDATA[<h2 id="web-xml文件"><a href="#web-xml文件" class="headerlink" title="web.xml文件"></a>web.xml文件</h2><p><em>参考自:</em><a href="https://zhuanlan.zhihu.com/p/26150612">web.xml配置</a></p><p><code>web.xml</code>是网络程序中的一个很重要的配置文件。在启动一个WEB项目的时候,WEB容器(比如<code>tomcat</code>)会去读取它的配置文件web.xml,读取到不同的节点时,WEB容器就会创建相应的<code>过滤器</code>、<code>监听器</code>等为这个web项目服务。</p><p>IDEA初始化后,修改web.xml文件</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><?xml version="1.0" encoding="UTF-8"?></span><br><span class="line"><web-app xmlns="http://java.sun.com/xml/ns/javaee"</span><br><span class="line"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"</span><br><span class="line"> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee</span><br><span class="line"> http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"</span><br><span class="line"> version="3.0"></span><br><span class="line"> <display-name>WebApplication</display-name></span><br><span class="line"></span><br><span class="line"> <!--指定spring的配置文件--></span><br><span class="line"> <context-param></span><br><span class="line"> <param-name>contextConfigLocation</param-name></span><br><span class="line"> <param-value>classpath:applicationContext.xml</param-value></span><br><span class="line"> </context-param></span><br><span class="line"> <!--配置spring核心监听器--></span><br><span class="line"> <listener></span><br><span class="line"> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></span><br><span class="line"> </listener></span><br><span class="line"> <!--spring MVC 的前端控制器--></span><br><span class="line"> <servlet></span><br><span class="line"> <servlet-name>dispatcher</servlet-name></span><br><span class="line"> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class></span><br><span class="line"> <init-param></span><br><span class="line"> <param-name>contextConfigLocation</param-name></span><br><span class="line"> <param-value>classpath:dispatcher-servlet.xml</param-value></span><br><span class="line"> </init-param></span><br><span class="line"> <load-on-startup>1</load-on-startup></span><br><span class="line"> </servlet></span><br><span class="line"> <servlet-mapping></span><br><span class="line"> <servlet-name>dispatcher</servlet-name></span><br><span class="line"> <url-pattern>*.form</url-pattern></span><br><span class="line"> </servlet-mapping></span><br><span class="line"> <!-- 编码过滤器--></span><br><span class="line"> <filter></span><br><span class="line"> <filter-name>encodingFilter</filter-name></span><br><span class="line"> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class></span><br><span class="line"> <init-param></span><br><span class="line"> <param-name>encoding</param-name></span><br><span class="line"> <param-value>UTF-8</param-value></span><br><span class="line"> </init-param></span><br><span class="line"> </filter></span><br><span class="line"> <filter-mapping></span><br><span class="line"> <filter-name>encodingFilter</filter-name></span><br><span class="line"> <url-pattern>/*</url-pattern></span><br><span class="line"> </filter-mapping></span><br><span class="line"></span><br><span class="line"></web-app></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p><strong>说明:</strong></p><ul><li><p><code>listener</code>:监听器,能捕捉到服务器的启动和停止,在启动和停止触发里面的方法做相应的操作。必须在<code>web.xml</code>中配置才能使用,是配置监听类的。</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><listener></span><br><span class="line"> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></span><br><span class="line"> </listener></span><br></pre></td></tr></tbody></table></figure></li><li><p><code>contenxt-param</code>:该节点用来声明应用范围(整个WEB项目)内的上下文初始化参数。param-name设定上下文的参数名称。必须是唯一名称,而param-value 是设定参数名称的值。</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><context-param></span><br><span class="line"> <param-name>contextConfigLocation</param-name></span><br><span class="line"> <param-value>classpath:applicationContext.xml</param-value></span><br><span class="line"> </context-param></span><br></pre></td></tr></tbody></table></figure></li><li><p><code>servlet</code>:这是个比较重要的节点。该servlet用于拦截请求(<code>url-pattern</code>为 / ,说明拦截所有请求。如果想拦截.do后缀文件的请求,就改为*.do),并交由SpringMVC的后台控制器来处理。这一项配置是必须的。<code>load-on-startup</code>节点用于标记容器是否在启动的时候就加载这个servlet。当值为0或者大于0时,表示容器在应用启动时就加载这个servlet;当是一个负数时或者没有指定时,则指示容器在该servlet被选择时才加载。正数的值越小,启动该servlet的优先级越高。</p><figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><servlet></span><br><span class="line"> <servlet-name>dispatcher</servlet-name></span><br><span class="line"> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class></span><br><span class="line"> <init-param></span><br><span class="line"> <param-name>contextConfigLocation</param-name></span><br><span class="line"> <param-value>classpath:dispatcher-servlet.xml</param-value></span><br><span class="line"> </init-param></span><br><span class="line"> <load-on-startup><span class="number">1</span></load-on-startup></span><br><span class="line"> </servlet></span><br><span class="line"> <servlet-mapping></span><br><span class="line"> <servlet-name>dispatcher</servlet-name></span><br><span class="line"> <url-pattern>*.form</url-pattern></span><br><span class="line"> </servlet-mapping></span><br></pre></td></tr></tbody></table></figure></li><li><p><code>filter</code>:过滤器。为了能够处理中文的post请求,post上传的编码统统改为utf-8。</p></li></ul><blockquote><p>web.xml的加载过程是:context-param -> listener -> fileter -> servlet。</p></blockquote><p><em>application.xml—>listener—->fileter—->dispatcher-servlet.xml</em></p><h2 id="数据库连接池配置"><a href="#数据库连接池配置" class="headerlink" title="数据库连接池配置"></a>数据库连接池配置</h2><p><em>参考自:</em><a href="http://blog.csdn.net/fysuccess/article/details/66972554">java数据连接池</a></p><p>pom.xml</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><!--mysql依赖--></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>mysql</groupId></span><br><span class="line"> <artifactId> mysql-connector-java</artifactId></span><br><span class="line"> <version>5.1.44</version></span><br><span class="line"> </dependency></span><br><span class="line"> <dependency></span><br><span class="line"> <groupId>com.alibaba</groupId></span><br><span class="line"> <artifactId>druid</artifactId></span><br><span class="line"> <version>1.1.6</version></span><br><span class="line"> </dependency></span><br></pre></td></tr></tbody></table></figure><p>db.properties</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">jdbc.driver=com.mysql.jdbc.Driver</span><br><span class="line">jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8</span><br><span class="line">jdbc.username=root</span><br><span class="line">jdbc.password=XXX</span><br></pre></td></tr></tbody></table></figure><p>applicationContext.xml</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><!--导入外部的properties文件--></span><br><span class="line"> <context:property-placeholder location="classpath:db.properties"/></span><br><span class="line"> <!--Spring Druid 数据源配置--></span><br><span class="line"> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" </span><br><span class="line"> init-method="init" destroy-method="close"></span><br><span class="line"> <!-- 基本属性 url、user、password --></span><br><span class="line"> <property name="url" value="${jdbc.url}" /></span><br><span class="line"> <property name="username" value="${jdbc.username}" /></span><br><span class="line"> <property name="password" value="${jdbc.password}" /></span><br><span class="line"> <!-- 配置初始化大小、最小、最大 --></span><br><span class="line"> <property name="initialSize" value="1" /></span><br><span class="line"> <property name="minIdle" value="1" /></span><br><span class="line"> <property name="maxActive" value="20" /></span><br><span class="line"> <!-- 配置获取连接等待超时的时间 --></span><br><span class="line"> <property name="maxWait" value="60000" /></span><br><span class="line"> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --></span><br><span class="line"> <property name="timeBetweenEvictionRunsMillis" value="60000" /></span><br><span class="line"> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --></span><br><span class="line"> <property name="minEvictableIdleTimeMillis" value="300000" /></span><br><span class="line"> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --></span><br><span class="line"> <property name="poolPreparedStatements" value="true" /></span><br><span class="line"> <property name="maxPoolPreparedStatementPerConnectionSize" value="20" /></span><br><span class="line"> <!-- 配置监控统计拦截的filters,去掉后监控界面sql无法统计 --></span><br><span class="line"> <property name="filters" value="stat" /></span><br><span class="line"> </bean></span><br></pre></td></tr></tbody></table></figure><p>web.xml</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><!--数据库连接池监控配置--></span><br><span class="line"> <filter></span><br><span class="line"> <filter-name>DruidWebStatFilter</filter-name></span><br><span class="line"> <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class></span><br><span class="line"> <init-param></span><br><span class="line"> <param-name>exclusions</param-name></span><br><span class="line"> <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value></span><br><span class="line"> </init-param></span><br><span class="line"> </filter></span><br><span class="line"> <filter-mapping></span><br><span class="line"> <filter-name>DruidWebStatFilter</filter-name></span><br><span class="line"> <url-pattern>/*</url-pattern></span><br><span class="line"> </filter-mapping></span><br><span class="line"> <servlet></span><br><span class="line"> <servlet-name>DruidStatView</servlet-name></span><br><span class="line"> <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class></span><br><span class="line"> </servlet></span><br><span class="line"> <servlet-mapping></span><br><span class="line"> <servlet-name>DruidStatView</servlet-name></span><br><span class="line"> <url-pattern>/druid/*</url-pattern></span><br><span class="line"> </servlet-mapping></span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>该配置可以访问监控界面,监控数据库访问性能,访问地址:<br><code>http://ip:port/项目名/druid/index.html</code> </p>]]></content>
<categories>
<category> Spring </category>
</categories>
<tags>
<tag> IDEA </tag>
<tag> SSM </tag>
</tags>
</entry>
<entry>
<title>Linux下MySQL 5.7.22安装和忘记密码</title>
<link href="/2018/08/23/linux-xia-mysql-5.7.22-an-zhuang-he-wang-ji-mi-ma/"/>
<url>/2018/08/23/linux-xia-mysql-5.7.22-an-zhuang-he-wang-ji-mi-ma/</url>
<content type="html"><![CDATA[<h2 id="简述"><a href="#简述" class="headerlink" title="简述"></a>简述</h2><p>Redhat下安装MySQL5.7.22教程,安装完成后成功忘记密码-_-</p><h2 id="安装MySQL"><a href="#安装MySQL" class="headerlink" title="安装MySQL"></a>安装MySQL</h2><h4 id="1-压缩包处理"><a href="#1-压缩包处理" class="headerlink" title="1. 压缩包处理"></a>1. 压缩包处理</h4><p>解压压缩包</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz </span><br></pre></td></tr></tbody></table></figure><p>重命名mysql解压文件</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql</span><br></pre></td></tr></tbody></table></figure><p>复制mysql文件</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp -r mysql /usr/local/mysql</span><br></pre></td></tr></tbody></table></figure><h4 id="2-添加系统mysql组合mysql用户"><a href="#2-添加系统mysql组合mysql用户" class="headerlink" title="2. 添加系统mysql组合mysql用户"></a>2. 添加系统mysql组合mysql用户</h4><p>添加系统mysql组</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">groupadd mysql</span><br></pre></td></tr></tbody></table></figure><p>添加mysql用户</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">useradd -r -g mysql mysql</span><br></pre></td></tr></tbody></table></figure><p>添加mysql目录所有者为mysql</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chown -R mysql:mysql /usr/local/mysql</span><br></pre></td></tr></tbody></table></figure><p>添加data目录所有者为mysql(<em>在mysql目录下新建data文件夹</em>)</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chown -R mysql:mysql data</span><br></pre></td></tr></tbody></table></figure><h4 id="3-配置my-cnf"><a href="#3-配置my-cnf" class="headerlink" title="3. 配置my.cnf"></a>3. 配置my.cnf</h4><p><code>vim /etc/my.cnf</code><br>(如果没有这个文件,直接新建)</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[mysqld]</span><br><span class="line">character_set_server=utf8</span><br><span class="line">init_connect='SET NAMES utf8'</span><br><span class="line">basedir=/usr/local/mysql</span><br><span class="line">datadir=/usr/local/mysql/data</span><br><span class="line">socket=/tmp/mysql.sock</span><br><span class="line">#不区分大小写</span><br><span class="line">sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES</span><br><span class="line">lower_case_table_names = 1</span><br><span class="line">#log-error=/var/log/mysqld.log</span><br><span class="line">pid-file=/usr/local/mysql/data/mysqld.pid</span><br></pre></td></tr></tbody></table></figure><h4 id="4-安装数据库"><a href="#4-安装数据库" class="headerlink" title="4. 安装数据库"></a>4. 安装数据库</h4><p>在mysql目录下,初始化数据库</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bin/mysqld --initialize --user=mysql </span><br></pre></td></tr></tbody></table></figure><p>成功后,会生成临时密码,在最后一行。记住这个密码</p><p>执行以下命令创建RSA private key </p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data</span><br></pre></td></tr></tbody></table></figure><h4 id="5-添加开机启动"><a href="#5-添加开机启动" class="headerlink" title="5. 添加开机启动"></a>5. 添加开机启动</h4><p>复制mysql.server</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld</span><br></pre></td></tr></tbody></table></figure><p>修改mysql.server</p><p><code>vim /etc/init.d/mysqld </code></p><p>添加basedir和datadir</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">basedir=/usr/local/mysql</span><br><span class="line">datadir=/usr/local/mysql/data</span><br></pre></td></tr></tbody></table></figure><h4 id="6-启动MySQL"><a href="#6-启动MySQL" class="headerlink" title="6.启动MySQL"></a>6.启动MySQL</h4><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">service mysqld start #启动</span><br><span class="line">service mysqld stop #停止</span><br><span class="line">service mysqld status #查看状态</span><br></pre></td></tr></tbody></table></figure><h4 id="7-开机启动"><a href="#7-开机启动" class="headerlink" title="7.开机启动"></a>7.开机启动</h4><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chkconfig --add mysqld</span><br></pre></td></tr></tbody></table></figure><h4 id="8-登陆修改密码"><a href="#8-登陆修改密码" class="headerlink" title="8. 登陆修改密码"></a>8. 登陆修改密码</h4><p>首次登陆,密码为之前的临时密码</p><p><code>mysql -uroot -p</code></p><pre><code>如果出现`-bash: mysql:command not found`问题添加软连接` ln -s /usr/local/mysql/bin/mysql /usr/bin`</code></pre><p>输入密码后</p><pre><code>如果出现Your password has expired. To log in you must change it using a client that supports expired passwords这样的问题,那么跟我一样,重置密码</code></pre><p>正常访问,进入<code>mysql></code></p><p>修改之前的临时密码</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">alter user 'root'@'localhost' identified by 'your password'; </span><br></pre></td></tr></tbody></table></figure><p>刷新权限</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">flush privileges; </span><br></pre></td></tr></tbody></table></figure><p>授权新用户</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' IDENTIFIED BY 'test password' WITH GRANT OPTION; </span><br></pre></td></tr></tbody></table></figure><h2 id="允许用户远程访问"><a href="#允许用户远程访问" class="headerlink" title="允许用户远程访问"></a>允许用户远程访问</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">select 'host' from user where user='root';</span><br><span class="line">update user set host = '%' where user ='root';</span><br><span class="line">flush privileges;</span><br></pre></td></tr></tbody></table></figure><h2 id="忘记密码"><a href="#忘记密码" class="headerlink" title="忘记密码"></a>忘记密码</h2><p>关闭mysql</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">service mysqld stop</span><br><span class="line"># 或者</span><br><span class="line">kill MYSQL_PID</span><br></pre></td></tr></tbody></table></figure><p>进入安全模式(mysql的bin目录下<code>cd mysql/bin</code>)</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./mysqld_safe --skip-grant-tables &</span><br></pre></td></tr></tbody></table></figure><p>root用户无密码登陆</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql -uroot</span><br></pre></td></tr></tbody></table></figure><p>进入之后,选择mysql数据库</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">use mysql;</span><br></pre></td></tr></tbody></table></figure><p>更新密码 </p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">update user set authentication_string=password('ustc@mysql123') where user='root'; </span><br></pre></td></tr></tbody></table></figure><p><em>authentication_string字段变化,以前为password字段</em><br>刷新权限表 </p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">flush privileges;</span><br></pre></td></tr></tbody></table></figure><p>退出</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">quit;</span><br></pre></td></tr></tbody></table></figure><p>重启mysql,新密码登录(陆?)</p><p><a href="https://blog.csdn.net/zmx729618/article/details/78026497">mysql.user表权限</a></p><h2 id="mysql创建用户与授权"><a href="#mysql创建用户与授权" class="headerlink" title="mysql创建用户与授权"></a>mysql创建用户与授权</h2><p>CREATE USER ‘ustc‘@’%’ IDENTIFIED BY ‘ustc’;</p><p>GRANT ALL ON <em>.</em> TO ‘ustc‘@’%’;</p><p> grant all privileges on <em>.</em> to root@”%” with grant option</p>]]></content>
<categories>
<category> 数据库 </category>
</categories>
<tags>
<tag> MySQL </tag>
</tags>
</entry>
<entry>
<title>Redhat更换yum源</title>
<link href="/2018/08/14/redhat-geng-huan-yum-yuan/"/>
<url>/2018/08/14/redhat-geng-huan-yum-yuan/</url>
<content type="html"><![CDATA[<h2 id="简述"><a href="#简述" class="headerlink" title="简述"></a>简述</h2><p>redhat没有进行注册(收费了),不能够使用其自带的yum源,所以需要第三方的源来代替。</p><h2 id="阿里云镜像源"><a href="#阿里云镜像源" class="headerlink" title="阿里云镜像源"></a>阿里云镜像源</h2><p>查看自带yum源</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa | grep yum</span><br><span class="line"># 查询结果</span><br><span class="line">yum-utils-1.1.31-24.el7.noarch</span><br><span class="line">yum-langpacks-0.4.2-3.el7.noarch</span><br><span class="line">yum-metadata-parser-1.1.4-10.el7.x86_64</span><br><span class="line">yum-rhn-plugin-2.0.1-4.el7.noarch</span><br><span class="line">PackageKit-yum-0.8.9-11.el7.x86_64</span><br><span class="line">yum-3.4.3-118.el7.noarch</span><br></pre></td></tr></tbody></table></figure><p><code>(这些安装包都需要从阿里源重新下载)</code></p><p>卸载RedHat自带yum源</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa|grep yum|xargs rpm -e --nodeps</span><br></pre></td></tr></tbody></table></figure><p>配置redhat DNS解析(否则不能解析域名)</p><p><code>vim /etc/sysconfig/network-scripts/ifcfg-lo</code></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">#ifcfg-lo文件添加DNS映射</span><br><span class="line">DNS1=8.8.8.8</span><br><span class="line">DNS2=8.8.8.4</span><br></pre></td></tr></tbody></table></figure><p>使用<code>wget</code>将需要的安装包从<a href="https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/">阿里yum源</a><br>下载下来</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-158.el7.centos.noarch.rpm</span><br><span class="line">...</span><br><span class="line">...</span><br></pre></td></tr></tbody></table></figure><p>安装</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -ivh yum-3.4.3-158.el7.centos.noarch.rpm --nodes --force</span><br></pre></td></tr></tbody></table></figure><p><code>建议一个一个安装</code></p><p>新建配置文件(用于阿里源配置)<br><code>vim /etc/yum.repos.d/CentOS-Base.repo</code></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">baseurl=https://mirrors.aliyun.com/centos/7/os/$basearch/</span><br><span class="line">gpgcheck=1</span><br><span class="line">gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7</span><br><span class="line"></span><br><span class="line">#released updates</span><br><span class="line">[updates]</span><br><span class="line">name=CentOS-$7 - Updates - aliyun.com</span><br><span class="line">#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=updates</span><br><span class="line">baseurl=https://mirrors.aliyun.com/centos/7/updates/$basearch/</span><br><span class="line">gpgcheck=1</span><br><span class="line">gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7</span><br><span class="line"></span><br><span class="line">#additional packages that may be useful</span><br><span class="line">[extras]</span><br><span class="line">name=CentOS-$7 - Extras - aliyun.com</span><br><span class="line">#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=extras</span><br><span class="line">baseurl=https://mirrors.aliyun.com/centos/7/extras/$basearch/</span><br><span class="line">gpgcheck=1</span><br><span class="line">gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7</span><br><span class="line"></span><br><span class="line">#additional packages that extend functionality of existing packages</span><br><span class="line">[centosplus]</span><br><span class="line">name=CentOS-$7 - Plus - aliyun.com</span><br><span class="line">baseurl=https://mirrors.aliyun.com/centos/7/centosplus/$basearch/</span><br><span class="line">gpgcheck=1</span><br><span class="line">enabled=0</span><br><span class="line"></span><br><span class="line">gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7</span><br><span class="line"></span><br></pre></td></tr></tbody></table></figure><p>下载软件测试下</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum -y install tree</span><br></pre></td></tr></tbody></table></figure><h2 id="本地iso镜像源"><a href="#本地iso镜像源" class="headerlink" title="本地iso镜像源"></a>本地iso镜像源</h2><p>上传文件到服务器目录rhel-server-6.5-x86_64-dvd-1.iso</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># 创建文件</span><br><span class="line">mkdir /mnt/yum</span><br><span class="line"># 挂载镜像</span><br><span class="line">mount -o loop rhel-server-6.5-x86_64-dvd-1.iso /mnt/yum</span><br></pre></td></tr></tbody></table></figure><p>修改配置文件vim /etc/yum.repos.d/rhel.repo</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[redhat]</span><br><span class="line"># 改为1</span><br><span class="line">enabled=1</span><br><span class="line"># 文件挂载位置</span><br><span class="line">baseurl=file:///mnt/yum</span><br><span class="line">#其他配置不用改</span><br></pre></td></tr></tbody></table></figure><p><strong>测试</strong></p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">yum clean</span><br><span class="line">yum install tree</span><br></pre></td></tr></tbody></table></figure><h2 id="用过的命令"><a href="#用过的命令" class="headerlink" title="用过的命令"></a>用过的命令</h2><p><strong>RPM—>Redhat package Manager软件管理工具</strong></p><p>常用命令:</p><ul><li>-ivh : 安装显示安装进度 –install–verbose–hash</li><li>-Uvh : 升级软件报 –Update</li><li>-e : 删除包</li><li>-qpl :列出RPM软件包内的文件信息Query Package list</li><li>-qpi :列出RPM软件包的描述信息Query Package install package(s)</li><li>-qf :查找指定文件属于哪个RPM软件包Query File</li><li>-Va:校验所有的RPM软件包,查找丢失的文件View Lost</li></ul><p>参考自:<br><br><a href="https://blog.csdn.net/hongbin_xu/article/details/79316614">yum</a><br><a href="https://www.cnblogs.com/xiaochaohuashengmi/archive/2011/10/08/2203153.html">rpm</a></p>]]></content>
<categories>
<category> Linux </category>
</categories>
<tags>
<tag> Linux </tag>
</tags>
</entry>
<entry>
<title>IntelliJ IDEA license server搭建</title>
<link href="/2017/12/30/intellij-idea-license-server-da-jian/"/>
<url>/2017/12/30/intellij-idea-license-server-da-jian/</url>
<content type="html"><![CDATA[<p><em>本文用于搭建JetBrains系列软件激活服务器,如有能力,请支持正版</em><br>##准备</p><ul><li>Centos 7</li><li>Nginx</li><li>适用于JetBrains系列</li></ul><p>##安装nginx</p><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">yum install epel-release</span><br><span class="line">yum -y install nginx</span><br><span class="line">service nginx start</span><br><span class="line">systemctl enable nginx</span><br></pre></td></tr></tbody></table></figure><h2 id="nginx配置"><a href="#nginx配置" class="headerlink" title="nginx配置"></a>nginx配置</h2><figure class="highlight plaintext"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">server {</span><br><span class="line"> listen 主机IP:端口port; </span><br><span class="line"> # 需要自己配置 例: 123.33.32.23:8888</span><br><span class="line"> # listen [::]:8888 default_server ipv6only=on ;</span><br><span class="line"> server_name localhost;</span><br><span class="line"> root /usr/share/nginx/html;</span><br><span class="line"></span><br><span class="line"> # Load configuration files for the default server block.</span><br><span class="line"> include /etc/nginx/default.d/*.conf;</span><br><span class="line"></span><br><span class="line"> location / {</span><br><span class="line"> # 反向代理</span><br><span class="line"> proxy_pass http://idea.lanyus.com:80; </span><br><span class="line"> proxy_set_header X-Real-IP $remote_addr;</span><br><span class="line"> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> error_page 404 /404.html;</span><br><span class="line"> location = /40x.html {</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> error_page 500 502 503 504 /50x.html;</span><br><span class="line"> location = /50x.html {</span><br><span class="line"> }</span><br><span class="line"> }</span><br></pre></td></tr></tbody></table></figure><h2 id="重启nginx,加载配置"><a href="#重启nginx,加载配置" class="headerlink" title="重启nginx,加载配置"></a>重启nginx,加载配置</h2><p>查看nginx主进程</p><pre><code>ps -aux |grep nginx</code></pre><p>master 为主进程,使用kill -HUP 777平滑重启</p><pre><code>kill -HUP 777</code></pre><h2 id="配置防火墙"><a href="#配置防火墙" class="headerlink" title="配置防火墙"></a>配置防火墙</h2><p>centos7默认安装了firewalld,若没有安装,执行<code>yum install firewalld firewalld-config</code>安装</p><pre><code>systemctl start firewalld # 启动</code></pre><p>打开监听端口(上文绑定端口<code>ip:port</code>)</p><pre><code>firewall-cmd --zone=public --add-port=8080/tcp --permanent // 永久开启8080端口</code></pre><p>重新加载防火墙</p><pre><code> firewall-cmd --reload</code></pre><p>现在可以使用你的<code>ip:port</code>激活</p>]]></content>
<categories>
<category> IDEA </category>
</categories>
<tags>
<tag> IDEA </tag>
</tags>
</entry>
</search>