-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1280 lines (816 loc) · 55 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
Tidy的个人博客
</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta property="og:type" content="website">
<meta property="og:title" content="Tidy的个人博客">
<meta property="og:url" content="https://www.tidyko.com/index.html">
<meta property="og:site_name" content="Tidy的个人博客">
<meta property="og:locale" content="zh-CN">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Tidy的个人博客">
<link rel="alternate" href="/atom.xml" title="Tidy的个人博客" type="application/atom+xml">
<link rel="icon" href="/favicon.ico">
<link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/css/style.css">
<!-- <link rel="stylesheet" href="/plugin/bganimation/bg.css"> -->
<!-- Google Adsense -->
<!-- <script async custom-element="amp-auto-ads" src="https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js">
</script> -->
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-1522837637326007",
enable_page_level_ads: true
});
</script>
<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
<!-- End Google Adsense -->
</head>
<body>
<div id="container">
<div id="wrap">
<div class="outer">
<div class="widget-wrap mobile-header">
<h3 class="widget-title"></h3>
<div class="widget">
<img class="avatar" src="http://tidyko.oss-cn-hongkong.aliyuncs.com/avatar.jpg">
<h2 class="author"></h2>
<h3 class="description"></h3>
<div class="count-box">
<a href="/archives"><div><strong>161</strong><br>文章</div></a>
<a href="/categories"><div><strong>58</strong><br>分类</div></a>
<a href="/tags"><div><strong>118</strong><br>标签</div></a>
</div>
<ul class="blog-link">
<a href="/" title="Home">
<li>主页</li>
</a>
<a href="/archives" title="Archives">
<li>归档</li>
</a>
<a href="/categories" title="Categories">
<li>分类</li>
</a>
<a href="/tags" title="Tags">
<li>标签</li>
</a>
</ul>
</div>
</div>
<section id="main">
<article id="post-Docker 搭建Jenkins Agent" class="article" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/posts/87e86852.html" class="article-date">
<time class="post-time" datetime="2020-09-17T04:00:00.000Z" itemprop="datePublished">
<span class="post-month">9月</span><br/>
<span class="post-day">17</span>
</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/posts/87e86852.html">Docker 搭建Jenkins Agent</a>
</h1>
<div>
<div class="article-category">
<a class="article-category-link" href="/categories/DevOps/">DevOps</a>,<a class="article-category-link" href="/categories/DevOps/Docker/">Docker</a>,<a class="article-category-link" href="/categories/DevOps/Docker/Jenkins/">Jenkins</a>
</div>
|
<div class="view-box">
<span id="/posts/87e86852.html" class="leancloud_visitors" data-flag-title="Docker 搭建Jenkins Agent">
阅读次数 <span class="leancloud-visitors-count"></span>
</span>
</div>
|
<div class="view-box">
<span>字数 478</span>
</div>
|
<div class="view-box">
<span>时长 ≈ 2 分钟</span>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p>使用Docker搭建Jenkins服务后,因单节点不允许设置太大的执行数,所以可以创建Jenkins集群,使用Agent分担Jenkins构建的压力。</p>
<h2 id="进入管理Jenkins"><a href="#进入管理Jenkins" class="headerlink" title="进入管理Jenkins"></a>进入管理Jenkins</h2><p>点击左侧菜单“Manage Jenkins(管理Jenkins)” –> “Manage Nods and Clous(管理节点)”进入节点配置界面。<br><img src="http://tidyko.oss-cn-hongkong.aliyuncs.com/blog/jenkins_agent_1.png" alt="Docker 搭建Jenkins Agent-1"><br>
<p class="article-more-link">
<a href="/posts/87e86852.html#more">
Read More</a>
</p>
</div>
<footer class="article-footer">
<a data-url="https://www.tidyko.com/posts/87e86852.html" data-id="ckmn5b0xo000plmqp3y4dlrew" class="article-share-link">
分享</a>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/DevOps/">DevOps</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Docker/">Docker</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Jenkins/">Jenkins</a></li></ul>
</footer>
</div>
</article>
<article id="post-Docker 搭建Jenkins" class="article" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/posts/b4c2554f.html" class="article-date">
<time class="post-time" datetime="2020-09-16T04:00:00.000Z" itemprop="datePublished">
<span class="post-month">9月</span><br/>
<span class="post-day">16</span>
</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/posts/b4c2554f.html">Docker 搭建Jenkins</a>
</h1>
<div>
<div class="article-category">
<a class="article-category-link" href="/categories/DevOps/">DevOps</a>,<a class="article-category-link" href="/categories/DevOps/Docker/">Docker</a>,<a class="article-category-link" href="/categories/DevOps/Docker/Jenkins/">Jenkins</a>
</div>
|
<div class="view-box">
<span id="/posts/b4c2554f.html" class="leancloud_visitors" data-flag-title="Docker 搭建Jenkins">
阅读次数 <span class="leancloud-visitors-count"></span>
</span>
</div>
|
<div class="view-box">
<span>字数 304</span>
</div>
|
<div class="view-box">
<span>时长 ≈ 2 分钟</span>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p>使用Docker搭建Jenkins服务,因为Jenkins Job需要执行Python脚本,需要安装Paramiko模块,所以需要编写下Dockerfile进行构建。</p>
<h2 id="目录结构"><a href="#目录结构" class="headerlink" title="目录结构"></a>目录结构</h2><p>jenkins</p>
<ul>
<li>jenkins_home</li>
<li>dockerfile_2.257<ul>
<li>build.sh</li>
<li>Dockerfile</li>
</ul>
</li>
<li>docker-compose.yml</li>
</ul>
<h2 id="编写dockerfile-2-257-Dockerfile"><a href="#编写dockerfile-2-257-Dockerfile" class="headerlink" title="编写dockerfile_2.257/Dockerfile:"></a>编写dockerfile_2.257/Dockerfile:</h2><figure class="highlight dockerfile"><table><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="keyword">FROM</span> jenkins/jenkins:<span class="number">2.257</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">USER</span> root</span><br><span class="line"></span><br><span class="line"><span class="keyword">RUN</span><span class="bash"> sed -i <span class="string">'s/deb.debian.org/mirrors.aliyun.com/g'</span> /etc/apt/sources.list \</span></span><br><span class="line"><span class="bash"> && sed -i <span class="string">'s/security.debian.org/mirrors.aliyun.com/g'</span> /etc/apt/sources.list \</span></span><br><span class="line"><span class="bash"> && apt-get clean \</span></span><br><span class="line"><span class="bash"> && apt-get update \</span></span><br><span class="line"><span class="bash"> && apt-get install -y python-pip \</span></span><br><span class="line"><span class="bash"> && rm -rf /var/lib/apt/lists/* \</span></span><br><span class="line"><span class="bash"> && pip install -i https://pypi.tuna.tsinghua.edu.cn/simple cffi \</span></span><br><span class="line"><span class="bash"> && pip install -i https://pypi.tuna.tsinghua.edu.cn/simple paramiko</span></span><br><span class="line"><span class="bash"></span></span><br><span class="line"><span class="bash">USER jenkins</span></span><br></pre></td></tr></table></figure>
<p class="article-more-link">
<a href="/posts/b4c2554f.html#more">
Read More</a>
</p>
</div>
<footer class="article-footer">
<a data-url="https://www.tidyko.com/posts/b4c2554f.html" data-id="ckmn5b0xw0011lmqpcycot0h2" class="article-share-link">
分享</a>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/DevOps/">DevOps</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Docker/">Docker</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Jenkins/">Jenkins</a></li></ul>
</footer>
</div>
</article>
<article id="post-Mpvue中使用云函数" class="article" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/posts/d2036d9e.html" class="article-date">
<time class="post-time" datetime="2020-07-13T02:38:00.000Z" itemprop="datePublished">
<span class="post-month">7月</span><br/>
<span class="post-day">13</span>
</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/posts/d2036d9e.html">Mpvue中使用云函数</a>
</h1>
<div>
<div class="article-category">
<a class="article-category-link" href="/categories/编程语言/">编程语言</a>,<a class="article-category-link" href="/categories/编程语言/Vue/">Vue</a>
</div>
|
<div class="view-box">
<span id="/posts/d2036d9e.html" class="leancloud_visitors" data-flag-title="Mpvue中使用云函数">
阅读次数 <span class="leancloud-visitors-count"></span>
</span>
</div>
|
<div class="view-box">
<span>字数 460</span>
</div>
|
<div class="view-box">
<span>时长 ≈ 2 分钟</span>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<h1 id="一、介绍"><a href="#一、介绍" class="headerlink" title="一、介绍"></a>一、介绍</h1><p>在Mpvue中编辑、上传并使用小程序云函数</p>
<h1 id="二、配置、使用"><a href="#二、配置、使用" class="headerlink" title="二、配置、使用"></a>二、配置、使用</h1><ol>
<li><p>配置小程序云函数根目录,<br>在/static目录下创建cloud/function目录,<br>在该目录底下随便创建一个文件,比如“test.js”,主要目的是使发布时dist目录下面新增刚刚添加的目录。</p>
</li>
<li><p>配置project.config.json文件<br>在project.config.json文件下面新增以下字段</p>
<figure class="highlight json"><table><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><br><span class="line"> <span class="attr">"cloudfunctionRoot"</span>: <span class="string">"/static/cloud/functions/"</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
<li><p>编译<br>运行 npm run dev 编译<br>注意:这可能在编译后不会生效,<br>保险起见,应在后检查dist/project.config.json文件,<br>看看刚刚的字段是否添加成功,如果没有,请在dist/project.config.json中也添加上述字段。</p>
<p class="article-more-link">
<a href="/posts/d2036d9e.html#more">
Read More</a>
</p>
</div>
<footer class="article-footer">
<a data-url="https://www.tidyko.com/posts/d2036d9e.html" data-id="ckmn5b13a009blmqpyajnfn2o" class="article-share-link">
分享</a>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Vue/">Vue</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mpvue/">mpvue</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/云函数/">云函数</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/小程序/">小程序</a></li></ul>
</footer>
</div>
</article>
<article id="post-Tampermonkey 网站自动登录脚本" class="article" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/posts/ee559db8.html" class="article-date">
<time class="post-time" datetime="2019-12-25T04:00:00.000Z" itemprop="datePublished">
<span class="post-month">12月</span><br/>
<span class="post-day">25</span>
</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/posts/ee559db8.html">Tampermonkey 网站自动登录脚本</a>
</h1>
<div>
<div class="article-category">
<a class="article-category-link" href="/categories/浏览器/">浏览器</a>,<a class="article-category-link" href="/categories/浏览器/Chrome/">Chrome</a>
</div>
|
<div class="view-box">
<span id="/posts/ee559db8.html" class="leancloud_visitors" data-flag-title="Tampermonkey 网站自动登录脚本">
阅读次数 <span class="leancloud-visitors-count"></span>
</span>
</div>
|
<div class="view-box">
<span>字数 601</span>
</div>
|
<div class="view-box">
<span>时长 ≈ 3 分钟</span>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p>工作中经常会使用到一些内部网站,每次登录都得频繁输入用户名密码,这些动作日积月累显得很浪费时间,现在让我们来使用Chrome浏览器的Tampermonkey插件,编写一段脚本来帮我们实现自动登录功能吧。</p>
<ol>
<li>先在Chrome浏览器的谷歌应用商店上面安装Tampermonkey。</li>
</ol>
<p><img src="http://tidyko.oss-cn-hongkong.aliyuncs.com/blog/Tampermonkey_1.png" alt=""></p>
<p class="article-more-link">
<a href="/posts/ee559db8.html#more">
Read More</a>
</p>
</div>
<footer class="article-footer">
<a data-url="https://www.tidyko.com/posts/ee559db8.html" data-id="ckmn5b14r00bhlmqphouhk3qq" class="article-share-link">
分享</a>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Tampermonkey/">Tampermonkey</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/油猴/">油猴</a></li></ul>
</footer>
</div>
</article>
<article id="post-SpringBoot integration redis分布式锁" class="article" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/posts/c682cc65.html" class="article-date">
<time class="post-time" datetime="2019-12-23T06:38:00.000Z" itemprop="datePublished">
<span class="post-month">12月</span><br/>
<span class="post-day">23</span>
</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/posts/c682cc65.html">SpringBoot integration redis分布式锁</a>
</h1>
<div>
<div class="article-category">
<a class="article-category-link" href="/categories/编程语言/">编程语言</a>,<a class="article-category-link" href="/categories/编程语言/Java/">Java</a>
</div>
|
<div class="view-box">
<span id="/posts/c682cc65.html" class="leancloud_visitors" data-flag-title="SpringBoot integration redis分布式锁">
阅读次数 <span class="leancloud-visitors-count"></span>
</span>
</div>
|
<div class="view-box">
<span>字数 876</span>
</div>
|
<div class="view-box">
<span>时长 ≈ 4 分钟</span>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p>在使用Redis的发布/订阅功能时,由于多节点同时订阅同个通道后会同时消费,此时需要使用一定的策略来避免重复消费的情况。</p>
<p>以下有两种方案:</p>
<ol>
<li>将发布者与订阅者部署在同一台机器上,然后在启动应用时动态初始化通道名称加上IP,这样由当前机器发布的消息只能由当前机器来消费,使用此方法消费者在同一机器上也最多只能部署一台。</li>
<li>使用分布式锁,在订阅者收到通道消息后,对当前资源加锁,抢到锁的则有权限执行业务代码。这种相对于前者而言,就显得便捷很多。本次我们使用SpringBoot Integration Redis的分布式锁完成此功能。</li>
</ol>
<h2 id="pom依赖"><a href="#pom依赖" class="headerlink" title="pom依赖"></a>pom依赖</h2><figure class="highlight xml"><table><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="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><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-integration<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.integration<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>spring-integration-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></table></figure>
<p class="article-more-link">
<a href="/posts/c682cc65.html#more">
Read More</a>
</p>
</div>
<footer class="article-footer">
<a data-url="https://www.tidyko.com/posts/c682cc65.html" data-id="ckmn5b15500c3lmqpaojy9mtv" class="article-share-link">
分享</a>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Java/">Java</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Redis/">Redis</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/SpringBoot/">SpringBoot</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/分布式锁/">分布式锁</a></li></ul>
</footer>
</div>
</article>
<article id="post-Dubbo Filter + SLF4J MDC 实现分布式日志追踪" class="article" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/posts/9f95e5a1.html" class="article-date">
<time class="post-time" datetime="2019-11-18T02:44:00.000Z" itemprop="datePublished">
<span class="post-month">11月</span><br/>
<span class="post-day">18</span>
</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/posts/9f95e5a1.html">Dubbo Filter + SLF4J MDC 实现分布式日志追踪</a>
</h1>
<div>
<div class="article-category">
<a class="article-category-link" href="/categories/编程语言/">编程语言</a>,<a class="article-category-link" href="/categories/编程语言/Java/">Java</a>
</div>
|
<div class="view-box">
<span id="/posts/9f95e5a1.html" class="leancloud_visitors" data-flag-title="Dubbo Filter + SLF4J MDC 实现分布式日志追踪">
阅读次数 <span class="leancloud-visitors-count"></span>
</span>
</div>
|
<div class="view-box">
<span>字数 1,211</span>
</div>
|
<div class="view-box">
<span>时长 ≈ 6 分钟</span>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p>在使用dubbo进行分布式服务开发时,一个大系统会拆分成很多领域以及很多子服务,而且部署时会部署在不同服务器里面,这在我们使用日志排查问题时将会十分麻烦。</p>
<p>这里我们使用Dubbo的Filter以及SLF4J的MDC功能,来共同完成这个事情。</p>
<p>主要思路是:</p>
<ol>
<li>消费端在调用调用服务端时,生成请求ID,然后将请求ID、服务器IP等参数在调用服务前进行注入,将参数带到服务提供方。</li>
<li>提供方在执行方法前,获取消费端设置的参数,包括请求ID、主机IP等需要用到的参数,然后设置到MDC里面,供打印日志使用,再将参数往下游服务进行传递。</li>
</ol>
<h2 id="代码实现:"><a href="#代码实现:" class="headerlink" title="代码实现:"></a>代码实现:</h2><p>由于dubbo在2.7.*的版本以及之前的版本包结构有所变更,<br>为了让大家明白这不同版本的配置差异,<br>这里服务端使用2.7.3的版本,消费端使用2.6.5的版本,来演示下不同版本下配置的异同。</p>
<h3 id="1-定义上下游服务DubboFilter"><a href="#1-定义上下游服务DubboFilter" class="headerlink" title="1.定义上下游服务DubboFilter"></a>1.定义上下游服务DubboFilter</h3><p>服务消费端:ConsumerRpcTraceFilter</p>
<figure class="highlight java"><table><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></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.faq.filter;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.alibaba.dubbo.common.Constants;</span><br><span class="line"><span class="keyword">import</span> com.alibaba.dubbo.common.extension.Activate;</span><br><span class="line"><span class="keyword">import</span> com.alibaba.dubbo.common.utils.NetUtils;</span><br><span class="line"><span class="keyword">import</span> com.alibaba.dubbo.rpc.Filter;</span><br><span class="line"><span class="keyword">import</span> com.alibaba.dubbo.rpc.Invocation;</span><br><span class="line"><span class="keyword">import</span> com.alibaba.dubbo.rpc.Invoker;</span><br><span class="line"><span class="keyword">import</span> com.alibaba.dubbo.rpc.Result;</span><br><span class="line"><span class="keyword">import</span> com.alibaba.dubbo.rpc.RpcContext;</span><br><span class="line"><span class="keyword">import</span> com.alibaba.dubbo.rpc.RpcException;</span><br><span class="line"><span class="keyword">import</span> lombok.extern.slf4j.Slf4j;</span><br><span class="line"><span class="keyword">import</span> org.apache.commons.lang3.StringUtils;</span><br><span class="line"><span class="keyword">import</span> org.slf4j.MDC;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.UUID;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 服务消费端TraceFilter</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> tidy</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> 2019/11/15 11:23</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Activate</span>(group = {Constants.CONSUMER})</span><br><span class="line"><span class="meta">@Slf</span>4j</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ConsumerRpcTraceFilter</span> <span class="keyword">implements</span> <span class="title">Filter</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> invoker</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> invocation</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@throws</span> RpcException</span></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="function"><span class="keyword">public</span> Result <span class="title">invoke</span><span class="params">(Invoker<?> invoker, Invocation invocation)</span> <span class="keyword">throws</span> RpcException </span>{</span><br><span class="line"> <span class="comment">// 如果连续调用多个服务,则会使用同个线程里之前设置的traceId</span></span><br><span class="line"> String traceId = MDC.get(<span class="string">"traceId"</span>);</span><br><span class="line"> <span class="keyword">if</span> (StringUtils.isBlank(traceId)) {</span><br><span class="line"> <span class="comment">// 线程内,首次调用远端服务</span></span><br><span class="line"> traceId = UUID.randomUUID().toString();</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 设置日志traceId变量</span></span><br><span class="line"> MDC.put(<span class="string">"traceId"</span>, traceId);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 设置传递到提供端的参数</span></span><br><span class="line"> RpcContext.getContext().setAttachment(<span class="string">"host"</span>, NetUtils.getLocalHost());</span><br><span class="line"> RpcContext.getContext().setAttachment(<span class="string">"trace_id"</span>, traceId);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> invoker.invoke(invocation);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p class="article-more-link">
<a href="/posts/9f95e5a1.html#more">
Read More</a>
</p>
</div>
<footer class="article-footer">
<a data-url="https://www.tidyko.com/posts/9f95e5a1.html" data-id="ckmn5b0xs000xlmqpvpk9ug3c" class="article-share-link">
分享</a>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Dubbo/">Dubbo</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/J2EE/">J2EE</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Java/">Java</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/SLF4J/">SLF4J</a></li></ul>
</footer>
</div>
</article>
<article id="post-Grafana ESDOC一对多变量" class="article" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/posts/4db18d9b.html" class="article-date">
<time class="post-time" datetime="2019-11-11T10:48:00.000Z" itemprop="datePublished">
<span class="post-month">11月</span><br/>
<span class="post-day">11</span>
</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/posts/4db18d9b.html">Grafana ESDOC一对多变量</a>
</h1>
<div>
<div class="article-category">
<a class="article-category-link" href="/categories/中间件/">中间件</a>,<a class="article-category-link" href="/categories/中间件/Grafana/">Grafana</a>
</div>
|
<div class="view-box">
<span id="/posts/4db18d9b.html" class="leancloud_visitors" data-flag-title="Grafana ESDOC一对多变量">
阅读次数 <span class="leancloud-visitors-count"></span>
</span>
</div>
|
<div class="view-box">
<span>字数 600</span>
</div>
|
<div class="view-box">
<span>时长 ≈ 2 分钟</span>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<h3 id="1-需求场景"><a href="#1-需求场景" class="headerlink" title="1.需求场景"></a>1.需求场景</h3><p>需要添加一个Grafana变量,让一条ES的Document在Grafana展示时,可以出现在不同的变量筛选结果上。</p>
<h3 id="2-需求效果"><a href="#2-需求效果" class="headerlink" title="2.需求效果"></a>2.需求效果</h3><p>新建的变量名为“功能类”,需求值为(ALL、查询类、办理类、故障类、通用域)<br>我ES索引里面,一条Doc通过变量筛选后,可以对应多个功能类。</p>
<p>A -> 查询类、故障类<br>B -> 查询类<br>C -> 查询类、故障类、通用域</p>
<p>这里如果我们使用<code>查询类</code>的变量值进行筛选,应该出来A、B、C三条记录,如果使用<code>故障类</code>进行筛选,那出来的记录应该是A、C。</p>
<h3 id="3-实现思路"><a href="#3-实现思路" class="headerlink" title="3.实现思路"></a>3.实现思路</h3><ol>
<li>在Doc上面加入新的Field,存储doc对应的功能类范围,例如上面的<code>查询类、故障类</code> 以及 <code>查询类、故障类、通用域</code>。</li>
<li>在Grafana上新建<code>Custom</code>类型的变量,手动写上四个变量值。这里变量不适合使用<code>Query</code>类型,因为如果使用<code>Query</code>只能查出来<code>查询类、故障类、通用域</code>这种我们保存在文档里面的原始数据,而我们展示是需要每个种类单独展示的。</li>
<li>修改<code>Grafana Panel</code>,在查询语句上面使用<code>模糊查询</code>,将变量与Field值进行匹配。
<p class="article-more-link">
<a href="/posts/4db18d9b.html#more">
Read More</a>
</p>
</div>
<footer class="article-footer">
<a data-url="https://www.tidyko.com/posts/4db18d9b.html" data-id="ckmn5b0z9002ulmqp1qyjklb2" class="article-share-link">
分享</a>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ELK/">ELK</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Grafana/">Grafana</a></li></ul>
</footer>
</div>
</article>
<article id="post-Dubbo 服务提供者部署在GBK服务器环境的乱码问题" class="article" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/posts/2b4e0834.html" class="article-date">
<time class="post-time" datetime="2019-11-07T08:33:00.000Z" itemprop="datePublished">
<span class="post-month">11月</span><br/>
<span class="post-day">07</span>
</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/posts/2b4e0834.html">Dubbo 服务提供者部署在GBK服务器环境的乱码问题</a>
</h1>
<div>
<div class="article-category">
<a class="article-category-link" href="/categories/编程语言/">编程语言</a>,<a class="article-category-link" href="/categories/编程语言/Java/">Java</a>
</div>
|
<div class="view-box">
<span id="/posts/2b4e0834.html" class="leancloud_visitors" data-flag-title="Dubbo 服务提供者部署在GBK服务器环境的乱码问题">
阅读次数 <span class="leancloud-visitors-count"></span>
</span>
</div>
|
<div class="view-box">
<span>字数 269</span>
</div>
|
<div class="view-box">
<span>时长 ≈ 1 分钟</span>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<h3 id="1-场景"><a href="#1-场景" class="headerlink" title="1.场景"></a>1.场景</h3><p>将服务部署在一台机器上,过后发现消费端在注册中心中获取服务时,<br>如果获取到该服务器上的服务进行请求,处理结果为乱码,而请求另外一台服务器的服务时,结果却是正常。</p>
<h3 id="2-排查"><a href="#2-排查" class="headerlink" title="2.排查"></a>2.排查</h3><p>经排查这台服务器上的服务器编码为GBK,而其他正常的服务器则为UTF-8</p>
<figure class="highlight shell"><table><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"><span class="meta">$</span><span class="bash"> locale</span></span><br><span class="line">LANG=zh_CN.GBK</span><br><span class="line">LC_CTYPE="zh_CN.GBK"</span><br><span class="line">LC_NUMERIC="zh_CN.GBK"</span><br><span class="line">LC_TIME="zh_CN.GBK"</span><br><span class="line">LC_COLLATE="zh_CN.GBK"</span><br><span class="line">LC_MONETARY="zh_CN.GBK"</span><br><span class="line">LC_MESSAGES="zh_CN.GBK"</span><br><span class="line">LC_PAPER="zh_CN.GBK"</span><br><span class="line">LC_NAME="zh_CN.GBK"</span><br><span class="line">LC_ADDRESS="zh_CN.GBK"</span><br><span class="line">LC_TELEPHONE="zh_CN.GBK"</span><br><span class="line">LC_MEASUREMENT="zh_CN.GBK"</span><br><span class="line">LC_IDENTIFICATION="zh_CN.GBK"</span><br><span class="line">LC_ALL=zh_CN.GBK</span><br></pre></td></tr></table></figure>
<h3 id="3-解决"><a href="#3-解决" class="headerlink" title="3.解决"></a>3.解决</h3><p>这时有两种解决方案:</p>
<ol>
<li>修改系统的全局服务器编码为UTF-8(不知道为何,在启动脚本使用临时环境变量的方式提前执行了 <code>export LANG=en_US.UTF-8</code> 却无法生效。)</li>
<li>在启动脚本里,对jvm启动参数进行调整,设置编码格式,添加以下参数重启即可。</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">-Dfile.encoding=UTF-8</span><br></pre></td></tr></table></figure>
</div>
<footer class="article-footer">
<a data-url="https://www.tidyko.com/posts/2b4e0834.html" data-id="ckmn5b0y4001blmqpvw7lwfiw" class="article-share-link">
分享</a>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Dubbo/">Dubbo</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Java/">Java</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/乱码/">乱码</a></li></ul>
</footer>
</div>
</article>
<article id="post-IDEA 利用Maven依赖图解决包冲突" class="article" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/posts/82922308.html" class="article-date">
<time class="post-time" datetime="2019-10-15T02:28:00.000Z" itemprop="datePublished">
<span class="post-month">10月</span><br/>
<span class="post-day">15</span>
</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/posts/82922308.html">IDEA 利用Maven依赖图解决包冲突</a>
</h1>
<div>
<div class="article-category">
<a class="article-category-link" href="/categories/开发调试工具/">开发调试工具</a>,<a class="article-category-link" href="/categories/开发调试工具/IDEA/">IDEA</a>
</div>
|
<div class="view-box">
<span id="/posts/82922308.html" class="leancloud_visitors" data-flag-title="IDEA 利用Maven依赖图解决包冲突">
阅读次数 <span class="leancloud-visitors-count"></span>
</span>
</div>
|
<div class="view-box">
<span>字数 635</span>
</div>
|
<div class="view-box">
<span>时长 ≈ 2 分钟</span>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p>当我们试图向Maven项目里添加新依赖时,经常会遇到新依赖包与旧依赖包产生冲突的问题,如下图所示:<br><img src="http://tidyko.oss-cn-hongkong.aliyuncs.com/blog/bct_1.png" alt=""><br>这里面,因为有两个包里面都包含完整路径为<code>org/slf4j/impl/StaticLoggerBinder.class</code>的类,所以导致系统不知道使用哪一个,从而启动失败,<br>所以,我们只需要将这两个包其中一个去除即可,现在让我们使用IDEA的一个小功能来完美解决这个包冲突问题吧。</p>
<p class="article-more-link">
<a href="/posts/82922308.html#more">
Read More</a>
</p>
</div>
<footer class="article-footer">
<a data-url="https://www.tidyko.com/posts/82922308.html" data-id="ckmn5b0zo003llmqp01mg7g4j" class="article-share-link">
分享</a>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/IDEA/">IDEA</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Maven/">Maven</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/依赖图/">依赖图</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/包冲突/">包冲突</a></li></ul>
</footer>
</div>
</article>
<article id="post-J2EE Spring @Resource注解的扫描顺序" class="article" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/posts/ff68fd05.html" class="article-date">
<time class="post-time" datetime="2019-10-14T02:11:00.000Z" itemprop="datePublished">
<span class="post-month">10月</span><br/>
<span class="post-day">14</span>
</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/posts/ff68fd05.html">J2EE Spring @Resource注解的扫描顺序</a>
</h1>
<div>
<div class="article-category">
<a class="article-category-link" href="/categories/编程语言/">编程语言</a>,<a class="article-category-link" href="/categories/编程语言/Java/">Java</a>
</div>
|
<div class="view-box">
<span id="/posts/ff68fd05.html" class="leancloud_visitors" data-flag-title="J2EE Spring @Resource注解的扫描顺序">
阅读次数 <span class="leancloud-visitors-count"></span>
</span>
</div>
|
<div class="view-box">
<span>字数 836</span>
</div>
|
<div class="view-box">
<span>时长 ≈ 3 分钟</span>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p>让我们先来看看两段代码:</p>
<p>一:<br><figure class="highlight java"><table><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"><span class="meta">@Service</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">FooService</span> </span>{}</span><br><span class="line"></span><br><span class="line"><span class="meta">@Service</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">BarService</span> </span>{}</span><br><span class="line"></span><br><span class="line"><span class="meta">@Controller</span></span><br><span class="line"><span class="meta">@RequestMapping</span>(value = <span class="string">"/foo"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">FooController</span> </span>{</span><br><span class="line"> <span class="meta">@Resource</span></span><br><span class="line"> <span class="keyword">private</span> FooService service;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="meta">@Controller</span></span><br><span class="line"><span class="meta">@RequestMapping</span>(value = <span class="string">"/bar"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">BarController</span> </span>{</span><br><span class="line"> <span class="meta">@Resource</span></span><br><span class="line"> <span class="keyword">private</span> BarService service;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></p>
<p class="article-more-link">
<a href="/posts/ff68fd05.html#more">
Read More</a>
</p>
</div>
<footer class="article-footer">
<a data-url="https://www.tidyko.com/posts/ff68fd05.html" data-id="ckmn5b10u0050lmqpqn661x21" class="article-share-link">
分享</a>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/J2EE/">J2EE</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Java/">Java</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Spring/">Spring</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/依赖注入/">依赖注入</a></li></ul>
</footer>
</div>
</article>