-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
449 lines (219 loc) · 178 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>程序员七平</title>
<icon>https://www.gravatar.com/avatar/36bf0b263c9f9fbd67bf7dac97a6ae64</icon>
<subtitle>日拱一卒</subtitle>
<link href="https://lixiaw.github.io/atom.xml" rel="self"/>
<link href="https://lixiaw.github.io/"/>
<updated>2024-12-15T13:08:08.118Z</updated>
<id>https://lixiaw.github.io/</id>
<author>
<name>程序员七平</name>
<email>[email protected]</email>
</author>
<generator uri="https://hexo.io/">Hexo</generator>
<entry>
<title>七平与写作</title>
<link href="https://lixiaw.github.io/posts/58040.html"/>
<id>https://lixiaw.github.io/posts/58040.html</id>
<published>2024-12-15T13:07:40.000Z</published>
<updated>2024-12-15T13:08:08.118Z</updated>
<category term="个人成长" scheme="https://lixiaw.github.io/categories/%E4%B8%AA%E4%BA%BA%E6%88%90%E9%95%BF/"/>
<category term="探索" scheme="https://lixiaw.github.io/tags/%E6%8E%A2%E7%B4%A2/"/>
</entry>
<entry>
<title>七平与编程</title>
<link href="https://lixiaw.github.io/posts/36828.html"/>
<id>https://lixiaw.github.io/posts/36828.html</id>
<published>2024-12-15T13:07:40.000Z</published>
<updated>2024-12-15T13:07:56.770Z</updated>
<content type="html"><![CDATA[<h2 id="写在前面"><a href="#写在前面" class="headerlink" title="写在前面"></a>写在前面</h2>]]></content>
<summary type="html"><h2 id="写在前面"><a href="#写在前面" class="headerlink" title="写在前面"></a>写在前面</h2></summary>
<category term="个人成长" scheme="https://lixiaw.github.io/categories/%E4%B8%AA%E4%BA%BA%E6%88%90%E9%95%BF/"/>
<category term="探索" scheme="https://lixiaw.github.io/tags/%E6%8E%A2%E7%B4%A2/"/>
</entry>
<entry>
<title>国产AI编程助手_豆包MarsCode使用教程</title>
<link href="https://lixiaw.github.io/posts/58484.html"/>
<id>https://lixiaw.github.io/posts/58484.html</id>
<published>2024-12-15T04:33:40.000Z</published>
<updated>2024-12-15T13:09:00.919Z</updated>
<content type="html"><![CDATA[<h2 id="写在前面"><a href="#写在前面" class="headerlink" title="写在前面"></a>写在前面</h2><p>大家好,我是程序员七平。<br>这篇文章主要介绍豆包旗下的一款编程助手<code>MarsCode</code>,方便大家对于这款插件有初步的了解。</p><p>本文主要按照以下目录进行介绍和演示:</p><ul><li><p>1、豆包MarsCode是什么?</p></li><li><p>2、在Idea中使用:</p><ul><li>① 代码补全、② 生成单元测试、③ 解释代码、④ 错误修复、⑤ AI问答</li></ul></li><li><p>3、在VsCode中使用:</p><ul><li>① 代码补全、② 生成单元测试、③ 解释代码、④ 错误修复、⑤ AI问答</li></ul></li><li><p>4、豆包在线编辑器 <code>MarsCode IDE</code> 初体验</p></li></ul><h2 id="1、豆包MarsCode是什么?"><a href="#1、豆包MarsCode是什么?" class="headerlink" title="1、豆包MarsCode是什么?"></a>1、豆包MarsCode是什么?</h2><blockquote><p>豆包MarsCode是豆包旗下的编程助手,能够提供<strong>智能补全</strong>、<strong>智能预测</strong>、<strong>智能问答</strong>等能力。</p></blockquote><p>MarsCode的功能简要如下,后面我会逐项进行操作演示:</p><p><strong>① 代码补全</strong>、<strong>② 生成单元测试</strong>、<strong>③ 解释代码</strong> 、<strong>④ 错误修复</strong>、<strong>⑤ AI问答</strong></p><ul><li>官网地址:<a href="https://www.marscode.cn/home">https://www.marscode.cn/home</a>;</li></ul><h2 id="2、豆包MarsCode怎么用?"><a href="#2、豆包MarsCode怎么用?" class="headerlink" title="2、豆包MarsCode怎么用?"></a>2、豆包MarsCode怎么用?</h2><p>从官网的介绍看到,MarsCode支持超过100种语言,并且兼容VSCode和JetBrains IDE。</p><p>对于我来说,最关注的IDE就是IDEA和VS Code,能够在这两个编辑器中使用就已经很好了。</p><p>先了解一下快捷键,快捷键说明官方文档:<a href="https://docs.marscode.cn/docs/extension-keyboard-shortcuts">https://docs.marscode.cn/docs/extension-keyboard-shortcuts</a></p><ul><li>【快捷键】打开侧边 AI 对话框:Windows下快捷键:Ctrl + U;</li><li>【快捷命令】输入<code>#</code>可以选择上下文,有3个选项,<strong>我觉得这个功能后续应该会有更大的作用</strong>,类似于<code>Cursor</code>的<code>CodeBase</code>:<ul><li>添加代码块作为上下文;</li><li>添加文件作为上下文;</li><li>添加工作区代码作为上下文;(这个比较强大)</li></ul></li></ul><p>接下来,通过具体的操作,来看看在这两个编辑器中怎么使用。</p><h3 id="2-1-在-IntelliJ-IDEA中使用:"><a href="#2-1-在-IntelliJ-IDEA中使用:" class="headerlink" title="2.1 在 IntelliJ IDEA中使用:"></a>2.1 在 IntelliJ IDEA中使用:</h3><h4 id="2-1-1-安装插件"><a href="#2-1-1-安装插件" class="headerlink" title="2.1.1 安装插件"></a>2.1.1 安装插件</h4><p>在IDEA的“setting”->“plugins”->”Marketplace”中搜索“豆包”或者“MarsCode”进行插件安装,完成后重启并登录。</p><p><img src="/images/posts/ai/20241215/20_IDEA%E5%AE%89%E8%A3%85%E8%B1%86%E5%8C%85MarsCode%E6%8F%92%E4%BB%B6.png"></p><p>这里我拉取了<code>ruoyi 前后端分离版本</code>的代码进行的操作和演示,我们一起来看看吧(很详细)。</p><h4 id="2-1-2-代码补全-功能演示【应用建议代码快捷键:Tab键】"><a href="#2-1-2-代码补全-功能演示【应用建议代码快捷键:Tab键】" class="headerlink" title="2.1.2 代码补全-功能演示【应用建议代码快捷键:Tab键】"></a>2.1.2 代码补全-功能演示【应用建议代码快捷键:Tab键】</h4><p>1)正常编写代码,会出现对应代码建议,按下<code>Tab</code>键即可应用这部分建议代码,写代码方便了不少:</p><p><img src="/images/posts/ai/20241215/24_IDEA%E4%BB%A3%E7%A0%81%E8%A1%A5%E5%85%A8.png"></p><p>2)代码自动生成(选中代码文件点击”插入”图标按钮自动插入代码,或者是点击“复制”图标按钮手动粘贴):</p><p><img src="/images/posts/ai/20241215/22_IDEA%E9%98%85%E8%AF%BB%E6%95%B4%E4%B8%AA%E5%B7%A5%E7%A8%8B%E5%B9%B6%E7%94%9F%E6%88%90%E6%8E%A5%E5%8F%A3%E6%97%A5%E5%BF%97%E7%9A%84%E5%B7%AE%E5%A2%9E%E5%88%A0%E6%94%B9%E5%8A%9F%E8%83%BD.png"></p><h4 id="2-1-3-生成单元测试【对话框命令:-test】"><a href="#2-1-3-生成单元测试【对话框命令:-test】" class="headerlink" title="2.1.3 生成单元测试【对话框命令:/test】"></a>2.1.3 生成单元测试【对话框命令:/test】</h4><p>选中代码,在AI对话框,输入<code>/test</code>直接回车,会针对选中的代码有完整的用例代码生成,直接点击创建文件按钮并保存到对应目录下就行:</p><p><img src="/images/posts/ai/20241215/25_IDEA%E7%94%9F%E6%88%90%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E7%94%A8%E4%BE%8B.png"></p><p>或者结合IDEA快捷键(<code>Ctrl</code>+<code>Shift</code>+<code>T</code>),让IDEA自动创建测试用例的文件,再点击MarsCode生成测试用例的代码块右上角的“插入”图标按钮进行代码的插入,是不是很省事?</p><h4 id="2-1-4-解释代码"><a href="#2-1-4-解释代码" class="headerlink" title="2.1.4 解释代码"></a>2.1.4 解释代码</h4><h5 id="1-解释整个工作区代码【对话框输入-选择Workspace】(比较强大)"><a href="#1-解释整个工作区代码【对话框输入-选择Workspace】(比较强大)" class="headerlink" title="1) 解释整个工作区代码【对话框输入#选择Workspace】(比较强大)"></a>1) 解释整个工作区代码【对话框输入<code>#</code>选择<code>Workspace</code>】(比较强大)</h5><p>在对话框输入<code># </code>选择<code>Workspace</code>,可以选中整个工作区项目文件,通过对话框要求解释代码,MarsCode会扫描整个工作区的所有代码文件并给出解释,<strong>个人认为,这个比较强大,直接解释整个项目</strong>,示例:</p><p><img src="/images/posts/ai/20241215/21_IDEA%E8%A7%A3%E9%87%8A%E6%95%B4%E4%B8%AA%E9%A1%B9%E7%9B%AE.png"></p><h5 id="2-解释选中代码【对话框命令:-explain】"><a href="#2-解释选中代码【对话框命令:-explain】" class="headerlink" title="2) 解释选中代码【对话框命令:/explain】"></a>2) 解释选中代码【对话框命令:/explain】</h5><p>选中代码后,输入上述对话框命令,解释代码并给出改进建议和修复后的代码:</p><p><img src="/images/posts/ai/20241215/21_IDEA%E8%A7%A3%E9%87%8A%E9%80%89%E4%B8%AD%E4%BB%A3%E7%A0%81%E5%B9%B6%E7%BB%99%E5%87%BA%E6%94%B9%E8%BF%9B%E5%BB%BA%E8%AE%AE%E5%92%8C%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81.png"></p><h5 id="3-为选中代码添加更详细的注释【对话框命令:-doc】"><a href="#3-为选中代码添加更详细的注释【对话框命令:-doc】" class="headerlink" title="3) 为选中代码添加更详细的注释【对话框命令:/doc】"></a>3) 为选中代码添加更详细的注释【对话框命令:/doc】</h5><p>选中代码后,输入上述对话框命令,会给原有代码添加方法级注释和行级注释。左边原始代码,右边是MarsCode生成的,<strong>不喜欢写注释又不得不写的同学的福音</strong>:</p><p><img src="/images/posts/ai/20241215/21_IDEA%E4%B8%BA%E9%80%89%E4%B8%AD%E4%BB%A3%E7%A0%81%E6%B7%BB%E5%8A%A0%E6%96%B9%E6%B3%95%E7%BA%A7%E6%B3%A8%E9%87%8A%E5%92%8C%E8%A1%8C%E7%BA%A7%E6%B3%A8%E9%87%8A.png"></p><h4 id="2-1-5-错误修复【对话框命令:-fix】"><a href="#2-1-5-错误修复【对话框命令:-fix】" class="headerlink" title="2.1.5 错误修复【对话框命令:/fix】"></a>2.1.5 错误修复【对话框命令:/fix】</h4><p>选中需要修复的代码,在AI对话框,输入<code>/fix</code>直接回车,会帮助我们修复代码,并支持插入到代码文件中,查看示例:</p><p><img src="/images/posts/ai/20241215/27_IDEA%E9%94%99%E8%AF%AF%E4%BF%AE%E5%A4%8D.png"></p><p><img src="/images/posts/ai/20241215/26_IDEA%E9%94%99%E8%AF%AF%E4%BF%AE%E5%A4%8D.png"></p><h3 id="2-2-在VsCode中使用"><a href="#2-2-在VsCode中使用" class="headerlink" title="2.2 在VsCode中使用"></a>2.2 在VsCode中使用</h3><p>打开项目,这里我使用<code>ruoyi-vue</code>的前端代码。</p><h4 id="2-2-1-安装插件"><a href="#2-2-1-安装插件" class="headerlink" title="2.2.1 安装插件"></a>2.2.1 安装插件</h4><p>点击官网的【立即获取编程助手】,然后点击【立即安装】会自动打开VSCode IDE,下载插件后点击登录(支持掘金登录),如下图:</p><p><img src="/images/posts/ai/20241215/02_VSCode%E4%B8%AD%E5%AE%89%E8%A3%85.png"></p><p>或者直接在VSCode的【扩展】中搜索”豆包MarsCode“自行安装,然后登录也可以。</p><h4 id="2-2-2-代码补全"><a href="#2-2-2-代码补全" class="headerlink" title="2.2.2 代码补全"></a>2.2.2 代码补全</h4><p>与IDEA操作相同</p><h4 id="2-2-3-生成单元测试"><a href="#2-2-3-生成单元测试" class="headerlink" title="2.2.3 生成单元测试"></a>2.2.3 生成单元测试</h4><p>与IDEA操作相同</p><h4 id="2-2-4-解释代码"><a href="#2-2-4-解释代码" class="headerlink" title="2.2.4 解释代码"></a>2.2.4 解释代码</h4><p>与IDEA操作相同</p><h5 id="1-解释工作区代码:"><a href="#1-解释工作区代码:" class="headerlink" title="1) 解释工作区代码:"></a>1) 解释工作区代码:</h5><p><img src="/images/posts/ai/20241215/05_VSCode%E4%B8%AD%E8%A7%A3%E9%87%8A%E6%95%B4%E4%B8%AA%E9%A1%B9%E7%9B%AE.png"></p><h5 id="2-解释选中代码:"><a href="#2-解释选中代码:" class="headerlink" title="2) 解释选中代码:"></a>2) 解释选中代码:</h5><p>选中代码之后,在AI对话框中输入“/explain”或者点击解释代码,可以看到对代码的解释:</p><p><img src="/images/posts/ai/20241215/04_VSCode%E4%B8%AD%E8%A7%A3%E9%87%8A%E4%BB%A3%E7%A0%81.png"></p><h4 id="2-2-5-错误修复"><a href="#2-2-5-错误修复" class="headerlink" title="2.2.5 错误修复"></a>2.2.5 错误修复</h4><p>与IDEA操作相同</p><h3 id="2-3-豆包在线编辑器-MarsCode-IDE-初体验"><a href="#2-3-豆包在线编辑器-MarsCode-IDE-初体验" class="headerlink" title="2.3 豆包在线编辑器 MarsCode IDE 初体验"></a>2.3 豆包在线编辑器 <code>MarsCode IDE</code> 初体验</h3><blockquote><p>不下载IDE就能在网页写代码、运行代码,支持内置webview预览</p></blockquote><p>访问地址:<a href="https://www.marscode.cn/workbench">https://www.marscode.cn/workbench</a></p><p><img src="/images/posts/ai/20241215/10_MarsCodeIDE.png"></p><p>支持<code>手机号</code>、<code>掘金</code>、<code>抖音方式登录</code>:</p><p><img src="/images/posts/ai/20241215/11_MarsCodeIDE%E7%99%BB%E5%BD%95.png"></p><h4 id="1)通过选定模板来创建项目"><a href="#1)通过选定模板来创建项目" class="headerlink" title="1)通过选定模板来创建项目"></a>1)通过选定模板来创建项目</h4><p><img src="/images/posts/ai/20241215/12_01%E5%88%9B%E5%BB%BA%E9%A1%B9%E7%9B%AE.png"></p><p>我通过vue模板创建了一个项目,直接点击上方的<code>Run</code>按钮可以看到自动安装依赖并启动预览,<strong>无需本地下载依赖,速度也很快、无需切换浏览器</strong>,效果看下图:</p><p><img src="/images/posts/ai/20241215/15_%E5%9C%A8%E7%BA%BF%E8%BF%90%E8%A1%8C%E5%B9%B6%E9%A2%84%E8%A7%88.png"></p><h4 id="2)支持从Github导入项目"><a href="#2)支持从Github导入项目" class="headerlink" title="2)支持从Github导入项目"></a>2)支持从Github导入项目</h4><p>通过Github授权之后可以访问所有代码仓库,我这里选择的是前一段时间开发的定时提醒休息的客户端软件。</p><p><img src="/images/posts/ai/20241215/12_%E4%BB%8EGithub%E4%B8%AD%E5%AF%BC%E5%85%A5%E9%A1%B9%E7%9B%AE.png"></p><p><img src="/images/posts/ai/20241215/13_%E4%B8%BB%E7%95%8C%E9%9D%A2.png"></p><p>不过有一个限制,就是没法像前面两个插件一样扫描整个项目代码,应该是权限问题。</p><p>个人感受:<code>MarsCode IDE</code>这个在线编辑器 目前支持比较好的就是<strong>前端项目</strong>,很快就能出效果。</p><p>对于我来说,能在IDEA和VSCode中使用就已经很满意了,期待豆包MarsCode后续越来越强大!</p><h3 id="总结:"><a href="#总结:" class="headerlink" title="总结:"></a>总结:</h3><p><strong>① 代码补全</strong>:根据开发过程中输入内容自动生成代码推荐;【自动帮写代码】</p><p><strong>② 生成单元测试</strong>:为选中的函数生成单元测试用例;【自动帮写单元测试用例】</p><p><strong>③ 解释代码</strong>:根据提供的代码帮助我们解释代码的作用;【接手“祖传代码”、或者阅读别人写的代码时很好用】</p><p><strong>④ 错误修复</strong>:帮助我们发现代码中的问题并说明怎么改;</p><p><strong>⑤ AI问答</strong>:省去了频繁切换IDE和去浏览器检索的时间,直接在IDE中进行提问,集中精力、更好的禅模式!</p><p>我认为:AI,对于程序员来说是能力的拓展和效率的提升。拥抱AI、主动适应AI带来的改变,主动找到在AI时代我们新的定位,积极探索更多AI的应用场景,成为AI赋能的超级程序员(超级个体),这对程序员来说得天独厚!</p>]]></content>
<summary type="html"><h2 id="写在前面"><a href="#写在前面" class="headerlink" title="写在前面"></a>写在前面</h2><p>大家好,我是程序员七平。<br>这篇文章主要介绍豆包旗下的一款编程助手<code>MarsCode</code>,方便大家对</summary>
<category term="AI, AI编程" scheme="https://lixiaw.github.io/categories/AI-AI%E7%BC%96%E7%A8%8B/"/>
<category term="豆包MarsCode" scheme="https://lixiaw.github.io/tags/%E8%B1%86%E5%8C%85MarsCode/"/>
</entry>
<entry>
<title>AI编程工具Cursor使用教程</title>
<link href="https://lixiaw.github.io/posts/47517.html"/>
<id>https://lixiaw.github.io/posts/47517.html</id>
<published>2024-12-15T04:22:00.000Z</published>
<updated>2024-12-15T13:09:03.993Z</updated>
<content type="html"><![CDATA[<h2 id="1-Cursor-介绍:"><a href="#1-Cursor-介绍:" class="headerlink" title="1. Cursor 介绍:"></a>1. Cursor 介绍:</h2><p><strong>Cursor</strong> AI 编程工具是一个智能开发环境(IDE),它结合了人工智能(AI)技术来增强开发人员的编码体验。与传统的编程工具不同,Cursor AI 通过嵌入的 AI 功能(如自动补全、错误检查、代码生成等)来加速开发过程。</p><p><img src="/images/posts/ai/1/cursor_%E5%AE%98%E7%BD%91.png"></p><p><strong>Cursor 内置的AI模型</strong>:</p><p>最先进的gpt-4、claude-3.5和openAI的模型o1-mini、o1-preview。</p><p>收费情况:免费版本:专业版两周试用、50个慢速高级版请求、2000次“完成”(生成代码/请求AI等)使用。</p><p>我是使用免费版本的claude-3.5模型开发的工具“护腰神器”。</p><h2 id="2-Cursor使用:"><a href="#2-Cursor使用:" class="headerlink" title="2. Cursor使用:"></a>2. Cursor使用:</h2><p>下载地址在文末,我们先看主要功能,大概10分钟上手。</p><h4 id="1)Cursor界面"><a href="#1)Cursor界面" class="headerlink" title="1)Cursor界面"></a>1)Cursor界面</h4><p><img src="/images/posts/ai/1/cursor_1.png"></p><h4 id="2)语言切换,切换成中文:"><a href="#2)语言切换,切换成中文:" class="headerlink" title="2)语言切换,切换成中文:"></a>2)语言切换,切换成中文:</h4><p>界面上方的放大镜,点击输入<code>>language</code>,选择简体中文即可。</p><h4 id="3)常用快捷键"><a href="#3)常用快捷键" class="headerlink" title="3)常用快捷键"></a>3)常用快捷键</h4><p>因为我也没搞过这个WPF,完全小白。基本全自动开发,我主要使用的就是下面命令(这个命令最强大):</p><p><code>Ctrl+i</code>:打开<code>Composer</code>,用于输入自然语言命令(像跟朋友聊天一样),编辑代码。</p><ul><li><code>@Codebase</code>:提供对代码库的高级控制,检索当前代码库,通常适用于需要更高精度和更复杂查询的场景;</li></ul><p>其余快捷键:</p><ul><li><code>Tab</code>:自己写代码的话,会给你自动提供建议,按tab进行应用(跟idea里面通义灵码一样);</li><li><code>Ctrl+K</code>:主要负责用来生成或修改局部的代码。</li><li><code>Ctrl+L</code>:聊天(CHAT对话框);回答用户关于代码和整个项目的问题;比如上图展示的“告诉我这个项目是做什么的”。</li></ul><h2 id="3-附录"><a href="#3-附录" class="headerlink" title="3. 附录"></a>3. 附录</h2><p>Cursor 下载地址:<a href="https://www.cursor.com/">https://www.cursor.com/</a></p>]]></content>
<summary type="html"><h2 id="1-Cursor-介绍:"><a href="#1-Cursor-介绍:" class="headerlink" title="1. Cursor 介绍:"></a>1. Cursor 介绍:</h2><p><strong>Cursor</strong> AI 编</summary>
<category term="AI" scheme="https://lixiaw.github.io/categories/AI/"/>
<category term="cursor" scheme="https://lixiaw.github.io/tags/cursor/"/>
</entry>
<entry>
<title>解决从官方仓库下载网络不通畅问题,搭建私有化镜像仓库</title>
<link href="https://lixiaw.github.io/posts/55211.html"/>
<id>https://lixiaw.github.io/posts/55211.html</id>
<published>2024-12-04T01:51:54.000Z</published>
<updated>2024-12-15T06:26:19.915Z</updated>
<content type="html"><![CDATA[<h1 id="解决从官方仓库下载网络不通畅问题,搭建私有化镜像仓库"><a href="#解决从官方仓库下载网络不通畅问题,搭建私有化镜像仓库" class="headerlink" title="解决从官方仓库下载网络不通畅问题,搭建私有化镜像仓库"></a>解决从官方仓库下载网络不通畅问题,搭建私有化镜像仓库</h1><p>本文主要针对适用于个人的镜像仓库<code>Registry</code>和适用于企业的镜像仓库<code>Harbor</code> 做介绍。</p><p>先看看搭建私有化镜像仓库能解决什么问题?</p><h2 id="1-搭建Docker私有化仓库能解决什么问题?"><a href="#1-搭建Docker私有化仓库能解决什么问题?" class="headerlink" title="1.搭建Docker私有化仓库能解决什么问题?"></a>1.搭建Docker私有化仓库能解决什么问题?</h2><ol><li><strong>镜像拉取、下载慢</strong>:从本地私有仓库下载镜像比从远程公共仓库下载要快得多,因为数据传输的延迟和带宽限制被大大降低。(个人使用很重要)</li><li><strong>节省网络带宽</strong>:私有仓库允许用户在本地网络内下载和分发Docker镜像,因此能够尽量避免从远程公共仓库进行下载。(个人使用很重要)</li><li><strong>增强安全性</strong>:私有化仓库允许对镜像进行更严格的安全控制和审计、进行更细粒度的访问权限限制,确保只有授权用户才能下载和上传镜像。</li><li><strong>镜像的统一管理和分发</strong>:私有仓库使得Docker镜像的管理和分发更加集中和统一,管理员可以轻松地管理不同版本和标签的镜像,确保团队成员使用一致的镜像版本。</li></ol><p>如果平时使用过程中有使用的比较好的镜像,可以拉取下来,然后推送到自己的仓库收藏一下。有时候想用的时候又拉取不下来,很是折腾、费时间。</p><h2 id="2-常用私有化镜像仓库介绍"><a href="#2-常用私有化镜像仓库介绍" class="headerlink" title="2.常用私有化镜像仓库介绍"></a>2.常用私有化镜像仓库介绍</h2><h3 id="2-1-Docker官方Registry镜像"><a href="#2-1-Docker官方Registry镜像" class="headerlink" title="2.1 Docker官方Registry镜像"></a>2.1 Docker官方Registry镜像</h3><blockquote><p>Docker官方Registry镜像是一个开源的、轻量级的Docker镜像仓库解决方案。它提供了基本的镜像存储和分发功能,是Docker官方推荐的私有仓库搭建方式之一。</p></blockquote><p><strong>适用场景</strong>:一个简单、轻量级的Docker私有仓库,适用于<strong>小型团队</strong>或<strong>个人开发者</strong>,对镜像管理功能要求不高,主要关注基本的镜像存储和分发;</p><p><strong>注意:Registry:本身默认并不提供图形化界面</strong></p><h3 id="2-2-Harbor"><a href="#2-2-Harbor" class="headerlink" title="2.2 Harbor"></a>2.2 Harbor</h3><blockquote><p>Harbor是一个企业级的Docker Registry服务器,由VMware开源并维护。</p></blockquote><p><strong>适用场景</strong>:</p><ul><li><p>一个功能全面的Docker私有仓库,适用于<strong>中大型企业或团队</strong>;</p></li><li><p>对用户和镜像进行细粒度的权限控制;</p></li><li><p>对镜像的安全性、可靠性和性能有较高要求;</p></li><li><p>需要与CI/CD系统集成,实现自动化构建和部署;</p></li></ul><h2 id="3-安装部署(compose方式)"><a href="#3-安装部署(compose方式)" class="headerlink" title="3.安装部署(compose方式)"></a>3.安装部署(compose方式)</h2><p>本文安装优先采用<code>docker compose</code>方式进行安装部署,如果有不清楚的,可以去看前面的文章。</p><h3 id="3-1-Docker-Registry和Docker-registry-ui"><a href="#3-1-Docker-Registry和Docker-registry-ui" class="headerlink" title="3.1 Docker Registry和Docker-registry-ui"></a>3.1 Docker Registry和Docker-registry-ui</h3><p>前提条件:已经安装了docker。</p><p>1、docker-compose.yml文件示例内容:</p><p>解释:</p><p>① 定义了一个名为<code>my-registry</code>的服务,它使用官方的<code>registry</code>镜像,并在容器内运行。容器内的5000端口被映射到宿主机的15000端口,同时,<code>./data</code>目录被用作镜像的存储位置</p><p>② 定义了一个名为<code>my-registry-ui</code>的服务</p><figure class="highlight yaml"><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></pre></td><td class="code"><pre><span class="line"><span class="attr">services:</span></span><br><span class="line"> <span class="attr">my-registry:</span></span><br><span class="line"> <span class="attr">privileged:</span> <span class="literal">true</span></span><br><span class="line"> <span class="comment">#image: registry</span></span><br><span class="line"> <span class="comment"># 如果拉取不下来,可以用下面的加速地址</span></span><br><span class="line"> <span class="attr">image:</span> <span class="string">dockerproxy.net/library/registry:latest</span></span><br><span class="line"> <span class="attr">restart:</span> <span class="string">always</span></span><br><span class="line"> <span class="attr">container_name:</span> <span class="string">my-registry</span></span><br><span class="line"> <span class="attr">ports:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">"15000:5000"</span></span><br><span class="line"> <span class="attr">volumes:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">"./data:/var/lib/registry"</span></span><br><span class="line"> <span class="comment"># 图形化界面</span></span><br><span class="line"> <span class="attr">my-registry-ui:</span></span><br><span class="line"> <span class="comment">#image: joxit/docker-registry-ui:1.5-static</span></span><br><span class="line"> <span class="attr">image:</span> <span class="string">dockerproxy.net/joxit/docker-registry-ui:1.5-static</span></span><br><span class="line"> <span class="comment"># 或者使用特定的版本,例如 joxit/docker-registry-ui:1.5-static</span></span><br><span class="line"> <span class="attr">container_name:</span> <span class="string">my-registry-ui</span></span><br><span class="line"> <span class="attr">restart:</span> <span class="string">always</span></span><br><span class="line"> <span class="attr">ports:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="number">18080</span><span class="string">:80</span></span><br><span class="line"> <span class="attr">environment:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">REGISTRY_TITLE=My</span> <span class="string">Private</span> <span class="string">Registry</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">REGISTRY_URL=http://my-registry:5000</span></span><br><span class="line"> <span class="comment"># 可选:设置CATALOG_ELEMENTS_LIMIT来限制UI中显示的镜像数量</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">CATALOG_ELEMENTS_LIMIT="1000"</span></span><br><span class="line"> <span class="attr">depends_on:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">my-registry</span></span><br></pre></td></tr></table></figure><ol start="2"><li>启动服务</li></ol><p>在<code>docker-compose.yml</code>文件所在的目录下,运行以下命令来启动服务:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker-compose up -d</span><br></pre></td></tr></table></figure><p>这个命令会启动Docker Registry容器,并在后台运行。</p><p><img src="/images/posts/docker/4/1_registry.png"></p><h3 id="3-2-Harbor"><a href="#3-2-Harbor" class="headerlink" title="3.2 Harbor"></a>3.2 Harbor</h3><p>前提条件:已经安装了docker。</p><p>PS:如果公网访问的话,还需要:</p><ul><li>一个域名或IP地址,用于访问Harbor;</li><li>一个SSL证书(可选,但推荐用于保护通信);</li></ul><ol><li>下载<code>harbor</code>并安装</li></ol><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1. 从github下载harbor仓库(如果实在觉得慢或者其他网络原因,也有快的办法:离线包下载然后上传到服务器。不清楚的可以联系我)</span></span><br><span class="line">wget https://github.com/goharbor/harbor/releases/download/v2.11.2/harbor-offline-installer-v2.11.2.tgz</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2.解压</span></span><br><span class="line">tar xvf harbor-offline-installer-v2.11.2.tgz</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3.打开解压后的文件夹</span></span><br><span class="line"><span class="built_in">cd</span> harbor</span><br><span class="line"></span><br><span class="line"><span class="comment"># 4. 配置Harbor(修改harbor.yml文件)</span></span><br><span class="line"><span class="built_in">cp</span> harbor.yml.tmpl harbor.yml</span><br><span class="line"><span class="comment"># 编辑harbor.yml,例如修改hostname主机名(我这边使用的127.0.0.1)、端口(默认80端口)、存储位置等等</span></span><br><span class="line"><span class="comment"># 如果不需要HTTPS的话,把这个选项也注释掉。</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 5. 安装Harbor(运行自动化安装脚本来部署Harbor)</span></span><br><span class="line">./install.sh</span><br><span class="line"></span><br></pre></td></tr></table></figure><ol start="2"><li>安装完成后服务自动启动:</li></ol><p>访问地址(我没有使用域名,配置的是IP、端口改为8314):<a href="http://hostname:8314/%EF%BC%8C%E9%BB%98%E8%AE%A4%E8%B4%A6%E5%8F%B7%EF%BC%9Aadmin/Harbor12345%E3%80%82">http://hostname:8314/,默认账号:admin/Harbor12345。</a></p><p>可以看到以下界面。</p><p><img src="/images/posts/docker/4/1_harbor%E7%99%BB%E5%BD%95%E9%A1%B5.png"></p><p>首页:</p><p><img src="/images/posts/docker/4/2_harbor%E9%A6%96%E9%A1%B5.png"></p><h2 id="4-使用"><a href="#4-使用" class="headerlink" title="4.使用"></a>4.使用</h2><h3 id="4-1-配置Docker守护进程(在Docker客户端上)"><a href="#4-1-配置Docker守护进程(在Docker客户端上)" class="headerlink" title="4.1 配置Docker守护进程(在Docker客户端上)"></a>4.1 配置Docker守护进程(在Docker客户端上)</h3><ul><li>编辑Docker的配置文件(通常是<code>/etc/docker/daemon.json</code>),添加<code>insecure-registries</code>字段,并将Harbor的地址添加到该字段中。</li><li>需要配置Docker守护进程以信任Harbor/Registry的仓库。</li></ul><figure class="highlight bash"><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">vim /etc/docker/daemon.json</span><br><span class="line"></span><br><span class="line"><span class="comment">## 内容大概如下</span></span><br><span class="line">{</span><br><span class="line"> <span class="comment">#################开始##################</span></span><br><span class="line"> <span class="string">"insecure-registries"</span>: [</span><br><span class="line"> <span class="string">"192.168.1.153:8314"</span></span><br><span class="line"> ],</span><br><span class="line"> <span class="comment">#################结束##################</span></span><br><span class="line"></span><br><span class="line"> <span class="string">"registry-mirrors"</span>: [</span><br><span class="line"> <span class="string">"https://dockerproxy.com"</span></span><br><span class="line"> ]</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><p>记得</p><figure class="highlight bash"><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">systemctl daemon-reload</span><br><span class="line">systemctl restart docker</span><br></pre></td></tr></table></figure><h3 id="4-2-推送和拉取镜像-Docker-Registry和Harbor"><a href="#4-2-推送和拉取镜像-Docker-Registry和Harbor" class="headerlink" title="4.2 推送和拉取镜像(Docker Registry和Harbor)"></a>4.2 推送和拉取镜像(Docker Registry和Harbor)</h3><p>这两个仓库的登录、推送、拉取命令基本是一样的。</p><ol><li>如果要推送和拉取镜像,一般需要进行登录:</li></ol><ul><li>在Docker客户端上,使用docker login命令登录到镜像仓库。</li><li>输入用户名和密码(Harbor默认是admin/Harbor12345;Docker Registry 默认没有密码,随便输)。</li></ul><figure class="highlight bash"><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"><span class="comment"># 登录Harbor,docker login harbor.example.com</span></span><br><span class="line">docker login <Harbor/Docker Registry服务器地址></span><br></pre></td></tr></table></figure><ol start="2"><li>推送</li></ol><p>为要推送的本地镜像打上一个新的标签(Tag),这个标签应该包含仓库的地址、项目名和镜像名。例如:</p><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># Harbor 命令</span></span><br><span class="line">docker tag your-image-name:tag registry.<Harbor服务器地址>/<项目名>/<镜像名>:tag</span><br><span class="line"></span><br><span class="line"><span class="comment"># Docker Registry命令</span></span><br><span class="line">docker tag your-image-name:tag <Docker Registry服务器地址>/<仓库名>/<镜像名>:tag</span><br><span class="line"></span><br><span class="line"><span class="comment">## 示例(注意:默认端口5000,我设置为15000):docker tag grafana/grafana:9.2.4 192.168.1.153:15000/my_registry/grafana:9.2.4</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><p>最后,使用<code>docker push</code>命令将镜像推送到Harbor/Docker Registry:</p><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># Harbor</span></span><br><span class="line">docker push registry.<Harbor服务器地址>/<项目名>/<镜像名>:tag</span><br><span class="line"></span><br><span class="line"><span class="comment"># Registry</span></span><br><span class="line">docker push <Docker Registry服务器地址>/<项目名>/<镜像名>:tag</span><br><span class="line"></span><br><span class="line"><span class="comment">## 示例:docker push 192.168.1.153:15000/my_registry/grafana:9.2.4</span></span><br></pre></td></tr></table></figure><p>Docker Registry 推送:</p><p><img src="/images/posts/docker/4/2_registry%E6%8E%A8%E9%80%81%E5%90%8E.png"></p><ol start="3"><li>拉取</li></ol><p>同样,首先确保你已经登录到Harbor。</p><p>使用<code>docker pull</code>命令从Harbor拉取镜像。命令格式如下:</p><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># Harbor命令</span></span><br><span class="line">docker pull registry.<Harbor服务器地址>/<项目名>/<镜像名>:tag</span><br><span class="line"></span><br><span class="line"><span class="comment">#Docker Registry命令</span></span><br><span class="line">docker pull <Docker Registry服务器地址>/<仓库名>/<镜像名>:tag</span><br></pre></td></tr></table></figure><p>这里的<code><Harbor/Docker Registry服务器地址></code>、<code><项目名></code>、<code><镜像名></code>和<code>:tag</code>应该与你推送镜像时使用的相同。</p>]]></content>
<summary type="html"><h1 id="解决从官方仓库下载网络不通畅问题,搭建私有化镜像仓库"><a href="#解决从官方仓库下载网络不通畅问题,搭建私有化镜像仓库" class="headerlink" title="解决从官方仓库下载网络不通畅问题,搭建私有化镜像仓库"></a>解决从官方仓库下</summary>
<category term="Docker" scheme="https://lixiaw.github.io/categories/Docker/"/>
<category term="Docker" scheme="https://lixiaw.github.io/tags/Docker/"/>
</entry>
<entry>
<title>副业探索方向</title>
<link href="https://lixiaw.github.io/posts/1.html"/>
<id>https://lixiaw.github.io/posts/1.html</id>
<published>2024-11-30T01:51:54.000Z</published>
<updated>2024-12-15T06:26:19.896Z</updated>
<content type="html"><![CDATA[<h1 id="副业探索方向"><a href="#副业探索方向" class="headerlink" title="副业探索方向"></a>副业探索方向</h1>]]></content>
<summary type="html"><h1 id="副业探索方向"><a href="#副业探索方向" class="headerlink" title="副业探索方向"></a>副业探索方向</h1></summary>
<category term="AI" scheme="https://lixiaw.github.io/categories/AI/"/>
<category term="cursor" scheme="https://lixiaw.github.io/tags/cursor/"/>
</entry>
<entry>
<title>不写一行代码,用AI编程工具Cursor做个Win工具“护腰神器”,附使用教程及心得</title>
<link href="https://lixiaw.github.io/posts/36072.html"/>
<id>https://lixiaw.github.io/posts/36072.html</id>
<published>2024-11-30T01:51:54.000Z</published>
<updated>2024-12-15T06:26:19.898Z</updated>
<content type="html"><![CDATA[<h1 id="不到6小时,不敲一行代码,做出一个Win客户端工具“护腰神器”"><a href="#不到6小时,不敲一行代码,做出一个Win客户端工具“护腰神器”" class="headerlink" title="不到6小时,不敲一行代码,做出一个Win客户端工具“护腰神器”"></a>不到6小时,不敲一行代码,做出一个Win客户端工具“护腰神器”</h1><blockquote><p>你好,我是程序员七平。一个10年的Javaer,目前研究AI以及AIGC,副业探索中。</p></blockquote><p>感兴趣的朋友可以关注这个公众号。</p><p><code>Cursor</code>(一款基于<code>Vs Code</code>构建的、与AI结合的现代化编程工具)发布也挺长时间了。</p><p>前些天才腾出手研究了一下Cursor的使用,因为自己平时坐的时间长一些,就顺便做了一个小工具。</p><p>发给了几个朋友和同事,说是觉得还不错。当知道这是完全使用AI做的的时候,表示很吃惊和好奇,纷纷表示让我详细说说。</p><p>我答应了他们我会在公众号写一篇文章,让他们自己来看(哈哈,算盘响不响?)。</p><p>不多废话,以下是本文内容大纲:</p><ol><li><p>“护腰神器”介绍;</p></li><li><p>Cursor工具介绍;</p></li><li><p>使用的提示词及调试过程;</p></li><li><p>实践过程的踩坑和使用心得;</p></li><li><p>附录资源;</p></li></ol><h3 id="1-“护腰神器”工具:"><a href="#1-“护腰神器”工具:" class="headerlink" title="1. “护腰神器”工具:"></a>1. “护腰神器”工具:</h3><h4 id="1)功能介绍"><a href="#1)功能介绍" class="headerlink" title="1)功能介绍"></a>1)功能介绍</h4><p>让Cursor来介绍一下这款护腰神器”的功能:</p><ol><li><p>工作与休息计时:</p><ol><li>可以设置<strong>工作时长</strong>和<strong>休息时长</strong>,自动提醒用户休息。</li><li>全屏的休息窗口显示倒计时。</li></ol></li><li><p>休息窗口:</p></li><li><p>窗口全屏显示,防止用户继续工作。</p></li><li><p>可以手动结束休息。</p></li><li><p>休息窗口会屏蔽键盘输入,确保用户专注于休息。</p></li><li><p>预休息提醒:</p><ol><li>休息时间到来之前,会弹出一个预休息窗口,提醒用户即将进入休息时间。</li><li>用户可以选择延迟休息,延迟时间为3分钟(不限次)。</li></ol></li><li><p>设置界面:</p><ol><li>可以在设置界面中调整工作和休息的时长。</li><li>可以选择是否在系统启动时自动运行软件。</li><li>可以编辑休息提示语句,软件会在休息窗口中循环显示这些提示。</li></ol></li><li><p>系统托盘图标:</p><ol><li>在系统托盘中运行,可以通过托盘图标快速访问软件的主要功能或设置。</li></ol></li></ol><h4 id="2)软件界面:"><a href="#2)软件界面:" class="headerlink" title="2)软件界面:"></a>2)软件界面:</h4><ol><li>托盘任务栏右键菜单:</li></ol><p><img src="/images/posts/ai/1/%E4%BB%BB%E5%8A%A1%E6%A0%8F%E8%8F%9C%E5%8D%95.png"></p><ol start="2"><li>主界面:</li></ol><p><img src="/images/posts/ai/1/%E4%B8%BB%E7%95%8C%E9%9D%A2.png"></p><ol start="3"><li>设置界面:</li></ol><p><img src="/images/posts/ai/1/%E8%AE%BE%E7%BD%AE%E7%95%8C%E9%9D%A2.png"></p><ol start="4"><li>预休息界面:</li></ol><p><img src="/images/posts/ai/1/%E9%A2%84%E4%BC%91%E6%81%AF%E7%95%8C%E9%9D%A2.png"></p><ol start="5"><li>休息界面:</li></ol><p><img src="/images/posts/ai/1/%E4%BC%91%E6%81%AF%E7%95%8C%E9%9D%A2.png"></p><h3 id="2-Cursor-介绍:"><a href="#2-Cursor-介绍:" class="headerlink" title="2. Cursor 介绍:"></a>2. Cursor 介绍:</h3><blockquote><p><strong>Cursor</strong> AI 编程工具是一个智能开发环境(IDE),它结合了人工智能(AI)技术来增强开发人员的编码体验。与传统的编程工具不同,Cursor AI 通过嵌入的 AI 功能(如自动补全、错误检查、代码生成等)来加速开发过程。</p></blockquote><p><img src="/images/posts/ai/1/cursor_%E5%AE%98%E7%BD%91.png"></p><p><strong>Cursor 内置的AI模型</strong>:</p><p>最先进的gpt-4、claude-3.5和openAI的模型o1-mini、o1-preview。</p><p>收费情况:免费版本:专业版两周试用、50个慢速高级版请求、2000次“完成”(生成代码/请求AI等)使用。</p><p>我是使用免费版本的claude-3.5模型开发的工具“护腰神器”。</p><h3 id="3-Cursor使用:"><a href="#3-Cursor使用:" class="headerlink" title="3. Cursor使用:"></a>3. Cursor使用:</h3><p>下载地址在文末,我们先看主要功能,大概10分钟上手。</p><h4 id="1)界面"><a href="#1)界面" class="headerlink" title="1)界面"></a>1)界面</h4><p><img src="/images/posts/ai/1/cursor_1.png"></p><h4 id="2)语言切换,切换成中文:"><a href="#2)语言切换,切换成中文:" class="headerlink" title="2)语言切换,切换成中文:"></a>2)语言切换,切换成中文:</h4><p>界面上方的放大镜,点击输入<code>>language</code>,选择简体中文即可。</p><h4 id="3)常用快捷键"><a href="#3)常用快捷键" class="headerlink" title="3)常用快捷键"></a>3)常用快捷键</h4><p>因为我也没搞过这个WPF,完全小白。基本全自动开发,我主要使用的就是下面命令(这个命令最强大):</p><p><code>Ctrl+i</code>:打开<code>Composer</code>,用于输入自然语言命令(像跟朋友聊天一样),编辑代码。</p><ul><li><code>@Codebase</code>:提供对代码库的高级控制,检索当前代码库,通常适用于需要更高精度和更复杂查询的场景;</li></ul><p>其余快捷键:</p><ul><li><code>Tab</code>:自己写代码的话,会给你自动提供建议,按tab进行应用(跟idea里面通义灵码一样);</li><li><code>Ctrl+K</code>:主要负责用来生成或修改局部的代码。</li><li><code>Ctrl+L</code>:聊天(CHAT对话框);回答用户关于代码和整个项目的问题;比如上图展示的“告诉我这个项目是做什么的”。</li></ul><h4 id="4)使用的提示词及调试过程(部分)"><a href="#4)使用的提示词及调试过程(部分)" class="headerlink" title="4)使用的提示词及调试过程(部分)"></a>4)使用的提示词及调试过程(部分)</h4><blockquote><p>做一个软件名称为“护腰使者”的windows客户端,从0-1在当前目录创建项目根目录,初始化项目并生成完整代码。</p><p>需要具备以下功能:<br>1、每隔45分钟(可以设置)锁定键盘,弹出全屏页面提醒使用者该休息啦,休息时间默认为5分钟(可以设置),此时展示倒计时(分钟:秒);用户每次可以选择延时3分钟;<br>2、可以设置开机启动,任务栏图标支持右键选中;功能:重新计时;关闭软件;关于我<br>3、软件开发语言使用市面上最流行的WPF就行<br>4、主窗口打开之后显示“已工作时长:xx分钟:xx秒”</p></blockquote><p>如下图:</p><p><img src="/images/posts/ai/1/hysq_1.png"></p><p>后续Cursor告诉我们如何使用命令运行项目,然后根据自己想要的效果一点点去让Cursor调试就行,最后让Cursor说明如何打包项目。</p><h3 id="4-实践过程的踩坑和使用心得"><a href="#4-实践过程的踩坑和使用心得" class="headerlink" title="4. 实践过程的踩坑和使用心得"></a>4. 实践过程的踩坑和使用心得</h3><p>在实际使用的过程中,并不是十分的顺利,主要还是不太习惯这种和AI的聊天式编程。这也是为什么这么简单的功能,用了差不多6个小时。</p><ol><li><p>从0到1全新生成项目代码时会先列文件列表,然后一两个一两个地输出,需要人为一步步确认(一开始我以为直接会把上面的需求全部实现了再让我确认);</p></li><li><p>提问的过程中注意纠正(比如:注意跟前面提供的项目结构保持一致。要不然会跑偏,比如一直提供不需要的工具类、要么就是前后回答不一致);</p></li><li><p>代码调试:使用Cursor完全生成的过程,自己频繁进行调试,避免跑偏;一旦出现跑偏或者报错,及时把错误告诉Cursor;</p></li><li><p>生成的项目有时会和一开始文件结构会出现对不上的情况(比如生成到其他目录,需要一开始就明确:请确认当前项目绝对路径展示给我,后续操作全部基于此目录进行。就跟看的科幻电影那种人机对话的感觉一样);</p></li><li><p>经常会出现为了解决A问题而直接把其他的关键信息改了的情况,注意自己要频繁调试去纠正;</p></li><li><p>一两次解决不了的涉及整个项目的问题,最好还是用一下前面提到的命令 <code>@codebase</code>;</p></li></ol><p>这个WPF项目输出后的exe包体积有点大,70M左右。当然,我让Cursor推荐了另外一种语言重写了一遍,输出exe体积只有300K。因为是重复的东西,就后面看情况分享吧。</p><h3 id="5-附录"><a href="#5-附录" class="headerlink" title="5. 附录"></a>5. 附录</h3><p>Cursor 下载地址:<a href="https://www.cursor.com/">https://www.cursor.com/</a></p><h4 id="题外话"><a href="#题外话" class="headerlink" title="题外话"></a>题外话</h4><p>前两天有个事情,大家应该看到了《我用Cursor1小时开发的App,上了AppStore排行榜Top20》。大家看到的时候,心中有没有一些担忧(之前idea的几个编码插件出来的时候也一样):现在AI正在改变着各行各业的这种事实,我们更多的普通人应该何去何从?</p><p>从我这次使用的经历(我还用Cursor做了个由微信小程序+node服务端+vue3后台web的门店档口营业额上报系统)来看,庞大复杂的业务暂时还不存在被AI接替的可能,现在这个Cursor还是有一些使用门槛的要求。</p><p>但这也给我们一个警醒:世界是变化的,日新月异,固步自封不可取。</p><p>我的思考是,不论AI怎样发展,都应该去主动的去接受这种现实,拥抱变化。积极探索程序员以及其他普通人跟AI协作和配合的更多方式,有兴趣的可以看看我发的这篇《》。</p><p>你好,我是七平。一个10年的Javaer,研究AI以及AIGC,副业探索中。有兴趣的朋友可以关注公众号“weyoung”。分享更多实用的东西</p>]]></content>
<summary type="html"><h1 id="不到6小时,不敲一行代码,做出一个Win客户端工具“护腰神器”"><a href="#不到6小时,不敲一行代码,做出一个Win客户端工具“护腰神器”" class="headerlink" title="不到6小时,不敲一行代码,做出一个Win客户端工具“护腰神器</summary>
<category term="AI" scheme="https://lixiaw.github.io/categories/AI/"/>
<category term="cursor" scheme="https://lixiaw.github.io/tags/cursor/"/>
</entry>
<entry>
<title>Docker工具之可视化操作portainer介绍</title>
<link href="https://lixiaw.github.io/posts/27676.html"/>
<id>https://lixiaw.github.io/posts/27676.html</id>
<published>2024-11-21T01:51:54.000Z</published>
<updated>2024-12-15T06:26:19.900Z</updated>
<content type="html"><![CDATA[<h1 id="docker工具之可视化操作portainer介绍"><a href="#docker工具之可视化操作portainer介绍" class="headerlink" title="docker工具之可视化操作portainer介绍"></a>docker工具之可视化操作portainer介绍</h1><h2 id="引"><a href="#引" class="headerlink" title="引"></a>引</h2><blockquote><p>Portainer 是一个轻量级、开源的容器管理平台,提供简单的图形化界面,用于管理 Docker 容器、镜像、网络、卷、管理docker swarm 集群和 Kubernetes 集群。</p></blockquote><h2 id="应用场景"><a href="#应用场景" class="headerlink" title="应用场景"></a>应用场景</h2><blockquote><p>适合开发者、运维人员以及初学者使用,帮助用户快速上手容器化技术,减少 CLI 操作的复杂性。</p><p>PS:我主要用来在自己开发机器上测试、再就是给公司搭建测试环境供测试同事使用。</p></blockquote><h2 id="安装使用"><a href="#安装使用" class="headerlink" title="安装使用"></a>安装使用</h2><p>我一般习惯使用docker-compose文件进行部署,方便修改:</p><p>tools.yml 文件内容如下</p><figure class="highlight yaml"><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></pre></td><td class="code"><pre><span class="line"><span class="attr">services:</span></span><br><span class="line"> <span class="comment"># docker 图形化界面工具</span></span><br><span class="line"> <span class="attr">dc-portainer:</span></span><br><span class="line"> <span class="attr">image:</span> <span class="string">portainer/portainer-ce:2.21.4</span></span><br><span class="line"> <span class="attr">container_name:</span> <span class="string">dc-portainer</span></span><br><span class="line"> <span class="attr">volumes:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">/var/run/docker.sock:/var/run/docker.sock</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">/decard/install/portainer/data:/data</span></span><br><span class="line"> <span class="attr">ports:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="number">8000</span><span class="string">:8000</span></span><br><span class="line"> <span class="bullet">-</span> <span class="number">9000</span><span class="string">:9000</span></span><br><span class="line"> <span class="bullet">-</span> <span class="number">9443</span><span class="string">:9443</span></span><br><span class="line"> <span class="attr">networks:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">my_network</span></span><br><span class="line"> <span class="attr">restart:</span> <span class="string">always</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">networks:</span></span><br><span class="line"> <span class="attr">my_network:</span></span><br><span class="line"> <span class="attr">driver:</span> <span class="string">bridge</span></span><br><span class="line"> <span class="attr">external:</span> <span class="literal">true</span></span><br></pre></td></tr></table></figure><h2 id="访问使用"><a href="#访问使用" class="headerlink" title="访问使用"></a>访问使用</h2><p>浏览器中输入<code>http://IP:9000</code>,注意开放防火墙端口。</p><h3 id="1)初次登录需要设置密码:"><a href="#1)初次登录需要设置密码:" class="headerlink" title="1)初次登录需要设置密码:"></a>1)初次登录需要设置密码:</h3><p><img src="/images/posts/docker/2/init_pages.png"></p><h3 id="2)首页"><a href="#2)首页" class="headerlink" title="2)首页"></a>2)首页</h3><p><img src="/images/posts/docker/2/home_page.png"></p><p>容器操作界面:可以看到容器的详细信息,并进行容器的操作。</p><p><img src="/images/posts/docker/2/container_page.png"></p><h2 id="汉化版本(见文末):"><a href="#汉化版本(见文末):" class="headerlink" title="汉化版本(见文末):"></a>汉化版本(见文末):</h2><p><img src="/images/posts/docker/2/cn_home.png"></p><p><img src="/images/posts/docker/2/cn_home1.png"></p><p><img src="/images/posts/docker/2/cn_container.png"></p><p>具体更详细的使用就不演示了,自行探索吧~~</p><h2 id="相关资料"><a href="#相关资料" class="headerlink" title="相关资料"></a>相关资料</h2><ul><li><code>portainer</code> 官网:<a href="https://www.portainer.io/">https://www.portainer.io/</a></li><li>如果想要使用汉化版本的,<code>portainer</code> 汉化版项目地址:<ul><li><a href="https://github.com/eysp/portainer-ce">https://github.com/eysp/portainer-ce</a>, 截止本文创建日期,版本到<code>2.19.5</code>;</li><li><code>docker hub</code> 地址:<a href="https://hub.docker.com/r/6053537/portainer-ce">https://hub.docker.com/r/6053537/portainer-ce</a></li></ul></li></ul><h2 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h2><h3 id="Q1-如果遇到镜像拉取不下来的问题怎么办?"><a href="#Q1-如果遇到镜像拉取不下来的问题怎么办?" class="headerlink" title="Q1:如果遇到镜像拉取不下来的问题怎么办?"></a>Q1:如果遇到镜像拉取不下来的问题怎么办?</h3><p>方式有很多,本文使用的是docker镜像加速。<a href="https://dockerproxy.net/">https://dockerproxy.net/</a></p><p>使用方式将上面yml中镜像地址改为:<code>dockerproxy.net/portainer/portainer-ce:2.21.4</code>。</p>]]></content>
<summary type="html"><h1 id="docker工具之可视化操作portainer介绍"><a href="#docker工具之可视化操作portainer介绍" class="headerlink" title="docker工具之可视化操作portainer介绍"></a>docker工具之可视</summary>
<category term="Docker" scheme="https://lixiaw.github.io/categories/Docker/"/>
<category term="Docker" scheme="https://lixiaw.github.io/tags/Docker/"/>
</entry>
<entry>
<title>Docker:在国产欧拉系统安装部署及docker和docker compose使用,附常用命令【建议收藏】</title>
<link href="https://lixiaw.github.io/posts/40292.html"/>
<id>https://lixiaw.github.io/posts/40292.html</id>
<published>2024-11-20T01:51:54.000Z</published>
<updated>2024-12-15T06:26:19.900Z</updated>
<content type="html"><![CDATA[<h1 id="docker:在国产欧拉系统安装部署及docker和docker-compose使用,附常用命令【建议收藏】"><a href="#docker:在国产欧拉系统安装部署及docker和docker-compose使用,附常用命令【建议收藏】" class="headerlink" title="docker:在国产欧拉系统安装部署及docker和docker compose使用,附常用命令【建议收藏】"></a>docker:在国产欧拉系统安装部署及docker和docker compose使用,附常用命令【建议收藏】</h1><h2 id="引言"><a href="#引言" class="headerlink" title="引言"></a>引言</h2><p>前面一篇文章对docker的作用和重大版本变更做了描述,有兴趣的可以去看看《》,此文不赘述。</p><blockquote><p>体会很深的一句话,送给各位:</p><p>技术虽然重要,但它本身并不直接产生巨大的或过度的价值,其价值在于如何被应用。此时选择用这篇文章来分享实现它的一部分价值。</p></blockquote><h2 id="1、docker安装和配置"><a href="#1、docker安装和配置" class="headerlink" title="1、docker安装和配置"></a>1、docker安装和配置</h2><p>操作环境如下:</p><ul><li>openEuler 24.03 LTS;获取地址:见文末【相关资料】</li><li>docker-ce-26.1.4;</li></ul><p><strong>准备工作</strong>:</p><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># 关闭 SELinux(Security-Enhanced Linux),因为 SELinux 可能会导致 Docker 的某些功能出现权限问题,尤其是与容器存储和挂载卷相关的操作。</span></span><br><span class="line"><span class="comment">#临时关闭</span></span><br><span class="line">setenforce 0</span><br><span class="line"></span><br><span class="line"><span class="comment">#永久关闭</span></span><br><span class="line">sed -i <span class="string">'s/SELINUX=enforcing/SELINUX=disabled/'</span> /etc/selinux/config</span><br><span class="line"></span><br><span class="line"><span class="comment">#状态查询</span></span><br><span class="line">sestatus</span><br></pre></td></tr></table></figure><h3 id="①-增加Docker源:"><a href="#①-增加Docker源:" class="headerlink" title="① 增加Docker源:"></a>① 增加Docker源:</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dnf config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo</span><br></pre></td></tr></table></figure><h3 id="②-增加Docker源地址:"><a href="#②-增加Docker源地址:" class="headerlink" title="② 增加Docker源地址:"></a>② 增加Docker源地址:</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sed -i <span class="string">'s/$releasever/7/g'</span> /etc/yum.repos.d/docker-ce.repo</span><br></pre></td></tr></table></figure><h3 id="③-更新缓存:"><a href="#③-更新缓存:" class="headerlink" title="③ 更新缓存:"></a>③ 更新缓存:</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dnf makecache timer</span><br></pre></td></tr></table></figure><h3 id="④-安装docker:"><a href="#④-安装docker:" class="headerlink" title="④ 安装docker:"></a>④ 安装docker:</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dnf install -y docker-ce-26.1.4</span><br></pre></td></tr></table></figure><p>等待安装完成。</p><h3 id="⑤-docker镜像加速:"><a href="#⑤-docker镜像加速:" class="headerlink" title="⑤ docker镜像加速:"></a>⑤ docker镜像加速:</h3><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> /etc/docker && vi daemon.json</span><br><span class="line"><span class="comment"># 粘贴以下内容进行保存</span></span><br><span class="line">{ <span class="string">"registry-mirrors"</span>: [</span><br><span class="line"> <span class="string">"https://hub.uuuadc.top"</span>,</span><br><span class="line"> <span class="string">"https://docker.anyhub.us.kg"</span>,</span><br><span class="line"> <span class="string">"https://dockerhub.jobcher.com"</span>,</span><br><span class="line"> <span class="string">"https://dockerhub.icu"</span>,</span><br><span class="line"> <span class="string">"https://docker.ckyl.me"</span>,</span><br><span class="line"> <span class="string">"https://docker.awsl9527.cn"</span></span><br><span class="line"> ]</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h3 id="⑥-设置docker开机自启"><a href="#⑥-设置docker开机自启" class="headerlink" title="⑥ 设置docker开机自启"></a>⑥ 设置docker开机自启</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl <span class="built_in">enable</span> docker</span><br></pre></td></tr></table></figure><h3 id="⑦-修改docker创建容器的默认ulimit配置"><a href="#⑦-修改docker创建容器的默认ulimit配置" class="headerlink" title="⑦ 修改docker创建容器的默认ulimit配置"></a>⑦ 修改docker创建容器的默认ulimit配置</h3><figure class="highlight bash"><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">vi /usr/lib/systemd/system/docker.service</span><br><span class="line"><span class="comment"># 编辑docker.service,在ExecStart命令后加上创建容器的默认ulimit配置,如下:</span></span><br><span class="line">ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --default-ulimit nofile=65535:65535</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="⑧-启动docker"><a href="#⑧-启动docker" class="headerlink" title="⑧ 启动docker"></a>⑧ 启动docker</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl start docker</span><br></pre></td></tr></table></figure><blockquote><p>注意:</p><p>如果中途已经启动docker,修改配置文件后重启需使用以下命令来使配置生效。</p><figure class="highlight bash"><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">systemctl daemon-reload</span><br><span class="line">systemctl restart docker</span><br></pre></td></tr></table></figure></blockquote><p>输入<code>docker info</code>,查看docker信息的<code>plugins</code>部分,可以看到有了<code>buildx</code>和<code>compose</code>插件,无需再单独安装<code>docker compose</code>。</p><p><img src="/images/posts/docker/2/1.png"></p><h2 id="2、docker常用命令"><a href="#2、docker常用命令" class="headerlink" title="2、docker常用命令"></a>2、docker常用命令</h2><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># 使用指定镜像运行一个容器,-p 指定端口映射;</span></span><br><span class="line">docker run -p [host_port]:[container_port] [image_name]</span><br><span class="line"></span><br><span class="line"><span class="comment">#显示状态为运行的容器</span></span><br><span class="line">docker ps </span><br><span class="line"></span><br><span class="line"><span class="comment">#显示所有容器,包括运行中的和退出的</span></span><br><span class="line">docker ps -a </span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看容器的日志</span></span><br><span class="line">docker logs 容器ID</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看容器的端口映射</span></span><br><span class="line">docker port </span><br><span class="line"></span><br><span class="line"><span class="comment">#重启一个容器</span></span><br><span class="line">docker restart 容器ID </span><br><span class="line"></span><br><span class="line"><span class="comment">#停止容器运行</span></span><br><span class="line">docker stop 容器ID </span><br><span class="line"></span><br><span class="line"><span class="comment">#删除一个容器</span></span><br><span class="line">docker <span class="built_in">rm</span> 容器ID </span><br><span class="line"></span><br><span class="line"><span class="comment">#在容器里执行一个命令</span></span><br><span class="line">docker <span class="built_in">exec</span> </span><br><span class="line"></span><br><span class="line"><span class="comment"># 进入容器控制台</span></span><br><span class="line">docker <span class="built_in">exec</span> -it 容器ID bash </span><br><span class="line"></span><br><span class="line"><span class="comment"># 镜像操作,显示所有的镜像列表</span></span><br><span class="line">docker images <span class="comment"># </span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 从镜像仓库拉取镜像</span></span><br><span class="line">docker pull </span><br><span class="line"></span><br><span class="line"><span class="comment"># 实时查看容器日志</span></span><br><span class="line">docker logs -f 容器ID</span><br></pre></td></tr></table></figure><p>这篇文章《》演示了如何快速用<code>docker</code>运行一个<code>IT-TOOLS</code>工具站,有兴趣的可以去看看。</p><h2 id="3、docker-compose"><a href="#3、docker-compose" class="headerlink" title="3、docker compose"></a>3、docker compose</h2><blockquote><p><code>docker compose</code>是用于定义和运行多容器 <code>docker</code> 应用的工具。它使用一个 <code>YAML</code> 文件(通常命名为 <code>docker-compose.yml</code>)来定义服务、网络和卷等资源。通过一条命令即可高效管理和操作这些容器。</p><p>docker compose 的命令跟docker的差不多</p></blockquote><h4 id="1-docker-compose-文件及释义"><a href="#1-docker-compose-文件及释义" class="headerlink" title="1) docker compose 文件及释义"></a>1) docker compose 文件及释义</h4><p>释义:</p><ul><li>1)<code>services</code>:定义了一个服务(容器),这里是 <code>my-prometheus</code>;</li><li>2)<code>networks</code>:定义了 Docker 网络,名为<code>my_network</code>,用于容器之间的通信;<ul><li>①<code>driver: bridge</code>,使用桥接网络模式(默认模式);容器可以通过网络名称互相通信,但主机外部无法直接访问。</li><li>②<code>external: true</code>,表示 <code>my_network</code> 是一个外部预先创建的网络,Compose 不会自动创建。所以在运行这个文件之前,需要手动创建网络<code>docker network create my_network</code>。</li></ul></li><li>3)<code>image: prom/prometheus:v2.40.1</code>,使用 Docker 镜像 <code>prom/prometheus</code>,版本为 <code>v2.40.1</code>;</li><li>4)<code>container_name: my-prometheus</code>,创建一个容器名为<code>my-prometheus</code>的prometheus容器;</li><li>5)<code>ports: - "9090:9090"</code>,端口映射, 左边是映射到宿主机的端口,右边是内部端口9090;</li><li>6)<code>volumns</code>,存储卷挂载,左边是宿主机的路径,右边是容器内部地址;</li><li>7)<code>restart: always</code>,如果容器因故停止,Docker 会自动尝试重新启动容器,适合长期运行的服务。</li><li>8)<code>networks: - my_network</code>,将容器加入名为 <code>my_network</code> 的 Docker 网络中,便于与其他容器通信</li></ul><p>docker-compose.yml 内容如下:</p><figure class="highlight yaml"><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></pre></td><td class="code"><pre><span class="line"><span class="attr">services:</span></span><br><span class="line"> </span><br><span class="line"> <span class="attr">my-prometheus:</span></span><br><span class="line"> <span class="attr">image:</span> <span class="string">prom/prometheus:v2.40.1</span></span><br><span class="line"> <span class="attr">container_name:</span> <span class="string">my-prometheus</span></span><br><span class="line"> <span class="attr">ports:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">"9090:9090"</span></span><br><span class="line"> <span class="attr">volumes:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">/data/install/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml</span></span><br><span class="line"> <span class="attr">restart:</span> <span class="string">always</span></span><br><span class="line"> <span class="attr">networks:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">my_network</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">networks:</span></span><br><span class="line"> <span class="attr">my_network:</span></span><br><span class="line"> <span class="attr">driver:</span> <span class="string">bridge</span></span><br><span class="line"> <span class="attr">external:</span> <span class="literal">true</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><p>运行服务后,通过浏览器访问 <code>http://主机IP:9090</code> 查看 Prometheus 界面。</p><h4 id="2-docker-compose-常用命令"><a href="#2-docker-compose-常用命令" class="headerlink" title="2) docker compose 常用命令"></a>2) docker compose 常用命令</h4><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># 显示所有容器</span></span><br><span class="line">docker compose ps </span><br><span class="line"></span><br><span class="line"><span class="comment">#删除所有nginx容器,镜像</span></span><br><span class="line">docker compose down </span><br><span class="line"></span><br><span class="line"><span class="comment"># 启动当前目录中docker-compose.yml文件中所有的服务; -d 用于在后台(daemon)运行Docker</span></span><br><span class="line">docker compose up -d</span><br><span class="line"></span><br><span class="line"><span class="comment"># 指定某个xxx.yml启动其中所有的服务</span></span><br><span class="line">docker compose -f xxx.yml up -d</span><br><span class="line"></span><br><span class="line"><span class="comment">#构建建启动nignx容器</span></span><br><span class="line">docker compose up -d nginx </span><br><span class="line"></span><br><span class="line"><span class="comment">#登录到nginx容器中</span></span><br><span class="line">docker compose <span class="built_in">exec</span> nginx bash </span><br><span class="line"></span><br><span class="line"><span class="comment">#重新启动nginx容器</span></span><br><span class="line">docker compose restart nginx</span><br><span class="line"></span><br><span class="line"><span class="comment">#停止nignx容器</span></span><br><span class="line">docker compose stop nginx </span><br><span class="line"></span><br><span class="line"><span class="comment">#启动nignx容器</span></span><br><span class="line">docker compose start nginx</span><br><span class="line"></span><br><span class="line"><span class="comment">#暂停nignx容器</span></span><br><span class="line">docker compose pause nginx </span><br><span class="line"></span><br><span class="line"><span class="comment">#恢复ningx容器</span></span><br><span class="line">docker compose unpause nginx </span><br><span class="line"></span><br><span class="line"><span class="comment">#查看nginx的日志 </span></span><br><span class="line">docker compose logs nginx </span><br><span class="line"></span><br><span class="line"><span class="comment">#查看nginx的实时日志</span></span><br><span class="line">docker compose logs -f nginx </span><br><span class="line"></span><br><span class="line"><span class="comment">#删除容器(删除前必须关闭容器)</span></span><br><span class="line">docker compose <span class="built_in">rm</span> nginx </span><br><span class="line"></span><br><span class="line"><span class="comment">#在php-fpm中不启动关联容器,并容器执行php -v 执行完成后删除容器</span></span><br><span class="line">docker compose run --no-deps --<span class="built_in">rm</span> php-fpm php -v </span><br><span class="line"></span><br><span class="line"><span class="comment">#验证(docker compose.yml)文件配置,当配置正确时,不输出任何内容,当文件配置错误,输出错误信息。 </span></span><br><span class="line">docker compose config -q </span><br><span class="line"></span><br><span class="line"><span class="comment">#以json的形式输出nginx的docker日志</span></span><br><span class="line">docker compose events --json nginx </span><br></pre></td></tr></table></figure><h2 id="相关资料"><a href="#相关资料" class="headerlink" title="相关资料"></a>相关资料</h2><ul><li>openEuler 24.03 LTS:<a href="https://www.openeuler.org/zh/download/?version=openEuler%2024.03%20LTS">https://www.openeuler.org/zh/download/?version=openEuler%2024.03%20LTS</a></li></ul><p>docker 以及docker compose的简单使用就到这儿了。</p><ul><li>欧拉系统介绍:《》</li></ul><h2 id="结语"><a href="#结语" class="headerlink" title="结语"></a>结语</h2><p>本文初步介绍了在openEuler系统上的<strong>docker安装</strong>、<strong>配置镜像加速</strong>、<strong>docker常用命令</strong>、<strong>docker compose文件示例及解释</strong>、<strong>docker compose常用命令</strong>等,后续还会继续分享基于在生产环境的使用。</p><p><strong>文章创建日期2024年11月20日,你好,我是程序员七平,有帮助的话还请点个关注,谢谢。</strong></p>]]></content>
<summary type="html"><h1 id="docker:在国产欧拉系统安装部署及docker和docker-compose使用,附常用命令【建议收藏】"><a href="#docker:在国产欧拉系统安装部署及docker和docker-compose使用,附常用命令【建议收藏】" class="hea</summary>
<category term="Docker" scheme="https://lixiaw.github.io/categories/Docker/"/>
<category term="Docker" scheme="https://lixiaw.github.io/tags/Docker/"/>
</entry>
<entry>
<title>Docker介绍和重大版本变更历史</title>
<link href="https://lixiaw.github.io/posts/39461.html"/>
<id>https://lixiaw.github.io/posts/39461.html</id>
<published>2024-11-19T01:51:54.000Z</published>
<updated>2024-12-15T06:26:19.899Z</updated>
<content type="html"><![CDATA[<h2 id="Docker是什么?"><a href="#Docker是什么?" class="headerlink" title="Docker是什么?"></a>Docker是什么?</h2><h3 id="Docker-的定义"><a href="#Docker-的定义" class="headerlink" title="Docker 的定义"></a>Docker 的定义</h3><p>Docker 是一个<strong>完整的容器化平台,它包含多个工具和技术,用于开发、部署和运行容器化应用程序</strong>。Docker 提供了从开发到生产的一体化工作流,帮助开发者和运维团队构建和管理容器。</p><p>Docker 包括:</p><ul><li><strong>Docker Engine</strong>:用于构建和运行容器的核心引擎。</li><li><strong>Docker CLI</strong>:与 <code>Docker Daemon</code> 交互的命令行工具。</li><li><strong>Docker Compose</strong>:用于定义和管理多容器应用的工具。</li><li><strong>Docker Hub</strong>:公共镜像仓库,用于存储和分发容器镜像。</li><li><strong>Docker Desktop</strong>:开发者友好的 <code>GUI</code> 工具,包含 <code>Docker Engine</code> 和其他工具。</li><li><strong>Docker Swarm</strong>:<ul><li>Docker 的内置容器编排工具,用于管理和部署分布式集群。</li><li>提供高可用性、负载均衡和容器调度功能。</li><li>使用简单,直接通过 <code>Docker CLI</code> 管理 <code>Swarm</code> 集群。</li></ul></li></ul><p>等等。</p><p><img src="/images/posts/docker/1/docker%E5%8C%85%E5%90%AB%E7%9A%84%E5%B7%A5%E5%85%B7.png"></p><h3 id="Docker-Engine-的定义"><a href="#Docker-Engine-的定义" class="headerlink" title="Docker Engine 的定义"></a>Docker Engine 的定义</h3><p><code>Docker Engine</code> 是 Docker 平台的核心组件,<strong>专注于容器的运行时管理</strong>。它具体包括以下部分:</p><ol><li>**Docker Daemon (<code>dockerd</code>)**:核心服务,负责实际的容器操作。</li><li>**Docker CLI (<code>docker</code>)**:命令行工具,用于与 <code>Daemon</code> 交互。</li><li><strong>REST API</strong>:允许通过编程方式与 <code>Daemon</code> 交互。</li><li><strong>Container Runtime</strong>:底层运行时,用于执行和隔离容器(如 <code>containerd</code>)。</li></ol><h3 id="Docker-与-Docker-Engine-的关系"><a href="#Docker-与-Docker-Engine-的关系" class="headerlink" title="Docker 与 Docker Engine 的关系"></a>Docker 与 Docker Engine 的关系</h3><ol><li><strong>Docker 是整个平台,Docker Engine 是其中的核心技术</strong>:<ul><li><code>Docker Engine</code> 提供容器的创建、管理、运行、网络、存储等核心功能。</li><li><code>Docker</code> 作为平台,整合了多个工具和生态系统(如 <code>Docker Compose</code>、<code>Docker Swarm</code>、<code>Docker Hub</code>)。</li></ul></li><li><strong>Docker CLI 是 Docker Engine 的一部分</strong>:<ul><li><code>Docker CLI</code> 是一个直接与 <code>Docker Engine</code> 交互的工具,是开发者使用 <code>Docker</code> 最常接触的部分。</li></ul></li><li><strong>品牌与技术的区别</strong>:<ul><li>Docker 是一个品牌,覆盖了从开发到生产的容器化工作流。</li><li><code>Docker Engine</code> 是技术栈中的运行时,用于实际操作容器。</li></ul></li></ol><p><strong>简单理解</strong>:Docker 是大框架,Docker Engine 是框架的核心技术,离开了 Docker Engine,Docker 就无法工作。</p><table><thead><tr><th>特性</th><th>Docker 平台</th><th>Docker Engine</th></tr></thead><tbody><tr><td>定义</td><td>一个容器化平台,提供全栈工具。</td><td>核心组件,负责运行容器的引擎。</td></tr><tr><td>包含内容</td><td>Docker Engine、Compose、Hub 等。</td><td>Docker Daemon、CLI、REST API 等。</td></tr><tr><td>作用</td><td>开发到生产的一体化工作流。</td><td>容器创建、管理、运行的底层运行时支持。</td></tr><tr><td>用户接触</td><td>通过 CLI、Desktop 等工具接触。</td><td>通常通过 CLI 或 API 间接操作。</td></tr></tbody></table><h2 id="Docker-版本发布历史:较大的几次版本变更"><a href="#Docker-版本发布历史:较大的几次版本变更" class="headerlink" title="Docker 版本发布历史:较大的几次版本变更"></a>Docker 版本发布历史:较大的几次版本变更</h2><p>Docker自问世以来,经历了多次重大版本变更,这些变更是为了提升性能、安全性、稳定性和用户体验。以下是一些较为重要的版本变更:</p><ul><li><p><strong>Docker Engine 1.x 系列(2013-2017)</strong></p><ul><li>Docker 项目刚刚起步,主要用于容器化和镜像管理。</li><li><code>docker-compose</code> 作为一个独立工具(由 Python 编写)于 2014 年发布。</li></ul></li><li><p><strong>Docker 1.13.1(2017 年 2 月)</strong></p><ul><li>引入 <code>docker stack</code> 命令,支持基于 Compose 文件的服务编排(Swarm 模式)。</li><li>支持 Compose v3 文件格式,优化多容器服务定义与 Swarm 集成。</li></ul></li><li><p><strong>Docker Engine 17.x(2017)(<code>Community</code> 和 <code>Enterprise</code> 分离)</strong></p><ul><li><code>Docker Engine</code> 被分为 <code>Docker CE</code>(社区版)和 <code>Docker EE</code>(企业版)。</li><li>仍然使用独立的 <code>docker-compose</code>,其功能逐步完善,支持更多的 Docker 功能,如网络和卷。</li><li><code>Compose v1</code> 成为大规模生产环境的实际标准。</li></ul></li><li><p><strong>Docker Engine 20.10(2020 年 12 月,支持 Compose v2 的起点)</strong></p><ul><li>引入了对 <strong>Compose v2</strong> 的支持(<code>docker-compose</code>v1继续保留,但逐渐转向 v2。),这是一个基于 Go 的重写版本,作为 Docker CLI 的插件运行。</li><li>v2 的主要改进包括性能优化、原生支持 Kubernetes,以及改用 <code>docker compose</code> 命令(无破折号)。</li><li>用户开始过渡到使用 <code>docker compose</code>。</li></ul></li><li><p><strong>Docker Desktop 4.4 / Docker Engine 20.10.13(2021 年底)</strong></p><ul><li>在 Docker Desktop 中,Compose v2 成为默认工具。</li><li>官方明确推荐使用 <code>docker compose</code> 命令。</li><li>在 Docker Desktop 和 Linux 系统中,<code>docker-compose-plugin</code> 替代了 <code>docker-compose</code>。<ul><li>可以通过 <code>docker compose version</code> 验证是否使用了 v2。</li></ul></li></ul></li><li><p><strong>Docker Engine 24.0(2023 年 5 月)</strong></p><ul><li>完全移除了对 <code>docker-compose</code>(v1)的支持。</li><li>Compose v2 成为唯一选项,并直接作为 Docker 的插件运行。</li><li>不再包含独立的 <code>docker-compose</code>,用户需要切换到 <code>docker compose</code>。(如果手动方式安装独立版本的话,基本还是可用的,不太建议)</li></ul></li></ul><h3 id="为了展示的更加直观一些,整理为表格如下:"><a href="#为了展示的更加直观一些,整理为表格如下:" class="headerlink" title="为了展示的更加直观一些,整理为表格如下:"></a>为了展示的更加直观一些,整理为表格如下:</h3><table><thead><tr><th>时间</th><th>Docker 版本</th><th>重要变更</th><th>对 Compose 的支持</th></tr></thead><tbody><tr><td>2014 年 10 月</td><td>Docker Compose 发布</td><td>Docker Compose (v1) 发布,作为独立工具,用于定义和管理多容器应用(以 Python 编写)。</td><td>初始支持,需单独安装 <code>docker-compose</code> 工具。</td></tr><tr><td>2017 年 2 月</td><td>Docker 1.13.1</td><td>引入 <code>docker stack</code> 命令,支持基于 Compose 文件的服务编排(Swarm 模式)。</td><td>支持 Compose v3 文件格式,优化多容器服务定义与 Swarm 集成。</td></tr><tr><td>2017 年 3 月</td><td>Docker 17.03</td><td>Docker 开始分为 CE 和 EE 版本,采用新的版本命名规则。</td><td>继续支持独立的 <code>docker-compose</code>,推荐使用 v3 文件格式进行编排。</td></tr><tr><td>2020 年 12 月</td><td>Docker 20.10</td><td>引入 Compose v2(基于 Go 重写),作为 Docker CLI 插件运行,支持 <code>docker compose</code> 命令。</td><td>初步支持 Compose v2,但 <code>docker-compose</code> 工具仍保留。</td></tr><tr><td>2021 年底</td><td>Docker 20.10.13</td><td>在 Docker Desktop 中,Compose v2 成为默认工具,推荐使用 <code>docker compose</code>。</td><td>v2 稳定版发布,独立的 <code>docker-compose</code>(v1)逐渐被弃用。</td></tr><tr><td>2023 年 5 月</td><td>Docker 24.0</td><td>完全移除对 Compose v1 的支持,Compose v2 成为唯一选项。</td><td>不再支持 <code>docker-compose</code> 命令,用户必须使用 <code>docker compose</code>。</td></tr></tbody></table><h3 id="docker-compose文件版本的变更整理为表格如下:"><a href="#docker-compose文件版本的变更整理为表格如下:" class="headerlink" title="docker compose文件版本的变更整理为表格如下:"></a>docker compose文件版本的变更整理为表格如下:</h3><table><thead><tr><th>文件格式版本</th><th>引入版本</th><th>关键特性</th><th>支持工具版本</th></tr></thead><tbody><tr><td>v1</td><td>初始版本</td><td>基础服务、网络、卷支持</td><td>Compose v1</td></tr><tr><td>v2</td><td>Docker 1.10+</td><td>网络隔离、命名卷等新特性</td><td>Compose v1</td></tr><tr><td>v3</td><td>Docker 1.13+</td><td>Swarm 支持、服务扩展、更新策略</td><td>Compose v1/v2</td></tr><tr><td>v3.9</td><td>Docker 20.10+</td><td>最新功能优化,兼容性更新</td><td>Compose v2</td></tr></tbody></table><h2 id="结语"><a href="#结语" class="headerlink" title="结语"></a>结语</h2><p>Docker 在多次版本变更中逐步增强对 Compose 的支持,从最初的独立工具到深度集成,最终形成现代化的 <code>docker compose</code> 命令,支持多容器编排的强大生态系统。</p><p>我们日常在使用docker或者其他工具的时候,尽量做到了解到其重要的版本变更(所有的版本的话那就太多了,也没有记的必要),更好地根据自己的实际需求选择合适的版本。</p>]]></content>
<summary type="html"><h2 id="Docker是什么?"><a href="#Docker是什么?" class="headerlink" title="Docker是什么?"></a>Docker是什么?</h2><h3 id="Docker-的定义"><a href="#Docker-的定义"</summary>
<category term="Docker" scheme="https://lixiaw.github.io/categories/Docker/"/>
<category term="Docker" scheme="https://lixiaw.github.io/tags/Docker/"/>
</entry>
<entry>
<title>Java系列-SpringBoot-1-入参及出参扩展XML支持</title>
<link href="https://lixiaw.github.io/posts/20998.html"/>
<id>https://lixiaw.github.io/posts/20998.html</id>
<published>2021-05-09T10:51:10.000Z</published>
<updated>2024-12-15T06:26:19.861Z</updated>
<content type="html"><![CDATA[<h2 id="Java系列-SpringBoot-1-入参及出参扩展XML支持"><a href="#Java系列-SpringBoot-1-入参及出参扩展XML支持" class="headerlink" title="Java系列-SpringBoot-1-入参及出参扩展XML支持"></a>Java系列-SpringBoot-1-入参及出参扩展XML支持</h2><h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>现在Java后端项目基本都使用json格式请求和响应数据,因此一般的配置返回json格式数据便能够满足需求。但仍有一些场景需要支持xml格式的请求和响应数据,针对此类需求,<br>本文在SpringBoot框架上进行配置说明。 </p><p>注:原spring mvc使用xml配置也支持此配置。</p><h1 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h1><ul><li>SpringBoot 版本:2.2.8.RELEASE</li></ul><h1 id="相关知识点"><a href="#相关知识点" class="headerlink" title="相关知识点"></a>相关知识点</h1><h2 id="Http请求Header中Accept和Content-Type的区别"><a href="#Http请求Header中Accept和Content-Type的区别" class="headerlink" title="Http请求Header中Accept和Content-Type的区别"></a>Http请求Header中Accept和Content-Type的区别</h2><p>Http报头分为通用报头,请求报头,响应报头和实体报头。</p><p>请求方的http报头结构:通用报头|请求报头|实体报头</p><p>响应方的http报头结构:通用报头|响应报头|实体报头</p><ul><li><code>Accept</code>:属于请求头,代表发送端(客户端)希望接受的数据类型。<ul><li><code>application/xml</code>,</li><li><code>application/json</code>;java枚举:<code>MediaType</code></li></ul></li><li><code>Content-Type</code>:代表发送端(客户端|服务器)发送的实体数据的数据类型<ul><li><code>application/xml</code>,</li><li><code>application/json</code>;java枚举:<code>MediaType</code></li></ul></li></ul><p>常见的媒体格式类型如下:</p><ul><li>text/html : HTML格式</li><li>text/plain :纯文本格式 </li><li>text/xml : XML格式</li><li>image/gif :gif图片格式 </li><li>image/jpeg :jpg图片格式 </li><li>image/png:png图片格式</li><li>multipart/form-data : 表单中进行文件上传时使用该格式</li></ul><p>以application开头的媒体格式类型:</p><ul><li>application/xhtml+xml :XHTML格式</li><li>application/xml : XML数据格式</li><li>application/atom+xml :Atom XML聚合格式 </li><li>application/json : JSON数据格式</li><li>application/pdf :pdf格式 </li><li>application/msword : Word文档格式</li><li>application/octet-stream : 二进制流数据(如常见的文件下载)</li><li>application/x-www-form-urlencoded : <form encType=””>中默认的encType,form表单数据被编码为key/value格式发送到服务器(表单默认的提交数据的格式)</li></ul><h2 id="Spring中consumes和produces的区别"><a href="#Spring中consumes和produces的区别" class="headerlink" title="Spring中consumes和produces的区别"></a>Spring中consumes和produces的区别</h2><p><code>SpringMvc</code>中如<code>@RequestMapping</code>之类的注解(<code>@PostMapping</code>等)有<code>consumes</code>和<code>produces</code>这两个属性;</p><ul><li><code>consumes</code>: 指定处理请求的提交内容类型(Content-Type),例如application/json, text/html;</li><li><code>produces</code>: 指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回;</li><li><code>params</code>: 指定request中必须包含某些参数值是,才让该方法处理</li><li><code>headers</code>: 指定request中必须包含某些指定的header值,才能让该方法处理请求</li></ul><p>使用示例:</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></pre></td><td class="code"><pre><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RequestMapping("/api/v1")</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ApiTestController</span> {</span><br><span class="line"> <span class="meta">@PostMapping(value = "/pay",</span></span><br><span class="line"><span class="meta"> consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE},</span></span><br><span class="line"><span class="meta"> produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})</span></span><br><span class="line"> <span class="keyword">public</span> ApiResponse<TestResponse> <span class="title function_">testPay</span><span class="params">(<span class="meta">@Validated</span> <span class="meta">@RequestBody</span> TestRequest request)</span> {</span><br><span class="line"> log.info(<span class="string">"测试post方法:【{}】"</span>, JSON.toJSONString(request));</span><br><span class="line"> <span class="type">TestResponse</span> <span class="variable">response</span> <span class="operator">=</span> TestResponse.builder()</span><br><span class="line"> .field1(<span class="string">"field1"</span>)</span><br><span class="line"> .field2(<span class="string">"field2"</span>)</span><br><span class="line"> .field3(<span class="string">"field3"</span>)</span><br><span class="line"> .build();</span><br><span class="line"> <span class="keyword">return</span> ApiResponse.ok(<span class="string">"请求成功"</span>, <span class="string">"1234"</span>, <span class="string">"业务成功"</span>, response);</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="SpringMVC输出格式"><a href="#SpringMVC输出格式" class="headerlink" title="SpringMVC输出格式"></a>SpringMVC输出格式</h2><p>在SpringMVC使用ContentNegotiation来判断用户请求希望得到什么格式的数据。</p><p>ContentNegotiation 设置了三种方式来设置相应数据的格式,优先级由上至下:</p><ul><li>通过请求URL后缀:/list.html 返回html格式;</li><li>通过请求的参数:/list?format=html 该设置默认不开启,默认key是format。</li><li>通过HTTP Header的Accept:Accept:application/xml</li></ul><p>本文在springboot中配置扩展xml格式:</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></pre></td><td class="code"><pre><span class="line"><span class="comment">// SpringMvc中配置(如需修改默认配置,在SpringBoot中也可这样配置)</span></span><br><span class="line"><span class="comment">// ApiMessageConverterConfig extends WebMvcConfigurerAdapter</span></span><br><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ApiMessageConverterConfig</span> <span class="keyword">implements</span> <span class="title class_">WebMvcConfigurer</span> {</span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">configureContentNegotiation</span><span class="params">(ContentNegotiationConfigurer configurer)</span> {</span><br><span class="line"> configurer</span><br><span class="line"> <span class="comment">// 是否通过请求Url的扩展名来决定media type,默认为false(不支持),扩展名指的xxx.json、xxx.xml等形式</span></span><br><span class="line"> .favorPathExtension(<span class="literal">true</span>)</span><br><span class="line"> <span class="comment">// favorParameter:这里是是否启用参数支持,默认是false(不支持);例如 /user/{userid}?format=json</span></span><br><span class="line"> .favorParameter(<span class="literal">true</span>)</span><br><span class="line"> .parameterName(<span class="string">"mediaType"</span>)</span><br><span class="line"> <span class="comment">// 不检查Accept请求头 ,默认是false(不忽略),即请求时指定的contentType:application/json等</span></span><br><span class="line"> .ignoreAcceptHeader(<span class="literal">false</span>)</span><br><span class="line"> <span class="comment">/* 设置默认的media type */</span></span><br><span class="line"> .defaultContentType(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)</span><br><span class="line"> <span class="comment">// mediaTypes:配置扩展名到mimeType的映射,json和xml的映射;</span></span><br><span class="line"> .mediaType(<span class="string">"xml"</span>, MediaType.APPLICATION_XML)</span><br><span class="line"> .mediaType(<span class="string">"html"</span>, MediaType.TEXT_HTML)</span><br><span class="line"> .mediaType(<span class="string">"json"</span>, MediaType.APPLICATION_JSON);</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>pom.xml中引入依赖:</p><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></pre></td><td class="code"><pre><span class="line"><span class="comment"><!-- 加入jackson-dataformat-xml依赖,Spring Boot就会自动引入MappingJackson2XmlHttpMessageConverter的实现:--></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>com.fasterxml.jackson.dataformat<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>jackson-dataformat-xml<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>请求实体类配置,需要使用上述依赖中<code>@JacksonXmlRootElement</code>和<code>@JacksonXmlProperty</code>注解:<br>注:xml格式的必须指定根节点;</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></pre></td><td class="code"><pre><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="meta">@Builder</span></span><br><span class="line"><span class="meta">@NoArgsConstructor</span></span><br><span class="line"><span class="meta">@AllArgsConstructor</span></span><br><span class="line"><span class="meta">@JacksonXmlRootElement(localName = "request")</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">TestRequest</span> <span class="keyword">extends</span> <span class="title class_">ApiPayV1Request</span><TestResponse> <span class="keyword">implements</span> <span class="title class_">Serializable</span> {</span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">long</span> <span class="variable">serialVersionUID</span> <span class="operator">=</span> -<span class="number">3135169148798610260L</span>;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@JacksonXmlProperty(localName = "field1")</span></span><br><span class="line"> <span class="keyword">private</span> String field1;</span><br><span class="line"> <span class="keyword">private</span> String field2;</span><br><span class="line"> <span class="keyword">private</span> String field3;</span><br><span class="line"></span><br><span class="line"> <span class="meta">@Override</span></span><br><span class="line"> <span class="keyword">public</span> Class<TestResponse> <span class="title function_">getResponseClass</span><span class="params">()</span> {</span><br><span class="line"> <span class="keyword">return</span> TestResponse.class;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br></pre></td></tr></table></figure><p>响应实体类配置,同上</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></pre></td><td class="code"><pre><span class="line"><span class="meta">@JacksonXmlRootElement(localName = "root")</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ApiResponse</span><T> <span class="keyword">implements</span> <span class="title class_">Serializable</span> {</span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">long</span> <span class="variable">serialVersionUID</span> <span class="operator">=</span> -<span class="number">3798634638472229369L</span>;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 是否成功</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@JacksonXmlProperty(localName = "success")</span></span><br><span class="line"> <span class="keyword">private</span> <span class="type">boolean</span> success;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 返回状态编码</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@JacksonXmlProperty(localName = "code")</span></span><br><span class="line"> <span class="keyword">private</span> String code;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 返回状态描述</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@JacksonXmlProperty(localName = "message")</span></span><br><span class="line"> <span class="keyword">private</span> String message;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 返回业务执行状态码</span></span><br><span class="line"><span class="comment"> * 需要特殊处理的</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@JacksonXmlProperty(localName = "sub_code")</span></span><br><span class="line"> <span class="keyword">private</span> String sub_code;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 返回业务执行状态描述</span></span><br><span class="line"><span class="comment"> * 需要特殊处理的</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@JacksonXmlProperty(localName = "sub_msg")</span></span><br><span class="line"> <span class="keyword">private</span> String sub_msg;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 接口调用时间</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@JacksonXmlProperty(localName = "time")</span></span><br><span class="line"> <span class="meta">@JsonFormat(pattern = "yyyyMMddHHmmssSSS", timezone = "GMT+8")</span></span><br><span class="line"> <span class="keyword">private</span> Timestamp time;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 接口返回数据</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@JacksonXmlProperty(localName = "data")</span></span><br><span class="line"> <span class="keyword">private</span> T data;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 接口签名</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="meta">@JacksonXmlProperty(localName = "sign")</span></span><br><span class="line"> <span class="keyword">private</span> String sign;</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure><h1 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h1><ul><li><a href="https://blog.csdn.net/shinebar/article/details/54408020">Http请求中Content-Type讲解以及在Spring MVC注解中produce和consumes配置详解</a></li><li><a href="https://segmentfault.com/a/1190000021074627">Spring Boot配置接口WebMvcConfigurer</a></li><li><a href="https://blog.csdn.net/fmwind/article/details/81235401">Spring Boot配置接口 WebMvcConfigurer</a></li></ul>]]></content>
<summary type="html"><h2 id="Java系列-SpringBoot-1-入参及出参扩展XML支持"><a href="#Java系列-SpringBoot-1-入参及出参扩展XML支持" class="headerlink" title="Java系列-SpringBoot-1-入参及出参扩展X</summary>
</entry>
<entry>
<title>Linux使用5—Linux使用5—CentOS7离线安装ftp</title>
<link href="https://lixiaw.github.io/posts/545.html"/>
<id>https://lixiaw.github.io/posts/545.html</id>
<published>2021-02-27T16:52:30.000Z</published>
<updated>2024-12-15T06:26:19.892Z</updated>
<content type="html"><![CDATA[<h1 id="CentOS-7-离线安装-FTP"><a href="#CentOS-7-离线安装-FTP" class="headerlink" title="CentOS 7 离线安装 FTP"></a>CentOS 7 离线安装 FTP</h1><h2 id="一、检查是否已经安装,什么都没出现,说明没有安装。"><a href="#一、检查是否已经安装,什么都没出现,说明没有安装。" class="headerlink" title="一、检查是否已经安装,什么都没出现,说明没有安装。"></a>一、检查是否已经安装,什么都没出现,说明没有安装。</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa | grep vsftpd</span><br></pre></td></tr></table></figure><h2 id="二、下载rpm包"><a href="#二、下载rpm包" class="headerlink" title="二、下载rpm包"></a>二、下载rpm包</h2><p>下载对应版本的FTP服务器:<a href="http://rpmfind.net/linux/rpm2html/search.php?query=vsftpd(x86-64)">http://rpmfind.net/linux/rpm2html/search.php?query=vsftpd(x86-64)</a></p><p>我下载这个<code>vsftpd-3.0.2-28.el7.x86_64.rpm</code>;</p><p>搜索 <code>ftp(x86-64)</code>下载ftp客户端,为了测试准备。我下载这个<code>ftp-0.17-67.el7.x86_64.rpm</code></p><h2 id="三、安装vsftpd"><a href="#三、安装vsftpd" class="headerlink" title="三、安装vsftpd"></a>三、安装vsftpd</h2><figure class="highlight plaintext"><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">将下载的rpm包上传到服务器,然后执行以下命令安装:</span><br><span class="line">rpm -ivh vsftpd-3.0.2-28.el7.x86_64.rpm --force --nodeps</span><br></pre></td></tr></table></figure><h2 id="四、配置ftp,主要配置-vsftpd-conf-文件"><a href="#四、配置ftp,主要配置-vsftpd-conf-文件" class="headerlink" title="四、配置ftp,主要配置 vsftpd.conf 文件"></a>四、配置ftp,主要配置 vsftpd.conf 文件</h2><p>配置文件目录<code>vim /etc/vsftpd/vsftpd.conf</code>,修改为以下内容:</p><figure class="highlight plaintext"><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></pre></td><td class="code"><pre><span class="line"># 禁止匿名登入</span><br><span class="line">anonymous_enable=NO</span><br><span class="line"></span><br><span class="line"># 对用户访问只限制在主目录,不能访问其他目录</span><br><span class="line">chroot_local_user=YES</span><br><span class="line">chroot_list_enable=NO</span><br><span class="line"># (default follows)</span><br><span class="line">chroot_list_file=/etc/vsftpd/chroot_list</span><br><span class="line">userlist_deny=NO</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">reverse_lookup_enable=NO</span><br><span class="line">allow_writeable_chroot=YES</span><br><span class="line">local_root=/home/ftp</span><br><span class="line">pasv_enable=YES</span><br><span class="line">pasv_min_port=6000</span><br><span class="line">pasv_max_port=7000</span><br></pre></td></tr></table></figure><h2 id="五、开放相关防火墙端口-21-6000-7000端口"><a href="#五、开放相关防火墙端口-21-6000-7000端口" class="headerlink" title="五、开放相关防火墙端口(21,6000-7000端口)"></a>五、开放相关防火墙端口(21,6000-7000端口)</h2><figure class="highlight plaintext"><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></pre></td><td class="code"><pre><span class="line">firewall-cmd --zone=public --add-port=6000-7000/tcp --permanent # 开放6000-7000端口</span><br><span class="line"> </span><br><span class="line">firewall-cmd --zone=public --remove-port=6000-7000/tcp --permanent #关闭6000-7000端口</span><br><span class="line"> </span><br><span class="line">firewall-cmd --reload # 配置立即生效</span><br><span class="line"> </span><br><span class="line">firewall-cmd --zone=public --list-ports #查看防火墙所有开放的端口</span><br></pre></td></tr></table></figure><p>添加ftp用户及权限</p><figure class="highlight plaintext"><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></pre></td><td class="code"><pre><span class="line">#添加用户 ftpup,并指定该用户的主目录为/home/ftp</span><br><span class="line">useradd -d /home/ftp -s /sbin/nologin ftpup</span><br><span class="line">#为用户ftpup设置密码</span><br><span class="line">passwd ftpup </span><br><span class="line">#输入用户密码 #输入密码</span><br><span class="line">#再次输入密码 #再次输入密码</span><br><span class="line"></span><br><span class="line"># 文件夹权限</span><br><span class="line">chmod -R 755 /home/ftp</span><br><span class="line">chown -R ftpup /home/ftp</span><br></pre></td></tr></table></figure><p>重启ftp</p><figure class="highlight plaintext"><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">#停止ftp</span><br><span class="line">service vsftpd stop</span><br><span class="line">#启动ftp</span><br><span class="line">service vsftpd start </span><br><span class="line">#重启ftp</span><br><span class="line">service vsftpd restart </span><br></pre></td></tr></table></figure><h1 id="安装ftp客户端"><a href="#安装ftp客户端" class="headerlink" title="安装ftp客户端"></a>安装ftp客户端</h1><h2 id="一、同样先检查是否安装:"><a href="#一、同样先检查是否安装:" class="headerlink" title="一、同样先检查是否安装:"></a>一、同样先检查是否安装:</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rpm -qa | grep ftp</span><br></pre></td></tr></table></figure><h2 id="二、以强制安装方式-进行安装:"><a href="#二、以强制安装方式-进行安装:" class="headerlink" title="二、以强制安装方式 进行安装:"></a>二、以强制安装方式 进行安装:</h2><figure class="highlight plaintext"><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">rpm -ivh ftp-0.17-67.el7.x86_64.rpm --force --nodeps</span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="三、测试"><a href="#三、测试" class="headerlink" title="三、测试"></a>三、测试</h2><figure class="highlight plaintext"><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">ftp localhost</span><br><span class="line">#输入用户名</span><br><span class="line">#输入密码</span><br><span class="line">#提示:login successful </span><br></pre></td></tr></table></figure><h2 id="四、常用命令"><a href="#四、常用命令" class="headerlink" title="四、常用命令"></a>四、常用命令</h2><p>1、将源主机文件传到连接的主机上 </p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">put 源文件路径 目标文件路径 </span><br></pre></td></tr></table></figure><p>2、将目标主机文件传到源主机上 </p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">get 目标文件路径 源文件路径 </span><br></pre></td></tr></table></figure><p>3、退出</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">quit</span><br></pre></td></tr></table></figure><h1 id="问题一:"><a href="#问题一:" class="headerlink" title="问题一:"></a>问题一:</h1><blockquote><p>Connected to localhost (::1).<br> 220 (vsFTPd 3.0.2)<br> Name (localhost:root): ftpup<br> 530 Permission denied.</p></blockquote><p>处理:<code>/etc/vsftpd/vsftpd.conf</code>中一下内容从<code>YES</code>修改为<code>NO</code>,如下<br><code>userlist_enable=NO</code></p><h1 id="问题二:"><a href="#问题二:" class="headerlink" title="问题二:"></a>问题二:</h1><blockquote><p>331 Please specify the password.</p></blockquote><p>出现错误的原因,是因为ubuntu启用了PAM,所在用到vsftp时需要用到 /etc/pam.d/vsftpd 这个文件(默认源码安装的不会有这个文件),因此除了匿名用户外本地用户无法登录。所以解决的办法就是删除这个文件</p><p>处理:<code>rm /etc/pam.d/vsftpd</code> </p><p><a href="https://blog.csdn.net/yunhan0609/article/details/83055883">https://blog.csdn.net/yunhan0609/article/details/83055883</a></p>]]></content>
<summary type="html"><h1 id="CentOS-7-离线安装-FTP"><a href="#CentOS-7-离线安装-FTP" class="headerlink" title="CentOS 7 离线安装 FTP"></a>CentOS 7 离线安装 FTP</h1><h2 id="一、检查是</summary>
</entry>
<entry>
<title>Linux使用6—CentOS7运维常用命令</title>
<link href="https://lixiaw.github.io/posts/1154.html"/>
<id>https://lixiaw.github.io/posts/1154.html</id>
<published>2021-02-27T16:52:30.000Z</published>
<updated>2024-12-15T06:26:19.892Z</updated>
<content type="html"><![CDATA[<h1 id="Linux使用6—CentOS7运维常用命令"><a href="#Linux使用6—CentOS7运维常用命令" class="headerlink" title="Linux使用6—CentOS7运维常用命令"></a>Linux使用6—CentOS7运维常用命令</h1><h2 id="一、linux下进程号查看和pid查看端口号"><a href="#一、linux下进程号查看和pid查看端口号" class="headerlink" title="一、linux下进程号查看和pid查看端口号"></a>一、linux下进程号查看和pid查看端口号</h2><blockquote><p>根据ps -aux | grep xxx就是很快实现进程名和进程号的互查, 所以我们只说进程号pid就行。 如下示例中, 进程pid常驻。</p></blockquote><figure class="highlight plaintext"><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></pre></td><td class="code"><pre><span class="line">1. 根据进程pid查端口:</span><br><span class="line"> lsof -i | grep pid</span><br><span class="line">2. 根据端口port查进程(某次面试还考过):</span><br><span class="line"> lsof -i:port </span><br><span class="line">3. 根据进程pid查端口:</span><br><span class="line"> netstat -nap | grep pid</span><br><span class="line">4. 根据端口port查进程:</span><br><span class="line"> netstat -nap | grep port</span><br></pre></td></tr></table></figure><h2 id="二、linux下top命令使用"><a href="#二、linux下top命令使用" class="headerlink" title="二、linux下top命令使用"></a>二、linux下top命令使用</h2><blockquote><p>top命令用于实时监测系统资源使用状况,包含,进程、cpu,内存等。</p></blockquote><figure class="highlight plaintext"><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></pre></td><td class="code"><pre><span class="line"> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND </span><br><span class="line">14410 root 20 0 5532880 1.2g 23764 S 3.0 16.8 1:00.47 java </span><br><span class="line">31869 root 10 -10 140084 12096 1392 S 0.7 0.2 6:01.34 AliYunDun </span><br><span class="line"> 2767 mysql 20 0 2681972 464940 0 S 0.3 6.0 33:13.39 mysqld </span><br><span class="line"> 3370 root 20 0 5693644 1.0g 2224 S 0.3 13.9 2:21.60 java </span><br><span class="line"> 8278 root 20 0 5783204 1.3g 1288 S 0.3 17.7 227:28.38 java </span><br><span class="line">24825 root 20 0 50304 8684 128 S 0.3 0.1 38:29.82 redis-server </span><br><span class="line">27133 root 20 0 5654132 990464 0 S 0.3 12.8 4:44.72 java </span><br><span class="line"> 1 root 20 0 51752 2636 1224 S 0.0 0.0 0:19.22 systemd </span><br></pre></td></tr></table></figure><h2 id="三、linux下free命令使用"><a href="#三、linux下free命令使用" class="headerlink" title="三、linux下free命令使用"></a>三、linux下free命令使用</h2><figure class="highlight plaintext"><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></pre></td><td class="code"><pre><span class="line"># total:表示 总计物理内存的大小。used+free+buff/cache</span><br><span class="line"># used:表示 已使用多少。</span><br><span class="line"># free:表示 可用内存多少。</span><br><span class="line"># Shared:表示多个进程共享的内存总额。</span><br><span class="line"># Buffers/cached:表示 磁盘缓存的大小。</span><br><span class="line">available: 是一个估计值,比较准确</span><br><span class="line"> total used free shared buff/cache available</span><br><span class="line">Mem: 7.4G 5.3G 1.6G 760K 487M 1.9G</span><br><span class="line">Swap: 0B 0B 0B</span><br><span class="line"></span><br><span class="line">top和free看的结果一致;</span><br><span class="line">free命令中used的结果,不包含buffer/cache</span><br><span class="line">旧版本的free命令才有:-/+ buffers/cache,新版的加入了available参数</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><h1 id="Linux使用6—CentOS7运维常用命令"><a href="#Linux使用6—CentOS7运维常用命令" class="headerlink" title="Linux使用6—CentOS7运维常用命令"></a>Linux使用6—CentOS7运维常用</summary>
</entry>
<entry>
<title>Linux使用1-1—Centos7离线安装MySQL服务</title>
<link href="https://lixiaw.github.io/posts/8928.html"/>
<id>https://lixiaw.github.io/posts/8928.html</id>
<published>2021-02-27T10:01:28.000Z</published>
<updated>2024-12-15T06:26:19.888Z</updated>
<content type="html"><![CDATA[<h2 id="Centos7离线安装MySQL服务"><a href="#Centos7离线安装MySQL服务" class="headerlink" title="Centos7离线安装MySQL服务"></a>Centos7离线安装MySQL服务</h2><span id="more"></span><h1 id="0-前言"><a href="#0-前言" class="headerlink" title="0 前言"></a>0 前言</h1><p>网上已经有那么多的关于<code>CentOS 7</code>如何安装<code>MySQL</code>的文章了,但是很多都是在线安装;<br>由于很多时候,在生产环境进行部署时,生产机器都是不可能直接连公网的,导致网上很多的文章没有借鉴意义;</p><h1 id="1-下载"><a href="#1-下载" class="headerlink" title="1 下载"></a>1 下载</h1><p>在有网的环境下载 <code>mysql</code> 的安装包:</p><p><a href="http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz">http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz</a></p><p>或者去<a href="https://dev.mysql.com/downloads/mysql/">点击访问官网</a>点击下载:</p><p>并把 安装包<code>mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz</code>拷贝到 离线生产环境<code>/usr/local</code>目录下。</p><h1 id="2-安装"><a href="#2-安装" class="headerlink" title="2 安装"></a>2 安装</h1><h2 id="2-1-创建用户"><a href="#2-1-创建用户" class="headerlink" title="2.1 创建用户"></a>2.1 创建用户</h2><p>为了方便数据库管理,对于安装的<code>MySQL</code>数据库,生产上我们都会建立一个<code>mysql</code>用户和<code>mysql</code>用户组:</p><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># 添加mysql用户组</span></span><br><span class="line">groupadd mysql</span><br><span class="line"></span><br><span class="line"><span class="comment"># 添加mysql用户</span></span><br><span class="line">useradd -g mysql mysql -d /home/mysql</span><br><span class="line"></span><br><span class="line"><span class="comment"># 修改mysql用户的登陆密码</span></span><br><span class="line">passwd mysql</span><br></pre></td></tr></table></figure><h2 id="2-2-解压缩"><a href="#2-2-解压缩" class="headerlink" title="2.2 解压缩"></a>2.2 解压缩</h2><p>在<code>/usr/local/</code>中解压压缩包,并改名为<code>mysql</code></p><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> /usr/local/</span><br><span class="line"></span><br><span class="line">tar -xzvf /data/software/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz (我的下载目录为 data/software)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 改名为mysql</span></span><br><span class="line"><span class="built_in">mv</span> mysql-5.7.13-linux-glibc2.5-x86_64 mysql</span><br><span class="line"></span><br><span class="line"><span class="comment"># 并赋予用户读写权限(此处也可以换位你的用户)</span></span><br><span class="line"><span class="built_in">chown</span> -R mysql:mysql mysql/</span><br></pre></td></tr></table></figure><h2 id="2-3-创建配置文件"><a href="#2-3-创建配置文件" class="headerlink" title="2.3 创建配置文件"></a>2.3 创建配置文件</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/my.cnf</span><br></pre></td></tr></table></figure><p>复制以下内容:</p><figure class="highlight ini"><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"><span class="section">[client]</span></span><br><span class="line"><span class="attr">port</span> = <span class="number">3306</span></span><br><span class="line"><span class="attr">socket</span> = /tmp/mysql.sock</span><br><span class="line"></span><br><span class="line"><span class="section">[mysqld]</span></span><br><span class="line"><span class="attr">character_set_server</span>=utf8</span><br><span class="line"><span class="attr">init_connect</span>=<span class="string">'SET NAMES utf8'</span></span><br><span class="line"><span class="attr">basedir</span>=/usr/local/mysql</span><br><span class="line"><span class="attr">datadir</span>=/usr/local/mysql/data</span><br><span class="line"><span class="attr">socket</span>=/tmp/mysql.sock</span><br><span class="line"><span class="attr">log-error</span>=/var/log/mysqld.log</span><br><span class="line"><span class="attr">pid-file</span>=/var/run/mysqld/mysqld.pid</span><br><span class="line"></span><br><span class="line"><span class="comment">#不区分大小写</span></span><br><span class="line"><span class="attr">lower_case_table_names</span> = <span class="number">1</span></span><br><span class="line"></span><br><span class="line"><span class="attr">sql_mode</span>=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION</span><br><span class="line"></span><br><span class="line"><span class="attr">max_connections</span>=<span class="number">5000</span></span><br><span class="line"></span><br><span class="line"><span class="attr">default-time_zone</span> = <span class="string">'+8:00'</span></span><br></pre></td></tr></table></figure><h2 id="2-4-初始化文件"><a href="#2-4-初始化文件" class="headerlink" title="2.4 初始化文件"></a>2.4 初始化文件</h2><blockquote><p>1、初始化<code>log</code>文件,防止没有权限。</p></blockquote><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment">#手动编辑一下日志文件,什么也不用写,直接保存退出</span></span><br><span class="line"><span class="built_in">cd</span> /var/log/</span><br><span class="line"></span><br><span class="line">vim mysqld.log</span><br><span class="line">:wq</span><br><span class="line"></span><br><span class="line"><span class="built_in">chmod</span> 777 mysqld.log</span><br><span class="line"><span class="built_in">chown</span> mysql:mysql mysqld.log</span><br></pre></td></tr></table></figure><blockquote><p>2、初始化<code>pid</code>文件,防止没有权限。</p></blockquote><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment">#手动编辑一下日志文件,什么也不用写,直接保存退出</span></span><br><span class="line"><span class="built_in">cd</span> /var/run/</span><br><span class="line"><span class="built_in">mkdir</span> mysqld</span><br><span class="line"><span class="built_in">cd</span> mysqld</span><br><span class="line">vi mysqld.pid</span><br><span class="line">:wq</span><br><span class="line"><span class="comment"># 给权限</span></span><br><span class="line"><span class="built_in">cd</span> ..</span><br><span class="line"><span class="built_in">chmod</span> 777 mysqld</span><br><span class="line"><span class="built_in">chown</span> -R mysql:mysql /mysqld</span><br></pre></td></tr></table></figure><blockquote><p>3、初始化数据库</p></blockquote><figure class="highlight bash"><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"><span class="comment"># 初始化数据库,并指定启动mysql的用户,否则就会在启动MySQL时出现权限不足的问题</span></span><br><span class="line">/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US</span><br></pre></td></tr></table></figure><p>初始化完成后,在<code>my.cnf</code>中配置的<code>datadir</code>目录(<code>/var/log/mysqld.log</code>)下生成一个<code>error.log</code>文件,里面记录了<code>root</code>用户的随机密码。</p><figure class="highlight bash"><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">cat</span> /var/log/mysqld.log</span><br></pre></td></tr></table></figure><p>执行后记录查看到文件中最后一行:<code>root@localhost: xxxxx </code> 这里的<code>xxxxx</code>就是初始密码。</p><h2 id="2-5-启动数据库"><a href="#2-5-启动数据库" class="headerlink" title="2.5 启动数据库"></a>2.5 启动数据库</h2><p>启动数据库</p><figure class="highlight bash"><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"><span class="comment">#源目录启动:</span></span><br><span class="line">/usr/local/mysql/support-files/mysql.server start</span><br></pre></td></tr></table></figure><p>并设置开机自启动服务:</p><figure class="highlight bash"><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="comment"># 复制启动脚本到资源目录</span></span><br><span class="line"><span class="built_in">cp</span> /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld</span><br><span class="line"></span><br><span class="line"><span class="comment"># 增加mysqld服务控制脚本执行权限</span></span><br><span class="line"><span class="built_in">chmod</span> +x /etc/rc.d/init.d/mysqld</span><br><span class="line"></span><br><span class="line"><span class="comment"># 将mysqld服务加入到系统服务</span></span><br><span class="line">chkconfig --add mysqld</span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查mysqld服务是否已经生效</span></span><br><span class="line">chkconfig --list mysqld</span><br><span class="line"></span><br><span class="line"><span class="comment"># 切换至mysql用户,启动mysql,或者稍后下一步再启动。</span></span><br><span class="line">service mysqld start </span><br></pre></td></tr></table></figure><p>从此就可以使用<code>service mysqld</code>命令启动/停止服务:</p><figure class="highlight bash"><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">su mysql</span><br><span class="line"></span><br><span class="line">service mysqld start/stop/restart/status</span><br></pre></td></tr></table></figure><h2 id="2-6-配置环境变量"><a href="#2-6-配置环境变量" class="headerlink" title="2.6 配置环境变量"></a>2.6 配置环境变量</h2><p>为了更好的操作<code>mysql</code>,配置环境变量。</p><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># 切换至mysql用户</span></span><br><span class="line">su mysql</span><br><span class="line"></span><br><span class="line">vi .bash_profile</span><br><span class="line"><span class="comment"># 修改配置文件,增加export PATH=$PATH:/usr/local/mysql/bin</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 立即生效</span></span><br><span class="line"><span class="built_in">source</span> .bash_profile</span><br></pre></td></tr></table></figure><h2 id="2-7-登陆,修改密码"><a href="#2-7-登陆,修改密码" class="headerlink" title="2.7 登陆,修改密码"></a>2.7 登陆,修改密码</h2><p>必须修改初始的随机密码:</p><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># 系统默认会查找/usr/bin下的命令;建立一个链接文件。</span></span><br><span class="line"><span class="built_in">ln</span> -s /usr/local/mysql/bin/mysql /usr/bin</span><br><span class="line"></span><br><span class="line"><span class="comment"># 登陆mysql的root用户</span></span><br><span class="line">mysql -uroot -p</span><br><span class="line"><span class="comment"># 输入2.4生成的 随机密码</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 修改root用户密码为123456</span></span><br><span class="line"><span class="built_in">set</span> password <span class="keyword">for</span> root@localhost=password(<span class="string">"123456"</span>);</span><br></pre></td></tr></table></figure><h1 id="3-使用mysql"><a href="#3-使用mysql" class="headerlink" title="3 使用mysql"></a>3 使用mysql</h1><p>##3.1 用户建立<br>以下命令只需要改动用户名和密码:</p><figure class="highlight bash"><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">grant all privileges on *.* to <span class="string">'新用户名'</span>@<span class="string">'%'</span> identified by <span class="string">'新密码'</span>;</span><br><span class="line"></span><br><span class="line">flush privileges;</span><br></pre></td></tr></table></figure><p>其中通配符%表示让该用户可以从任意远程主机登陆。</p><p>##3.2 创建数据库<br>登陆用户后:</p><figure class="highlight bash"><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="comment"># 查询现有的数据库:</span></span><br><span class="line">show databases;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建</span></span><br><span class="line">CREATE DATABASE 数据库名;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 进入数据库:</span></span><br><span class="line">use 数据库名;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看所有的表</span></span><br><span class="line">show tables;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 退出:</span></span><br><span class="line"><span class="built_in">exit</span></span><br></pre></td></tr></table></figure><h1 id="参考文献:"><a href="#参考文献:" class="headerlink" title="参考文献:"></a>参考文献:</h1><ul><li>《Linux CentOS 7离线安装MySQL 5.7》<a href="https://blog.csdn.net/u012052268/article/details/103923056">https://blog.csdn.net/u012052268/article/details/103923056</a></li><li>《CentOS 7离线安装MySQL 5.7》<a href="https://www.jellythink.com/archives/14">https://www.jellythink.com/archives/14</a></li><li>《linux 安装MySql 5.7.20 操作步骤【亲测】》<a href="https://segmentfault.com/a/1190000012703513">https://segmentfault.com/a/1190000012703513</a></li></ul>]]></content>
<summary type="html"><h2 id="Centos7离线安装MySQL服务"><a href="#Centos7离线安装MySQL服务" class="headerlink" title="Centos7离线安装MySQL服务"></a>Centos7离线安装MySQL服务</h2></summary>
</entry>
<entry>
<title>Shiro系列-常见问题处理</title>
<link href="https://lixiaw.github.io/posts/58218.html"/>
<id>https://lixiaw.github.io/posts/58218.html</id>
<published>2020-01-10T13:41:20.000Z</published>
<updated>2024-12-15T06:26:19.874Z</updated>
<content type="html"><![CDATA[<h3 id="错误一"><a href="#错误一" class="headerlink" title="错误一"></a>错误一</h3><h4 id="错误描述:"><a href="#错误描述:" class="headerlink" title="错误描述:"></a>错误描述:</h4><blockquote><p>ERROR [authentication_cache.data] net.sf.ehcache.store.disk.DiskStorageFactory - Disk Write of weyoung failed:<br>java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource</p></blockquote><span id="more"></span><h4 id="错误原因:"><a href="#错误原因:" class="headerlink" title="错误原因:"></a>错误原因:</h4><ul><li>因为ehcache开启了缓存存储到物理影片上,所以需要序列化对象;</li><li>SimpleByteSource没有默认构造方法,导致反序列化的时候失败。</li></ul><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></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">cache</span> <span class="attr">name</span>=<span class="string">"authentication_cache"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">maxElementsInMemory</span>=<span class="string">"1000"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">eternal</span>=<span class="string">"true"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">timeToIdleSeconds</span>=<span class="string">"0"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">timeToLiveSeconds</span>=<span class="string">"0"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">overflowToDisk</span>=<span class="string">"true"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">diskPersistent</span>=<span class="string">"true"</span></span></span><br><span class="line"><span class="tag"> <span class="attr">memoryStoreEvictionPolicy</span>=<span class="string">"LRU"</span>/></span></span><br></pre></td></tr></table></figure><h4 id="解决办法:"><a href="#解决办法:" class="headerlink" title="解决办法:"></a>解决办法:</h4><p>新建类:</p><p><code>ByteSourceUtils.java</code></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></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ByteSourceUtils</span> {</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> ByteSource <span class="title function_">bytes</span><span class="params">(<span class="type">byte</span>[] bytes)</span> {</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">MySimpleByteSource</span>(bytes);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">static</span> ByteSource <span class="title function_">bytes</span><span class="params">(String arg0)</span> {</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">MySimpleByteSource</span>(arg0.getBytes());</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>新建类:</p><p><code>MySimpleByteSource.java</code></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></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Author</span> Mr.wang</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Description</span> shiro 使用缓存时出现:java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource</span></span><br><span class="line"><span class="comment"> * 序列化后,无法反序列化的问题</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Date</span> 2020/1/10</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MySimpleByteSource</span> <span class="keyword">extends</span> <span class="title class_">SimpleByteSource</span> <span class="keyword">implements</span> <span class="title class_">Serializable</span> {</span><br><span class="line"></span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">long</span> <span class="variable">serialVersionUID</span> <span class="operator">=</span> <span class="number">2719919888511993867L</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">public</span> <span class="title function_">MySimpleByteSource</span><span class="params">(<span class="type">byte</span>[] bytes)</span> {</span><br><span class="line"> <span class="built_in">super</span>(bytes);</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><h3 id="错误一"><a href="#错误一" class="headerlink" title="错误一"></a>错误一</h3><h4 id="错误描述:"><a href="#错误描述:" class="headerlink" title="错误描述:"></a>错误描述:</h4><blockquote>
<p>ERROR [authentication_cache.data] net.sf.ehcache.store.disk.DiskStorageFactory - Disk Write of weyoung failed:<br>java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource</p>
</blockquote></summary>
</entry>
<entry>
<title>SSM报错处理</title>
<link href="https://lixiaw.github.io/posts/5641.html"/>
<id>https://lixiaw.github.io/posts/5641.html</id>
<published>2020-01-05T16:01:53.000Z</published>
<updated>2024-12-15T06:26:19.864Z</updated>
<content type="html"><![CDATA[<h3 id="错误描述一"><a href="#错误描述一" class="headerlink" title="错误描述一"></a>错误描述一</h3><blockquote><p>org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header<br> Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.<br> java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986<br> at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:476)<br> at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687)<br> at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)<br> at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)<br> at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)<br> at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)<br> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)<br> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)<br> at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)<br> at java.lang.Thread.run(Thread.java:748)</p></blockquote><span id="more"></span><p>问题原因:</p><p>加载图片时,<code><img src=""></code> 中的路径中有特殊字符。</p><p>解决方式:</p><ul><li>去除URL中的特殊字符;</li><li>使用 Post 方法提交数据</li><li>更换低版本的Tomcat来规避这种问题。本文使用8.5.27版本的tomcat出现此问题;之前有类似的错误,8.5.6版本未出现过此类问题;</li><li>在 Tomcat conf/catalina.properties 添加或者修改:</li></ul><figure class="highlight bash"><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="comment"># 添加 </span></span><br><span class="line">tomcat.util.http.parser.HttpParser.requestTargetAllow=|{} </span><br><span class="line"><span class="comment"># 【实测】添加了上述文件后,仍然会有400错误,在加上 encodeURIComponent方法对url进行编码之后,就可以了,希望对您有用;</span></span><br><span class="line"><span class="comment"># 【实测】使用8.5.6版本的Tomcat,该问题得到解决;</span></span><br></pre></td></tr></table></figure><p>Tomcat在 7.0.73, 8.0.39, 8.5.7 版本后,添加了对于http头的验证。具体来说,就是添加了些规则去限制HTTP头的规范性org.apache.tomcat.util.http.parser.HttpParser#IS_NOT_REQUEST_TARGET[]中定义了一堆not request targetif(IS_CONTROL[i] || i > 127 || i == 32 || i == 34 || i == 35 || i == 60 || i == 62 || i == 92 || i == 94 || i == 96 || i == 123 || i == 124 || i == 125) {IS_NOT_REQUEST_TARGET[i] = true;}转换过来就是以下字符(对应10进制ASCII看):键盘上那些控制键:(<32或者=127)非英文字符(>127)空格(32)双引号(34)#(35)<(60)>(62)反斜杠(92)^(94)TAB上面那个键,我也不晓得嫩个读(96){(123)}(124)|(125)</p><h3 id="错误描述二"><a href="#错误描述二" class="headerlink" title="错误描述二"></a>错误描述二</h3><blockquote><p>javax.management.InstanceNotFoundException: com.alibaba.druid:type=DruidDataSourceStat</p></blockquote><p>原因:在一台服务器上启动了两个tomcat,两个tomcat都是用druid。</p><p>解决方案:</p><p>修改Tomcat 下的 catalina.sh:<br>修改Tomcat 下bin目录下的的 catalina.sh,:在# OS specific support. $var <em>must</em> be set to either true or false.与cygwin=false之间<br>增加此句代码: JAVA_OPTS=”-Ddruid.registerToSysProperty=true”</p><h3 id="错误描述三"><a href="#错误描述三" class="headerlink" title="错误描述三"></a>错误描述三</h3><p>tomcat下启动多个应用时可能遇到的异常:</p><blockquote><p>11-Jan-2020 17:38:17.244 信息 [mysql-cj-abandoned-connection-cleanup] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.<br> java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.<br> at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1311)<br> at org.apache.catalina.loader.WebappClassLoaderBase.getResource(WebappClassLoaderBase.java:986)<br> at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.checkThreadContextClassLoader(AbandonedConnectionCleanupThread.java:117)<br> at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:84)<br> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)<br> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)<br> at java.lang.Thread.run(Thread.java:748)</p></blockquote><p>原因:从日志文件可以看出是说Web应用程序根系统属性已经被设置,’webapp.root’ 这个配置名称已经被使用,提示了Choose unique values for the ‘webAppRootKey’ context-param in your web.xml files ,也就是说在web.xml里配置一个唯一的’webAppRootKey’ ,这样就不会发生冲突。</p><p>解决办法<br>在web.xml指定webAppRootKey</p><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></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">context-param</span>></span> </span><br><span class="line"> <span class="tag"><<span class="name">param-name</span>></span>webAppRootKey<span class="tag"></<span class="name">param-name</span>></span> </span><br><span class="line"> <span class="tag"><<span class="name">param-value</span>></span>myapp.root<span class="tag"></<span class="name">param-value</span>></span> </span><br><span class="line"><span class="tag"></<span class="name">context-param</span>></span> </span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><h3 id="错误描述一"><a href="#错误描述一" class="headerlink" title="错误描述一"></a>错误描述一</h3><blockquote>
<p>org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header<br> Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.<br> java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986<br> at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:476)<br> at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:687)<br> at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)<br> at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)<br> at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)<br> at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)<br> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)<br> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)<br> at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)<br> at java.lang.Thread.run(Thread.java:748)</p>
</blockquote></summary>
</entry>
<entry>
<title>SSM框架-整合笔记11-配置Redis</title>
<link href="https://lixiaw.github.io/posts/10752.html"/>
<id>https://lixiaw.github.io/posts/10752.html</id>
<published>2019-12-16T14:03:26.000Z</published>
<updated>2024-12-15T06:26:19.868Z</updated>
<content type="html"><![CDATA[<h2 id="配置redis报错"><a href="#配置redis报错" class="headerlink" title="配置redis报错"></a>配置redis报错</h2><blockquote><p>org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field ‘redis_allMenuTree’ cannot be found on object of type ‘org.springframework.cache.interceptor.CacheExpressionRootObject’ - maybe not public?</p></blockquote><h3 id="报错原因"><a href="#报错原因" class="headerlink" title="报错原因"></a>报错原因</h3><p>// @Cacheable 上面的错误是因为:注解中key的值变量之前没有加#(井号)</p><h3 id="解决"><a href="#解决" class="headerlink" title="解决"></a>解决</h3><figure class="highlight java"><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"><span class="meta">@Cacheable(value = CACHE_REDIS_PREFIX + "menus", key = "#sysUser.userId")</span></span><br><span class="line"><span class="keyword">public</span> List<BaseMenuVo> <span class="title function_">queryMenuTree</span><span class="params">(SysUserVo sysUser)</span>;</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><h2 id="配置redis报错"><a href="#配置redis报错" class="headerlink" title="配置redis报错"></a>配置redis报错</h2><blockquote>
<p>org.springframework.expressio</summary>
</entry>
<entry>
<title>SSM框架-整合笔记10-配置工作流Activiti</title>
<link href="https://lixiaw.github.io/posts/11858.html"/>
<id>https://lixiaw.github.io/posts/11858.html</id>
<published>2019-12-15T17:04:59.000Z</published>
<updated>2024-12-15T06:26:19.867Z</updated>
<content type="html"><![CDATA[<h2 id="配置工作流Activiti"><a href="#配置工作流Activiti" class="headerlink" title="配置工作流Activiti"></a>配置工作流Activiti</h2><h3 id="添加依赖"><a href="#添加依赖" class="headerlink" title="添加依赖"></a>添加依赖</h3><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><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">activiti.version</span>></span>5.17.0<span class="tag"></<span class="name">activiti.version</span>></span></span><br><span class="line"></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.activiti<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>activiti-engine<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>${activiti.version}<span class="tag"></<span class="name">version</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.activiti<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>activiti-bpmn-model<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>${activiti.version}<span class="tag"></<span class="name">version</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.activiti<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>activiti-rest<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>${activiti.version}<span class="tag"></<span class="name">version</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.activiti<span class="tag"></<span class="name">groupId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">artifactId</span>></span>activiti-spring<span class="tag"></<span class="name">artifactId</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">version</span>></span>${activiti.version}<span class="tag"></<span class="name">version</span>></span></span><br><span class="line"><span class="tag"></<span class="name">dependency</span>></span></span><br></pre></td></tr></table></figure><h2 id="报错"><a href="#报错" class="headerlink" title="报错"></a>报错</h2><blockquote><p>execute error. select * from ACT_GE_PROPERTY where NAME_ = ?<br>java.sql.SQLSyntaxErrorException: Table ‘lx_parent.act_ge_property’ doesn’t exist</p></blockquote><p>问题出现的原因:<br>出现这种问题的原因是mysql版本问题,mysql8.xxx以上驱动会出现这个问题。<br>因为mysql使用schema标识库名而不是catalog,因此mysql会扫描所有的库来找表,如果其他库中有相同名称的表,activiti就以为找到了,本质上这个表在当前数据库中并不存在。<br>设置nullCatalogMeansCurrent=true,表示mysql默认当前数据库操作,在mysql-connector-java 5.xxx该参数默认为true,在6.xxx以上默认为false,因此需要设置nullCatalogMeansCurrent=true。</p>]]></content>
<summary type="html"><h2 id="配置工作流Activiti"><a href="#配置工作流Activiti" class="headerlink" title="配置工作流Activiti"></a>配置工作流Activiti</h2><h3 id="添加依赖"><a href="#添加依赖"</summary>
</entry>
<entry>
<title>Nginx反向代理和负载均衡使用</title>
<link href="https://lixiaw.github.io/posts/9986.html"/>
<id>https://lixiaw.github.io/posts/9986.html</id>
<published>2019-12-13T15:19:09.000Z</published>
<updated>2024-12-15T06:26:19.893Z</updated>
<content type="html"><![CDATA[<h2 id="业务场景"><a href="#业务场景" class="headerlink" title="业务场景"></a>业务场景</h2><p>部署两个tomcat,一个端口8080、另一个端口8081,使用nginx作为反向代理服务器。</p><h2 id="问题描述"><a href="#问题描述" class="headerlink" title="问题描述"></a>问题描述</h2><p>直接访问具体端口进行访问并登录,程序能够正常使用。但是通过nginx访问程序时,登录是状态为302(Moved Temporarily)。</p><p>问题即:nginx代理多次导致302问题</p>]]></content>
<summary type="html"><h2 id="业务场景"><a href="#业务场景" class="headerlink" title="业务场景"></a>业务场景</h2><p>部署两个tomcat,一个端口8080、另一个端口8081,使用nginx作为反向代理服务器。</p>
<h2 id="问题</summary>
</entry>
<entry>
<title>Linux使用4—CentOS7安装Docker及基本使用</title>
<link href="https://lixiaw.github.io/posts/6812.html"/>
<id>https://lixiaw.github.io/posts/6812.html</id>
<published>2019-12-12T01:51:56.000Z</published>
<updated>2024-12-15T06:26:19.891Z</updated>
<content type="html"><![CDATA[<h3 id="CentOS-7-安装-docker"><a href="#CentOS-7-安装-docker" class="headerlink" title="CentOS 7 安装 docker"></a>CentOS 7 安装 docker</h3><figure class="highlight bash"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># 安装gcc</span></span><br><span class="line">yum -y install gcc</span><br><span class="line"><span class="comment"># 安装gcc-c++</span></span><br><span class="line">yum -y install gcc-c++</span><br><span class="line"><span class="comment"># 验证gcc是否安装成功</span></span><br><span class="line">gcc -v</span><br><span class="line"></span><br><span class="line"><span class="comment"># 安装需要的软件包</span></span><br><span class="line">yum install -y yum-utils device-mapper-persistent-data lvm2</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置stable镜像仓库</span></span><br><span class="line">yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo</span><br><span class="line"></span><br><span class="line"><span class="comment"># 更新yum软件包索引</span></span><br><span class="line">yum makecache fast</span><br><span class="line"></span><br><span class="line"><span class="comment"># 安装DOCKER CE</span></span><br><span class="line">yum -y install docker-ce</span><br><span class="line"></span><br><span class="line"><span class="comment">### (可选)如果要安装指定版本,查看repo的可用版本</span></span><br><span class="line">yum list docker-ce --showduplicates | <span class="built_in">sort</span> -r</span><br><span class="line"></span><br><span class="line"><span class="comment">### (可选)安装指定版本</span></span><br><span class="line">yum install docker-ce-<VERSION STRING></span><br><span class="line"></span><br><span class="line"><span class="comment"># 启动docker</span></span><br><span class="line">systemctl start docker</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看docker版本</span></span><br><span class="line">docker version</span><br></pre></td></tr></table></figure><h3 id="CentOS-7-安装-docker-compose"><a href="#CentOS-7-安装-docker-compose" class="headerlink" title="CentOS 7 安装 docker-compose"></a>CentOS 7 安装 docker-compose</h3><h4 id="curl方式"><a href="#curl方式" class="headerlink" title="curl方式"></a>curl方式</h4><figure class="highlight bash"><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">curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(<span class="built_in">uname</span> -s)-$(<span class="built_in">uname</span> -m) -o /usr/local/bin/docker-compose</span><br><span class="line"><span class="comment"># 授权</span></span><br><span class="line"><span class="built_in">sudo</span> <span class="built_in">chmod</span> +x /usr/local/bin/docker-compose</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看版本信息</span></span><br><span class="line">docker-compose --version</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><h3 id="CentOS-7-安装-docker"><a href="#CentOS-7-安装-docker" class="headerlink" title="CentOS 7 安装 docker"></a>CentOS 7 安装 docker</h3><figure c</summary>
</entry>
</feed>