-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
343 lines (165 loc) · 156 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>GraphQL入门到aws实战 - 1. 了解GraphQL</title>
<link href="/2023/11/08/graphql-ru-men-dao-aws-shi-zhan/"/>
<url>/2023/11/08/graphql-ru-men-dao-aws-shi-zhan/</url>
<content type="html"><![CDATA[<h1 id="准备工作"><a href="#准备工作" class="headerlink" title="准备工作"></a>准备工作</h1><p>我们使用 <code>express</code>将js运行为一个可被浏览器打开的网页(可以访问<code>localhost:4000</code>),使用 <code>express-graphql</code>将GraphQL的运行环境放入express容器中(访问的内容是<code>GraphQL的测试环境</code>)。</p><pre class="line-numbers language-javascript"><code class="language-javascript"><span class="token keyword">const</span> express <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"express"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token keyword">const</span> <span class="token punctuation">{</span> graphqlHTTP <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"express-graphql"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token function">express</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>app<span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span> <span class="token string">"/graphql"</span><span class="token punctuation">,</span> <span class="token function">graphqlHTTP</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token comment" spellcheck="true">// 交互式地访问GraphQL</span> graphiql<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>app<span class="token punctuation">.</span><span class="token function">listen</span><span class="token punctuation">(</span><span class="token number">4000</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h1 id="了解graphql"><a href="#了解graphql" class="headerlink" title="了解graphql"></a>了解graphql</h1><p><code>graphql</code>的宗旨是需要的数据都要,不需要的数据一点也不要,即它可以查询多个表中的每一项信息。在传统的Rest中,如果我们需要2个表的信息,我们可能需要请求2个Rest API然后自己拼接信息,这会导致浪费大量的网络带宽请求不需要的资源。另一种解决方案是后端增加一个Rest API接口,后端进行数据库的连表查询。</p><p><code>graphql</code>就是为了解决这个痛点而生的,只要是graphql的服务器,前端需要什么数据就拿什么数据。</p><h1 id="定义有什么数据"><a href="#定义有什么数据" class="headerlink" title="定义有什么数据"></a>定义有什么数据</h1><p>和传统数据库类似的,需要有个建表语句。<code>graphql</code>也要定义数据类型。</p><pre class="line-numbers language-javascript"><code class="language-javascript"><span class="token keyword">const</span> <span class="token punctuation">{</span> buildSchema <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"graphql"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token keyword">const</span> schema <span class="token operator">=</span> <span class="token function">buildSchema</span><span class="token punctuation">(</span><span class="token template-string"><span class="token string">` type Account{ age: Int name: String, todos: [String] } type Query { hello: String account: Account }`</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>最重要的是第8行的<code>Query</code>,它定义了前端可以执行查询语句。它代表前端查询hello的话会返回一个string,而查询account的话会返回一个Account对象。Account对象有3个字段:年龄(int类型)、名字(string类型)和待做的事(string数组)</p><h1 id="模拟数据库存储的数据"><a href="#模拟数据库存储的数据" class="headerlink" title="模拟数据库存储的数据"></a>模拟数据库存储的数据</h1><p>没有花里胡哨,简单易懂的js。</p><pre class="line-numbers language-javascript"><code class="language-javascript"><span class="token keyword">const</span> root <span class="token operator">=</span> <span class="token punctuation">{</span> hello<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token string">"hello world"</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> account<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token punctuation">{</span> age<span class="token punctuation">:</span> <span class="token number">18</span><span class="token punctuation">,</span> name<span class="token punctuation">:</span> <span class="token string">"jimmy"</span><span class="token punctuation">,</span> todos<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">"eat"</span><span class="token punctuation">,</span> <span class="token string">"sleep"</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token punctuation">}</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h1 id="整合"><a href="#整合" class="headerlink" title="整合"></a>整合</h1><p>将上述的所有代码整合,形成一个完整的<code>hello.js</code>如下:</p><pre class="line-numbers language-javascript"><code class="language-javascript"><span class="token keyword">const</span> <span class="token punctuation">{</span> buildSchema <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"graphql"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token keyword">const</span> express <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"express"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token keyword">const</span> <span class="token punctuation">{</span> graphqlHTTP <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">"express-graphql"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token keyword">const</span> schema <span class="token operator">=</span> <span class="token function">buildSchema</span><span class="token punctuation">(</span><span class="token template-string"><span class="token string">` type Account{ age: Int name: String, todos: [String] } type Query { hello: String account: Account }`</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token keyword">const</span> root <span class="token operator">=</span> <span class="token punctuation">{</span> hello<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token string">"hello world"</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> account<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token punctuation">{</span> age<span class="token punctuation">:</span> <span class="token number">18</span><span class="token punctuation">,</span> name<span class="token punctuation">:</span> <span class="token string">"jimmy"</span><span class="token punctuation">,</span> todos<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">"eat"</span><span class="token punctuation">,</span> <span class="token string">"sleep"</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token punctuation">}</span><span class="token punctuation">;</span><span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token function">express</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>app<span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span> <span class="token string">"/graphql"</span><span class="token punctuation">,</span> <span class="token function">graphqlHTTP</span><span class="token punctuation">(</span><span class="token punctuation">{</span> schema<span class="token punctuation">:</span> schema<span class="token punctuation">,</span> graphiql<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> rootValue<span class="token punctuation">:</span> root<span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>app<span class="token punctuation">.</span><span class="token function">listen</span><span class="token punctuation">(</span><span class="token number">4000</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>在<code>hello.js</code>存储的路径下,使用<code>node init -y</code>初始化并使用<code>npm install graphql express express-graphql -S </code>安装依赖。最后,使用 <code>node hello.js</code>运行,访问<code>localhost:4000/graphql</code>即可。</p>]]></content>
<categories>
<category> graphql </category>
</categories>
<tags>
<tag> GraphQL </tag>
<tag> aws </tag>
</tags>
</entry>
<entry>
<title>从0搭建Django项目 - 2. Django逆向工程</title>
<link href="/2023/10/26/python3-django-ni-xiang-gong-cheng/"/>
<url>/2023/10/26/python3-django-ni-xiang-gong-cheng/</url>
<content type="html"><![CDATA[<h1 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h1><p>最近重新研究了Django,发现也没想象中那么简单,也没那么好用。</p><p>我们会编写一个类,然后希望数据库也对应生成这个表。而逆向工程就是自动化这个步骤。</p><p>由于现在用的都是python3,所以接下来的所有命令,可能要将<code>python</code>改为<code>python3</code>.</p><h1 id="Django项目逻辑"><a href="#Django项目逻辑" class="headerlink" title="Django项目逻辑"></a>Django项目逻辑</h1><p>在新建项目后,是没有app的,项目里一开始只有django的管理端。此时我们还不能写任何的业务逻辑。</p><h2 id="目录介绍"><a href="#目录介绍" class="headerlink" title="目录介绍"></a>目录介绍</h2><p>这个管理端的文件夹的名字与你新建Django项目时的一致。比如你使用<code>django-admin startproject mysite</code>新建项目,此时你的项目名称就是mysite。目录如下:</p><pre class="line-numbers language-bash"><code class="language-bash">mysite/ manage.py mysite/ __init__.py settings.py urls.py asgi.py wsgi.py<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>你的文件将存在第一行的<code>mysite</code>目录下,而<code>manage.py</code>就是管理这个项目的入口。项目的具体设置(比如配置文件)就在<code>mysite/mysite</code>下,这个目录就是我们说的管理端。此时可以使用<code>python manage.py runserver</code>来运行Django.</p><h2 id="新建app"><a href="#新建app" class="headerlink" title="新建app"></a>新建app</h2><p>使用<code>python manager.py startapp myappname</code>来新建一个叫<code>myappname</code>的应用。因为Django使用的不是MVC模型,所以一个这样创建的app就是一个Service,这有点类似于微服务。比如用<code>python manager.py startapp account</code>来管理登录,而同时用<code>python manager.py startapp payment</code> 创建一个app来管理支付。</p><h1 id="流程"><a href="#流程" class="headerlink" title="流程"></a>流程</h1><p>终于到逆向工程的步骤了。总体步骤是:</p><ol><li>新建一个app。</li><li>在app的<code>models.py</code>中编写要被逆向的类。</li><li>使用下面的步骤完成逆向工程。</li></ol><h2 id="步骤"><a href="#步骤" class="headerlink" title="步骤"></a>步骤</h2><p>开始前,默认已经完成了上述的流程2:在app的<code>models.py</code>中编写要被逆向的类。</p><ol><li><p>和上面介绍的一样,我在Django中新建一个app叫<code>myappF23</code>。</p></li><li><p>在Django的<code>mysite/settings.py</code>中</p><pre class="line-numbers language-python"><code class="language-python">INSTALLED_APPS <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token string">'django.contrib.admin'</span><span class="token punctuation">,</span> <span class="token string">'django.contrib.auth'</span><span class="token punctuation">,</span> <span class="token string">'django.contrib.contenttypes'</span><span class="token punctuation">,</span> <span class="token string">'django.contrib.sessions'</span><span class="token punctuation">,</span> <span class="token string">'django.contrib.messages'</span><span class="token punctuation">,</span> <span class="token string">'django.contrib.staticfiles'</span><span class="token punctuation">,</span> <span class="token string">'myappF23.apps.Myappf23Config'</span><span class="token punctuation">,</span><span class="token punctuation">]</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>在第8行将告诉Django:myappF23是一个app项目,而不是一个普通文件夹。</p></li><li><p>运行<code>python manage.py makemigrations myappF23</code>,让逆向工程为<code>settings.py</code>里的<code>myappF23</code>这个app创建一个<code>migrations</code>文件夹。这里的<code>0001_initial.py</code>将是逆向工程会运行的代码。(这个<code>.py</code>文件中存储的显然是python代码。此时,你可以使用<code> python manage.py sqlmigrate myappF23 0001</code>来查看<code>0001_initial.py</code>将会执行什么具体的SQL语句)</p></li><li><p>运行<code>python manage.py migrate 0001 </code>,这步将让Django使用这个0001创建数据库。因此你的目录下会多出<code>db.sqlite3</code>文件。</p></li><li><p>在完成创建数据库后,创建超级管理员,<code>python manage.py createsuperuser</code>。</p></li><li><p>可以使用<code>127.0.0.1:8000/admin</code>,使用你在第四步创建的账号密码登录。登录后,可以在网页中对数据库进行CRUD。</p></li></ol><h2 id="更新步骤"><a href="#更新步骤" class="headerlink" title="更新步骤"></a>更新步骤</h2><p>上述步骤适用于新建,如果更改了<code>models.py</code>,还需要重新执行一遍下述步骤才能更新数据库。</p><ol><li>运行<code>python manage.py makemigrations myappF23</code>,重新生成一个0002为前缀的py文件。如果多次编写,请在文件夹下查看最新的编号。</li><li>使用<code>python manage.py migrate myappF23 0002 </code>使得更改生效。</li></ol><h3 id="更新示例"><a href="#更新示例" class="headerlink" title="更新示例"></a>更新示例</h3><p>我意外删除了一个表Course,现在想重新生成。</p><p>但是如果按照上述步骤更新,会出现报错:无法找到该表。这也是我讨厌Django的地方,非常难用,完全没考虑很多情况。</p><p>解决方法:</p><ol><li><p>先在<code>models.py</code>中注释掉Course类</p></li><li><p>运行<code>python manage.py makemigrations myappF23</code>,此时显示如下:</p><pre class="line-numbers language-shell"><code class="language-shell">Migrations for 'myappF23': myappF23/migrations/0004_delete_course.py - Delete model Course<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></li><li><p>按理说,我们应该执行<code>python manage.py migrate myappF23 0004 </code>来运行这个编号为0004的代码从而删除Course表,但是由于我已经手动删了,所以需要虚假执行。使用<code>python manage.py migrate myappF23 0004 --fake </code>.该方法多了最后的参数,代表我们已经手动替Django操作过这个步骤了,只是让Django记录一下。</p><pre class="line-numbers language-shell"><code class="language-shell">Operations to perform: Target specific migration: 0004_delete_course, from myappF23Running migrations: Applying myappF23.0004_delete_course... FAKED<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre></li><li><p>取消注释Course类</p></li><li><p>重新<code>python manage.py makemigrations myappF23</code>与<code>python manage.py migrate myappF23 0005</code>。成功</p></li></ol><h1 id="类的编写"><a href="#类的编写" class="headerlink" title="类的编写"></a>类的编写</h1><p>在流程中的第二步提到,我们需要编写类,让其能被逆向,并且在Django中使用类似ORM的方式去对其CRUD。</p><p>那么,如何编写类呢?</p><p>首先,所有类必须写在 <code>models.py</code>中,并且继承<code>models.Model</code>这个类。</p><p>因此,<code>models.py</code>的第一句总是<code>from django.db import models</code>.</p><h2 id="简单示例"><a href="#简单示例" class="headerlink" title="简单示例"></a>简单示例</h2><pre class="line-numbers language-python"><code class="language-python"><span class="token comment" spellcheck="true"># CREATE TABLE "myappF23_student" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "first_name" varchar(100) NOT NULL, "last_name" varchar(100) NOT NULL, "email" varchar(200) NOT NULL UNIQUE, "date_of_birth" date NOT NULL);</span><span class="token keyword">class</span> <span class="token class-name">Student</span><span class="token punctuation">(</span>models<span class="token punctuation">.</span>Model<span class="token punctuation">)</span><span class="token punctuation">:</span> STUDENT_STATUS_CHOICES <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token punctuation">(</span><span class="token string">'ER'</span><span class="token punctuation">,</span> <span class="token string">'Enrolled'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">'SP'</span><span class="token punctuation">,</span> <span class="token string">'Suspended'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">'GD'</span><span class="token punctuation">,</span> <span class="token string">'Graduated'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">]</span> first_name <span class="token operator">=</span> models<span class="token punctuation">.</span>CharField<span class="token punctuation">(</span>max_length<span class="token operator">=</span><span class="token number">100</span><span class="token punctuation">)</span> last_name <span class="token operator">=</span> models<span class="token punctuation">.</span>CharField<span class="token punctuation">(</span>max_length<span class="token operator">=</span><span class="token number">100</span><span class="token punctuation">)</span> email <span class="token operator">=</span> models<span class="token punctuation">.</span>EmailField<span class="token punctuation">(</span>max_length<span class="token operator">=</span><span class="token number">200</span><span class="token punctuation">,</span> unique<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span> date_of_birth <span class="token operator">=</span> models<span class="token punctuation">.</span>DateField<span class="token punctuation">(</span><span class="token punctuation">)</span> status <span class="token operator">=</span> models<span class="token punctuation">.</span>CharField<span class="token punctuation">(</span>max_length<span class="token operator">=</span><span class="token number">10</span><span class="token punctuation">,</span> choices<span class="token operator">=</span>STUDENT_STATUS_CHOICES<span class="token punctuation">,</span> default<span class="token operator">=</span><span class="token string">'ER'</span><span class="token punctuation">)</span> <span class="token keyword">def</span> <span class="token function">__str__</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">return</span> self<span class="token punctuation">.</span>first_name<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p><strong>这样创建的类会有一个默认的id作为主键。</strong>也可以使用<code>sid = models.IntegerField(primary_key=True) </code>或者<code>sid = models.AutoField(primary_key=True)</code>来给student类一个id。</p><h2 id="类与类的关系"><a href="#类与类的关系" class="headerlink" title="类与类的关系"></a>类与类的关系</h2><p>类与类之间有2中关系:<strong>多对一</strong>和<strong>多对多</strong>。注意,没有 <strong>一对多或者一对一</strong>,永远只有 **’多对’**开头的关系。</p><p> 额外创建一个类:教师类</p><pre class="line-numbers language-python"><code class="language-python"><span class="token keyword">class</span> <span class="token class-name">Instructor</span><span class="token punctuation">(</span>models<span class="token punctuation">.</span>Model<span class="token punctuation">)</span><span class="token punctuation">:</span> first_name <span class="token operator">=</span> models<span class="token punctuation">.</span>CharField<span class="token punctuation">(</span>max_length<span class="token operator">=</span><span class="token number">128</span><span class="token punctuation">)</span> last_name <span class="token operator">=</span> models<span class="token punctuation">.</span>CharField<span class="token punctuation">(</span>max_length<span class="token operator">=</span><span class="token number">128</span><span class="token punctuation">)</span> bio <span class="token operator">=</span> models<span class="token punctuation">.</span>TextField<span class="token punctuation">(</span>null<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">,</span> blank<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span> <span class="token keyword">def</span> <span class="token function">__str__</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">return</span> self<span class="token punctuation">.</span>first_name<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>其中bio字段是老师的简介:</p><ul><li><code>blank=True</code>: 表示在表单验证时,该字段可以为空。这影响到表单的验证行为,允许用户在表单中不填写这个字段。</li><li><code>null=True</code>: 表示在数据库中,该字段可以存储为 NULL。如果这个字段不设置为可空 (<code>null=False</code>),那么在数据库中该字段将不允许存储为 NULL 值。</li></ul><p> 再额外创建一个类:课程类</p><p>该课程有多对一(1个课程只有1个老师)和多对多(1个课程可以有多个学生上,1个学生也可以选多个课程)关系。</p><pre class="line-numbers language-python"><code class="language-python"><span class="token keyword">class</span> <span class="token class-name">Course</span><span class="token punctuation">(</span>models<span class="token punctuation">.</span>Model<span class="token punctuation">)</span><span class="token punctuation">:</span> COURSE_LEVEL_CHOICES <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token punctuation">(</span><span class="token string">'BE'</span><span class="token punctuation">,</span> <span class="token string">'Beginner'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">'IN'</span><span class="token punctuation">,</span> <span class="token string">'Intermediate'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token string">'AD'</span><span class="token punctuation">,</span> <span class="token string">'Advanced'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">]</span> title <span class="token operator">=</span> models<span class="token punctuation">.</span>CharField<span class="token punctuation">(</span>max_length<span class="token operator">=</span><span class="token number">200</span><span class="token punctuation">)</span> description <span class="token operator">=</span> models<span class="token punctuation">.</span>TextField<span class="token punctuation">(</span><span class="token punctuation">)</span> Instructor <span class="token operator">=</span> models<span class="token punctuation">.</span>ForeignKey<span class="token punctuation">(</span>Instructor<span class="token punctuation">,</span> on_delete<span class="token operator">=</span>models<span class="token punctuation">.</span>CASCADE<span class="token punctuation">)</span> students <span class="token operator">=</span> models<span class="token punctuation">.</span>ManyToManyField<span class="token punctuation">(</span>Student<span class="token punctuation">,</span> blank<span class="token operator">=</span><span class="token boolean">True</span><span class="token punctuation">)</span> start_date <span class="token operator">=</span> models<span class="token punctuation">.</span>DateField<span class="token punctuation">(</span><span class="token punctuation">)</span> end_date <span class="token operator">=</span> models<span class="token punctuation">.</span>DateField<span class="token punctuation">(</span><span class="token punctuation">)</span> price <span class="token operator">=</span> models<span class="token punctuation">.</span>DecimalField<span class="token punctuation">(</span>max_digits<span class="token operator">=</span><span class="token number">10</span><span class="token punctuation">,</span> decimal_places<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">)</span> level <span class="token operator">=</span> models<span class="token punctuation">.</span>CharField<span class="token punctuation">(</span>max_length<span class="token operator">=</span><span class="token number">100</span><span class="token punctuation">,</span> choices<span class="token operator">=</span>COURSE_LEVEL_CHOICES<span class="token punctuation">,</span> default<span class="token operator">=</span><span class="token string">'BE'</span><span class="token punctuation">)</span> <span class="token keyword">def</span> <span class="token function">__str__</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">return</span> self<span class="token punctuation">.</span>title<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>肉眼可见地,多对一关系为一个普通的外键,其中第9行里的<code>on_delete=models.CASCADE</code>代表级联删除,表示如果删除了这个教授,那么对应的这个课程也会被删除。<strong>记住,因为是多对一,所以这个关系会写在“多”的类里,那个“一”应该写在前面</strong>。在本案例中,教师类写在课程类的前面,并且外键写在课程类中。</p><p>而多对多关系就无所谓定义在哪了。本案例中,因为我是先写的学生类,再写的课程类,所以我将多对多关系写在课程类中。这个关系的定义在第10行。遇到这种情况时,Django其实会额外创建一个表<code>course_student</code>来表示多对多关系。<code>blank=True</code>代表这个关联表是空也无所谓。</p><p>至此,我有了4个表:<code>course, course_student, student, instructor</code>.</p><h2 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h2><p>至于如何编写自增主键啥的,或者想了解更多信息的,请看文档:<a href="https://docs.djangoproject.com/en/4.2/topics/db/models/">https://docs.djangoproject.com/en/4.2/topics/db/models/</a></p><h1 id="References"><a href="#References" class="headerlink" title="References"></a>References</h1><ol><li>官方文档:<a href="https://docs.djangoproject.com/en/4.2/intro/tutorial02/">https://docs.djangoproject.com/en/4.2/intro/tutorial02/</a></li></ol>]]></content>
<categories>
<category> python </category>
</categories>
<tags>
<tag> python </tag>
<tag> Django </tag>
<tag> 逆向工程 </tag>
</tags>
</entry>
<entry>
<title>Cpp 数组与vector操作技巧</title>
<link href="/2023/10/15/cpp-shu-zu-yu-vector-cao-zuo-ji-qiao/"/>
<url>/2023/10/15/cpp-shu-zu-yu-vector-cao-zuo-ji-qiao/</url>
<content type="html"><![CDATA[<h1 id="memset填充问题"><a href="#memset填充问题" class="headerlink" title="memset填充问题"></a>memset填充问题</h1><p>我们知道,使用 <code>memset()</code>只能将整数数组填充0和-1,为了将其填充为我们想要的值,可以使用<code>fill</code>初始化而非 <code>memset()</code>。</p><pre class="line-numbers language-c++"><code class="language-c++">int ary[10];memset(ary,-2,sizeof ary); // failfill(ary, ary + 10, -2); // ok<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>这样,即使要填充我们想要的值是自定义类也无所谓。</p><pre class="line-numbers language-c++"><code class="language-c++">class T{ public: int a; int b; int c; T(){}; T(int a, int b) : a(a), b(b) { c = a + b; };};T ts[3];fill(ts, ts + 3, T(1, 3)); // it worksvector<T> vt(3, T(1, 2)); // ok<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>而使用<code>vector</code>则更为方便,直接在构造函数中填充3个T对象。</p><h1 id="非容器对象使用-max-element"><a href="#非容器对象使用-max-element" class="headerlink" title="非容器对象使用 max_element"></a>非容器对象使用 max_element</h1><p>容器类对象可以使用 <code>max_element</code>方法找到容器中的最大值,如:</p><pre class="line-numbers language-c++"><code class="language-c++">vector<int> v{1, 9, 5, 4};auto iter = max_element(v.begin(), v.end()); // iterator<vector<int>>cout << *iter << endl; // value of the max elementcout<< iter - v.begin()<<endl;// index of the max element<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><p>而非容器对象没有迭代器,所以会返回地址。这里上下两块的代码运行结果完全一致。</p><pre class="line-numbers language-c++"><code class="language-c++">int v[] = {1, 9, 5, 4};auto iter = max_element(v, v + 4); // address of the max elementcout << *iter << endl; // value of the max elementcout << iter - v[0] << endl; // index of the max element<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><h1 id="获得数组长度"><a href="#获得数组长度" class="headerlink" title="获得数组长度"></a>获得数组长度</h1><p>容器类对象提供 <code>size()和length()</code>函数都表示存储了几个对象,而普通数组没有。此时可使用</p><pre class="line-numbers language-c++"><code class="language-c++">#define arySize(arr) sizeof(arr) / sizeof(arr[0])int v[] = {1, 9, 5, 4};cout<< arySize(v) << endl;<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>第一行的宏定义来获取数组长度,类似于 python 的 <code>len()</code>函数。</p>]]></content>
<categories>
<category> C/C++ </category>
</categories>
<tags>
<tag> C/C++ </tag>
<tag> vector </tag>
</tags>
</entry>
<entry>
<title>Cpp使用pair或tuple返回多个值</title>
<link href="/2023/10/15/cpp-shi-yong-pair-huo-tuple-fan-hui-duo-ge-zhi/"/>
<url>/2023/10/15/cpp-shi-yong-pair-huo-tuple-fan-hui-duo-ge-zhi/</url>
<content type="html"><![CDATA[<h1 id="解决的问题"><a href="#解决的问题" class="headerlink" title="解决的问题"></a>解决的问题</h1><p>函数接受3个参数,并将它们由大到小排序。</p><pre class="line-numbers language-c++"><code class="language-c++">tuple<int, int, int> func(int a, int b, int c){ vector<int> ary{a, b, c};#define rall(v) v.rbegin(), v.rend() sort(rall(ary)); return make_tuple(ary[0], ary[1], ary[2]);}int main(int argc, char *argv[]){ int a, b, c; auto res1 = func(1, 2, 3); tie(a, b, c) = res1; cout << a << b << c << endl; return 0;}<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>结果输出321.</p><h1 id="详解"><a href="#详解" class="headerlink" title="详解"></a>详解</h1><p><code>tuple<></code>可以理解为一个包,可以对多个值进行打包。而这个“包”本身只是一个变量,这样就能达成“C++函数只能返回一个变量”的条件,同时满足“返回了多个值”。</p><p>上述例子中,函数<code>func()</code>返回了一个tuple变量(通过使用<code>make_tuple()</code>函数生成的)。这样调用方就能接收一个变量。</p><p>但是这个变量不能直接使用,需要使用<code>std::tie()</code>函数来解包才能使用。</p><p>上述13与14行可以改为</p><pre class="line-numbers language-c++"><code class="language-c++">tie(std::ignore, std::ignore, c) = res1;cout << a << endl;<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p>从而只取最小值</p><h1 id="其他听闻"><a href="#其他听闻" class="headerlink" title="其他听闻"></a>其他听闻</h1><p><code>tuple</code> 即元组,可以理解为pair的扩展,可以用来将不同类型的元素存放在一起,常用于函数的多返回值。在c++ 11标准库中,加入了std::tie,在c++ 14中改进,方便使用。[1]</p><p>pair只能把2个数据打包,而tuple可以打包更多的数据,虽然超过了9个时,其方式就比较搞笑了。[2]</p><h1 id="References"><a href="#References" class="headerlink" title="References"></a>References</h1><ol><li><a href="https://www.cnblogs.com/RioTian/p/14076214.html">https://www.cnblogs.com/RioTian/p/14076214.html</a></li><li><a href="https://blog.csdn.net/whereismatrix/article/details/125071222">https://blog.csdn.net/whereismatrix/article/details/125071222</a></li></ol>]]></content>
<categories>
<category> C/C++ </category>
</categories>
<tags>
<tag> C/C++ </tag>
<tag> pair </tag>
<tag> tuple </tag>
</tags>
</entry>
<entry>
<title>创建mysql账户并在vscode中使用</title>
<link href="/2022/07/04/chuang-jian-mysql-zhang-hu-bing-zai-vscode-zhong-shi-yong/"/>
<url>/2022/07/04/chuang-jian-mysql-zhang-hu-bing-zai-vscode-zhong-shi-yong/</url>
<content type="html"><![CDATA[<h1 id="好处"><a href="#好处" class="headerlink" title="好处"></a>好处</h1><p>不使用root用户很关键。</p><h1 id="命令"><a href="#命令" class="headerlink" title="命令"></a>命令</h1><pre class="line-numbers language-sql"><code class="language-sql"><span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'username'</span>@'LOCALHOST<span class="token string">' IDENTIFIED BY '</span>password<span class="token string">';GRANT ALL PRIVILEGES ON databaseName.* TO username@localhost ;ALTER USER '</span>username<span class="token string">'@'</span>localhost<span class="token string">' IDENTIFIED WITH mysql_native_password BY '</span>password'<span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>将其中的username、password和databaseName变成你需要的值。</p><h1 id="vscode中"><a href="#vscode中" class="headerlink" title="vscode中"></a>vscode中</h1><ol><li>安装2个扩展:<ol><li>MySQL - 作者是 Jun Han</li><li>MySQL Syntax - 作者是Jake Bathman</li></ol></li><li>打开资源管理器,在最下面找到mysql,点击加号</li><li>输入localhost、用户名、密码和端口号,ssl证书可以直接回车不输入</li></ol>]]></content>
<categories>
<category> 运维 </category>
</categories>
<tags>
<tag> 数据库 </tag>
<tag> sql </tag>
<tag> vscode </tag>
</tags>
</entry>
<entry>
<title>从0搭建Django项目 - 1. 初始化项目</title>
<link href="/2022/03/24/xue-xi-da-jian-django-xiang-mu-1/"/>
<url>/2022/03/24/xue-xi-da-jian-django-xiang-mu-1/</url>
<content type="html"><![CDATA[<h1 id="从0搭建Django项目-1"><a href="#从0搭建Django项目-1" class="headerlink" title="从0搭建Django项目 - 1"></a>从0搭建Django项目 - 1</h1><p>项目采用python3.9+Django 4.0.3,项目github:<a href="https://github.com/VsKendo/django_demo%E3%80%82">https://github.com/VsKendo/django_demo。</a></p><p>本教程将指引你阅读官方文档,推荐在阅读官方文档的时候同步查看本教程。</p><p>更新时间:2022年3月25日</p><p>官方文档信息:</p><ul><li><p> <a href="https://docs.djangoproject.com/zh-hans/4.0/faq/help/"> Getting Help </a> </p></li><li><p> 语言: <strong>zh-hans</strong> </p></li><li><p> 文档版本: <strong>4.0</strong></p></li></ul><h2 id="安装Python和Django"><a href="#安装Python和Django" class="headerlink" title="安装Python和Django"></a>安装Python和Django</h2><p>若你还未安装Python或Django,请看官方文档【中文】:</p><p>快速下载和安装指南: <a href="https://docs.djangoproject.com/zh-hans/4.0/intro/install/">https://docs.djangoproject.com/zh-hans/4.0/intro/install/</a></p><p>这里不再赘述。</p><hr><h1 id="开始"><a href="#开始" class="headerlink" title="开始"></a>开始</h1><p>本教程需配合官方文档【中文】:<a href="https://docs.djangoproject.com/zh-hans/4.0/intro/tutorial01/">https://docs.djangoproject.com/zh-hans/4.0/intro/tutorial01/</a> 使用,因为有些官方文档已经说得很详细了,这里不再赘述。</p><p><strong>查看官方文档过程中请配合本教程使用</strong>。</p><p>当您<strong>看完</strong>官方文档“编写你的第一个 Django 应用,第 1 部分”后,建议按照本教程对项目进行修改。</p><h2 id="文件说明(tree)"><a href="#文件说明(tree)" class="headerlink" title="文件说明(tree)"></a>文件说明(tree)</h2><p>在你新建了Django项目后,你会得到以下文件。</p><pre class="line-numbers language-html"><code class="language-html">. //根目录只是你项目的容器, 名称对 Django 没有影响,可以将它重命名为任何你喜欢的名称。├── manage.py //一个让你用各种方式管理 Django 项目的命令行工具。├── ossbe //包名(项目名),引用它内部任何东西时需要用到。│ ├── __init__.py //一个空文件,告诉 Python 这个目录应该被认为是一个 Python 包。│ ├── asgi.py //运行在 ASGI 兼容的 Web 服务器上的入口。│ ├── settings.py //Django 项目的配置文件。│ ├── urls.py //Django 项目的 URL 声明,就像你网站的“目录”。│ └── wsgi.py //运行在 WSGI 兼容的Web服务器上的入口。└── templates<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><hr><h1 id="注册app"><a href="#注册app" class="headerlink" title="注册app"></a>注册app</h1><p>请修改<code>settings.py</code>中的 <code>INSTALLED_APPS</code>,加上你的网站中的Config类。</p><h3 id="注意"><a href="#注意" class="headerlink" title="注意"></a>注意</h3><p>在教程中,会让你使用 <code>python manage.py startapp websitename</code>命令创建一个<strong>网站</strong>(我更愿意称之为<strong>拦截器</strong>),这个命令可以运行多次,即一个项目中可以用这个命令创建多个网站(拦截器)。后面的 websitename 为你给网站(拦截器)的名字。每次运行这个命令,都要在 <code>INSTALLED_APPS</code>中加上一行 <code>'websitename.apps.websitenameConfig'</code>。</p><pre class="line-numbers language-python"><code class="language-python">INSTALLED_APPS <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token string">'django.contrib.admin'</span><span class="token punctuation">,</span> <span class="token string">'django.contrib.auth'</span><span class="token punctuation">,</span> <span class="token string">'django.contrib.contenttypes'</span><span class="token punctuation">,</span> <span class="token string">'django.contrib.sessions'</span><span class="token punctuation">,</span> <span class="token string">'django.contrib.messages'</span><span class="token punctuation">,</span> <span class="token string">'django.contrib.staticfiles'</span><span class="token punctuation">,</span> <span class="token string">'manager.apps.ManagerConfig'</span><span class="token punctuation">,</span><span class="token punctuation">]</span> <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>最后一行便是我添加的,我的项目名为 ossback ,网站(拦截器)文件夹名为 manager。因此只增加一行: <code>'manager.apps.ManagerConfig'</code> 。</p><p>在往后所有的教程中,使用 <code>python manage.py startapp websitename</code>命令创建的文件夹,我都会叫它“<strong>拦截器</strong>”而非“<strong>网站</strong>”(为了避免混淆)。</p><h1 id="创建templates文件夹"><a href="#创建templates文件夹" class="headerlink" title="创建templates文件夹"></a>创建templates文件夹</h1><p>你要创建templates文件夹,用于存储html文件。这时候就要说到项目规范问题了。</p><ol><li>显然,我们目前开发的Django是<strong>前后端不分离</strong>的</li><li>每个网站都有其各自使用的 <code>html 和静态(js、css、img)文件</code>,以及可能会有公用的 <code>html 和静态(js、css、img)文件</code></li></ol><p>终上所述,后端文件和前端文件应该单独存放,我个人推荐使用如下目录结构。</p><h2 id="目录结构"><a href="#目录结构" class="headerlink" title="目录结构"></a>目录结构</h2><ol><li>每个网站都有自己的 static 文件夹,但都<strong>没有</strong> templates 文件夹。所以,在<strong>每个网站文件夹中</strong>创建static文件夹,static文件夹下再创建css、js和img文件夹,用于存储静态文件。</li><li>只有一个 templates 文件夹,其和 manage.py 同级</li><li>在 templates 文件夹中,只能出现 html 文件。</li><li>在 templates 文件夹中,子文件夹命名为 websitename1、websitename2…以及shared。用于存放网站1、网站2…和共享的 html 文件。</li><li>在 templates 文件夹的同级创建一个 common_static 文件夹,用于存放共用的css、js和img文件。</li></ol><p>目录结构大概如下:</p><pre class="line-numbers language-html"><code class="language-html">. (省略不重要的文件和文件夹)├── website1 (网站1文件夹)│ ├── __init__.py│ ├── admin.py│ ├── apps.py│ ├── models.py│ ├── static (网站1私有的静态文件的文件夹)│ │ ├── css│ │ ├── img│ │ └── js│ ├── tests.py│ ├── urls.py│ └── views.py├── website2 (网站2文件夹)│ ├── __init__.py│ ├── admin.py│ ├── apps.py│ ├── models.py│ ├── static (网站2私有的静态文件的文件夹)│ │ ├── css│ │ ├── img│ │ └── js│ ├── tests.py│ └── views.py├── collect_static (在部署到Nginx时,项目中所有静态文件会被统一放在这里)├── common_static (在开发时需要,用于存放共用的静态文件)│ ├── css│ ├── img│ └── js├── manage.py└── templates (所有前端文件位置) ├── website1 (网站1私有的 html 文件) │ └── test1.html └── website2 (网站2私有的 html 文件) └── test2.html └── shared (所有网站共用的 html 文件,如 footer.html 等) └── shared.html<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h2 id="修改-settings-py"><a href="#修改-settings-py" class="headerlink" title="修改 settings.py"></a>修改 settings.py</h2><p>只需要修改这个文件中的一些配置,便可以正常使用了。</p><ol><li><p>在开头增加了 <code>import os</code></p></li><li><p>修改了 TEMPLATES 中的 DIRS(确保值为<code>[BASE_DIR / './templates'] </code> ) 和 context_processors (增加了 <code>'django.template.context_processors.static',</code>)</p><pre class="line-numbers language-python"><code class="language-python">TEMPLATES <span class="token operator">=</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token string">'BACKEND'</span><span class="token punctuation">:</span> <span class="token string">'django.template.backends.django.DjangoTemplates'</span><span class="token punctuation">,</span> <span class="token string">'DIRS'</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>BASE_DIR <span class="token operator">/</span> <span class="token string">'./templates'</span><span class="token punctuation">]</span> <span class="token punctuation">,</span> <span class="token string">'APP_DIRS'</span><span class="token punctuation">:</span> <span class="token boolean">True</span><span class="token punctuation">,</span> <span class="token string">'OPTIONS'</span><span class="token punctuation">:</span> <span class="token punctuation">{</span> <span class="token string">'context_processors'</span><span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token string">'django.template.context_processors.debug'</span><span class="token punctuation">,</span> <span class="token string">'django.template.context_processors.request'</span><span class="token punctuation">,</span> <span class="token string">'django.template.context_processors.static'</span><span class="token punctuation">,</span> <span class="token string">'django.contrib.auth.context_processors.auth'</span><span class="token punctuation">,</span> <span class="token string">'django.contrib.messages.context_processors.messages'</span><span class="token punctuation">,</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token punctuation">]</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p>修改了语言、时区</p><pre class="line-numbers language-python"><code class="language-python">LANGUAGE_CODE <span class="token operator">=</span> <span class="token string">'zh-hans'</span>TIME_ZONE <span class="token operator">=</span> <span class="token string">'Asia/Shanghai'</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre></li><li><p>修改 <code>template_processors</code>配置,原本只有 <code>STATIC_URL</code> ,现在变为:</p><pre class="line-numbers language-python"><code class="language-python"><span class="token comment" spellcheck="true"># STATIC SETTINGS</span>STATIC_URL <span class="token operator">=</span> <span class="token string">'/static/'</span><span class="token comment" spellcheck="true"># BASE_DIR 是项目的绝对地址</span>STATIC_ROOT <span class="token operator">=</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>BASE_DIR<span class="token punctuation">,</span> <span class="token string">'collect_static'</span><span class="token punctuation">)</span><span class="token comment" spellcheck="true"># 以下不是必须的 各个app共用的文件可以放在这</span>STATICFILES_DIRS <span class="token operator">=</span> <span class="token punctuation">(</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>BASE_DIR<span class="token punctuation">,</span> <span class="token string">'common_static'</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ol><p>现在,关于 Django 显示页面的基本配置已经完成,接下来就是写 html 文件了。</p><h1 id="在views中返回html文件"><a href="#在views中返回html文件" class="headerlink" title="在views中返回html文件"></a>在views中返回html文件</h1><p>根据官方文档,我们知道,以下<code>views.py</code>中的代码将返回一串文字</p><pre class="line-numbers language-python"><code class="language-python"><span class="token keyword">def</span> <span class="token function">index</span><span class="token punctuation">(</span>request<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">return</span> HttpResponse<span class="token punctuation">(</span><span class="token string">"Hello, world. You're at the index."</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p>为了返回html页面,我们可以在它下面新增函数,如:</p><pre class="line-numbers language-python"><code class="language-python"><span class="token keyword">def</span> <span class="token function">test</span><span class="token punctuation">(</span>request<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">return</span> render<span class="token punctuation">(</span>request<span class="token punctuation">,</span> <span class="token string">"test.html"</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p>其中的html文件在template文件夹下,内容为:</p><pre class="line-numbers language-html"><code class="language-html">{% load static %}<span class="token doctype"><!DOCTYPE html></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>html</span> <span class="token attr-name">lang</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>en<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>head</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>meta</span> <span class="token attr-name">charset</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>UTF-8<span class="token punctuation">"</span></span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>title</span><span class="token punctuation">></span></span>欢迎来到测试文件页面<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>title</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>head</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>body</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>h1</span><span class="token punctuation">></span></span>测试html页面能否被正确引用<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>h1</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>{% static <span class="token punctuation">'</span>img/avatar.png<span class="token punctuation">'</span> %}<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>无<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>{{ STATIC_URL }}img/avatar.png<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>无<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>body</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>html</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>最后,修改<code>urls.py</code>:</p><pre class="line-numbers language-python"><code class="language-python">urlpatterns <span class="token operator">=</span> <span class="token punctuation">[</span> path<span class="token punctuation">(</span><span class="token string">'index/'</span><span class="token punctuation">,</span> views<span class="token punctuation">.</span>index<span class="token punctuation">,</span> name<span class="token operator">=</span><span class="token string">'index'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> path<span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">,</span> views<span class="token punctuation">.</span>index<span class="token punctuation">,</span> name<span class="token operator">=</span><span class="token string">'index'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> path<span class="token punctuation">(</span><span class="token string">'test/'</span><span class="token punctuation">,</span> views<span class="token punctuation">.</span>test<span class="token punctuation">,</span> name<span class="token operator">=</span><span class="token string">'test'</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token punctuation">]</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre><h2 id="html文件引用静态文件"><a href="#html文件引用静态文件" class="headerlink" title="html文件引用静态文件"></a>html文件引用静态文件</h2><p>在 html 文件头添加 <code>{% load static %}</code>,在需要引用的位置使用 <code>{% static '路径' %}</code></p><p>如,引用 static 文件夹下的 img 文件夹中的 img1.png:</p><pre class="line-numbers language-html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>{% static <span class="token punctuation">'</span>img/avatar.png<span class="token punctuation">'</span> %}<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>无<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>{{ STATIC_URL }}img/avatar.png<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>无<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><blockquote><p>其实,这种方法之所以能找到static文件夹,是因为 settings.py 中 STATIC_URL 的值为 ‘/static/‘</p></blockquote><p>以上两种方式都可以使用。</p><h2 id="访问我们刚创建的页面"><a href="#访问我们刚创建的页面" class="headerlink" title="访问我们刚创建的页面"></a>访问我们刚创建的页面</h2><p>url:<code>http://localhost:8000/websitename/test</code></p><p>其中 websitename 是你自己创建的拦截器的名字。</p><h1 id="创建一个新的网站(拦截器)"><a href="#创建一个新的网站(拦截器)" class="headerlink" title="创建一个新的网站(拦截器)"></a>创建一个新的网站(拦截器)</h1><p>根据单一职责原则,我们可能要使用指令 <code>python manage.py startapp websitename</code> 创建多个拦截器从而响应用户不同的请求。每次创建一个新的拦截器,你都应该至少进行以下步骤:</p><ol><li>使用指令 <code>python manage.py startapp websitename</code> </li><li>给 websitename 文件夹创建 static 文件夹。</li><li>新建 urls.py,并修改其中的内容</li><li>在项目的 urls.py 里引用你刚新建的 urls.py</li><li>在 templates 下新建 websitename 文件夹</li><li>修改 settings.py 中的 <code>INSTALLED_APPS</code>,注册新的拦截器</li></ol><hr><h1 id="References"><a href="#References" class="headerlink" title="References"></a>References</h1><ol><li>【官方中文文档】编写你的第一个 Django 应用:<a href="https://docs.djangoproject.com/zh-hans/4.0/intro/tutorial01/">https://docs.djangoproject.com/zh-hans/4.0/intro/tutorial01/</a></li><li>【该文章有一处错误】Django STATIC_URL 的理解:<a href="https://blog.csdn.net/qq_24551305/article/details/84865025">https://blog.csdn.net/qq_24551305/article/details/84865025</a></li><li>django中如何使用template_processors避免频繁的函数传递给html,使用template上下文的方法传递方法:<a href="https://blog.csdn.net/qq_37463791/article/details/103607884">https://blog.csdn.net/qq_37463791/article/details/103607884</a></li></ol>]]></content>
<categories>
<category> python </category>
</categories>
<tags>
<tag> python </tag>
<tag> Django </tag>
</tags>
</entry>
<entry>
<title>CentOS升级到CentOS Stream</title>
<link href="/2022/03/19/centos8-zhuan-yi-dao-centos-stream-shi-cuo-wu/"/>
<url>/2022/03/19/centos8-zhuan-yi-dao-centos-stream-shi-cuo-wu/</url>
<content type="html"><![CDATA[<h1 id="步骤"><a href="#步骤" class="headerlink" title="步骤"></a>步骤</h1><p>升级过程中,通常是先查看仓库是否有centos-release-stream仓库</p><pre class="line-numbers language-shell"><code class="language-shell">dnf search centos-release-stream<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>再试图安装centos-release-stream仓库</p><pre class="line-numbers language-shell"><code class="language-shell">dnf install -y centos-release-stream<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>这是通常会出现ERROR,导致无法升级成CentOS Stream。错误信息大概如下:</p><pre class="line-numbers language-shell"><code class="language-shell">conflicts with centos-repos(8) provided by centos-stream-repos-8-2.el8.noarch<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h1 id="解决错误"><a href="#解决错误" class="headerlink" title="解决错误"></a>解决错误</h1><p>如果你出现了这个错误,此时你使用 <code>yum update</code>应该也会出现这个错误。这是因为CentOS和CentOS Stream<strong>仓库冲突</strong>了。</p><p>所以<strong>将仓库切换为CentOS Stream的仓库</strong>即可。</p><pre class="line-numbers language-shell"><code class="language-shell">dnf swap centos-linux-repos centos-stream-repos<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>再安装</p><pre class="line-numbers language-shell"><code class="language-shell">dnf install centos-release-stream<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>检查是否成功</p><pre class="line-numbers language-shell"><code class="language-shell">cat /etc/centos-release<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h1 id="后话"><a href="#后话" class="headerlink" title="后话"></a>后话</h1><p>这个好像是官方故意引发的冲突,是为了防止运维使用了不同的仓库中下载的包,然后出现各种奇奇怪怪的问题。更新后记得 <code>yum update</code>一下,使用最新的软件保证安全性。</p><h1 id="References"><a href="#References" class="headerlink" title="References"></a>References</h1><p><a href="https://blog.csdn.net/weixin_66597089/article/details/122637503">https://blog.csdn.net/weixin_66597089/article/details/122637503</a></p>]]></content>
<categories>
<category> 运维 </category>
</categories>
<tags>
<tag> CentOS </tag>
<tag> CentOs Stream </tag>
<tag> linux </tag>
</tags>
</entry>
<entry>
<title>MAC - 在VsCode中运行和调试C/C++.md</title>
<link href="/2022/03/19/mac-zai-vs-code-zhong-yun-xing-he-diao-shi-c-c-md/"/>
<url>/2022/03/19/mac-zai-vs-code-zhong-yun-xing-he-diao-shi-c-c-md/</url>
<content type="html"><![CDATA[<h1 id="配置说明"><a href="#配置说明" class="headerlink" title="配置说明"></a>配置说明</h1><p>使用2020款m1的13.3英寸mbp,内存16GB。</p><h1 id="安装VsCode"><a href="#安装VsCode" class="headerlink" title="安装VsCode"></a>安装VsCode</h1><p>去<a href="https://code.visualstudio.com/">官网</a> 下载vscode。</p><p>现在vscode已经完美支持m1。</p><h1 id="安装VsCode的插件"><a href="#安装VsCode的插件" class="headerlink" title="安装VsCode的插件"></a>安装VsCode的插件</h1><ul><li>Reload:非必需。右下角多一个Reload标签,点击以后可以一键重启VsCode。</li><li>C/C++:用于运行C和C++的程序。这插件会安装gcc,这个gcc也是完美支持m1。</li><li>Code Runner:在右上角多出个箭头,可以一键运行。</li><li>CodeLLDB:用于调试,没有它vscode的断点会断不下来。</li><li>tabnine:非必需。强大的自动补全插件,基于AI。免费版每天可以补全5000次。</li></ul><h1 id="配置插件"><a href="#配置插件" class="headerlink" title="配置插件"></a>配置插件</h1><p>在<code>~/Library/Application Support/Code/User/settings.json</code>中配置<code>Code Runner</code>。</p><p>我们配置它的<code>code-runner.executorMap</code>中的</p><pre class="line-numbers language-json"><code class="language-json"><span class="token property">"cpp"</span><span class="token operator">:</span> <span class="token string">"cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"</span><span class="token punctuation">,</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>这样code runner才会编译成c++11。要不然一堆feature用不了。现在大大小小比赛都完美支持C++11了,部分大型比赛支持C++14。</p><p>然后在<code>code-runner.executorMap</code>下面,额外增加两行:</p><pre class="line-numbers language-json"><code class="language-json"><span class="token property">"code-runner.saveFileBeforeRun"</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span><span class="token property">"code-runner.runInTerminal"</span><span class="token operator">:</span> <span class="token boolean">true</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p>第一行会在运行前自动保存文件,不用每次都command+s保存然后再点运行。</p><p>第二行会让程序运行在控制台中,否则cin或者scanf等指令没办法输入。</p><h1 id="运行代码"><a href="#运行代码" class="headerlink" title="运行代码"></a>运行代码</h1><p>写一段代码后点击右上角运行,应该不会有问题。</p><p>vscode会自己拉起控制台,然后你就能看到你代码在vscode中的控制台运行了。</p><h1 id="调试代码"><a href="#调试代码" class="headerlink" title="调试代码"></a>调试代码</h1><p>这部分非常坑,我搞了好久。</p><p>总的来说,我们只需要在当前目录下的.vscode文件夹下新增2个json文件就好了。</p><p>新建tasks.json文件如下</p><pre class="line-numbers language-json"><code class="language-json"><span class="token punctuation">{</span> <span class="token property">"tasks"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"type"</span><span class="token operator">:</span> <span class="token string">"cppbuild"</span><span class="token punctuation">,</span> <span class="token property">"label"</span><span class="token operator">:</span> <span class="token string">"C/C++: g++"</span><span class="token punctuation">,</span> <span class="token property">"command"</span><span class="token operator">:</span> <span class="token string">"/usr/bin/g++"</span><span class="token punctuation">,</span> <span class="token property">"args"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token string">"-g"</span><span class="token punctuation">,</span> <span class="token string">"${file}"</span><span class="token punctuation">,</span> <span class="token string">"-o"</span><span class="token punctuation">,</span> <span class="token string">"${fileDirname}/${fileBasenameNoExtension}"</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"options"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"cwd"</span><span class="token operator">:</span> <span class="token string">"${fileDirname}"</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"problemMatcher"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token string">"$gcc"</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"group"</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"kind"</span><span class="token operator">:</span> <span class="token string">"build"</span><span class="token punctuation">,</span> <span class="token property">"isDefault"</span><span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"detail"</span><span class="token operator">:</span> <span class="token string">"调试器生成的任务。"</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"version"</span><span class="token operator">:</span> <span class="token string">"2.0.0"</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>新建launch.json文件如下</p><pre class="line-numbers language-json"><code class="language-json"><span class="token punctuation">{</span> <span class="token property">"version"</span><span class="token operator">:</span> <span class="token string">"0.2.0"</span><span class="token punctuation">,</span> <span class="token property">"configurations"</span><span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span> <span class="token property">"preLaunchTask"</span><span class="token operator">:</span> <span class="token string">"C/C++: g++"</span><span class="token punctuation">,</span> <span class="token property">"type"</span><span class="token operator">:</span> <span class="token string">"lldb"</span><span class="token punctuation">,</span> <span class="token property">"request"</span><span class="token operator">:</span> <span class="token string">"launch"</span><span class="token punctuation">,</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Debug"</span><span class="token punctuation">,</span> <span class="token property">"program"</span><span class="token operator">:</span> <span class="token string">"${fileDirname}/${fileBasenameNoExtension}"</span><span class="token punctuation">,</span> <span class="token property">"args"</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token property">"cwd"</span><span class="token operator">:</span> <span class="token string">"${workspaceFolder}"</span> <span class="token punctuation">}</span> <span class="token punctuation">]</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h1 id="开始调试"><a href="#开始调试" class="headerlink" title="开始调试"></a>开始调试</h1><p>在你要调试的位置打上断点。</p><p>3种方法来调试。</p><ol><li>快捷键:shift+command+f11</li><li>找到上方的Run,选择Start Debugging</li><li>在左边找到Run and Debug选项卡,点进去。可以看到里面有一个绿色的小箭头,点击,也是调试。</li></ol><h1 id="References"><a href="#References" class="headerlink" title="References"></a>References</h1><ol><li>MAC+VS Code+C/C++调试配置:<a href="https://blog.csdn.net/qq_37747262/article/details/81151037">https://blog.csdn.net/qq_37747262/article/details/81151037</a></li><li>解决Mac上VSCdoe断点失效问题:<a href="https://blog.csdn.net/fujz123/article/details/104426121">https://blog.csdn.net/fujz123/article/details/104426121</a></li><li>vscode的 code-runner插件运行前保存:<a href="https://www.cnblogs.com/yansc/p/13895314.html">https://www.cnblogs.com/yansc/p/13895314.html</a></li></ol>]]></content>
<categories>
<category> C/C++ </category>
</categories>
<tags>
<tag> C/C++ </tag>
<tag> VsCode </tag>
<tag> Mac </tag>
</tags>
</entry>
<entry>
<title>LaTex从入门到精通</title>
<link href="/2022/03/19/latex-cong-ru-men-dao-jing-tong/"/>
<url>/2022/03/19/latex-cong-ru-men-dao-jing-tong/</url>
<content type="html"><![CDATA[<h1 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h1><p>LaTeX是一种基于TeX的文档排版系统,把大片排版的格式细节隐藏在若干样式之后,以内容的逻辑结构统帅纷繁的格式,遂成为现在最流行的科技写作——尤其是数学写作的工具之一. 在Markdown中插入数学公式的语法是 <code>$数学公式$</code>和 <code>$$数学公式$$</code>.</p><h1 id="行内公式"><a href="#行内公式" class="headerlink" title="行内公式"></a>行内公式</h1><p>行内公式是可以让公式在文中与文字或其他东西混编,而不独占一行。在数学模式下,符号会使用单独的字体,字母通常是倾斜的意大利体,数字和符号则是直立体。而数学符号之间的距离也与一般的水平模式不同:</p><table><thead><tr><th>示例</th><th>显示</th></tr></thead><tbody><tr><td><code>$2x+3y=34$</code></td><td>$2x+3y=34$</td></tr><tr><td><code>2x+3y=34</code></td><td>2x+3y=34</td></tr></tbody></table><p>因此,在排版数学公式时,即使没有特殊符号的算式(如1+1=2),或者简单的一个字母变量,也建议进入数学模式,使用<code>$1+1=2$</code>,<code>$x$</code>,而不是使用排版普通文字的方式。</p><h2 id="注意"><a href="#注意" class="headerlink" title="注意"></a>注意</h2><p>并非所有的 Markdown解析器/编辑器 都支持数学公式。所以在不支持的情况下显示出来的东西可能不尽人意。hexo要安装mathjax数学公式支持插件才支持,JetBrains家的产品默认不支持。</p><p>在本博客中,使用的是2.7.9的mathjax.js解析器,并不能解析指令//和/newline。所以部分显示可能有bug。</p><h1 id="独立公式"><a href="#独立公式" class="headerlink" title="独立公式"></a>独立公式</h1><p>独立公式单独占一行,不和其他文字混编<br>示例: <code> $$c=2πr$$</code><br>显示: $$c=2πr$$</p><h1 id="断行和分页"><a href="#断行和分页" class="headerlink" title="断行和分页"></a>断行和分页</h1><p>使用 <code>\\</code>或 <code>\newline</code> 来换行。</p><p>也可以使用 <code>\\[5pt]</code>来指定换行后,与前一行之间间隔5个位置。</p><p>示例:</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span> 2x+3y=34<span class="token function selector">\\</span>x+4y=25<span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><p>显示<br>$$<br>2x+3y=34\<br>x+4y=25<br>$$</p><p>此处放上显示的效果的图片,因为本博客使用的mathjax无法解析。</p><p>真实的显示效果应该如下:</p><p><img src="https://vskendo-1255590242.cos.ap-guangzhou.myqcloud.com/2022/05/04/133602-b1.png" alt="image-20220504133602115"></p><h1 id="常用符号"><a href="#常用符号" class="headerlink" title="常用符号"></a>常用符号</h1><table><thead><tr><th>符号</th><th>示例</th><th>显示</th></tr></thead><tbody><tr><td>上下标</td><td><code>S=a_{1}^2+a_{2}^2+a_{3}^2$</code></td><td>$S=a_{1}^2+a_{2}^2+a_{3}^2$</td></tr><tr><td>括号</td><td><code>$f(x, y) = 100 * \lbrace[(x + y) * 3] - 5\rbrace$</code></td><td>$f(x, y) = 100 * \lbrace[(x + y) * 3] - 5\rbrace$</td></tr><tr><td>分数</td><td><code>$\frac{1}{3} 与 \cfrac{1}{3}$</code></td><td>$\frac{1}{3} 与 \cfrac{1}{3}$</td></tr><tr><td>开方</td><td><code>$\sqrt[3]{X}$</code>和<code>$\sqrt{5 - x}$</code></td><td>$\sqrt[3]{X}$<code>和</code>$\sqrt{5 - x}$</td></tr><tr><td>省略号</td><td><code>\dots</code>或<code>\cdots</code></td><td>$\dots$</td></tr><tr><td>加粗</td><td><code>$ f(x) = \textbf{x}^2 $ </code></td><td>$ f(x) = \textbf{x}^2 $</td></tr><tr><td>纯文本</td><td><code>$ f(x) = x^2 \mbox{abcd} $</code></td><td>$ f(x) = x^2 \mbox{abcd} $</td></tr><tr><td>特殊</td><td><code>$\TeX$ </code> 斜杠加上任意普通字符即可</td><td>$\TeX$</td></tr><tr><td>波浪线</td><td><code>$\sim$</code></td><td>$\sim$</td></tr><tr><td>空格</td><td><code>$\ $</code></td><td>$\ $</td></tr><tr><td>tab</td><td><code>$\qquad$</code></td><td>$\qquad$</td></tr><tr><td>爱心</td><td><code>$\heartsuit$</code></td><td>$\heartsuit$</td></tr></tbody></table><h1 id="其他字符"><a href="#其他字符" class="headerlink" title="其他字符"></a>其他字符</h1><p>数学中常用的字符,比如关系运算符、对数运算符、三角运算符等。</p><h2 id="关系运算符"><a href="#关系运算符" class="headerlink" title="关系运算符"></a>关系运算符</h2><table><thead><tr><th>代码</th><th>符号</th></tr></thead><tbody><tr><td>\pm</td><td>$\pm$</td></tr><tr><td>\times</td><td>$\times$</td></tr><tr><td>\div</td><td>$\div$</td></tr><tr><td>\mid</td><td>$\mid$</td></tr><tr><td>\nmid</td><td>$\nmid$</td></tr><tr><td>\cdot</td><td>$\cdot$</td></tr><tr><td>\circ</td><td>$\circ$</td></tr><tr><td>\ast</td><td>$\ast$</td></tr><tr><td>\bigodot</td><td>$\bigodot$</td></tr><tr><td>\bigotimes</td><td>$\bigotimes$</td></tr><tr><td>\bigoplus</td><td>$\bigoplus$</td></tr><tr><td>\leq</td><td>$\leq$</td></tr><tr><td>\geq</td><td>$\geq$</td></tr><tr><td>\neq</td><td>$\neq$</td></tr><tr><td>\approx</td><td>$\approx$</td></tr><tr><td>\equiv</td><td>$\equiv$</td></tr><tr><td>\sum</td><td>$\sum$</td></tr><tr><td>\prod</td><td>$\prod$</td></tr></tbody></table><h2 id="对数运算符"><a href="#对数运算符" class="headerlink" title="对数运算符"></a>对数运算符</h2><table><thead><tr><th>代码</th><th>符号</th></tr></thead><tbody><tr><td>\log</td><td>$\log$</td></tr><tr><td>\lg</td><td>$\lg$</td></tr><tr><td>\ln</td><td>$\ln$</td></tr></tbody></table><h2 id="三角运算符"><a href="#三角运算符" class="headerlink" title="三角运算符"></a>三角运算符</h2><table><thead><tr><th>代码</th><th>符号</th></tr></thead><tbody><tr><td>\bot</td><td>$\bot$</td></tr><tr><td>\angle</td><td>$\angle$</td></tr></tbody></table><p>还有\sin、\cos等,所有三角函数的缩写都可以。</p><h2 id="微积分运算符"><a href="#微积分运算符" class="headerlink" title="微积分运算符"></a>微积分运算符</h2><table><thead><tr><th>代码</th><th>符号</th></tr></thead><tbody><tr><td>\prime</td><td>$\prime$</td></tr><tr><td>\int</td><td>$\int$</td></tr><tr><td>\iint</td><td>$\iint$</td></tr><tr><td>\iiint</td><td>$\iiint$</td></tr><tr><td>\oint</td><td>$\oint$</td></tr><tr><td>\infty</td><td>$\infty$</td></tr><tr><td>\nabla</td><td>$\nabla$</td></tr><tr><td>\mathrm{d}</td><td>$\mathrm{d}$</td></tr></tbody></table><h2 id="集合运算符"><a href="#集合运算符" class="headerlink" title="集合运算符"></a>集合运算符</h2><table><thead><tr><th>代码</th><th>符号</th></tr></thead><tbody><tr><td>\emptyset</td><td>$\emptyset$</td></tr><tr><td>\in</td><td>$\in$</td></tr><tr><td>\notin</td><td>$\notin$</td></tr><tr><td>\subset</td><td>$\subset$</td></tr><tr><td>\subseteq</td><td>$\subseteq$</td></tr><tr><td>\supseteq</td><td>$\supseteq$</td></tr><tr><td>\bigcap</td><td>$\bigcap$</td></tr><tr><td>\bigcup</td><td>$\bigcup$</td></tr><tr><td>\bigvee</td><td>$\bigvee$</td></tr><tr><td>\bigwedge</td><td>$\bigwedge$</td></tr><tr><td>\biguplus</td><td>$\biguplus$</td></tr><tr><td>\bigsqcup</td><td>$\bigsqcup$</td></tr></tbody></table><h2 id="希腊字母"><a href="#希腊字母" class="headerlink" title="希腊字母"></a>希腊字母</h2><p>LATEX2$\epsilon$ 没有定义Alpha 的大写形式,因为它和普通的罗马字体A 很像。也许新的数学编码完成后会有所变化。</p><table><thead><tr><th>代码</th><th>大写</th><th>代码</th><th>小写</th></tr></thead><tbody><tr><td>A</td><td>$A$</td><td>\alpha</td><td>$\alpha$</td></tr><tr><td>B</td><td>$B$</td><td>\beta</td><td>$\beta$</td></tr><tr><td>\Gamma</td><td>$\Gamma$</td><td>\gamma</td><td>$\gamma$</td></tr><tr><td>\Delta</td><td>$\Delta$</td><td>\delta</td><td>$\delta$</td></tr><tr><td>E</td><td>$E$</td><td>\epsilon</td><td>$\epsilon$</td></tr><tr><td>Z</td><td>$Z$</td><td>\zeta</td><td>$\zeta$</td></tr><tr><td>H</td><td>$H$</td><td>\eta</td><td>$\eta$</td></tr><tr><td>\Theta</td><td>$\Theta$</td><td>\theta</td><td>$\theta$</td></tr><tr><td>I</td><td>$I$</td><td>\iota</td><td>$\iota$</td></tr><tr><td>K</td><td>$K$</td><td>\kappa</td><td>$\kappa$</td></tr><tr><td>Lambda</td><td>$\Lambda$</td><td>\lambda</td><td>$\lambda$</td></tr><tr><td>M</td><td>$M$</td><td>\mu</td><td>$\mu$</td></tr><tr><td>N</td><td>$N$</td><td>\nu</td><td>$\nu$</td></tr><tr><td>Xi</td><td>$Xi$</td><td>\xi</td><td>$\xi$</td></tr><tr><td>O</td><td>$O$</td><td>\omicron</td><td>$\omicron$</td></tr><tr><td>\Pi</td><td>$\Pi$</td><td>\pi</td><td>$\pi$</td></tr><tr><td>P</td><td>$P$</td><td>\rho</td><td>$\rho$</td></tr><tr><td>\Sigma</td><td>$\Sigma$</td><td>\sigma</td><td>$\sigma$</td></tr><tr><td>T</td><td>$T$</td><td>\tau</td><td>$\tau$</td></tr><tr><td>\Upsilon</td><td>$\Upsilon$</td><td>\upsilon</td><td>$\upsilon$</td></tr><tr><td>\Phi</td><td>$\Phi$</td><td>\phi</td><td>$\phi$</td></tr><tr><td>X</td><td>$X$</td><td>\chi</td><td>$\chi$</td></tr><tr><td>\Psi</td><td>$\Psi$</td><td>\psi</td><td>$\psi$</td></tr><tr><td>\Omega</td><td>$\Omega$</td><td>\omega</td><td>$\omega$</td></tr></tbody></table><h1 id="其他技巧"><a href="#其他技巧" class="headerlink" title="其他技巧"></a>其他技巧</h1><p>例子一:行距技巧</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\TeX</span><span class="token function selector">\ </span>is<span class="token function selector">\ </span>pronounced<span class="token function selector">\ </span>as<span class="token function selector">\ </span><span class="token function selector">\tau</span><span class="token function selector">\epsilon</span><span class="token function selector">\chi</span>.<span class="token function selector">\\</span><span class="token punctuation">[</span>6pt<span class="token punctuation">]</span>100-m^<span class="token punctuation">{</span>3<span class="token punctuation">}</span><span class="token function selector">\ </span>of<span class="token function selector">\ </span>water<span class="token function selector">\\</span><span class="token punctuation">[</span>6pt<span class="token punctuation">]</span>This<span class="token function selector">\ </span>comes<span class="token function selector">\ </span>from<span class="token function selector">\ </span>my<span class="token function selector">\ </span><span class="token function selector">\heartsuit</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\TeX\ is\ pronounced\ as\<br>\tau\epsilon\chi.<br>100-m^{3}\ of\ water<br>This\ comes\ from\ my\ \heartsuit<br>$$</p><p>此处放上显示的效果的图片,因为本博客使用的mathjax无法解析。</p><p>真实的显示效果应该如下:</p><p><img src="https://vskendo-1255590242.cos.ap-guangzhou.myqcloud.com/2022/05/04/133719-6d.png" alt="image-20220504133719255"></p><p>例子二:极限、求和、分数使用技巧</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\lim</span>_<span class="token punctuation">{</span>n <span class="token function selector">\to</span> <span class="token function selector">\infty</span><span class="token punctuation">}</span><span class="token function selector">\sum</span>_<span class="token punctuation">{</span>k=1<span class="token punctuation">}</span>^n <span class="token function selector">\frac</span><span class="token punctuation">{</span>1<span class="token punctuation">}</span><span class="token punctuation">{</span>k^2<span class="token punctuation">}</span>= <span class="token function selector">\frac</span><span class="token punctuation">{</span><span class="token function selector">\pi</span>^2<span class="token punctuation">}</span><span class="token punctuation">{</span>6<span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\lim_{n \to \infty}<br>\sum_{k=1}^n \frac{1}{k^2}<br>= \frac{\pi^2}{6}<br>$$</p><p>例子三:集合例子</p><p>数学家们通常对使用什么样的符号非常挑剔:习惯上使用“空心粗体”(blackboard bold)来表示实数集合。这种字体可用amsfonts 或amssymb 宏包中的命令\mathbb 来得到(如代码中的倒数第二行所示)。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span> <span class="token function selector">\forall</span> x <span class="token function selector">\in</span> <span class="token function selector">\mathbf</span><span class="token punctuation">{</span>R<span class="token punctuation">}</span>:<span class="token function selector">\qquad</span> x^<span class="token punctuation">{</span>2<span class="token punctuation">}</span> <span class="token function selector">\geq</span> 0<span class="token function selector">\</span>x^<span class="token punctuation">{</span>2<span class="token punctuation">}</span> <span class="token function selector">\geq</span> 0<span class="token function selector">\qquad</span><span class="token function selector">\textrm</span><span class="token punctuation">{</span>for all <span class="token punctuation">}</span>x<span class="token function selector">\in</span><span class="token function selector">\mathbf</span><span class="token punctuation">{</span>R<span class="token punctuation">}</span><span class="token function selector">\</span>x^<span class="token punctuation">{</span>2<span class="token punctuation">}</span> <span class="token function selector">\geq</span> 0<span class="token function selector">\qquad</span><span class="token function selector">\textrm</span><span class="token punctuation">{</span>for all <span class="token punctuation">}</span>x<span class="token function selector">\in</span><span class="token function selector">\mathbb</span><span class="token punctuation">{</span>R<span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\forall x \in \mathbf{R}:<br>\qquad x^{2} \geq 0<br>x^{2} \geq 0\qquad<br>\textrm{for all }x\in\mathbf{R}<br>x^{2} \geq 0\qquad<br>\textrm{for all }x\in\mathbb{R}<br>$$</p><p>例子四:简单等式</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span>a^x+y <span class="token function selector">\neq</span> a^<span class="token punctuation">{</span>x+y<span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>$$<br>a^x+y \neq a^{x+y}<br>$$</p><p>例子五:平方根。方根符号的大小由LATEX自动加以调整。也可用\surd 仅给出符号。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\sqrt</span><span class="token punctuation">{</span>x<span class="token punctuation">}</span> <span class="token function selector">\qquad</span><span class="token function selector">\sqrt</span><span class="token punctuation">{</span> x^<span class="token punctuation">{</span>2<span class="token punctuation">}</span>+<span class="token function selector">\sqrt</span><span class="token punctuation">{</span>y<span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token function selector">\qquad</span> <span class="token function selector">\sqrt</span><span class="token punctuation">[</span>3<span class="token punctuation">]</span><span class="token punctuation">{</span>2<span class="token punctuation">}</span><span class="token function selector">\</span><span class="token function selector">\surd</span><span class="token punctuation">[</span>x^2 + y^2<span class="token punctuation">]</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\sqrt{x} \qquad<br>\sqrt{ x^{2}+\sqrt{y} }<br>\qquad \sqrt[3]{2}<br>\surd[x^2 + y^2]<br>$$</p><p>例子六:命令\overline 和\underline 在表达式的上、下方画出水平线。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\overline</span><span class="token punctuation">{</span>m+n<span class="token punctuation">}</span> <span class="token function selector">\qquad</span><span class="token function selector">\underline</span><span class="token punctuation">{</span>m+n<span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\overline{m+n} \qquad<br>\underline{m+n}<br>$$</p><p>例子七:命令\overbrace 和\underbrace 在表达式的上、下方给出一水平的大括号。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\underbrace</span><span class="token punctuation">{</span> a+b+<span class="token function selector">\cdots</span>+z <span class="token punctuation">}</span>_<span class="token punctuation">{</span>26<span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>$$<br>\underbrace{ a+b+\cdots+z }_{26}<br>$$</p><p>例子八:数学重音符号如小箭头和˜(tilde)。可覆盖多个字符的宽重音符号可由\widetilde 和\widehat 等得到。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span>y=x^<span class="token punctuation">{</span>2<span class="token punctuation">}</span><span class="token function selector">\qquad</span> y'=2x<span class="token function selector">\qquad</span> y''=2<span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>$$<br>y=x^{2}\qquad y’=2x\qquad y’’=2<br>$$</p><p>例子九:向量(Vectors)通常用上方有小箭头(arrow symbols)的变量表示。这可由\vec 得到。</p><p>另两个命令\overrightarrow 和\overleftarrow在定义从A 到B 的向量时非常有用。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\vec</span> a<span class="token function selector">\quad</span><span class="token function selector">\overrightarrow</span><span class="token punctuation">{</span>AB<span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>$$<br>\vec a\quad\overrightarrow{AB}<br>$$</p><p>例子十:一般情况下,乘法算式中的圆点符可以省略。然而有时为了帮助读者解读复杂的公式,也有必要用命令\cdot 将圆点符表示出来。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span>v = <span class="token punctuation">{</span><span class="token function selector">\sigma</span><span class="token punctuation">}</span>_1 <span class="token function selector">\cdot</span> <span class="token punctuation">{</span><span class="token function selector">\sigma</span><span class="token punctuation">}</span>_2<span class="token punctuation">{</span><span class="token function selector">\tau</span><span class="token punctuation">}</span>_1 <span class="token function selector">\cdot</span> <span class="token punctuation">{</span><span class="token function selector">\tau</span><span class="token punctuation">}</span>_2<span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>v = {\sigma}_1 \cdot {\sigma}_2<br>{\tau}_1 \cdot {\tau}_2<br>$$</p><p>例子十一:分数(fraction)使用\frac{…}{…} 排版。一般来说,1/2 这种形式更受欢迎,因为对于少量的分式,它看起来更好些。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span>1<span class="token function selector">\frac</span><span class="token punctuation">{</span>1<span class="token punctuation">}</span><span class="token punctuation">{</span>2<span class="token punctuation">}</span>~hours<span class="token function selector">\\</span><span class="token function selector">\frac</span><span class="token punctuation">{</span> x^<span class="token punctuation">{</span>2<span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">{</span> k+1 <span class="token punctuation">}</span><span class="token function selector">\qquad</span>x^<span class="token punctuation">{</span> <span class="token function selector">\frac</span><span class="token punctuation">{</span>2<span class="token punctuation">}</span><span class="token punctuation">{</span>k+1<span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token function selector">\qquad</span>x^<span class="token punctuation">{</span> 1/2 <span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>1\frac{1}{2}~hours\<br>\frac{ x^{2} }{ k+1 }\qquad<br>x^{ \frac{2}{k+1} }\qquad<br>x^{ 1/2 }<br>$$</p><p>此处放上显示的效果的图片,因为本博客使用的mathjax无法解析。</p><p>真实的显示效果应该如下:</p><p><img src="https://vskendo-1255590242.cos.ap-guangzhou.myqcloud.com/2022/05/04/140314-6e.png" alt="image-20220504140314315"></p><p>例子十二:排版二项系数或类似的结构可以使用命令{… \choose …} 或{… \atop …}。</p><p>第二个命令与第一个命令的输出相同,只是没有括号。(注意这些旧命令在amsmath 宏集中禁止使用, 而是用\binom和\genfrac来代替。后者是所有相关结构的超集, 例如可以通过、newcommand{\newatop}[2]% 来得到\atop 的一个类似结构)</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token punctuation">{</span>n <span class="token function selector">\choose</span> k<span class="token punctuation">}</span><span class="token function selector">\qquad</span> <span class="token punctuation">{</span>x <span class="token function selector">\atop</span> y+2<span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>$$<br>{n \choose k}\qquad {x \atop y+2}<br>$$</p><p>例子十三:对于二元关系,将符号堆在一起可能更有用。\stackrel 将第一项中的符号以上标大小放在处于正常位置的第二项上。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\int</span> f_N(x) <span class="token function selector">\stackrel</span><span class="token punctuation">{</span>!<span class="token punctuation">}</span><span class="token punctuation">{</span>=<span class="token punctuation">}</span> 1<span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>$$<br>\int f_N(x) \stackrel{!}{=} 1<br>$$</p><p>例子十四:积分运算符(integral operator)。</p><p>求和运算符(sum operator)。</p><p>乘积运算符(product operator)</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\sum</span>_<span class="token punctuation">{</span>i=1<span class="token punctuation">}</span>^<span class="token punctuation">{</span>n<span class="token punctuation">}</span> <span class="token function selector">\qquad</span><span class="token function selector">\int</span>_<span class="token punctuation">{</span>0<span class="token punctuation">}</span>^<span class="token punctuation">{</span><span class="token function selector">\frac</span><span class="token punctuation">{</span><span class="token function selector">\pi</span><span class="token punctuation">}</span><span class="token punctuation">{</span>2<span class="token punctuation">}</span><span class="token punctuation">}</span> <span class="token function selector">\qquad</span><span class="token function selector">\prod</span>_<span class="token function selector">\epsilon</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\sum_{i=1}^{n} \qquad<br>\int_{0}^{\frac{\pi}{2}} \qquad<br>\prod_\epsilon<br>$$</p><p>例子十五:某些情况下有必要手工指出数学分隔符的正确大小。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\Big</span>( (x+1) (x-1) <span class="token function selector">\Big</span>) ^<span class="token punctuation">{</span>2<span class="token punctuation">}</span><span class="token function selector">\\</span><span class="token function selector">\big</span>(<span class="token function selector">\Big</span>(<span class="token function selector">\bigg</span>(<span class="token function selector">\Bigg</span>(<span class="token function selector">\quad</span><span class="token function selector">\big</span><span class="token function selector">\}</span><span class="token function selector">\Big</span><span class="token function selector">\}</span><span class="token function selector">\bigg</span><span class="token function selector">\}</span><span class="token function selector">\Bigg</span><span class="token function selector">\}</span><span class="token function selector">\quad</span><span class="token function selector">\big</span><span class="token function selector">\|</span><span class="token function selector">\Big</span><span class="token function selector">\|</span><span class="token function selector">\bigg</span><span class="token function selector">\|</span><span class="token function selector">\Bigg</span><span class="token function selector">\|</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\Big( (x+1) (x-1) \Big) ^{2}\<br>\big(\Big(\bigg(\Bigg(\quad<br>\big}\Big}\bigg}\Bigg}\quad<br>\big|\Big|\bigg|\Bigg|<br>$$</p><p>此处放上显示的效果的图片,因为本博客使用的mathjax无法解析。</p><p>真实的显示效果应该如下:</p><p><img src="https://vskendo-1255590242.cos.ap-guangzhou.myqcloud.com/2022/05/04/140243-08.png" alt="image-20220504140243018"></p><p>例子十六:如果公式中由TEX选择的的空格不令人满意,可以通过插入特殊的空格命令来进行调节。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\int</span><span class="token function selector">\!</span><span class="token function selector">\!</span><span class="token function selector">\!</span><span class="token function selector">\int</span>_<span class="token punctuation">{</span>D<span class="token punctuation">}</span> g(x,y)<span class="token function selector">\,</span> x<span class="token function selector">\,</span> y<span class="token function selector">\\</span>instead of<span class="token function selector">\\</span><span class="token function selector">\int</span><span class="token function selector">\int</span>_<span class="token punctuation">{</span>D<span class="token punctuation">}</span> g(x,y)x y<span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\int!!!\int_{D} g(x,y)<br>, x, y\<br>instead of\<br>\int\int_{D} g(x,y)x y<br>$$</p><p>此处放上显示的效果的图片,因为本博客使用的mathjax无法解析。</p><p>真实的显示效果应该如下:</p><p><img src="https://vskendo-1255590242.cos.ap-guangzhou.myqcloud.com/2022/05/04/140225-36.png" alt="image-20220504140225122"></p><p>例子十七:排版arrays 使用array 环境来排版数组(arrays)。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\mathbf</span><span class="token punctuation">{</span>X<span class="token punctuation">}</span> =<span class="token function selector">\left</span>( <span class="token function selector">\begin</span><span class="token punctuation">{</span><span class="token keyword">array</span><span class="token punctuation">}</span><span class="token punctuation">{</span>ccc<span class="token punctuation">}</span>x_<span class="token punctuation">{</span>11<span class="token punctuation">}</span> <span class="token punctuation">&</span> x_<span class="token punctuation">{</span>12<span class="token punctuation">}</span> <span class="token punctuation">&</span> <span class="token function selector">\ldots</span> <span class="token function selector">\\</span>x_<span class="token punctuation">{</span>21<span class="token punctuation">}</span> <span class="token punctuation">&</span> x_<span class="token punctuation">{</span>22<span class="token punctuation">}</span> <span class="token punctuation">&</span> <span class="token function selector">\ldots</span> <span class="token function selector">\\</span><span class="token function selector">\vdots</span> <span class="token punctuation">&</span> <span class="token function selector">\vdots</span> <span class="token punctuation">&</span> <span class="token function selector">\ddots</span><span class="token function selector">\end</span><span class="token punctuation">{</span><span class="token keyword">array</span><span class="token punctuation">}</span> <span class="token function selector">\right</span>)<span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\mathbf{X} =<br>\left( \begin{array}{ccc}<br>x_{11} & x_{12} & \ldots \<br>x_{21} & x_{22} & \ldots \<br>\vdots & \vdots & \ddots<br>\end{array} \right)<br>$$</p><p>此处放上显示的效果的图片,因为本博客使用的mathjax无法解析。</p><p>真实的显示效果应该如下:</p><p><img src="https://vskendo-1255590242.cos.ap-guangzhou.myqcloud.com/2022/05/04/135850-24.png" alt="image-20220504135850072"></p><p>例子十八:array 环境也可以使用“.” 作为隐藏右分隔符来排版只有一个大分隔符的表达式。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span>y = <span class="token function selector">\left</span><span class="token function selector">\{</span> <span class="token function selector">\begin</span><span class="token punctuation">{</span><span class="token keyword">array</span><span class="token punctuation">}</span><span class="token punctuation">{</span>ll<span class="token punctuation">}</span>a <span class="token punctuation">&</span> <span class="token function selector">\textrm</span><span class="token punctuation">{</span>if <span class="token equation string">$d>c$</span><span class="token punctuation">}</span><span class="token function selector">\\</span>b+x <span class="token punctuation">&</span> <span class="token function selector">\textrm</span><span class="token punctuation">{</span>in the morning<span class="token punctuation">}</span><span class="token function selector">\\</span>l <span class="token punctuation">&</span> <span class="token function selector">\textrm</span><span class="token punctuation">{</span>all day long<span class="token punctuation">}</span><span class="token function selector">\end</span><span class="token punctuation">{</span><span class="token keyword">array</span><span class="token punctuation">}</span> <span class="token function selector">\right</span>.<span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>y = \left{ \begin{array}{ll}<br>a & \textrm{if $d>c$}\<br>b+x & \textrm{in the morning}\<br>l & \textrm{all day long}<br>\end{array} \right.<br>$$</p><p>此处放上显示的效果的图片,因为本博客使用的mathjax无法解析。</p><p>真实的显示效果应该如下:</p><p><img src="https://vskendo-1255590242.cos.ap-guangzhou.myqcloud.com/2022/05/04/135832-6f.png" alt="image-20220504135831808"></p><p>例子十九:可以在array 环境中画线。例如分隔矩阵中的元素。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\left</span>(<span class="token function selector">\begin</span><span class="token punctuation">{</span><span class="token keyword">array</span><span class="token punctuation">}</span><span class="token punctuation">{</span>c|c<span class="token punctuation">}</span>1 <span class="token punctuation">&</span> 2 <span class="token function selector">\\</span><span class="token function selector">\hline</span>3 <span class="token punctuation">&</span> 4<span class="token function selector">\end</span><span class="token punctuation">{</span><span class="token keyword">array</span><span class="token punctuation">}</span><span class="token function selector">\right</span>)<span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\left(\begin{array}{c|c}<br>1 & 2 \<br>\hline<br>3 & 4<br>\end{array}\right)<br>$$</p><p>此处放上显示的效果的图片,因为本博客使用的mathjax无法解析。</p><p>真实的显示效果应该如下:</p><p><img src="https://vskendo-1255590242.cos.ap-guangzhou.myqcloud.com/2022/05/04/135816-99.png" alt="image-20220504135815862"></p><p>例子二十:长方程不会自动地分割成小的。作者必须指定在哪里分割以及缩进多少。以下是最常使用的两种方法。</p><p>其中,\nonumber 命令将阻止LATEX为此方程生成一个编号。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token punctuation">{</span><span class="token function selector">\begin</span><span class="token punctuation">{</span><span class="token keyword">eqnarray</span><span class="token punctuation">}</span><span class="token equation string"><span class="token equation-command regex">\sin</span> x & = & x -<span class="token equation-command regex">\frac</span>{x^{3}}{3!}+<span class="token equation-command regex">\frac</span>{x^{5}}{5!}-{}<span class="token equation-command regex">\nonumber</span><span class="token equation-command regex">\\</span>& & {}-<span class="token equation-command regex">\frac</span>{x^{7}}{7!}+{}<span class="token equation-command regex">\cdots</span></span><span class="token function selector">\end</span><span class="token punctuation">{</span><span class="token keyword">eqnarray</span><span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>{\begin{eqnarray}<br>\sin x & = & x -\frac{x^{3}}{3!}<br>+\frac{x^{5}}{5!}-{}<br>\nonumber\<br>& & {}-\frac{x^{7}}{7!}+{}\cdots<br>\end{eqnarray}}<br>$$</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\begin</span><span class="token punctuation">{</span><span class="token keyword">eqnarray</span><span class="token punctuation">}</span><span class="token equation string">{ <span class="token equation-command regex">\cos</span> x = 1-<span class="token equation-command regex">\frac</span>{x^{2}}{2!} +{} }<span class="token equation-command regex">\nonumber</span><span class="token equation-command regex">\\</span>& & {}+<span class="token equation-command regex">\frac</span>{x^{4}}{4!}-<span class="token equation-command regex">\frac</span>{x^{6}}{6!}+{}<span class="token equation-command regex">\cdots</span></span><span class="token function selector">\end</span><span class="token punctuation">{</span><span class="token keyword">eqnarray</span><span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\begin{eqnarray}<br>{ \cos x = 1<br>-\frac{x^{2}}{2!} +{} }<br>\nonumber\<br>& & {}+\frac{x^{4}}{4!}<br>-\frac{x^{6}}{6!}+{}\cdots<br>\end{eqnarray}<br>$$</p><p>例子二十一:改变式样。改变式样也会影响上下界显示的方式。</p><p>在数学模式中,字体大小用四个命令来设定:</p><p>\displaystyle (123), \textstyle (123), \scriptstyle (123) and\scriptscriptstyle (123).</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\mathop</span><span class="token punctuation">{</span><span class="token function selector">\mathrm</span><span class="token punctuation">{</span>corr<span class="token punctuation">}</span><span class="token punctuation">}</span>(X,Y)=<span class="token function selector">\frac</span><span class="token punctuation">{</span><span class="token function selector">\displaystyle</span><span class="token function selector">\sum</span>_<span class="token punctuation">{</span>i=1<span class="token punctuation">}</span>^n(x_i-<span class="token function selector">\overline</span> x)(y_i-<span class="token function selector">\overline</span> y)<span class="token punctuation">}</span><span class="token punctuation">{</span><span class="token function selector">\displaystyle</span><span class="token function selector">\biggl</span><span class="token punctuation">[</span><span class="token function selector">\sum</span>_<span class="token punctuation">{</span>i=1<span class="token punctuation">}</span>^n(x_i-<span class="token function selector">\overline</span> x)^2<span class="token function selector">\sum</span>_<span class="token punctuation">{</span>i=1<span class="token punctuation">}</span>^n(y_i-<span class="token function selector">\overline</span> y)^2<span class="token function selector">\biggr</span><span class="token punctuation">]</span>^<span class="token punctuation">{</span>1/2<span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\mathop{\mathrm{corr}}(X,Y)=<br>\frac{\displaystyle<br>\sum_{i=1}^n(x_i-\overline x)<br>(y_i-\overline y)}<br>{\displaystyle\biggl[<br>\sum_{i=1}^n(x_i-\overline x)^2<br>\sum_{i=1}^n(y_i-\overline y)^2<br>\biggr]^{1/2}}<br>$$</p><p>差距还是很明显的。行高大小明显不一样。显然是上面的舒服。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\mathop</span><span class="token punctuation">{</span><span class="token function selector">\mathrm</span><span class="token punctuation">{</span>corr<span class="token punctuation">}</span><span class="token punctuation">}</span>(X,Y)=<span class="token function selector">\frac</span><span class="token punctuation">{</span><span class="token function selector">\sum</span>_<span class="token punctuation">{</span>i=1<span class="token punctuation">}</span>^n(x_i-<span class="token function selector">\overline</span> x)(y_i-<span class="token function selector">\overline</span> y)<span class="token punctuation">}</span><span class="token punctuation">{</span><span class="token function selector">\biggl</span><span class="token punctuation">[</span><span class="token function selector">\sum</span>_<span class="token punctuation">{</span>i=1<span class="token punctuation">}</span>^n(x_i-<span class="token function selector">\overline</span> x)^2<span class="token function selector">\sum</span>_<span class="token punctuation">{</span>i=1<span class="token punctuation">}</span>^n(y_i-<span class="token function selector">\overline</span> y)^2<span class="token function selector">\biggr</span><span class="token punctuation">]</span>^<span class="token punctuation">{</span>1/2<span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\mathop{\mathrm{corr}}(X,Y)=<br>\frac{<br>\sum_{i=1}^n(x_i-\overline x)<br>(y_i-\overline y)}<br>{\biggl[<br>\sum_{i=1}^n(x_i-\overline x)^2<br>\sum_{i=1}^n(y_i-\overline y)^2<br>\biggr]^{1/2}}<br>$$</p><p>例子二十二:在LATEX中很难得到粗体符号。这也许是故意的,因为业余排版者总是过份使用粗体。字体改变命令\mathbf 给出粗体字母,但是这些是罗马字体(竖直的),而数学符号通常是斜体。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\mu</span>, M <span class="token function selector">\qquad</span> <span class="token function selector">\mathbf</span><span class="token punctuation">{</span>M<span class="token punctuation">}</span> <span class="token function selector">\qquad</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>$$<br>\mu, M \qquad \mathbf{M} \qquad<br>$$</p><p>例子二十三:推导过程</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\begin</span><span class="token punctuation">{</span><span class="token keyword">align</span><span class="token punctuation">}</span><span class="token equation string"> <span class="token equation-command regex">\frac</span>{<span class="token equation-command regex">\partial</span> J(<span class="token equation-command regex">\theta</span>)}{<span class="token equation-command regex">\partial</span><span class="token equation-command regex">\theta</span>_j} & = -<span class="token equation-command regex">\frac</span>1m<span class="token equation-command regex">\sum</span>_{i=0}^m(y^i - h_<span class="token equation-command regex">\theta</span>(x^i)) <span class="token equation-command regex">\frac</span>{<span class="token equation-command regex">\partial</span>}{<span class="token equation-command regex">\partial</span><span class="token equation-command regex">\theta</span>_j}(y^i-h_<span class="token equation-command regex">\theta</span>(x^i))<span class="token equation-command regex">\\</span> & = -<span class="token equation-command regex">\frac</span>1m<span class="token equation-command regex">\sum</span>_{i=0}^m(y^i-h_<span class="token equation-command regex">\theta</span>(x^i)) <span class="token equation-command regex">\frac</span>{<span class="token equation-command regex">\partial</span>}{<span class="token equation-command regex">\partial</span><span class="token equation-command regex">\theta</span>_j}(<span class="token equation-command regex">\sum</span>_{j=0}^n<span class="token equation-command regex">\theta</span>_j x^i_j-y^i)<span class="token equation-command regex">\\</span> &=-<span class="token equation-command regex">\frac</span>1m<span class="token equation-command regex">\sum</span>_{i=0}^m(y^i -h_<span class="token equation-command regex">\theta</span>(x^i)) x^i_j</span><span class="token function selector">\end</span><span class="token punctuation">{</span><span class="token keyword">align</span><span class="token punctuation">}</span><span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>$$<br>\begin{align}<br>\frac{\partial J(\theta)}{\partial\theta_j}<br>& = -\frac1m\sum_{i=0}^m(y^i - h_\theta(x^i)) \frac{\partial}{\partial\theta_j}(y^i-h_\theta(x^i))\<br>& = -\frac1m\sum_{i=0}^m(y^i-h_\theta(x^i)) \frac{\partial}{\partial\theta_j}(\sum_{j=0}^n\theta_j x^i_j-y^i)\<br>&=-\frac1m\sum_{i=0}^m(y^i -h_\theta(x^i)) x^i_j<br>\end{align}<br>$$</p><p>此处放上显示的效果的图片,因为本博客使用的mathjax无法解析。</p><p>真实的显示效果应该如下:<img src="https://vskendo-1255590242.cos.ap-guangzhou.myqcloud.com/2022/05/04/135645-95.png" alt="image-20220504135644915"></p><p>例子二十四:批量梯度下降。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\frac</span><span class="token punctuation">{</span><span class="token function selector">\partial</span> J(<span class="token function selector">\theta</span>)<span class="token punctuation">}</span><span class="token punctuation">{</span><span class="token function selector">\partial</span><span class="token function selector">\theta</span>_j<span class="token punctuation">}</span> = -<span class="token function selector">\frac</span>1m<span class="token function selector">\sum</span>_<span class="token punctuation">{</span>i=0<span class="token punctuation">}</span>^m(y^i - h_<span class="token function selector">\theta</span>(x^i))x^i_j<span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>$$<br>\frac{\partial J(\theta)}{\partial\theta_j} = -\frac1m\sum_{i=0}^m(y^i - h_\theta(x^i))x^i_j<br>$$</p><p>例子二十五:字符下标。</p><pre class="line-numbers language-latex"><code class="language-latex"><span class="token equation string">$$</span><span class="token function selector">\max</span> <span class="token function selector">\limits</span>_<span class="token punctuation">{</span>a<x<b<span class="token punctuation">}</span><span class="token function selector">\{</span>f(x)<span class="token function selector">\}</span> <span class="token equation string">$$</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p>$$<br>\max \limits_{a<x<b}{f(x)}<br>$$</p><h1 id="一些说明"><a href="#一些说明" class="headerlink" title="一些说明"></a>一些说明</h1><ol><li>函数名通常用罗马字体正体排版,而不是像变量名一样用意大利体排版。因此,LATEX提供下述命令来排版最重要的一些函数名。</li></ol><pre class="line-numbers language-latex"><code class="language-latex"><span class="token function selector">\arccos</span> <span class="token function selector">\cos</span> <span class="token function selector">\csc</span> <span class="token function selector">\exp</span> <span class="token function selector">\ker</span> <span class="token function selector">\limsup</span> <span class="token function selector">\min</span><span class="token function selector">\arcsin</span> <span class="token function selector">\cosh</span> <span class="token function selector">\deg</span> <span class="token function selector">\gcd</span> <span class="token function selector">\lg</span> <span class="token function selector">\ln</span> <span class="token function selector">\Pr</span><span class="token function selector">\arctan</span> <span class="token function selector">\cot</span> <span class="token function selector">\det</span> <span class="token function selector">\hom</span> <span class="token function selector">\lim</span> <span class="token function selector">\log</span> <span class="token function selector">\sec</span><span class="token function selector">\arg</span> <span class="token function selector">\coth</span> <span class="token function selector">\dim</span> <span class="token function selector">\inf</span> <span class="token function selector">\liminf</span> <span class="token function selector">\max</span> <span class="token function selector">\sin</span><span class="token function selector">\sinh</span> <span class="token function selector">\sup</span> <span class="token function selector">\tan</span> <span class="token function selector">\tanh</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><ol start="2"><li><p>如果将命令\left 放在开分隔符前,TEX会自动决定分隔符的正确大</p><p>小。注意必须用对应的右分隔符\right 来关闭每一个左分隔符\left,并</p><p>且只有当这两个分隔符排在同一行时大小才会被正确确定。如果不想在右</p><p>边放任何东西,使用隐藏的‘\right.’ !</p></li></ol><h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><ol><li>LaTeX写数学公式:<a href="https://www.jianshu.com/p/e6d2368e451a">https://www.jianshu.com/p/e6d2368e451a</a></li><li>LaTeX 中插入数学公式:<a href="https://blog.csdn.net/weixin_42373330/article/details/89785443">https://blog.csdn.net/weixin_42373330/article/details/89785443</a></li><li>Typora中利用LaTeX 插入数学公式: <a href="https://blog.csdn.net/happyday_d/article/details/83715440">https://blog.csdn.net/happyday_d/article/details/83715440</a></li><li>试试LaTeX插入数学公式:<a href="https://blog.csdn.net/baidu_38060633/article/details/79183905">https://blog.csdn.net/baidu_38060633/article/details/79183905</a></li><li>LaTeX官方文档:<a href="https://www.latex-project.org/help/">https://www.latex-project.org/help/</a></li><li>Tobias Oetiker,Hubert Partl, Irene Hyna and Elisabeth Schlegl. 中国CTEX 用户小组[译]. 一份不太简短的LATEX2 介绍。Version 3.20, 09 August, 2001</li></ol>]]></content>
<categories>
<category> 写作 </category>
</categories>
<tags>
<tag> LaTex </tag>
<tag> Math </tag>
</tags>
</entry>
<entry>
<title>【重坑】SQLErrorCodes loaded</title>
<link href="/2020/11/05/chong-keng-sqlerrorcodes-loaded/"/>
<url>/2020/11/05/chong-keng-sqlerrorcodes-loaded/</url>
<content type="html"><![CDATA[<h1 id="情况"><a href="#情况" class="headerlink" title="情况"></a>情况</h1><p>使用mysql 5.6版本<br>报错:异常 SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]</p><p>通常来讲,这是我们的sql语句写错了(比如mybatis的mapper中的sql语句有错误)</p><p>但奇怪的是,我linux和windows都是同样版本的mysql,跑了同一份.sql文件。在windows平台的mysql下完美运行,而连接linux的mysql数据库就不行!</p><p>所以可能是权限设置问题(一般出现在Linux平台等对权限有要求的地方)</p><p> 这个情况在windows平台下并不常见,因为Windows对权限并没有严格要求。</p><h1 id="原因"><a href="#原因" class="headerlink" title="原因"></a>原因</h1><p>一般是由于root用户对全局host无访问权限。因此只要给root用户添加一个访问权限即可。 </p><h1 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h1><p>就我目前掌握的情况来看,出现这个问题的原因有很多,我遇到的是这两种情况,也是比较常见的。<br> 1.数据库的字段和输入的数据库的数据类型不匹配<br>比如说,一个字段int,你设置的长度是5,但是你输入了一个长度为6的值,就会出现这个错误。<br> 解决方法:</p><pre class="line-numbers language-bash"><code class="language-bash">找到有问题的字段,并加以改正<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>2.权限设置问题(一般出现在Linux平台等对权限有要求的地方)<br> 这个情况在windows平台下并不常见,因为Windows对权限并没有严格要求。<br> 原因:一般是由于root用户对全局host无访问权限。因此只要给root用户添加一个访问权限即可。<br> 解决方案(此方案由网友提出,我使用后并未解决问题,正在尝试其他方法):</p><pre class="line-numbers language-bash"><code class="language-bash">登陆mysql ,执行mysql -u root -pPasswdmysql <span class="token operator">></span>grant all privileges on *.* to root@<span class="token string">"%"</span> identified by <span class="token string">"Passwd"</span><span class="token punctuation">;</span>mysql <span class="token operator">></span>flush privileges<span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><p><a href="https://cloud.tencent.com/developer/article/1142524">https://cloud.tencent.com/developer/article/1142524</a></p>]]></content>
<categories>
<category> 运维 </category>
</categories>
<tags>
<tag> linux </tag>
<tag> 数据库 </tag>
<tag> sql </tag>
</tags>
</entry>
<entry>
<title>CentOs 安装本地yum仓库(createrepo+nginx实现)</title>
<link href="/2020/10/30/centos-an-zhuang-ben-di-yum-cang-ku-createrepo-nginx-shi-xian/"/>
<url>/2020/10/30/centos-an-zhuang-ben-di-yum-cang-ku-createrepo-nginx-shi-xian/</url>
<content type="html"><![CDATA[<h2 id="0-目的"><a href="#0-目的" class="headerlink" title="0. 目的"></a>0. 目的</h2><p>想要建立私有Yum仓库,方便运维。<br>我感觉搭建好以后,甚至可以当作自己的对象存储oss来用</p><h2 id="1-开始"><a href="#1-开始" class="headerlink" title="1. 开始"></a>1. 开始</h2><p>安装的系统为CentOs6。</p><pre><code>Linux gdei 2.6.32-754.el6.x86_64 #1 SMP Tue Jun 19 21:26:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux</code></pre><p>服务器地址为:192.168.219.130(VM虚拟机)<br>先安装nginx,要不然没有网页端服务。不需要网页端的可以跳过。</p><h2 id="2-暂时关闭防火墙"><a href="#2-暂时关闭防火墙" class="headerlink" title="2. 暂时关闭防火墙"></a>2. 暂时关闭防火墙</h2><p>关闭iptables :</p><pre><code>service iptables stop</code></pre><p>关闭selinux:<br>查看SELinux状态:</p><pre><code>/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态getenforce ##也可以用这个命令检查</code></pre><p>关闭SELinux:<br>1、临时关闭(不用重启机器):</p><pre><code>setenforce 0 ##设置SELinux 成为permissive模式 ##setenforce 1 设置SELinux 成为enforcing模式</code></pre><p>2、修改配置文件需要重启机器:<br>修改/etc/selinux/config 文件<br>将SELINUX=enforcing改为SELINUX=disabled<br>重启机器后关闭selinux</p><h2 id="3-安装createrepo"><a href="#3-安装createrepo" class="headerlink" title="3. 安装createrepo"></a>3. 安装createrepo</h2><p>准备软件仓库目录:</p><pre><code>mkdir /home/data -p</code></pre><p>使用yum的只下载不安装的方式进行下载软件(下载啥都行,此处以下载gcc为例,你也可以自己打包rmp然后放到仓库)</p><pre><code>yum install --downloadonly --downloaddir=/home/data gcc</code></pre><p>下载creatrepo:</p><pre><code>yum -y install createrepo</code></pre><p>开始运行服务:</p><pre><code>createrepo /yum/downloade/</code></pre><p>现在,自定义yum仓库已经搭建完成,目前只有gcc这一个包可供下载</p><h2 id="4-更新"><a href="#4-更新" class="headerlink" title="4. 更新"></a>4. 更新</h2><p>更新源数据:如果有新的软件包放入到软件仓库,这里就需要更新元数据。<br>也就是说每次将数据放入这个文件夹下想共享出去,放到这下面以后就要使用下面的命令更新一次。</p><pre><code>createrepo --update /home/data</code></pre><p>至此,搭建完成。</p><h2 id="5-使用Nginx制造网页端查看页面"><a href="#5-使用Nginx制造网页端查看页面" class="headerlink" title="5. 使用Nginx制造网页端查看页面"></a>5. 使用Nginx制造网页端查看页面</h2><p>要安装Nginx之前要安装epel,要不然装不了nginx</p><pre><code>yum install epel-release</code></pre><p>然后安装nginx</p><pre><code>yum install nginx</code></pre><p>开始配置nginx,配置完毕后网页端就能访问了</p><pre><code>cd /etc/nginx/conf.d/</code></pre><p>备份配置文件</p><pre><code>cp default.conf default.conf.bak</code></pre><p>开始修改配置文件</p><pre><code>vi default.conf </code></pre><p>修改成如下的样子</p><pre><code>server { listen 80; server_name 192.168.219.130; root /home/data; location / { autoindex on; autoindex_exact_size off; autoindex_localtime on; autoindex_format html; charset utf-8,gbk; root /home/data; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { }}</code></pre><h2 id="6-成功"><a href="#6-成功" class="headerlink" title="6. 成功"></a>6. 成功</h2><p>访问192.168.219.130(服务器IP),成功!效果如下:</p><p><img src="https://vskendo-1255590242.cos.ap-guangzhou.myqcloud.com/2022/05/05/060035-e2.png" alt="image-20220505060035049"></p><p>点击文件,可以下载:</p><p><img src="https://vskendo-1255590242.cos.ap-guangzhou.myqcloud.com/2022/05/05/060047-03.png" alt="image-20220505060047071"></p><h2 id="7-使用"><a href="#7-使用" class="headerlink" title="7. 使用"></a>7. 使用</h2><p>需要使用yum的客户端,需编辑配置文件,命令操作如下所示:</p><pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">cd</span> /etc/yum.repos.d/<span class="token function">cp</span> CentOS-Base.repo CentOS-Base.repo.bakvim CentOS-Base.repo<span class="token punctuation">[</span>base<span class="token punctuation">]</span> //中括号里内容要求唯一,但不要出现特殊字符name<span class="token operator">=</span>A <span class="token function">nice</span> description //此为描述信息,可以看情况填写baseurl<span class="token operator">=</span>http://192.168.219.130/ //此项为yum软件仓库位置enabled<span class="token operator">=</span>1 //此项为是否开启,1为开启, 0为不开启gpgcheck<span class="token operator">=</span>1 //此项为是否检查签名,1为检测, 0为不检测cost<span class="token operator">=</span>1000 <span class="token comment" spellcheck="true"># 默认yum仓库cost为1000, cost越小越优先</span>gpgkey<span class="token operator">=</span>0 //签名认证信息的路径//有些baseurl设置的稍微复杂,比如://<span class="token variable">$releasever</span>/os/<span class="token variable">$basearch</span>///其中// <span class="token variable">$releasever</span> <span class="token comment" spellcheck="true"># 只替换主版本号</span>// <span class="token variable">$basearch</span> <span class="token comment" spellcheck="true"># 系统基本架构</span>//具体配置请自己根据yum的配置知识来陪<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>运行以下命令生成缓存 :</p><pre class="line-numbers language-bash"><code class="language-bash">yum clean allyum makecache<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p>(因为有备份文件,随时可以换回来,所以不怕翻车)<br>附上阿里云的yum源配置文件下载(如果你是Centos7就将这个6换成7)</p><pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">wget</span> http://mirrors.aliyun.com/repo/Centos-6.repo//用wget下载后,放到/etc/yum.repos.d/文件夹下,并改名为CentOS-Base.repo//再运行上面2个命令重新生成缓存即可。<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><h2 id="8-参考"><a href="#8-参考" class="headerlink" title="8.参考"></a>8.参考</h2><p>搭建yum私有仓库:<a href="https://www.jianshu.com/p/c7c2dea549b1?open_source=weibo_search">https://www.jianshu.com/p/c7c2dea549b1?open_source=weibo_search</a><br>搭建私有YUM仓库与内网镜像站:<a href="http://www.360doc.com/content/19/0819/08/36367108_855782032.shtml">http://www.360doc.com/content/19/0819/08/36367108_855782032.shtml</a><br>创建私有yum仓库:<a href="https://www.cnblogs.com/zakzhu/p/11632971.html">https://www.cnblogs.com/zakzhu/p/11632971.html</a><br>Linux yum 命令:<a href="https://www.runoob.com/linux/linux-yum.html">https://www.runoob.com/linux/linux-yum.html</a><br>搭建私有yum仓库:<a href="https://www.cnblogs.com/37yan/p/6879287.html">https://www.cnblogs.com/37yan/p/6879287.html</a></p>]]></content>
<categories>
<category> 运维 </category>
</categories>
<tags>
<tag> CentOs </tag>
<tag> createrepo </tag>
</tags>
</entry>
<entry>
<title>CentOS安装mfs3.0</title>
<link href="/2020/10/14/centos-an-zhuang-mfs3-0/"/>
<url>/2020/10/14/centos-an-zhuang-mfs3-0/</url>
<content type="html"><![CDATA[<h1 id="需求:"><a href="#需求:" class="headerlink" title="需求:"></a>需求:</h1><p>需要安装一个日志文件系统,于是服务器按要求装了centos6<br>有6块1TB的STAT hdd,还有一个300G的SAS作为系统盘。<br>日志要求使用nfs协议,考虑到维护、拓展等因素,决定搭建mfs,然后在这基础上使用nfs。<br>系统IP为内网IP:210.38.69.12/26<br>日志服务器和我的电脑IP段:10.2.100.0/19<br>(mfs好处真的多,不仅有web端管理界面,而且后期如果要加硬盘就只需要改改配置文件,维护太方便了)<br>PS:mfs可以当成raid0来用,即软RAID。6块1TB的硬盘通过mfs就变成了1块5TiB的大硬盘了!</p><h2 id="1-下载和查看官方文档"><a href="#1-下载和查看官方文档" class="headerlink" title="1 下载和查看官方文档"></a>1 下载和查看官方文档</h2><p>我是按照它一步步来的,本文可以配合官方文档来食用…<br>提供个官网,以备不时之需:</p><p>如果你是Ubuntu、MACOS系统,我的操作会和你有点不一样,这点可以在官方文档里找到解决方案<br>我会在本文最后列出一些参考网站,希望能对你有帮助。本文只是简单搭建,具体配置和优化还请自行百度。</p><h2 id="2-系统要求"><a href="#2-系统要求" class="headerlink" title="2 系统要求"></a>2 系统要求</h2><p>mfs要求使用FUSE,需要Linux API 7.8或以上,即内核版本号要在2.6.0以上。然后因为有些的Linux可能有bug,所以版本号最好在2.6.24以上。<br>centos7或以上就不需要管了肯定没问题,我刚好是6,所以用<code>uname -a</code>来查看内核版本号<br>我是2.6.32,幸好我支持…<br>其他要求就在文档里了,什么内存不小于多少多少,如何计算你需要多少空间啥的,没啥用我就不列出来了<br>【请在root下操作,请暂时关闭防火墙(centos6为iptables)或添加防火墙放行规则】</p><h2 id="3-一些概念"><a href="#3-一些概念" class="headerlink" title="3 一些概念"></a>3 一些概念</h2><p>我真不是复制黏贴党,简单说说Mfs安装的东西是什么以及有什么用。<br>Master Server(元数据服务器):就是一个主服务器,用于控制存储服务器们<br>MetaLogger(元数据日志服务器):备份Master服务器的变化日志文件,当master服务器损坏,这服务器可以恢复文件。【说白了如果不需要这个服务器可以不搭建】<br>Chunk Server(数据存储服务器):这就是真正存数据的服务器了,里面挂载了大量的硬盘用来存数据,上面说的Master就是用来控制这个服务器的。<br>Client(客户端): 可以像挂载NFS一样(但其本身不是NFS),挂载MFS文件系统。<br>一台服务器可以同时搭建Master Server+ Metalogger + Chunk Server + Client【究极四合一】</p><p>【根据上面的用途,可以得出结论:一般是搭建mfs的话是使用 一个Master和很多个这种Chunk Server,如果有需要的话还有个MetaLogger。客户端装个Client就完事了】</p><h2 id="4-开搞,安装主服务Master-Server"><a href="#4-开搞,安装主服务Master-Server" class="headerlink" title="4 开搞,安装主服务Master Server"></a>4 开搞,安装主服务Master Server</h2><p>开局先来5条命令<br><code>yum install rpm-build gcc gcc-c++ fuse-devel zlib-devel</code><br><code>useradd -s /sbin/nologin mfs</code><br><code>curl " http://ppa.moosefs.com/RPM -GPG -KEY - MooseFS " > /etc/pki/rpm -gpg/RPM -GPG -KEY -MooseFS</code><br>#centos7的话要将下面的el6改成el7<br> <code>curl " http://ppa.moosefs.com/MooseFS-3-el6.repo " > /etc/yum.repos.d/MooseFS.repo</code><br>更新一下yum<br><code>yum update</code><br>然后<br><code>yum install moosefs-master moosefs-cgi moosefs-cgiserv moosefs-cli</code><br>安装成功之后进入目录<br><code>cd / etc/ mfs</code><br>目录里有 cfg和 cfg.sample文件,通过diff我发现这两种文件是一样的…<br>我建议你先执行以下语句:<br><code>cp mfsmaster.cfg mfsmaster.cfg.bak</code><br><code>cp mfsexports.cfg mfsexports.cfg.bak</code><br>然后再是:<br><code>cp mfsmaster.cfg.sample mfsmaster.cfg</code><br><code>cp mfsexports.cfg.sample mfsexports.cfg</code><br>按照官方的说法,.cfg.sample文件是简单的例子,而.cfg是正在使用的配置文件,那既然这样我们就创建个.bak文件备份一下吧。<br>编辑mfsexports.cfg文件。这个文件是管理权限的,详细的文件意思可以百度或者看文档内的注释。<br>反正直接加上下面这条就好了<br><code>你客户端的网络号/你客户端的掩码 / rw,alldirs,maproot =0</code><br>(注意网络号不等于IP)<br>因为我电脑(win10)和日志服务器(CentOs)都在10.2.100.0/19网络中,所以我加的是<br><code>10.2.100.0/19 / rw,alldirs,maproot=0,password=mfs</code><br>即允许10.2.100.0/19中所有主机访问 MFS根目录 可读写、允许挂载任何指定的子目录、映射为root、密码为mfs<br>使用<code>mfsmaster -a start</code>来启动,网友建议启动时都加上<code>-a</code>,具体区别请自行百度。<br>其中,<code>mfsmaster stop</code>是关闭,<code>mfsmaster restart</code>是重启,这些基本知识就不说了。<br>如果没有报错,那么安装就成功了,记得将主服务器设为开机启动<br><code>chkconfig --add moosefs-master</code><br><code>chkconfig moosefs-master on</code> </p><h2 id="5-安装MFS元数据日志服务器"><a href="#5-安装MFS元数据日志服务器" class="headerlink" title="5 安装MFS元数据日志服务器"></a>5 安装MFS元数据日志服务器</h2><p>我没装,如果你要装可以看看本文最后面的参考资料。这个安装也简单。<br>【元数据日志守护进程是在安装master server 时一同安装的,最小的要求并不比master 本身大,可以被运行在任何机器上(例如任一台chunkserver),但是最好是放置在MooseFS master 的备份机上,备份master 服务器的变化日志文件,文件类型为changelog_ml.*.mfs。因为主要的master server 一旦失效,可能就会将这台metalogger 机器取代而作为master server。】</p><h2 id="6-安装web监视服务"><a href="#6-安装web监视服务" class="headerlink" title="6 安装web监视服务"></a>6 安装web监视服务</h2><p>按照官方文档的说法,只要是个Linux机器都能装这个监视服务,只要装了以后输入Master的ip就可以了。<br>但是官方强烈建议给装了Master Server的机器都装上这个web监视服务<br><code>yum install moosefs-cgi moosefs-cgiserv moosefs-cli</code><br>修改hosts文件 <code>vi /etc/hosts</code>,添加一条规则: <code>这台服务器的IP mfsmaster</code><br>然后就可以启动服务了<br><code>service moosefs-cgiserv start</code><br>web管理的URL是 <code>localhost:9425/mfs.cgi</code> ,其他电脑可以输入URL:<code>服务器IP:9425/mfs.cgi</code>进行访问<br>访问不了?看看防火墙设置!</p><h2 id="7-安装存储服务器Chunk-servers"><a href="#7-安装存储服务器Chunk-servers" class="headerlink" title="7 安装存储服务器Chunk servers"></a>7 安装存储服务器Chunk servers</h2><p>想要安装数据服务器(chunkservers),这些机器的磁盘上不仅要有适当的剩余空间,还要求操作系统遵循POSIX 标准(如:Linux, FreeBSD, Mac OS X and OpenSolaris)。<br>如果你的Chunk服务器和Master服务器不是同一台,记得安装mfs的依赖<br><code>yum install rpm-build gcc gcc-c++ fuse-devel zlib-devel –y</code><br> <code>useradd -s /sbin/nologin mfs</code><br>然后安装<code>yum install moosefs-chunkserver</code><br>备份一下配置文件。<br><code>cd /etc/mfs</code><br><code>cp mfschunkserver.cfg mfschunkserver.cfg.bak</code><br><code>cp mfshdd.cfg mfshdd.cfg.bak</code><br><code>cp mfschunkserver.cfg.sample mfschunkserver.cfg</code><br><code>cp mfshdd.cfg.sample mfshdd.cfg</code><br>这个时候你在文件mfshdd.cfg中指定要使用哪些硬盘,然后启动服务就搞定了<br>比如假设我要使用sde和sdc两块硬盘,那么久<br><code>chown -R mfs:mfs /mnt/sde</code><br><code>chown -R mfs:mfs /mnt/sdc</code><br>然后在mfshdd.cfg文件中添加2行<br><code>/mnt/sde</code><br><code>/mnt/sdc</code><br>启动服务<br><code>service moosefs-chunkserver start</code><br>加入开机启动项<br><code>chkconfig --add moosefs-chunkserver</code><br><code>chkconfig moosefs-chunkserver on</code><br>安装完成<br>但是我的服务器插了6块1T的硬盘还没挂载…我6块硬盘分别是 sdb sdc sdd sde sdf sdg<br>于是我要先将它们格式化,然后设置成开机自动挂载,然后挂载。<br><code>mkfs -t ext3 /dev/sdb</code><br><code>mkfs -t ext3 /dev/sdc</code><br><code>mkfs -t ext3 /dev/sdd</code><br><code>mkfs -t ext3 /dev/sde</code><br><code>mkfs -t ext3 /dev/sdf</code><br><code>mkfs -t ext3 /dev/sdg</code><br>所以我要用上面的格式化指令先格式化6块盘<br>然后在mnt目录下创建6个目录<br><code>mkdir -p /mnt/sdb</code><br><code>mkdir -p /mnt/sdc</code><br><code>mkdir -p /mnt/sdd</code><br><code>mkdir -p /mnt/sde</code><br><code>mkdir -p /mnt/sdf</code><br><code>mkdir -p /mnt/sdg</code><br>然后挂载我亲爱的STAT盘<br><code>mount /dev/sdb /mnt/sdb/</code><br><code>mount /dev/sdc /mnt/sdc/</code><br><code>mount /dev/sdd /mnt/sdd/</code><br><code>mount /dev/sde /mnt/sde/</code><br><code>mount /dev/sdf /mnt/sdf/</code><br><code>mount /dev/sdg /mnt/sdg/</code><br>更改权限<br><code>chown -R mfs:mfs /mnt/sdb chown -R mfs:mfs /mnt/sdc chown -R mfs:mfs /mnt/sdd chown -R mfs:mfs /mnt/sde chown -R mfs:mfs /mnt/sdf chown -R mfs:mfs /mnt/sdg</code><br>然后还得开机自动挂载,要不然重启一下chunk服务器就找不到磁盘咯<br><code>ll /dev/disk/by-uuid/</code>查找所有硬盘的UUID<br>然后<code>vim /etc/fstab</code>,在最后面加上6行(我UUID就删了哈,不给你们看)<br><code>UUID= /mnt/sdb ext3 defaults 0 0 UUID= /mnt/sdc ext3 defaults 0 0 UUID= /mnt/sdd ext3 defaults 0 0 UUID= /mnt/sde ext3 defaults 0 0 UUID= /mnt/sdf ext3 defaults 0 0 UUID= /mnt/sdg ext3 defaults 0 0</code><br>最后在/etc/mfs/mfshdd.cfg下增加6行<br><code>/mnt/sdb /mnt/sdc /mnt/sdd /mnt/sde /mnt/sdf /mnt/sdg</code><br>启动chunk服务,增加chunk服务开机自动启动,完事。</p><h2 id="8-验证安装结果"><a href="#8-验证安装结果" class="headerlink" title="8 验证安装结果"></a>8 验证安装结果</h2><p>所有服务都搭载在210.38.69.12上,没有问题</p><p><img src="https://vskendo-1255590242.cos.ap-guangzhou.myqcloud.com/2022/05/05/060526-91.png" alt="image-20220505060526805"></p><p>至此,mfs搭建完成</p><h2 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h2><p>MFS官网:<a href="http://www.moosefs.com/">http://www.moosefs.com</a><br>MFS分布式文件系统:<a href="https://blog.51cto.com/13555423/2082796">https://blog.51cto.com/13555423/2082796</a><br>MFS分布式文件系统:<a href="https://cloud.tencent.com/developer/article/1520226">https://cloud.tencent.com/developer/article/1520226</a><br>Linux的企業-分布式文件系統mfs(moosefs)搭建與配置:<a href="https://www.itread01.com/content/1508786402.html">https://www.itread01.com/content/1508786402.html</a></p>]]></content>
<categories>
<category> 运维 </category>
</categories>
<tags>
<tag> CentOS </tag>
<tag> mfs </tag>
</tags>
</entry>
</search>