forked from xudailong/xudailong.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
973 lines (677 loc) · 55.8 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
<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
<meta charset="utf-8">
<title>七乘三十一</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="keywords" content="汪 , 汪 ,汪">
<meta name="description" content="快来看这只蠢狗">
<meta name="keywords" content="汪 , 汪 ,汪">
<meta property="og:type" content="website">
<meta property="og:title" content="七乘三十一">
<meta property="og:url" content="http://kouke0305.github.io/index.html">
<meta property="og:site_name" content="七乘三十一">
<meta property="og:description" content="快来看这只蠢狗">
<meta property="og:locale" content="en">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="七乘三十一">
<meta name="twitter:description" content="快来看这只蠢狗">
<link rel="alternate" href="/atom.xml" title="七乘三十一" type="application/atom+xml">
<link rel="icon" href="/images/default-avatar.jpg">
<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="/css/highlight.css">
</head>
</html>
<body>
<div id="fullpage" class="mobile-nav-right">
<div id="wrapper" title="背景图片来自网络">
<header id="header">
<div id="nav-toggle" class="nav-toggle"></div>
<div class="head-box global-width">
<nav class="nav-box nav-right">
<a class="nav-item" href="/" title
>首页</a>
<a class="nav-item" href="/archives" title
>归档</a>
<a class="nav-item" href="/2019/11/01/hello-world/" title
>嘿嘿</a>
</nav>
</div>
</header>
<div id="middlecontent" title class="global-width sidebar-right">
<section id="main">
<article id="post-nginx" class="article global-container article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2020/01/04/nginx/">nginx</a>
</h1>
</header>
<div class="article-meta">
<a href="/2020/01/04/nginx/" class="article-date">
<time datetime="2020-01-04T09:40:34.000Z" itemprop="datePublished">2020-01-04</time>
</a>
</div>
<div class="article-inner">
<div class="article-content article-content-cloud" itemprop="articleBody">
<h2 id="1-nginx是什么"><a href="#1-nginx是什么" class="headerlink" title="1.nginx是什么"></a>1.nginx是什么</h2><ul>
<li>Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器。</li>
<li>因它的稳定性、丰富的功能集、实例配置文件和低系统资源的消耗而闻名。</li>
<li>其特点是占有内存少,并发能力强。</li>
</ul>
<h2 id="2-正向代理"><a href="#2-正向代理" class="headerlink" title="2.正向代理"></a>2.正向代理</h2><p>正向代理类似一个跳板机,代理访问外部资源。<br><img src="/img/nginx/nginx1.jpg" alt="a"></p>
<ul>
<li>总结来说:正向代理是一个位于客户端和原始服务器之间的服务器,为了从原始服务器取得内容,客户端向代理发送一个请求,并指定目标(原始服务器),然后代理向原始服务器转交请求并将获得的内容返回给客户端。客户端必须要进行一些特殊的设置才能使用正向代理。</li>
</ul>
<h2 id="3-正向代理的用途"><a href="#3-正向代理的用途" class="headerlink" title="3.正向代理的用途"></a>3.正向代理的用途</h2><ul>
<li>vpn</li>
<li>做缓存,加速访问资源</li>
<li>对客户端访问授权,上网进行认证</li>
<li>代理可以记录用户的访问记录(上网行为管理),对外隐藏用户信息</li>
</ul>
<h2 id="4-反向代理"><a href="#4-反向代理" class="headerlink" title="4.反向代理"></a>4.反向代理</h2><p>反向代理(Reverse Proxy)实际运行方式是指以代理服务器来接受网络上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上的得到的结果返回给网络上请求连接的客户端,此时代理服务器对外就表现为一个服务器。<br><img src="/img/nginx/nginx2.jpg" alt="aa"></p>
<h2 id="5-反向代理的作用"><a href="#5-反向代理的作用" class="headerlink" title="5.反向代理的作用"></a>5.反向代理的作用</h2><ul>
<li>保证内网的安全,可以使用反向代理提供WAF功能,阻止web攻击。大型网站通常将反向代理作为公网访问地址,web服务器是内网。</li>
<li>负载均衡,通过反向代理服务器来优化网站的负载</li>
</ul>
<h2 id="6-为什么要使用代理服务器"><a href="#6-为什么要使用代理服务器" class="headerlink" title="6.为什么要使用代理服务器"></a>6.为什么要使用代理服务器</h2><ul>
<li><p>提高访问速度<br>由于目标主机返回的数据会存放在代理服务器的硬盘中,因此下一次客户再访问相同的站点数据时,会直接从代理服务器的硬盘中读取,起到了缓存的作用,尤其对于热门站点能明显提高请求速度。</p>
</li>
<li><p>防火墙作用<br>由于所有的客户机请求都必须通过代理服务器访问远程站点,因此可在代理服务器上设限,过滤某些不安全信息。</p>
</li>
<li><p>通过代理服务器访问不能访问的目标站点<br>互联网上有许多开发的代理服务器,客户机在访问受限时,可通过不受限的代理服务器访问目标站点,通俗说,我们使用的翻墙浏览器就是利用了代理服务器,虽然不能出国,但也可直接访问外网。</p>
</li>
</ul>
<h2 id="7-nginx代理配置文件"><a href="#7-nginx代理配置文件" class="headerlink" title="7.nginx代理配置文件"></a>7.nginx代理配置文件</h2><div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><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></pre></td><td class="code"><pre><span class="line">server {</span><br><span class="line"> listen 80;</span><br><span class="line"> location / {</span><br><span class="line"> proxy_pass http://10.92.1.137:8080; <span class="comment"># 应用服务器HTTP地址</span></span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></div>
<h2 id="8-nginx虚拟主机"><a href="#8-nginx虚拟主机" class="headerlink" title="8.nginx虚拟主机"></a>8.nginx虚拟主机</h2><p>在nginx上可以配置多个server,每个server即一个虚拟主机,当nginx接收到请求,获取该请求中的host请求头,将host值与多个server的server_name进行匹配,由匹配成功的那个server来处理请求,然后将请求转发到server中指定不同的服务器。不同的server可以指定不同的tomcat或其它服务器,由服务器来处理请求。当只有一个服务器,所有的请求转发到同一个端口;当有多个服务器时,这些服务器对应的监听不同的端口,则请求根据配置转发到指定的端口,虚拟主机的作用真正发挥。</p>
<h2 id="9-虚拟主机配置"><a href="#9-虚拟主机配置" class="headerlink" title="9.虚拟主机配置"></a>9.虚拟主机配置</h2><div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><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></pre></td><td class="code"><pre><span class="line">server {</span><br><span class="line"> listen 80;</span><br><span class="line"> server_name www.jnaw.com;</span><br><span class="line"> location / {</span><br><span class="line"> proxy_pass http://10.92.1.137:8080;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line">server {</span><br><span class="line"> listen 80;</span><br><span class="line"> server_name app.jnaw.com;</span><br><span class="line"> location / {</span><br><span class="line"> proxy_pass http://10.92.1.138:8080;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line">server {</span><br><span class="line"> listen 80;</span><br><span class="line"> server_name 7.7.9.138;</span><br><span class="line"> location / {</span><br><span class="line"> proxy_pass http://10.92.9.138:8080;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></div>
<h2 id="10-nginx负载均衡"><a href="#10-nginx负载均衡" class="headerlink" title="10.nginx负载均衡"></a>10.nginx负载均衡</h2><h3 id="优点"><a href="#优点" class="headerlink" title="优点"></a>优点</h3><ul>
<li>可以针对http应用做一些分流的策略,比如针对域名、目录结构,它的正则</li>
<li>规则比HAProxy更为强大和灵活</li>
<li>Nginx对网络稳定性的依赖非常小,理论上能ping通就就能进行负载功能</li>
<li>Nginx安装和配置比较简单,测试起来比较方便,它基本能把错误用日志打印出来</li>
<li>可以承担高负载压力且稳定,在硬件不差的情况下一般能支撑几万次的并发量</li>
<li>Nginx可以通过端口检测到服务器内部的故障,比如根据服务器处理网页返回的状态码、超时等等</li>
<li>Nginx不仅仅是一款优秀的负载均衡器/反向代理软件,它同时也是功能强大的Web应用服务器</li>
<li>Nginx现在作为Web反向加速缓存越来越成熟了,速度比传统的服务器更快</li>
<li>Nginx也可作为静态网页和图片服务器,这方面的性能也无对手</li>
</ul>
<h3 id="缺点"><a href="#缺点" class="headerlink" title="缺点"></a>缺点</h3><ul>
<li>Nginx仅能支持http、https和Email协议</li>
<li>对后端服务器的健康检查,只支持通过端口来检测,不支持通过url来检测</li>
<li>不支持Session的直接保持,但能通过ip_hash来解决</li>
</ul>
</div>
</div>
</article>
<article id="post-Linux常用命令" class="article global-container article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/26/Linux常用命令/">Linux常用命令</a>
</h1>
</header>
<div class="article-meta">
<a href="/2019/12/26/Linux常用命令/" class="article-date">
<time datetime="2019-12-26T12:55:17.000Z" itemprop="datePublished">2019-12-26</time>
</a>
</div>
<div class="article-inner">
<div class="article-content article-content-cloud" itemprop="articleBody">
<h2 id="1-gpassword命令"><a href="#1-gpassword命令" class="headerlink" title="1.gpassword命令"></a>1.gpassword命令</h2><p>功能:管理组<br>用法:</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo gpasswd [-a user][-d user][-A user,...][-M user,...][-r][-R] groupname</span><br></pre></td></tr></table></figure></div>
<p>参数</p>
<ul>
<li>-a:添加到用户组</li>
<li>-d:从组删除</li>
<li>-A:指定管理员</li>
<li>-M:指定组成员和-A的用法差不多</li>
<li>-r:删除密码</li>
<li>-R:限制用户登入组,只有组内的成员才可以用newgrp加入该组</li>
</ul>
<p>示例:<br>将nginx加入到root组内</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo gpasswd -a nginx root</span><br></pre></td></tr></table></figure></div>
<h2 id="2-mkdir命令"><a href="#2-mkdir命令" class="headerlink" title="2.mkdir命令"></a>2.mkdir命令</h2><p>功能:创建目录<br>用法:</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo mkdir [参数] 目录</span><br></pre></td></tr></table></figure></div>
<p>参数:</p>
<ul>
<li>-m=mode 为目录指定访问权限,与chmod相似</li>
<li>-p 如果目录已经存在,则不会有错误提示。若父目录不存在,将会创建父目录。该选项常用于创建级联目录</li>
<li>-v 为每个目录显示提示信息</li>
</ul>
<p>示例:<br>创建级联目录。同一目录下的子目录放在大括号内用逗号隔开</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo mkdir -p baklog{bin,lib,<span class="built_in">log</span>/{cep,dod,testlog}}</span><br></pre></td></tr></table></figure></div>
<h2 id="3-文件权限"><a href="#3-文件权限" class="headerlink" title="3.文件权限"></a>3.文件权限</h2><p>linux系统文件夹644、755、777权限设置详情,左至右,第一位数字代表文件所有者的权限,第二位:同用户组用户的权限,第三位:其他用户的权限</p>
<ul>
<li>读取权限:4 r 表示;</li>
<li>写入—:2 w 表示;</li>
<li>执行—:1 x 表示;</li>
</ul>
<p>通过4、2、1的组合得到以下几种权限:</p>
<ul>
<li>0 (没有权限)</li>
<li>4 读取权限</li>
<li>5 4+1 读取+执行</li>
<li>6 4+2 读取+写入</li>
<li>7 4+2+1 读取+写入+执行</li>
</ul>
<p>以755为例</p>
<ul>
<li>所有者有读取、写入、执行权限</li>
<li>同用户组有读取、执行权限,但没有写入权限</li>
<li>同上</li>
</ul>
<h2 id="4-chmod命令"><a href="#4-chmod命令" class="headerlink" title="4.chmod命令"></a>4.chmod命令</h2><p>功能:修改文件权限<br>用法</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo chmod [-cfvr] [--<span class="built_in">help</span>][--version] mode file ...</span><br></pre></td></tr></table></figure></div>
<ul>
<li>u 表示该文件的拥有者,g 表示与该文件的拥有者属于同一个群体(group)者,o 表示其他以外的人,a 表示这三者皆是。</li>
<li>+ 表示增加权限、- 表示取消权限、= 表示唯一设定权限。</li>
<li>r 表示可读取,w 表示可写入,x 表示可执行,X 表示只有当该文件是个子目录或者该文件已经被设定过为可执行。</li>
<li>-c : 若该文件权限确实已经更改,才显示其更改动作</li>
<li>-f : 若该文件权限无法被更改也不要显示错误讯息</li>
<li>-v : 显示权限变更的详细资料</li>
<li>-R : 对目前目录下的所有文件与子目录进行相同的权限变更(即以递回的方式逐个变更)</li>
<li>–help : 显示辅助说明</li>
<li>–version : 显示版本</li>
</ul>
<p>示例:<br>将文件file1.txt 设置为所有人可读取</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><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">sudo chmod ugo+r file1.txt</span><br><span class="line">或</span><br><span class="line">chmod a+r file1.txt</span><br></pre></td></tr></table></figure></div>
<p>此外chmod也可以用数字来表示权限</p>
<p>语法:</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod abc file</span><br></pre></td></tr></table></figure></div>
<p>其中a,b,c各为一个数字,分别表示User、Group、及Other的权限。 r=4,w=2,x=1</p>
<p>若要rwx属性则4+2+1=7;<br>若要rw-属性则4+2=6;<br>若要r-x属性则4+1=5。<br>以下两种写法,效果相同</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><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">chmod a=rwx file</span><br><span class="line">chmod 777 file</span><br></pre></td></tr></table></figure></div>
<h2 id="5-ln命令"><a href="#5-ln命令" class="headerlink" title="5.ln命令"></a>5.ln命令</h2><p>用法:</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo ln [参数][源文件或目录][目标文件或目录]</span><br></pre></td></tr></table></figure></div>
<p>参数:</p>
<ul>
<li>-b 删除,覆盖以前建立的链接</li>
<li>-d 允许超级用户制作目录的硬链接</li>
<li>-f 强制执行</li>
<li>-i 交互模式,文件存在则提示用户是否覆盖</li>
<li>-n 把符号链接视为一般目录</li>
<li>-s 软链接(符号链接)</li>
<li>-v 显示详细的处理过程</li>
</ul>
<p>示例:</p>
<p>创建软链接</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo ln -s /srv/http/uploaded /srv/docker/uploaded</span><br></pre></td></tr></table></figure></div>
</div>
</div>
</article>
<article id="post-服务器安装" class="article global-container article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/26/服务器安装/">服务器安装</a>
</h1>
</header>
<div class="article-meta">
<a href="/2019/12/26/服务器安装/" class="article-date">
<time datetime="2019-12-26T03:54:17.000Z" itemprop="datePublished">2019-12-26</time>
</a>
</div>
<div class="article-inner">
<div class="article-content article-content-cloud" itemprop="articleBody">
<h2 id="1-系统更新"><a href="#1-系统更新" class="headerlink" title="1.系统更新"></a>1.系统更新</h2><ul>
<li>更新系统,升级系统包</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo yum update -y</span><br></pre></td></tr></table></figure></div>
<h2 id="2-用户"><a href="#2-用户" class="headerlink" title="2.用户"></a>2.用户</h2><ul>
<li>创建用户</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">adduser user_xxx</span><br></pre></td></tr></table></figure></div>
<ul>
<li>删除用户,及用户目录</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">userdel -r user_xxx</span><br></pre></td></tr></table></figure></div>
<ul>
<li>设置密码</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">passwd user_xxx</span><br></pre></td></tr></table></figure></div>
<ul>
<li>修改配置文件,添加sudo权限</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo visudo</span><br></pre></td></tr></table></figure></div>
<p>找到这一行 root ALL=(ALL) ALL,复制一行,然后将前面的用户名替换成需要修改的用户名,最后使用 Esc键 + :wq 保存并退出</p>
<h2 id="3-安装软件"><a href="#3-安装软件" class="headerlink" title="3.安装软件"></a>3.安装软件</h2><h3 id="3-1-docker"><a href="#3-1-docker" class="headerlink" title="3.1 docker"></a>3.1 docker</h3><ul>
<li>安装所需的软件包 yum-utils提供了yum-config-manager 效用,并device-mapper-persistent-data和lvm2由需要 devicemapper存储驱动程序。(楞恶心)</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo yum install -y yum-utils device-mapper-persistent-data lvm2</span><br></pre></td></tr></table></figure></div>
<ul>
<li>设置稳定版本库</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><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">sudo yum-config-manager \</span><br><span class="line"> --add-repo \</span><br><span class="line"> https://download.docker.com/linux/centos/docker-ce.repo</span><br></pre></td></tr></table></figure></div>
<ul>
<li>跟新yum包索引</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo yum makecache fast</span><br></pre></td></tr></table></figure></div>
<ul>
<li>安装docker-ce</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo yum install -y docker-ce</span><br></pre></td></tr></table></figure></div>
<ul>
<li>启动docker</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo systemctl start docker</span><br></pre></td></tr></table></figure></div>
<ul>
<li>查看当前安装版本,验证安装是否成功</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><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></table></figure></div>
<ul>
<li>设置开机自启,重新启动服务</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><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">sudo systemctl <span class="built_in">enable</span> docker</span><br><span class="line"></span><br><span class="line">sudo systemctl restart docker</span><br></pre></td></tr></table></figure></div>
<h3 id="3-2-安装-git-zsh-nginx-nodejs-jdk-p7zip-htop"><a href="#3-2-安装-git-zsh-nginx-nodejs-jdk-p7zip-htop" class="headerlink" title="3.2 安装 git zsh nginx nodejs jdk p7zip htop"></a>3.2 安装 git zsh nginx nodejs jdk p7zip htop</h3><div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo yun install -y git zsh nginx nodejs java-1.8.0-openjdk-devel p7zip htop</span><br></pre></td></tr></table></figure></div>
<h3 id="3-3-docker-compose"><a href="#3-3-docker-compose" class="headerlink" title="3.3 docker-compose"></a>3.3 docker-compose</h3><div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo yum -y install docker-compose</span><br></pre></td></tr></table></figure></div>
<h3 id="3-4-Gradle"><a href="#3-4-Gradle" class="headerlink" title="3.4 Gradle"></a>3.4 Gradle</h3><ul>
<li>下载安装包</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget https://downloads.gradle.org/distributions/gradle-5.4.1-all.zip</span><br></pre></td></tr></table></figure></div>
<ul>
<li>解压缩到目录 /usr/software/</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><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">sudo mkdir /usr/software/</span><br><span class="line"><span class="built_in">cd</span> /usr/softwware/</span><br><span class="line">sudo 7za x ~/gradle-5.4.1-all.zip</span><br></pre></td></tr></table></figure></div>
<ul>
<li>打开环境变量</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo vim /etc/profile</span><br></pre></td></tr></table></figure></div>
<p>将下面代码复制到底部</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># gradle settings start 2019-05-27</span></span><br><span class="line"></span><br><span class="line">GRADLE_HOME=/usr/software/gradle-5.4.1</span><br><span class="line"><span class="built_in">export</span> PATH=<span class="variable">${GRADLE_HOME}</span>/bin:<span class="variable">${PATH}</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># gradle settings end - 2019-05-27</span></span><br></pre></td></tr></table></figure></div>
<ul>
<li>重载这个文件</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">source</span> /etc/profile</span><br></pre></td></tr></table></figure></div>
<ul>
<li>检查安装</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gradle -version</span><br></pre></td></tr></table></figure></div>
<h3 id="3-5-安装gulp"><a href="#3-5-安装gulp" class="headerlink" title="3.5 安装gulp"></a>3.5 安装gulp</h3><div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo npm i -g gulp</span><br></pre></td></tr></table></figure></div>
<h3 id="3-6-注意"><a href="#3-6-注意" class="headerlink" title="3.6 注意"></a>3.6 注意</h3><p>-新服务器要打开80端口</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><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></pre></td><td class="code"><pre><span class="line"><span class="comment">#查看80端口是否开放</span></span><br><span class="line">firewall-cmd --query-port=80/tcp</span><br><span class="line"></span><br><span class="line"><span class="comment">#打开80</span></span><br><span class="line">firewall-cmd --add-port=80/tcp</span><br><span class="line">firewall-cmd --zone=public --add-port=80/tcp --permanent</span><br></pre></td></tr></table></figure></div>
</div>
</div>
</article>
<article id="post-git仓库迁移" class="article global-container article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/12/26/git仓库迁移/">git仓库迁移</a>
</h1>
</header>
<div class="article-meta">
<a href="/2019/12/26/git仓库迁移/" class="article-date">
<time datetime="2019-12-26T03:53:05.000Z" itemprop="datePublished">2019-12-26</time>
</a>
</div>
<div class="article-inner">
<div class="article-content article-content-cloud" itemprop="articleBody">
<h2 id="码云-Git-仓库迁移到-git-jnaw-top-服务器"><a href="#码云-Git-仓库迁移到-git-jnaw-top-服务器" class="headerlink" title="码云 Git 仓库迁移到 git.jnaw.top 服务器"></a>码云 Git 仓库迁移到 git.jnaw.top 服务器</h2><h2 id="公共账户"><a href="#公共账户" class="headerlink" title="公共账户"></a>公共账户</h2><ul>
<li>账户:git</li>
<li>密码:git</li>
</ul>
<h2 id="免密登录"><a href="#免密登录" class="headerlink" title="免密登录"></a>免密登录</h2><ul>
<li>先把自己电脑的公钥添加到 git 账户中</li>
<li><code>~/.ssh/authorized_keys</code> 【追加到此文件中】</li>
</ul>
<h2 id="以-ncp-项目为例迁移"><a href="#以-ncp-项目为例迁移" class="headerlink" title="以 ncp 项目为例迁移"></a>以 ncp 项目为例迁移</h2><ul>
<li>先在新的git服务器上创建一个空的项目ncp</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><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></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> ~/cwbu/</span><br><span class="line">mkdir ncp</span><br><span class="line"><span class="built_in">cd</span> ncp</span><br><span class="line">git init --bare</span><br></pre></td></tr></table></figure></div>
<h2 id="克隆旧的仓库,推送到新的服务器"><a href="#克隆旧的仓库,推送到新的服务器" class="headerlink" title="克隆旧的仓库,推送到新的服务器"></a>克隆旧的仓库,推送到新的服务器</h2><ul>
<li>在本地 Git Bash 中执行命令</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> --bare [email protected]:allview-cwbu/ncp.git</span><br></pre></td></tr></table></figure></div>
<ul>
<li><code>[email protected]:allview-cwbu/ncp.git</code> 为原仓库地址</li>
<li>会生成一个文件夹:ncp.git</li>
<li>进入文件夹中</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> ncp.git</span><br></pre></td></tr></table></figure></div>
<ul>
<li>推送到新的服务器</li>
</ul>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="SH"><figure class="iseeu highlight /sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push --mirror [email protected]:cwbu/ncp</span><br></pre></td></tr></table></figure></div>
<ul>
<li><code>[email protected]:cwbu/ncp</code> 为新的仓库地址</li>
</ul>
</div>
</div>
</article>
<article id="post-集群dockerswarm-cluster" class="article global-container article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/11/06/集群dockerswarm-cluster/">集群dockerswarm/cluster</a>
</h1>
</header>
<div class="article-meta">
<a href="/2019/11/06/集群dockerswarm-cluster/" class="article-date">
<time datetime="2019-11-06T12:09:54.000Z" itemprop="datePublished">2019-11-06</time>
</a>
</div>
<div class="article-inner">
<div class="article-content article-content-cloud" itemprop="articleBody">
<p><img src="/img/cluster/note.jpg" alt></p>
</div>
</div>
</article>
<article id="post-G1学习" class="article global-container article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/11/01/G1学习/">G1学习</a>
</h1>
</header>
<div class="article-meta">
<a href="/2019/11/01/G1学习/" class="article-date">
<time datetime="2019-11-01T07:53:07.000Z" itemprop="datePublished">2019-11-01</time>
</a>
</div>
<div class="article-inner">
<div class="article-content article-content-cloud" itemprop="articleBody">
</div>
</div>
</article>
<article id="post-cms详解" class="article global-container article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/11/01/cms详解/">CMS详解</a>
</h1>
</header>
<div class="article-meta">
<a href="/2019/11/01/cms详解/" class="article-date">
<time datetime="2019-11-01T07:43:34.000Z" itemprop="datePublished">2019-11-01</time>
</a>
</div>
<div class="article-inner">
<div class="article-content article-content-cloud" itemprop="articleBody">
<p>#CMS垃圾收集器</p>
<p>from :<a href="http://www.mashibing.com" target="_blank" rel="noopener">www.mashibing.com</a></p>
<h2 id="目标:"><a href="#目标:" class="headerlink" title="目标:"></a>目标:</h2><p>获取最短的STW时间<br>为什么要STW? 用户线程可能会修改对象的引用<br><a href="/img/jvm-cms/CMS.PDF">sad</a></p>
<h2 id="jvm内存模型"><a href="#jvm内存模型" class="headerlink" title="jvm内存模型"></a>jvm内存模型</h2><p><img src="/img/jvm-cms/jvm.jpg" alt></p>
<h2 id="常见的garbage-collection"><a href="#常见的garbage-collection" class="headerlink" title="常见的garbage collection"></a>常见的garbage collection</h2><p><img src="/img/jvm-cms/garbagecollection.png" alt></p>
<h3 id="各个GC之间的对比"><a href="#各个GC之间的对比" class="headerlink" title="各个GC之间的对比"></a>各个GC之间的对比</h3><p><img src="/img/jvm-cms/gc1.png" alt><br><img src="/img/jvm-cms/gc2.png" alt></p>
<p><img src="/img/jvm-cms/cms.png" alt><br><img src="/img/jvm-cms/cmsex.png" alt><br><img src="/img/jvm-cms/optimize1.png" alt><br><img src="/img/jvm-cms/optimize2.png" alt><br><img src="/img/jvm-cms/optimize3.png" alt></p>
</div>
</div>
</article>
<article id="post-hello-world" class="article global-container article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/11/01/hello-world/">helloworld</a>
</h1>
</header>
<div class="article-meta">
<a href="/2019/11/01/hello-world/" class="article-date">
<time datetime="2019-11-01T02:31:41.000Z" itemprop="datePublished">2019-11-01</time>
</a>
</div>
<div class="article-inner">
<div class="article-content article-content-cloud" itemprop="articleBody">
<p><img src="/img/helloworld/mama.png" alt><br><img src="/img/helloworld/1.png" alt><br><img src="/img/helloworld/2.png" alt><br><img src="/img/helloworld/3.png" alt></p>
</div>
</div>
</article>
<article id="post-jenkins" class="article global-container article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/11/01/jenkins/">jenkins 搭建</a>
</h1>
</header>
<div class="article-meta">
<a href="/2019/11/01/jenkins/" class="article-date">
<time datetime="2019-11-01T02:31:41.000Z" itemprop="datePublished">2019-11-01</time>
</a>
</div>
<div class="article-inner">
<div class="article-content article-content-cloud" itemprop="articleBody">
<h1 id="jenkins-搭建"><a href="#jenkins-搭建" class="headerlink" title="jenkins 搭建"></a>jenkins 搭建</h1><p><img src="/img/jenkins/jenkins.png" alt></p>
<h1 id="Problem"><a href="#Problem" class="headerlink" title="Problem:"></a>Problem:</h1><ol>
<li>centOS服务器上部署遇到插件版本缺失的问题,可以去下面网址下载再手动上传插件 <a href="http://updates.jenkins-ci.org/download/plugins/" target="_blank" rel="noopener">http://updates.jenkins-ci.org/download/plugins/</a></li>
<li>配置gradle 构建的时候,在高级中可以设置配置的路径<br>${workspace}/backstage_management/backend</li>
</ol>
</div>
</div>
</article>
<article id="post-GC and Tuning" class="article global-container article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/10/29/GC and Tuning/">jvm调优实践</a>
</h1>
</header>
<div class="article-meta">
<a href="/2019/10/29/GC and Tuning/" class="article-date">
<time datetime="2019-10-29T07:52:41.407Z" itemprop="datePublished">2019-10-29</time>
</a>
</div>
<div class="article-inner">
<div class="article-content article-content-cloud" itemprop="articleBody">
<h1 id="GC和GC-Tuning"><a href="#GC和GC-Tuning" class="headerlink" title="GC和GC Tuning"></a>GC和GC Tuning</h1><h3 id="GC的基础知识"><a href="#GC的基础知识" class="headerlink" title="GC的基础知识"></a>GC的基础知识</h3><p><img src="/img/jvmtuning/jvm1.png" alt><br><img src="/img/jvmtuning/jvm2.png" alt></p>
<p>Jdk 11 zgc 10ms (垃圾收集器的停顿时间)<br>Azul zing 1ms 收费 c4</p>
<p>• -Xms:初始堆大小<br>• -Xmx:最大堆大小<br>• xmn新生代大小</p>
<h4 id="1-什么是垃圾"><a href="#1-什么是垃圾" class="headerlink" title="1.什么是垃圾"></a>1.什么是垃圾</h4><p>· C语言申请内存:malloc free<br>·<br>· C++: new delete<br>·<br>· c/c++需要手动回收内存<br>·<br>· Java: new ?<br>·<br>· 自动内存回收,编程上简单,系统不容易出错,手动释放内存,容易出两种类型的问题:<br>·<br>· 1. 忘记回收<br>· 2. 多次回收</p>
<p>没有任何引用指向的一个对象或者循环引用多个对象 —– 垃圾</p>
<h4 id="2-如何定位垃圾"><a href="#2-如何定位垃圾" class="headerlink" title="2.如何定位垃圾"></a>2.如何定位垃圾</h4><ol>
<li>引用计数 reference count (不能解决循环引用的问题)</li>
<li>根可达算法 通过根对象能够链接到的 <img src="/img/jvmtuning/GCRoots.png" alt></li>
</ol>
<h4 id="3-常见的垃圾回收算法"><a href="#3-常见的垃圾回收算法" class="headerlink" title="3.常见的垃圾回收算法"></a>3.常见的垃圾回收算法</h4><ol>
<li>标记清除 Mark Sweep - 两边扫描,效率偏低,位置不连续 产生内存碎片化 适用存活对象较多的情况<img src="/img/jvmtuning/MSALG.png" alt></li>
<li>拷贝算法 Copy - 没有碎片,浪费空间 <img src="/img/jvmtuning/copyalg.png" alt></li>
<li>标记压缩 Mark Compact- 没有碎片,效率偏低(两边扫描,指针需要调整)<img src="/img/jvmtuning/MCALG.png" alt></li>
</ol>
<h4 id="4-JVM内存分代模型(用于分代垃圾回收算法)"><a href="#4-JVM内存分代模型(用于分代垃圾回收算法)" class="headerlink" title="4.JVM内存分代模型(用于分代垃圾回收算法)"></a>4.JVM内存分代模型(用于分代垃圾回收算法)</h4><p><img src="/img/jvmtuning/HEAPS.png" alt><br><img src="/img/jvmtuning/objectnew-dead.png" alt></p>
<ol>
<li>部分垃圾回收器使用的模型</li>
<li>新生代 + 老年代 + 永久代(1.7)/ 元数据区(1.8) Metaspace<ol>
<li>永久代 元数据 - Class</li>
<li>永久代必须指定大小限制 ,元数据可以设置,也可以不设置,无上限(受限于物理内存)</li>
<li>字符串常量 1.7 - 永久代,1.8 - 堆</li>
<li>MethodArea逻辑概念 - 永久代、元数据</li>
</ol>
</li>
<li>新生代 = Eden + 2个suvivor区 <ol>
<li>YGC回收之后,大多数的对象会被回收,活着的进入s0</li>
<li>再次YGC,活着的对象eden + s0 -> s1</li>
<li>再次YGC,eden + s1 -> s0</li>
<li>年龄足够 -> 老年代 (15 CMS 6)</li>
<li>s区装不下 -> 老年代</li>
</ol>
</li>
<li>老年代<ol>
<li>顽固分子</li>
<li>老年代满了FGC Full GC</li>
</ol>
</li>
<li>GC Tuning (Generation)<ol>
<li>尽量减少FGC</li>
<li>MinorGC = YGC</li>
<li>MajorGC = FGC</li>
</ol>
</li>
</ol>
<h4 id="5-常见的垃圾回收器-(所有的都会产生stw)"><a href="#5-常见的垃圾回收器-(所有的都会产生stw)" class="headerlink" title="5.常见的垃圾回收器 (所有的都会产生stw)"></a>5.常见的垃圾回收器 (所有的都会产生stw)</h4><p><img src="/img/jvmtuning/GC.png" alt></p>
<ol>
<li>Serial 年轻代 串行回收 单线程 会产生STW ,找到一个safe point (安全点)执行gc</li>
<li>Parallel Scavenge 年轻代 并行回收 有STW 吞吐量优先 </li>
<li>ParNew 年轻代 为了和配合CMS的并行回收 响应时间优先</li>
<li>SerialOld 单线程</li>
<li>ParallelOld</li>
<li>ConcurrentMarkSweep 老年代 并发的, 垃圾回收和应用程序同时运行,降低STW的时间(200ms) <img src="/img/jvmtuning/CMS.png" alt></li>
<li>G1(10ms)</li>
<li>ZGC (1ms) PK C++</li>
<li>Shenandoah</li>
<li>Eplison</li>
</ol>
<p>1.8默认的垃圾回收:PS + ParallelOld<br><img src="/img/jvmtuning/PN-PS.png" alt></p>
<h4 id="6-JVM调优第一步,了解生产环境下的垃圾回收器组合"><a href="#6-JVM调优第一步,了解生产环境下的垃圾回收器组合" class="headerlink" title="6.JVM调优第一步,了解生产环境下的垃圾回收器组合"></a>6.JVM调优第一步,了解生产环境下的垃圾回收器组合</h4><ul>
<li><p>JVM的命令行参数参考:<a href="https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html" target="_blank" rel="noopener">https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html</a></p>
</li>
<li><p>HotSpot参数分类<br> java -X</p>
<ol>
<li><p>标准: - 开头,所有的HotSpot都支持</p>
</li>
<li><p>非标准:-X 开头,特定版本HotSpot支持特定命令</p>
</li>
<li><p>不稳定:-XX 开头,下个版本可能取消</p>
</li>
</ol>
</li>
<li><p>测试代码</p>
<div class="highlight-box"autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true"data-rel="PLAIN"><figure class="iseeu highlight /plain"><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></pre></td><td class="code"><pre><span class="line">sout(hellogc)</span><br><span class="line">list </span><br><span class="line">for(){</span><br><span class="line"> byte [] = new byte[1024*1024]</span><br><span class="line"> list.add</span><br><span class="line">}</span><br></pre></td></tr></table></figure></div>
<ol>
<li><p>java -XX:+PrintCommandLineFlags HelloGC</p>
</li>
<li><p>java -Xmn 10M -Xms 10M -Xmx 40M -XX:+PrintCommandLineFlags HelloGC<br>java -XX:PrintGCDetails -Xms 10M Xmx 10M</p>
</li>
<li><p>-XX:+PrintFlagsFinal 最终参数值</p>
</li>
<li><p>-XX:+PrintFlagsInitial 默认参数值<br>java -XX:+PrintFlagsFinal | wc -l 统计结果有多少行</p>
</li>
<li><p>java -XX:+UseConcMarkSweepGC [文件名] 指定GC</p>
</li>
<li><p>java -XX:+PrintFlagsFinal -version | grep SerialGC 在查询得结果中搜索 ‘SerialGC’</p>
</li>
</ol>
</li>
</ul>
<ul>
<li><p>常见得垃圾回收器组合(1,8)</p>
<ol>
<li><p>-XX:+UseSerialGC = Serial New(DefNew) +Serial Old</p>
</li>
<li><p>-XX:UseParNewGC = ParNew + SerialOld<br>这个组合已经很少用,(在某些版本已经废弃)</p>
</li>
<li><p>UseConc<font color="red">(urrent)</font>MarkSweepGC = ParNew + CMS + SerialOld<br>老年代用标记清除长时间产生大量碎片化,会触发一次SerialOld得FGC,如果内存特别大得话会很慢.<br>使用CMS一定要避免频繁得FGC</p>
</li>
<li><p>UseParallelGC = Parallel Scavenge + Parallel Old <font color="red">(1.8默认)</font><br>[PS+SerialOld]</p>
</li>
<li><p>UseParallelOldGC = Parallel Scavenge + Parallel Old</p>
</li>
<li><p>UseG1GC</p>
</li>
</ol>
</li>
</ul>
<h4 id="7-调优-从规划开始"><a href="#7-调优-从规划开始" class="headerlink" title="7.调优 从规划开始"></a>7.调优 从规划开始</h4><p><img src="/img/jvmtuning/example1.png" alt><br>一台机器也可以干这个事,把eden区设大 ,慢慢处理,只要不触发ygc就ok,之不过这样的风险比较大</p>
<ul>
<li><p>调优,从业务场景开始,没有业务场景得调优是耍流氓</p>
</li>
<li><p>无监控,不调优</p>
</li>
<li><p>步骤:</p>
<ol>
<li>熟悉业务场景(没有最好的垃圾回收器,只有最合适的)<ol>
<li>响应时间、停顿时间</li>
<li>吞吐量 = 用户时间/用户时间+GC时间</li>
</ol>
</li>
<li>选择回收器组合</li>
<li>计算内存需求</li>
<li>设定年代大小,升级年龄</li>
<li>设定日志参数<br> java -Xloggc:/root/gc-%t.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLofFileSize=20M -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCCsuse (jdk9(包含)之后不再好用, 去除了UseGCLogFileRotation这个参数)<br> 1.9开始参考下文<br>java -Xlog:gc:file=gctrace.txt<font color="red"><strong>::</strong></font> filecount=5,filesize=1M<br> <a href="https://docs.oracle.com/javase/10/tools/java.htm#JSWOR-GUID-BE93ABDC-999C-4CB5-A88B-1994AAAC74D5" target="_blank" rel="noopener">https://docs.oracle.com/javase/10/tools/java.htm#JSWOR-GUID-BE93ABDC-999C-4CB5-A88B-1994AAAC74D5</a></li>
<li>观察日志情况<br>java -XX:PrintGCDetails -Xms 10M Xmx 10M<br><img src="/img/jvmtuning/logsdetail.png" alt><br><img src="/img/jvmtuning/logs2.png" alt></li>
</ol>
<p><img src="/img/jvmtuning/loggc.png" alt></p>
<p> 小问题:Linux下使用的垃圾回收器的版本看不出来<br> 1.8.0_181 看不出来 copy + mark compact<br> 1.8.0_222 默认 ps + po</p>
<p> 调优 跟使用的jdk版本有巨大的关系</p>
</li>
</ul>
<h4 id="8-实战操作"><a href="#8-实战操作" class="headerlink" title="8.实战操作"></a>8.实战操作</h4><ol>
<li>top 命令观察问题,看那个进程占用cpu和memory居高不下</li>
<li>jps 定位具体java进程</li>
<li>动态观察<br>jmap -histo pid 查看这个进程中对象占用内存情况<br>jstat -gc<br>Arthas 阿里分析工具<br>jmx<br>阅读gc日志发现频繁jc</li>
<li>导出dump文件<br>java -Xms 20M -Xmx 20M -XX:+HeapDumpOnOutOfMemoryError .java (死了以后会导出文件)<br>jmap -dumpL:format=b,file =aaa.dump pid 慎用 ,内存已经很大的情况下再执行这个可能会导致宕机</li>
<li>使用MAT/jhat分析文件 jhat aaa.dump <h3 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h3></li>
</ol>
<ol>
<li><a href="https://blogs.oracle.com/jonthecollector/our-collectors" target="_blank" rel="noopener">https://blogs.oracle.com/jonthecollector/our-collector</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html" target="_blank" rel="noopener">https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html</a></li>
<li><a href="http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp" target="_blank" rel="noopener">http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp</a></li>
</ol>
<h3 id="习题"><a href="#习题" class="headerlink" title="习题"></a>习题</h3><p><img src="/img/jvmtuning/task1.png" alt><br><img src="/img/jvmtuning/task2.png" alt></p>
</div>
</div>
</article>
<nav id="page-nav">
<span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><a class="extend next" rel="next" href="/page/2/">Next »</a>
</nav>
</section>
<aside id="sidebar">
<div class="widget-box">
<div class="avatar-box">
<img class="avatar" src="/images/default-avatar.jpg" title="图片来自网络"></img>
<h3 class="avatar-name">
ROCK CODER
</h3>
<p class="avatar-slogan">
走的时候没有带走美猴王的画像
</p>
</div>
</div>
<div class="widget-box">
<h3 class="widget-title">Archives</h3>
<div class="widget">
<ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/01/">January 2020</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/12/">December 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">November 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">October 2019</a></li></ul>
</div>
</div>
<div class="widget-box">
<h3 class="widget-title">Recent Posts</h3>
<div class="widget">
<ul>
<li>
<a href="/2020/01/04/nginx/">nginx</a>
</li>
<li>
<a href="/2019/12/26/Linux常用命令/">Linux常用命令</a>
</li>
<li>
<a href="/2019/12/26/服务器安装/">服务器安装</a>
</li>
<li>
<a href="/2019/12/26/git仓库迁移/">git仓库迁移</a>
</li>
<li>
<a href="/2019/11/06/集群dockerswarm-cluster/">集群dockerswarm/cluster</a>
</li>
</ul>
</div>
</div>
<div class="widget-box">
<h3 class="widget-title">友链</h3>
<div class="widget">
<a style="display: block;" href="/2019/11/01/hello-world/" title target='_blank'
>一起摇滚吗</a>
</div>
</div>
</aside>
</div>
<footer id="footer">
<div class="foot-box global-width">
© 2020 Gog
Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
| 主题 <a href="https://github.com/yiluyanxia/hexo-theme-antiquity">antiquity</a>
<br>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span id="busuanzi_container_site_pv">不蒜子告之 阁下是第<span id="busuanzi_value_site_pv"></span>个访客</span>
</div>
</footer>
<script src="https://code.jquery.com/jquery-2.0.3.min.js"></script>
<script>
if (!window.jQuery) {
var script = document.createElement('script');
script.src = "/js/jquery-2.0.3.min.js";
document.body.write(script);
}
</script>
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
<script src="/fancybox/jquery.fancybox.pack.js"></script>
<script src="/js/script.js"></script>
</div>
<nav id="mobile-nav" class="mobile-nav-box">
<div class="mobile-nav-img mobile-nav-top"></div>
<a href="/" class="mobile-nav-link">首页</a>
<a href="/archives" class="mobile-nav-link">归档</a>
<a href="/2019/11/01/hello-world/" class="mobile-nav-link">嘿嘿</a>
<div class="mobile-nav-img mobile-nav-bottom"></div>
</nav>
</div>
</body>
</html>