forked from fomalhaut1998/hexo-theme-Fomalhaut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
465 lines (246 loc) · 109 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>dddachui🚭</title>
<link href="https://www.dddachui.top/atom.xml" rel="self"/>
<link href="https://www.dddachui.top/"/>
<updated>2023-03-30T14:56:42.480Z</updated>
<id>https://www.dddachui.top/</id>
<author>
<name>dddachui.top</name>
</author>
<generator uri="https://hexo.io/">Hexo</generator>
<entry>
<title>三剑客-sed</title>
<link href="https://www.dddachui.top/posts/c9de9d82.html"/>
<id>https://www.dddachui.top/posts/c9de9d82.html</id>
<published>2023-03-30T14:28:45.000Z</published>
<updated>2023-03-30T14:56:42.480Z</updated>
<content type="html"><![CDATA[<h1>替换</h1><p>在Linux系统中,可以使用sed命令来替换文件中的文本内容。要将所有的“kylin”替换为“ikun”,可以使用以下命令:</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">sed</span> -i <span class="string">'s/kun/ikun/g'</span> filename</span><br></pre></td></tr></table></figure><p>将上面的 <code>filename</code> 替换为实际的文件名,这个命令将直接修改这个文件,将其中所有的“kylin”替换为“ikun”。</p><p>解释一下命令中的选项和参数:</p><ul><li><code>-i</code>:表示直接修改文件内容,而不是输出到终端或另一个文件中。</li><li><code>s/kun/ikun/g</code>:这是一个正则表达式,表示将“kylin”替换为“ikun”。其中,<code>s</code>表示替换操作,<code>/</code>是分隔符,<code>g</code>表示全局替换,即将每个匹配的“kun”都替换为“ikun”。</li></ul><p>请注意,在使用sed命令修改文件内容时,建议先备份原文件,以防止意外修改导致数据丢失。</p><h1>增加</h1><p>在Linux系统中,可以使用sed命令来修改GRUB引导参数,以添加 <code>net.ifnames=1 biosdevname</code> 选项。要在quiet选项后增加这个选项,可以使用以下命令:</p><figure class="highlight gradle"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo sed -i <span class="string">'s/quiet/quiet net.ifnames=1 biosdevname/g'</span> <span class="regexp">/etc/</span><span class="keyword">default</span>/grub</span><br></pre></td></tr></table></figure><p>这个命令将修改 <code>/etc/default/grub</code> 文件,将其中的 <code>quiet</code> 选项替换为 <code>quiet net.ifnames=1 biosdevname</code>,并保存修改后的文件。</p><p>解释一下命令中的选项和参数:</p><ul><li><code>sudo</code>:表示使用管理员权限来执行命令。</li><li><code>-i</code>:表示直接修改文件内容,而不是输出到终端或另一个文件中。</li><li><code>s/quiet/quiet net.ifnames=1 biosdevname/g</code>:这是一个正则表达式,表示将 <code>quiet</code> 替换为 <code>quiet net.ifnames=1 biosdevname</code>。其中,<code>s</code>表示替换操作,<code>/</code>是分隔符,<code>g</code>表示全局替换,即将每个匹配的 <code>quiet</code> 都替换为 <code>quiet net.ifnames=1 biosdevname</code>。</li><li><code>/etc/default/grub</code>:指定要修改的GRUB配置文件的路径。</li></ul><h1>删除</h1><p>在Linux系统中,可以使用sed命令来删除文件中的特定文本行。要删除文件中的 <code>modprobe.blacklist=nouveau</code> 行,可以使用以下命令:</p><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">sed</span> -i <span class="string">'/modprobe.blacklist=nouveau/d'</span> filename</span><br></pre></td></tr></table></figure><p>将上面的 <code>filename</code> 替换为实际的文件名,这个命令将直接修改这个文件,将其中所有包含 <code>modprobe.blacklist=nouveau</code> 的行删除。</p><p>解释一下命令中的选项和参数:</p><ul><li><code>-i</code>:表示直接修改文件内容,而不是输出到终端或另一个文件中。</li><li><code>/modprobe.blacklist=nouveau/d</code>:这是一个正则表达式,表示删除所有包含 <code>modprobe.blacklist=nouveau</code> 的行。其中,<code>/</code>是分隔符,<code>d</code>表示删除匹配的行。</li></ul><p>请注意,在使用sed命令修改文件内容时,建议先备份原文件,以防止意外修改导致数据丢失。</p>]]></content>
<summary type="html">描述</summary>
<category term="分类" scheme="https://www.dddachui.top/categories/%E5%88%86%E7%B1%BB/"/>
<category term="暂存" scheme="https://www.dddachui.top/tags/%E6%9A%82%E5%AD%98/"/>
</entry>
<entry>
<title>Linux好用命令之wall</title>
<link href="https://www.dddachui.top/posts/c4b461e0.html"/>
<id>https://www.dddachui.top/posts/c4b461e0.html</id>
<published>2023-03-30T06:03:12.000Z</published>
<updated>2023-03-30T14:56:42.477Z</updated>
<content type="html"><![CDATA[<h1>使用方式</h1><ul><li>向所有终端广播</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wall "hello"</span><br></pre></td></tr></table></figure><ul><li>排除邮件前面的头条文本</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wall -n "hello"</span><br></pre></td></tr></table></figure><ul><li>给组发信息</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wall -g <span class="built_in">test</span> <span class="string">"hello"</span></span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><h1>使用方式</h1>
<ul>
<li>向所有终端广播</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></summary>
<category term="linux命令" scheme="https://www.dddachui.top/categories/linux%E5%91%BD%E4%BB%A4/"/>
<category term="linux命令" scheme="https://www.dddachui.top/tags/linux%E5%91%BD%E4%BB%A4/"/>
</entry>
<entry>
<title>centos修改网卡名</title>
<link href="https://www.dddachui.top/posts/63943f11.html"/>
<id>https://www.dddachui.top/posts/63943f11.html</id>
<published>2023-03-29T14:08:29.000Z</published>
<updated>2023-03-30T14:56:42.482Z</updated>
<content type="html"><![CDATA[<h1>需求</h1><p>centos6系统使用的网卡名都是eth开头的,而centos7以上都是以设备类型来划分的,如果使用不习惯或者有其他xp兴趣可以根据自己的喜好来修改</p><h1>参数解释</h1><h2 id="net-ifnames">net.ifnames</h2><p>用于控制Linux系统中网络接口的命名规则,在不同发行版上有不同的命名方式,该参数有三种选项</p><ul><li>0:使用传统的命名,一般来说安装系统的时候使用这个参数就可以了,但难免会碰到一样的机器网卡物理位置一样但实际每台机器顺序可能不一样的问题</li><li>1:使用基于连接的命名方式</li><li>2:使用基于路径的命名方式</li></ul><h3 id="biosdevname">biosdevname</h3><p><code>biosdevname</code> 参数是用于控制Linux系统中网络接口命名的一种机制。当该参数启用时,Linux系统会在命名网络接口时使用BIOS提供的设备名称,而不是使用传统的基于总线、插槽和端口的命名方式。</p><p>启用<code>biosdevname</code>参数的主要作用是简化网络接口的管理和配置,特别是在具有多个网络接口的系统中。使用BIOS提供的设备名称可以使网络管理员更容易识别和区分不同的网络接口,并更容易地配置和管理网络接口。</p><p>请注意,启用<code>biosdevname</code>参数可能会导致Linux系统中网络接口的命名方式发生变化,因此在启用该参数之前,建议备份网络接口的配置文件。此外,该参数需要BIOS支持,因此不是所有的系统都支持该参数</p><h1>centos6修改</h1><h2 id="移除优先级高的udev规则">移除优先级高的udev规则</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mv /lib/udev/rules.d/75-persistent-net-generator.rules /tmp</span><br></pre></td></tr></table></figure><h2 id="修改udev规则">修改udev规则</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/udev/rules.d/70-persistent-net.rules</span><br></pre></td></tr></table></figure><p>修改内容如下,其中ATTR除是mac地址,NAME是你要修改的网卡名</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="00:0c:29:2c:ad:8e", NAME="eth1"</span><br></pre></td></tr></table></figure><h1>centos7 修改</h1><h2 id="修改引导">修改引导</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/default/grub</span><br></pre></td></tr></table></figure><p>在GRUB_CMDLINE_LINUX除加入<code>net.ifnames=1 bisodevname=0</code>选项并用<code>grub2-mkconfig</code>重新生成grub</p><h2 id="修改udev规则-2">修改udev规则</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/udev/rules.d/70-persistent-net.rules</span><br></pre></td></tr></table></figure><p>修改内容如下,其中ATTR除是mac地址,NAME是你要修改的网卡名</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="00:0c:29:2c:ad:8e", NAME="eth1"</span><br></pre></td></tr></table></figure><h2 id="修改配置文件">修改配置文件</h2><p>根据使用的网络管理器(NetworkManager或者Network)来修改配置文件,将网卡名替换掉</p><h2 id="重启验证">重启验证</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">reboot</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">修改网卡名</summary>
<category term="网络管理" scheme="https://www.dddachui.top/categories/%E7%BD%91%E7%BB%9C%E7%AE%A1%E7%90%86/"/>
<category term="网络管理" scheme="https://www.dddachui.top/tags/%E7%BD%91%E7%BB%9C%E7%AE%A1%E7%90%86/"/>
</entry>
<entry>
<title>Linux好用命令之auditctl</title>
<link href="https://www.dddachui.top/posts/ee30c79.html"/>
<id>https://www.dddachui.top/posts/ee30c79.html</id>
<published>2023-03-26T15:30:51.000Z</published>
<updated>2023-03-26T10:39:21.258Z</updated>
<content type="html"><![CDATA[<ul><li>列出规则</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">auditctl -l</span><br></pre></td></tr></table></figure><ul><li>写入规则</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">auditctl -w 目录的绝对路径</span><br></pre></td></tr></table></figure><ul><li>删除规则</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">audictl -W 目录的绝对路径</span><br></pre></td></tr></table></figure><ul><li>审计状态</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">auditctl -s</span><br></pre></td></tr></table></figure><ul><li>查看效果</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ausearch -f 目录的绝对路径</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><ul>
<li>列出规则</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td cl</summary>
<category term="linux命令" scheme="https://www.dddachui.top/categories/linux%E5%91%BD%E4%BB%A4/"/>
<category term="linux命令" scheme="https://www.dddachui.top/tags/linux%E5%91%BD%E4%BB%A4/"/>
</entry>
<entry>
<title>Linux好用命令之devtoolset</title>
<link href="https://www.dddachui.top/posts/d171c710.html"/>
<id>https://www.dddachui.top/posts/d171c710.html</id>
<published>2023-03-26T15:30:51.000Z</published>
<updated>2023-03-27T02:31:40.896Z</updated>
<content type="html"><![CDATA[<h1>前言</h1><p>CentOS/RHEL Linux 发行版以稳定性著称,所有的软件都要尽可能 stable,导致的一个结果就是基础软件的版本非常的低,比如 CentOS 6.7(15年发布) 中 gcc 版本还是 4.4.7(12年的版本)。这对开发来说就不是很友好,比如我们想用 C++ 11 中的某个特性,就必须自己编译一个高版本的 gcc 出来,但是这会有另外一个问题,开发环境不好维护,如果自己有多台电脑或者多个人合作的项目,每台机器上都要自己编一份,维护起来就比较麻烦。</p><h1>解决办法</h1><p>devtoolset + scl<br>在centos7上默认gcc是4.8.5,如果需要gcc10可以安装devtoolset-10版本来支持,其他版本也如此</p><h1>devtoolset-7依赖关系</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">先装这2两个依赖</span></span><br><span class="line">devtoolset-7-runtime-7.1-4.ky3.kb1.x86_64.rpm</span><br><span class="line">devtoolset-7-binutils-2.28-11.ky3.kb1.x86_64.rpm</span><br><span class="line">devtoolset-7-gcc-7.3.1-5.15.ky3.kb1.x86_64.rpm</span><br><span class="line">devtoolset-7-libstdc++-devel-7.3.1-5.15.ky3.kb1.x86_64.rpm</span><br><span class="line">devtoolset-7-gcc-c++-7.3.1-5.15.ky3.kb1.x86_64.rpm</span><br></pre></td></tr></table></figure><h1>切换</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">scl enable devtoolset-10 bash </span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><h1>前言</h1>
<p>CentOS/RHEL Linux 发行版以稳定性著称,所有的软件都要尽可能 stable,导致的一个结果就是基础软件的版本非常的低,比如 CentOS 6.7(15年发布) 中 gcc 版本还是 4.4.7(12年的版本)。这对开发来说就不是很友好</summary>
<category term="linux命令" scheme="https://www.dddachui.top/categories/linux%E5%91%BD%E4%BB%A4/"/>
<category term="linux命令" scheme="https://www.dddachui.top/tags/linux%E5%91%BD%E4%BB%A4/"/>
</entry>
<entry>
<title>Linux好用命令之ethtool</title>
<link href="https://www.dddachui.top/posts/c0d4357c.html"/>
<id>https://www.dddachui.top/posts/c0d4357c.html</id>
<published>2023-03-26T15:30:51.000Z</published>
<updated>2023-03-27T02:21:37.754Z</updated>
<content type="html"><![CDATA[<h1>命令简介</h1><p>查看网口信息</p><h1>查看网卡信息</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ethtool eth0</span><br></pre></td></tr></table></figure><ul><li>网卡信息如下<br>可以看出网卡的很多信息,包括网卡速率是百兆还是千兆</li></ul><figure class="highlight txt"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">Settings for enp2s0:</span><br><span class="line"> Supported ports: [ TP MII ]</span><br><span class="line"> Supported link modes: 10baseT/Half 10baseT/Full</span><br><span class="line"> 100baseT/Half 100baseT/Full</span><br><span class="line"> 1000baseT/Half 1000baseT/Full</span><br><span class="line"> Supported pause frame use: Symmetric Receive-only</span><br><span class="line"> Supports auto-negotiation: Yes</span><br><span class="line"> Supported FEC modes: Not reported</span><br><span class="line"> Advertised link modes: 10baseT/Half 10baseT/Full</span><br><span class="line"> 100baseT/Half 100baseT/Full</span><br><span class="line"> 1000baseT/Half 1000baseT/Full</span><br><span class="line"> Advertised pause frame use: Symmetric Receive-only</span><br><span class="line"> Advertised auto-negotiation: Yes</span><br><span class="line"> Advertised FEC modes: Not reported</span><br><span class="line"> Link partner advertised link modes: 10baseT/Half 10baseT/Full</span><br><span class="line"> 100baseT/Half 100baseT/Full</span><br><span class="line"> 1000baseT/Full</span><br><span class="line"> Link partner advertised pause frame use: Symmetric</span><br><span class="line"> Link partner advertised auto-negotiation: Yes</span><br><span class="line"> Link partner advertised FEC modes: Not reported</span><br><span class="line"> Speed: 1000Mb/s #当前速率</span><br><span class="line"> Duplex: Full </span><br><span class="line"> Auto-negotiation: on</span><br><span class="line"> master-slave cfg: preferred slave</span><br><span class="line"> master-slave status: slave</span><br><span class="line"> Port: Twisted Pair</span><br><span class="line"> PHYAD: 0</span><br><span class="line"> Transceiver: external</span><br><span class="line"> MDI-X: Unknown</span><br><span class="line"> Supports Wake-on: pumbg</span><br><span class="line"> Wake-on: d</span><br><span class="line"> Link detected: yes #是否连通物理网线</span><br></pre></td></tr></table></figure><h1>把网卡指示灯打开</h1><p>在网卡支持这种功能的前提下,使用此命令会使网卡的指示灯闪烁,但需要注意,有些系统会持续闪烁,但有些版本会闪烁几秒</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ethtool -p eth0</span><br></pre></td></tr></table></figure><h1>查看网卡驱动程序信息</h1><p>查询指定的网络设备以获取相关的驱动程序信息。</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ethtool -i eth0</span><br></pre></td></tr></table></figure><p>如下</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">driver: e1000</span><br><span class="line">version: 7.3.21-k8-NAPI</span><br><span class="line">firmware-version: </span><br><span class="line">expansion-rom-version: </span><br><span class="line">bus-info: 0000:02:01.0</span><br><span class="line">supports-statistics: yes</span><br><span class="line">supports-test: yes</span><br><span class="line">supports-eeprom-access: yes</span><br><span class="line">supports-register-dump: yes</span><br><span class="line">supports-priv-flags: no</span><br></pre></td></tr></table></figure><h1>列出网络接口统计信息</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ethtool -S eth0</span><br></pre></td></tr></table></figure><h1>设置网络接口速度</h1><p>eth0自适应100、1000,指定他是百兆</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ethtool -s eth0 speed 1000 duplex full autoneg off</span><br></pre></td></tr></table></figure><h1>重置网卡到自适应模式</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ethtool -r eth0</span><br></pre></td></tr></table></figure><h1>将ethtool的设置跟随网卡</h1><p>写在ifcfg-ethX配置里面</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ETHTOOL_OPTS="speed 100 deplex full autoneg off"</span><br></pre></td></tr></table></figure><h1>查看错误信息</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ethtool -S eth0 | grep error</span><br></pre></td></tr></table></figure><p>同时,使用<code>ifconfig</code> 也可以看错误信息</p><h2 id="错误信息">错误信息</h2><ul><li>RX errors<br>表示总的收包的错误数量,这包括 too-long-frames 错误,Ring Buffer 溢出错误,crc 校验错误,帧同步错误,fifo overruns 以及 missed pkg 等等</li><li>RX dropped<br>表示数据包已经进入了 Ring Buffer,但是由于内存不够等系统原因,导致在拷贝到内存的过程中被丢弃</li><li>RX overruns<br>表示了 fifo 的 overruns,这是由于 Ring Buffer(aka Driver Queue) 传输的 IO 大于 kernel 能够处理的 IO 导致的,而 Ring Buffer 则是指在发起 IRQ 请求之前的那块 buffer。很明显,overruns 的增大意味着数据包没到 Ring Buffer 就被网卡物理层给丢弃了(就是ring buffer满之后先有drop收到的,再overrun没收的),而 CPU 无法即使的处理中断是造成 Ring Buffer 满的原因之一</li><li>RX frame<br>表示 misaligned 的 frames</li></ul><h2 id="rx-crc-errors">rx_crc_errors</h2><p>在大多数情况下,增加rx_crc_errors的值意味着该问题出在网络模型的第1层,当在接口上接收到数据包时,它将经历数据完整性检查,这称为循环冗余检查。 如果数据包在该检查中失败,则将其标记为rx_crc_errors<br>1.更换电缆。<br>2.检查交换机配置。<br>3.更换网络接口卡。</p><h1>查看网卡</h1>]]></content>
<summary type="html">查看网口用的</summary>
<category term="linux命令" scheme="https://www.dddachui.top/categories/linux%E5%91%BD%E4%BB%A4/"/>
<category term="linux命令" scheme="https://www.dddachui.top/tags/linux%E5%91%BD%E4%BB%A4/"/>
</entry>
<entry>
<title>Linux好用命令之expect</title>
<link href="https://www.dddachui.top/posts/a5a7ce3.html"/>
<id>https://www.dddachui.top/posts/a5a7ce3.html</id>
<published>2023-03-26T15:30:51.000Z</published>
<updated>2023-03-26T10:40:20.644Z</updated>
<content type="html"><![CDATA[<h1>作用</h1><p>交互式自动输入</p><h1>安装</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y expect</span><br></pre></td></tr></table></figure><h1>简单示例</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">cat expect.sh </span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">!/usr/bin/expec</span></span><br><span class="line">set timeout 20</span><br><span class="line">spawn ssh [email protected]</span><br><span class="line">expect "root"</span><br><span class="line">send "paic1234\n"</span><br><span class="line">interact</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">自动化脚本输入</summary>
<category term="linux命令" scheme="https://www.dddachui.top/categories/linux%E5%91%BD%E4%BB%A4/"/>
<category term="linux命令" scheme="https://www.dddachui.top/tags/linux%E5%91%BD%E4%BB%A4/"/>
</entry>
<entry>
<title>Linux好用命令之nmcli</title>
<link href="https://www.dddachui.top/posts/6ad86d1e.html"/>
<id>https://www.dddachui.top/posts/6ad86d1e.html</id>
<published>2023-03-26T15:30:51.000Z</published>
<updated>2023-03-26T10:18:27.758Z</updated>
<content type="html"><![CDATA[<h1>NetworkManager</h1><ol><li>NetworkManager服务是管理和监控网络设置的守护进程,Centos7之前的版本都是通过network.service管理网络配置</li><li>到了Centos7就同时支持network.service和NetworkManager.service</li><li>在RHEL 8/Centos 8上已废弃network.service(默认不安装),只能通过NetworkManager进行网络配置。</li><li>NetworkManager主要管理2个对象 <code>Connection</code>(网卡连接配置) 和 <code>Device</code>(网卡设备),他们之间是多对一的关系,但是同一时刻只能有一个Connection对于Device才生效</li></ol><h1>启动方法</h1><p>启动+开机自启动</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl enable --now NetworkManager</span><br></pre></td></tr></table></figure><h1>三种方法配置网络</h1><ol><li>通过nmcli connection add命令配置,会自动生成ifcfg文件</li><li>手动配置ifcfg文件,通过nmcli connection reload来加载生效</li><li>手动配置ifcfg文件,通过传统network.service来加载生效</li></ol><h1>nmcli基操</h1><p>NetworkManager在系统中的管理工具为nmcli,这个命令<code>嘎嘎好用</code></p><h2 id="查看所有连接">查看所有连接</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection show </span><br></pre></td></tr></table></figure><h2 id="查看所有激活的连接">查看所有激活的连接</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection show --active</span><br></pre></td></tr></table></figure><h2 id="查看指定的网口的连接">查看指定的网口的连接</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection show eth0</span><br></pre></td></tr></table></figure><h2 id="关闭连接">关闭连接</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection down eth0</span><br></pre></td></tr></table></figure><h2 id="启用连接">启用连接</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection up eth0</span><br></pre></td></tr></table></figure><h1>nmcli配置网络实例-dhcp</h1><h2 id="新增连接">新增连接</h2><ul><li>创建一个连接名<code>dachui</code>,使用ens33设备</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection add con-name dachui type Ethernet ifname ens33</span><br></pre></td></tr></table></figure><h2 id="展示创建后的效果">展示创建后的效果</h2><p>(实在不想配图)<br>可以看出只有一个行<code>NAME</code>是ens33是激活的(因为激活的连接在终端显示绿色,或者用–active可以看出来)</p><figure class="highlight txt"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">NAME UUID TYPE DEVICE </span><br><span class="line">ens33 c96bc909-188e-ec64-3a96-6a90982b08ad ethernet ens33 </span><br><span class="line">dachui 4b27c0d3-17d5-434b-90d1-5ac57a0f6147 ethernet -- </span><br><span class="line">ens34 94aea789-efb3-ef4c-81b0-e8b18ecc9797 ethernet -- </span><br></pre></td></tr></table></figure><h2 id="查看dachui的配置">查看<code>dachui</code>的配置</h2><p>如果不加<code>grep</code>,他会显示很多信息,但我们只需要关注ipv4的信息</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection show dachui | grep ipv4</span><br></pre></td></tr></table></figure><h2 id="配置展示">配置展示</h2><p>可以看出第一行<code>ipv4.method</code>的是<code>auto</code>,他代表<code>dachui</code>这个连接是用<code>dhcp</code>的方式获取ip的</p><figure class="highlight txt"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">ipv4.method: auto</span><br><span class="line">ipv4.dns: --</span><br><span class="line">ipv4.dns-search: --</span><br><span class="line">ipv4.dns-options: ""</span><br><span class="line">ipv4.dns-priority: 0</span><br><span class="line">ipv4.addresses: --</span><br><span class="line">ipv4.gateway: --</span><br><span class="line">ipv4.routes: --</span><br><span class="line">ipv4.route-metric: -1</span><br><span class="line">ipv4.route-table: 0 (unspec)</span><br><span class="line">ipv4.routing-rules: --</span><br><span class="line">ipv4.ignore-auto-routes: 否</span><br><span class="line">ipv4.ignore-auto-dns: 否</span><br><span class="line">ipv4.dhcp-client-id: --</span><br><span class="line">ipv4.dhcp-timeout: 0 (default)</span><br><span class="line">ipv4.dhcp-send-hostname: 是</span><br><span class="line">ipv4.dhcp-hostname: --</span><br><span class="line">ipv4.dhcp-fqdn: --</span><br><span class="line">ipv4.never-default: 否</span><br><span class="line">ipv4.may-fail: 是</span><br><span class="line">ipv4.dad-timeout: -1 (default)</span><br></pre></td></tr></table></figure><h2 id="激活dhcp">激活dhcp</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli con show ens33 | grep IP4</span><br></pre></td></tr></table></figure><ul><li>激活的结果<br>可以看出这边ipv4的地址已经自动获取了</li></ul><figure class="highlight txt"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">IP4.ADDRESS[1]: 192.168.42.135/24</span><br><span class="line">IP4.GATEWAY: 192.168.42.2</span><br><span class="line">IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 192.168.42.2, mt = 102</span><br><span class="line">IP4.ROUTE[2]: dst = 192.168.42.0/24, nh = 0.0.0.0, mt = 102</span><br><span class="line">IP4.DNS[1]: 192.168.42.2</span><br><span class="line">IP4.DOMAIN[1]: localdomain</span><br></pre></td></tr></table></figure><h1>nmcli配置网络实例-static</h1><p>刚才是展示的新增一个连接,使用默认的<code>dhcp</code>方式配置网络,但实际项目中需要使用静态ip的方式,配置静态的手段有很多,可以对现在有<code>连接</code>进行系iu改,也可以再创建一个<code>连接</code>并且同时指定他的ip地址</p><h2 id="一次性创建">一次性创建</h2><p>乍一看命令<code>嘎嘎</code>长,其实很简单</p><ul><li><code>嘎嘎</code>长的命令,其实可以更长</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection add con-name dachui-static type ethernet ifname ens33 ipv4.method manual ipv4.address 192.168.42.5/24 ipv4.gateway 192.168.42.2</span><br></pre></td></tr></table></figure><blockquote><p>我拆开两部分分析</p></blockquote><ol><li>创建连接,指定模式<br>这边就是创建了<code>dahcui-static</code>的连接,使用<code>type</code>指定此连接为<code>ethernet</code>(以太网),并且设备是<code>ens33</code></li></ol><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection add con-name dachui-static type ethernet ifname ens33</span><br></pre></td></tr></table></figure><ol start="2"><li>配置网络要素<br>一个ip地址至少需要指定一个<code>ip</code>和<code>子网掩码</code>才可以生效,网关也是需要配置的,还有指定是手动</li></ol><figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">ipv4</span>.method manual ipv4.address <span class="number">192.168.42.5</span>/<span class="number">24</span> ipv4.gateway <span class="number">192.168.42.2</span></span><br></pre></td></tr></table></figure><ul><li>激活连接</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection up dachui-static</span><br></pre></td></tr></table></figure><ul><li>验证</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection up dachui-static | grep IP4</span><br></pre></td></tr></table></figure><blockquote><p>输出为下面的</p></blockquote><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">IP4.ADDRESS[1]: 192.168.42.5/24</span><br><span class="line">IP4.GATEWAY: 192.168.42.2</span><br><span class="line">IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 192.168.42.2, mt = 102</span><br><span class="line">IP4.ROUTE[2]: dst = 192.168.42.0/24, nh = 0.0.0.0, mt = 102</span><br><span class="line">IP4.DNS[1]: 192.168.42.2</span><br><span class="line">IP4.DOMAIN[1]: localdomain</span><br></pre></td></tr></table></figure><h2 id="编辑连接">编辑连接</h2><p>如果之前是创建好了多个连接,但是需要修改,可以通过modify的方法</p><ul><li>提示一点<br>如果要修改,请看好原先的<code>连接</code>是<code>自动获取</code>还是<code>手动获取</code>,如果是自动,需要改模式</li></ul><blockquote><p>可以一并加入修改的,我只是拆开提示一下,遇到过一次改了半天没生效,一看连接方式是dhcp</p></blockquote><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection modify dachui-static ipv4.method manual </span><br></pre></td></tr></table></figure><ul><li>修改ip<br>也可以修改其他的,在输入<code>dachui-static</code>之后按<code>tap</code>会列举出所有的<code>配置项</code>,然后根据语法修改</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection modify dachui-static ipv4.address 192.168.42.200/24</span><br></pre></td></tr></table></figure><ul><li>重启网卡<br>修改之后需要激活一下才能生效</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection up dachui-static</span><br></pre></td></tr></table></figure><blockquote><p>这样一个基本的nmlci创建连接就结束了</p></blockquote><h1>其他基操</h1><h2 id="增加路由">增加路由</h2><p>内网环境下,机器可能有多个网段,那么加路由肯定是必须的,比如我这需要访问<code>10.10.10.0/24</code>的机器,那么通过如下方法进行配置</p><ul><li>加路由</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection modify dachui-static +ipv4.routes "10.10.10.0/24 192.168.42.2"</span><br></pre></td></tr></table></figure><ul><li>激活看信息</li></ul><ol><li>配置信息</li></ol><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">IP4.ROUTE[5]: dst = 10.10.10.0/24, nh = 192.168.42.2, mt = 102</span><br></pre></td></tr></table></figure><ol start="2"><li>路由信息</li></ol><ul><li>route展示</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">route -n</span><br></pre></td></tr></table></figure><ul><li>输出结果</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Destination Gateway Genmask Flags Metric Ref Use Iface</span><br><span class="line">0.0.0.0 192.168.42.2 0.0.0.0 UG 102 0 0 ens33</span><br><span class="line">10.10.10.0 192.168.42.2 255.255.255.0 UG 102 0 0 ens33</span><br></pre></td></tr></table></figure><h2 id="删除路由">删除路由</h2><p>学会增加,也要学会删除</p><ul><li><code>乍一看</code>是不是一样的?其实将<code>+</code>改成<code>-</code>,然后<code>重新激活</code>就可以了</li></ul><blockquote><p>所以修改的逻辑很简单的,<code>+</code>就增加,<code>-</code>就是删除,<code>什么都不加</code>就是修改</p></blockquote><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection modify dachui-static -ipv4.routes "10.10.10.0/24 192.168.42.2"</span><br></pre></td></tr></table></figure><h2 id="增加ip">增加ip</h2><p>有时候需要在一个连接上加多个ip地址</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection modify dachui-static +ipv4.addresses 2.2.2.2/16</span><br></pre></td></tr></table></figure><h2 id="删除连接">删除连接</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection delete dachui-static</span><br></pre></td></tr></table></figure><h2 id="网卡开机自启动">网卡开机自启动</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection modify dachui-static autoconnect yes</span><br></pre></td></tr></table></figure><h1>nmtui</h1><p>其实nmcli的玩法有很多,但其实还有一个工具<code>nmtui</code>,他是<code>NetworkManager-tui</code>的一个工具,通过字符图形化配置网络</p>]]></content>
<summary type="html">配置网络工具</summary>
<category term="linux命令" scheme="https://www.dddachui.top/categories/linux%E5%91%BD%E4%BB%A4/"/>
<category term="linux命令" scheme="https://www.dddachui.top/tags/linux%E5%91%BD%E4%BB%A4/"/>
</entry>
<entry>
<title>Linux好用命令之systemctl</title>
<link href="https://www.dddachui.top/posts/5154c07a.html"/>
<id>https://www.dddachui.top/posts/5154c07a.html</id>
<published>2023-03-26T15:30:51.000Z</published>
<updated>2023-03-26T10:18:22.615Z</updated>
<content type="html"><![CDATA[<h1>systemd</h1><p>是一个用于linux的系统与服务管理器,内核启动后拉起的第一个进程,即init进程(用户空间1号进程),启动和维护各种用户开机的服务</p><h2 id="查看系统systemd的service情况">查看系统systemd的service情况</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl list-units --type service</span><br></pre></td></tr></table></figure><h2 id="解析systemd启动过程中的性能数据">解析systemd启动过程中的性能数据</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">systemd-analyze #系统启动时间总览</span><br><span class="line">systemd-analyze plot > p.svg#生成plot图</span><br><span class="line">systemd-analyze critical-chain xxx.service #某服务依赖关系中耗时最长的链条</span><br></pre></td></tr></table></figure><h1>systemctl</h1><h2 id="查看系统单元">查看系统单元</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">systemctl</span><br><span class="line">systemctl list-units</span><br></pre></td></tr></table></figure><h2 id="查看运行失败的单元">查看运行失败的单元</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl --failed</span><br></pre></td></tr></table></figure><h2 id="查看系统中安装的服务">查看系统中安装的服务</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl list-unit-files</span><br></pre></td></tr></table></figure><h2 id="启停查">启停查</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">systemctl start httpd</span><br><span class="line">systemctl stop httpd</span><br><span class="line">systemctl status httpd</span><br></pre></td></tr></table></figure><h2 id="设置启动模式-图形-命令行">设置启动模式(图形/命令行)</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">systemctl get-default</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">开机启动图形界面</span></span><br><span class="line">systemctl set-default graphical.target</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">字符界面模式</span></span><br><span class="line">systemctl set-default multi-user.target</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">服务管理</summary>
<category term="linux命令" scheme="https://www.dddachui.top/categories/linux%E5%91%BD%E4%BB%A4/"/>
<category term="linux命令" scheme="https://www.dddachui.top/tags/linux%E5%91%BD%E4%BB%A4/"/>
</entry>
<entry>
<title>shell编程</title>
<link href="https://www.dddachui.top/posts/e5954c2f.html"/>
<id>https://www.dddachui.top/posts/e5954c2f.html</id>
<published>2023-03-26T11:47:42.000Z</published>
<updated>2023-03-26T11:53:08.775Z</updated>
<content type="html"><![CDATA[<h2 id="1-终端打印">1.终端打印</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">1.输出特殊符号需要转义</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">2.使用<span class="built_in">printf</span>带格式输出</span></span><br><span class="line">printf "%-5s %-10s %-4s\n" No Name Mark</span><br><span class="line">printf "%-5s %-10s %-4.2f\n" 1 Sarath 80.3456</span><br><span class="line">printf "%-5s %-10s %-4.2f\n" 2 James 90.9989</span><br><span class="line">printf "%-5s %-10s %-4.2f\n" 3 Jeff 77.564</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">3.输出颜色</span></span><br><span class="line">字体颜色:重置=0,黑色=30,红色=31,绿色=32,黄色=33,蓝</span><br><span class="line">色=34,洋红=35,青色=36,白色=37</span><br><span class="line">底色:重置=0,黑色=40,红色=41,绿色=42,黄色=43,</span><br><span class="line">蓝色=44,洋红=45,青色=46,白色=47</span><br><span class="line">echo -e "\e[1;31m This is red text \e[0m"</span><br></pre></td></tr></table></figure><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">1.查看这个进程的变量</span></span><br><span class="line">cat /proc/$(pgrep java)/environ | tr '\0' '\n'</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">pgrep java 查看java进程的pid</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="built_in">tr</span> <span class="string">'\0'</span> <span class="string">'\n'</span> 格式化输出</span></span><br></pre></td></tr></table></figure><h2 id="2-环境变量">2.环境变量</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">var=value ##变量赋值,没有空格</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">1.输出变量</span></span><br><span class="line">echo $(var) #$()这个可以省略,但为了更好的显示建议加</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">2.变量长度</span></span><br><span class="line"><span class="meta prompt_">echo$</span><span class="language-bash">{<span class="comment">#var}</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">3.输出当前用的哪种shell</span></span><br><span class="line">echo $SHELL</span><br><span class="line">echo $0</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">4.检查是否是超户</span></span><br><span class="line">if [ $UID -ne 0 ]; then</span><br><span class="line">echo Non root user. Please run as root.</span><br><span class="line">else</span><br><span class="line">echo Root user</span><br><span class="line">fi</span><br></pre></td></tr></table></figure><h2 id="3-使用函数添加变量">3.使用函数添加变量</h2><h2 id="4-shell的数学运算">4.shell的数学运算</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">法1:定义的是字符串,使用<span class="built_in">let</span>直接计算</span></span><br><span class="line">no1=4</span><br><span class="line">no2=5</span><br><span class="line">let result=no1+no2</span><br><span class="line">echo $result</span><br><span class="line">let no1++</span><br><span class="line">let no1--</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">法2:操作符[]</span></span><br><span class="line">result=$[ no1 + no2 ]</span><br><span class="line">result=$[ $no1 + no2 ]</span><br></pre></td></tr></table></figure><h2 id="5-文件描述符和重定向">5.文件描述符和重定向</h2><p>0 —— stdin(标准输入)<br>1 —— stdout(标准输出)<br>2 —— stderr(标准错误)</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">将错误和正确分别写进文件</span></span><br><span class="line">cat a1 2> stderr.txt 1> stdout.txt</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将命令的报错丢弃</span></span><br><span class="line">cat 1 2>/dev/null</span><br></pre></td></tr></table></figure><h2 id="6-别名alias">6.别名alias</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">alias ifconfig='ip a | grep ens'</span><br><span class="line">ifconfig</span><br></pre></td></tr></table></figure><h2 id="7-时间">7.时间</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">date --date "Jan 20 2001" +%A</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">星期</span> </span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">a(例如:Sat)</span></span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">A(例如:Saturday</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">月</span> </span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">b(例如:Nov)</span></span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">B(例如:November)</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">日</span> </span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">d(例如:31)</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">固定格式日期(mm/dd/yy)</span> </span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">D(例如:10/18/10)</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">年</span></span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">y(例如:10)</span></span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">Y(例如:2010)</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">小时</span></span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">I或%H(例如:08)</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">分钟</span></span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">M(例如:33)</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">秒</span></span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">S(例如:10)</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">纳秒</span></span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">N(例如:695208515)</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">Unix纪元时(以秒为单位)</span></span><br><span class="line"><span class="meta prompt_">%</span><span class="language-bash">s(例如:1290049486)</span></span><br></pre></td></tr></table></figure><h2 id="8-shell的调试">8.shell的调试</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">1.使用vscode远程调试</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">2.bash -x a.sh</span></span><br></pre></td></tr></table></figure><h2 id="9-函数">9.函数</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">1.1定义方式a</span></span><br><span class="line">function fname()</span><br><span class="line">{</span><br><span class="line">statements;</span><br><span class="line">}</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">1.2.定义方式b</span></span><br><span class="line">fname()</span><br><span class="line">{</span><br><span class="line">statements;</span><br><span class="line">}</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">2.使用方式</span></span><br><span class="line">fname #只需要使用函数名</span><br><span class="line">fname argv1 argv2 #传参数</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">3.函数返回值</span></span><br><span class="line">echo $? #输出函数返回值</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">4.1实例a</span></span><br><span class="line">fname()</span><br><span class="line">{</span><br><span class="line">echo $1, $2; #访问参数1和参数2 $n就是第n个参数</span><br><span class="line">echo "$@";#所有参数</span><br><span class="line">echo "$*"; #类似于$@,但是参数被作为单个实体</span><br><span class="line">return 0; #返回值</span><br><span class="line">}</span><br><span class="line">fname 1 2</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">4.2实例b</span></span><br><span class="line">CMD="ifconfig" #command指代你要检测退出状态的目标命令</span><br><span class="line"><span class="meta prompt_">$</span><span class="language-bash">CMD > /dev/null</span></span><br><span class="line">if [ $? -eq 0 ];</span><br><span class="line">then</span><br><span class="line">echo "$CMD executed successfully"</span><br><span class="line">else</span><br><span class="line">echo "$CMD terminated unsuccessfully"</span><br><span class="line">fi</span><br></pre></td></tr></table></figure><h2 id="10-将命令序列的输出读入变量">10.将命令序列的输出读入变量</h2><h2 id="11-read读入输入值">11.read读入输入值</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">read -p "Enter input:" var #显示提示信息</span><br><span class="line">read -s var #用无回显的方式读取密码</span><br></pre></td></tr></table></figure><h2 id="12-字段分隔符和迭代器">12.字段分隔符和迭代器</h2><h2 id="13-if…else">13.if…else</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">#1.if..else</span></span></span><br><span class="line">if condition;</span><br><span class="line">then</span><br><span class="line">commands;</span><br><span class="line">fi</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash"><span class="comment">#1.if..else if..else</span></span></span><br><span class="line">if condition;</span><br><span class="line">then</span><br><span class="line">commands;</span><br><span class="line">else if condition; then</span><br><span class="line">commands;</span><br><span class="line">else</span><br><span class="line">commands;</span><br><span class="line">fi</span><br></pre></td></tr></table></figure><h2 id="14-比较测试">14.比较测试</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">1.计算条件</span></span><br><span class="line">[ $var -eq 0 ] #当 $var 等于 0 时,返回真</span><br><span class="line">[ $var -ne 0 ] #当 $var 为非 0 时,返回真</span><br><span class="line">-eq:等于</span><br><span class="line">-ne:不等于</span><br><span class="line">-gt:大于</span><br><span class="line">-lt:小于</span><br><span class="line">-ge:大于或等于</span><br><span class="line">-le:小于或等于</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">2.文件系统条件</span></span><br><span class="line">fpath="/etc/passwd"</span><br><span class="line">if [ -e $fpath ]; then</span><br><span class="line">echo File exists;</span><br><span class="line">else</span><br><span class="line">echo Does not exist;</span><br><span class="line">fi</span><br><span class="line">[ -f $var ]:如果给定的变量包含正常的文件路径或文件名,则返回真。</span><br><span class="line">[ -x $var ]:如果给定的变量包含的文件可执行,则返回真。</span><br><span class="line">[ -d $var ]:如果给定的变量包含的是目录,则返回真。</span><br><span class="line">[ -e $var ]:如果给定的变量包含的文件存在,则返回真。</span><br><span class="line">[ -c $var ]:如果给定的变量包含的是一个字符设备文件的路径,则返回真。</span><br><span class="line">[ -b $var ]:如果给定的变量包含的是一个块设备文件的路径,则返回真。</span><br><span class="line">[ -w $var ]:如果给定的变量包含的文件可写,则返回真。</span><br><span class="line">[ -r $var ]:如果给定的变量包含的文件可读,则返回真。</span><br><span class="line">[ -L $var ]:如果给定的变量包含的是一个符号链接,则返回真。</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">3.字符串比较</span></span><br><span class="line">[[ $str1 = $str2 ]]</span><br><span class="line">[[ $str1 == $str2 ]]</span><br><span class="line">[[ $str1 != $str2 ]]</span><br><span class="line">[[ $str1 > $str2 ]] #如果str1的字母序比str2大,则返回真</span><br><span class="line">[[ -z $str1 ]]:如果str1包含的是空字符串,则返回真。</span><br><span class="line">[[ -n $str1 ]]:如果str1包含的是非空字符串,则返回真。</span><br></pre></td></tr></table></figure><h2 id="15-命令">15.命令</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">1.<span class="built_in">cat</span></span> </span><br><span class="line">cat -n a.txt #显示行号</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">2.xargs</span></span><br><span class="line">command | xargs#接收到的数据重新格式化</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">3.<span class="built_in">tr</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">4.<span class="built_in">md5sum</span></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">5.加密指令</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">6.排序</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">7.临时文件名</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">8.分隔文件</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">9.批量重命名</span></span><br></pre></td></tr></table></figure><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">10.生成文件</span></span><br><span class="line">dd if=/dev/zero of=junk.data bs=1M count=1#bs代表以字节为单位的块大小(block size),count代表需要被</span><br><span class="line">复制的块数</span><br><span class="line">https://www.cnblogs.com/licheng/archive/2008/03/21/1116492.htm</span><br></pre></td></tr></table></figure><h2 id="16-文本文件的交集与差集">16.文本文件的交集与差集</h2><h2 id="17-查找并删除重复文件">17.查找并删除重复文件</h2><h2 id="18-文件权限、所有权和粘滞位">18.文件权限、所有权和粘滞位</h2><h2 id="19-创建不可修改的文件">19.创建不可修改的文件</h2><h2 id="20-批量生成空白文件">20.批量生成空白文件</h2><h2 id="21-查找符号链接及其指向目标">21.查找符号链接及其指向目标</h2><h2 id="22-列举文件类型统计信息">22.列举文件类型统计信息</h2><h2 id="23-使用环回文件">23.使用环回文件</h2><h2 id="24-生成-ISO-文件及混合型-ISO">24.生成 ISO 文件及混合型 ISO</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">1.制作iso</span></span><br><span class="line">cat /dev/cdrom > image.iso #不好</span><br><span class="line">dd if=/dev/cdrom of=image.iso #最好的方法</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">mkisofs命令用于创建ISO文件系统。可以用cdrecord之类的工具将mkisofs的输出文件直接刻录到CD-ROM或DVD-ROM上</span></span><br><span class="line">mkisofs -V "Label" -o image.iso source_dir/</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">2.isohybrid</span></span><br><span class="line">isohybrid image.iso</span><br><span class="line">dd if=image.iso of=/dev/sdb1</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">3.用命令行刻录ISO</span></span><br><span class="line">cdrecord -v dev=/dev/cdrom image.iso -speed 8</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">4.操作光驱器</span></span><br><span class="line">eject #弹开</span><br><span class="line">eject -t ##合上</span><br></pre></td></tr></table></figure><h1>25.统计文件的行数、单词数和字符数</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">1.统计行数</span></span><br><span class="line">wc -l file</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">2.统计单词数</span></span><br><span class="line">wc -w file</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">3.统计字符数</span></span><br><span class="line">wc -c file</span><br><span class="line">echo -n 1234 | wc -c #-n用于避免echo添加额外的换行符</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">4.不加参数</span></span><br><span class="line">wc file #文件的行数、单词数和字符数</span><br></pre></td></tr></table></figure><h1>26.tree目录</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">1.输出符合类型的文件</span></span><br><span class="line">tree /opt -P "*.sh"</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">2.打印目录树和大小</span></span><br><span class="line">tree -h</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">tree命令可以生成HTML输出</span></span><br><span class="line">tree PATH -H http://localhost -o out.html</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">描述</summary>
<category term="知识点" scheme="https://www.dddachui.top/categories/%E7%9F%A5%E8%AF%86%E7%82%B9/"/>
<category term="shell" scheme="https://www.dddachui.top/tags/shell/"/>
</entry>
<entry>
<title>perl过滤mac地址</title>
<link href="https://www.dddachui.top/posts/56f58a69.html"/>
<id>https://www.dddachui.top/posts/56f58a69.html</id>
<published>2023-03-26T11:47:30.000Z</published>
<updated>2023-03-26T11:52:41.744Z</updated>
<content type="html"><![CDATA[<ul><li>下载包</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://cpan.metacpan.org/authors/id/A/AB/ABIGAIL/Regexp-Common-2017060201.tar.gz</span><br></pre></td></tr></table></figure><ul><li>安装包</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">tar xf Regexp-Common-2017060201.tar.gz </span><br><span class="line">cd Regexp-Common-2017060201/</span><br><span class="line">perl Makefile.PL</span><br><span class="line">make install</span><br></pre></td></tr></table></figure><ul><li>过滤指定网口mac地址</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ifconfig eth0 |perl -MRegexp::Common=net -lnE 'say $& if /$RE{net}{MAC}/g'</span><br></pre></td></tr></table></figure><ul><li>过滤指定网卡IPv4</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ifconfig eth1 |perl -MRegexp::Common=net -lnE 'say $& if /$RE{net}{IPv4}/g'</span><br></pre></td></tr></table></figure><ul><li>过滤指定网卡IPv6</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ifconfig eth1 |perl -MRegexp::Common=net -lnE 'say $& if /$RE{net}{IPv6}/g'</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">描述</summary>
<category term="知识点" scheme="https://www.dddachui.top/categories/%E7%9F%A5%E8%AF%86%E7%82%B9/"/>
<category term="基操" scheme="https://www.dddachui.top/tags/%E5%9F%BA%E6%93%8D/"/>
</entry>
<entry>
<title>nfs搭建</title>
<link href="https://www.dddachui.top/posts/941a0cef.html"/>
<id>https://www.dddachui.top/posts/941a0cef.html</id>
<published>2023-03-26T11:47:06.000Z</published>
<updated>2023-03-26T11:52:18.995Z</updated>
<content type="html"><![CDATA[<h1>环境</h1><ul><li>节点server,充当nfs服务端,ip是192.168.42.141</li><li>节点client,充当nfs客户端,ip是192.168.42.0/24下的,可以ping通</li><li>机器均关闭selinux(我不用)</li><li>机器均关闭firewalld (我也不用)</li></ul><h1>服务端配置</h1><ul><li>安装软件</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y nfs-utils rpcbind</span><br></pre></td></tr></table></figure><ul><li>创建服务端nfs目录</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mkdir /mnt/nfs-server</span><br><span class="line">chmod 777 /mnt/nfs-server</span><br></pre></td></tr></table></figure><ul><li>配置/etc/exports文件</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">下面是放开192.168.42.0/24网段</span></span><br><span class="line">/mnt/nfs-server 192.168.42.0/24(rw,sync,no_root_squash)</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">也可以放开所有的网段,写法如下</span></span><br><span class="line">/mnt/nfs-server *(ro)</span><br></pre></td></tr></table></figure><ul><li>查看服务端NFS共享目录</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">showmount -e</span><br></pre></td></tr></table></figure><ul><li>设置服务端自启动</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">systemctl enable nfs-server rpcbind</span><br><span class="line">systemctl start nfs-server rpcbind</span><br></pre></td></tr></table></figure><ul><li>检测nfs端口是否正常</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">lsof -i:111</span><br></pre></td></tr></table></figure><ul><li>防火墙配置</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">关闭防火墙,</span></span><br><span class="line">systemctl disable --now firewalld</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">不关闭防火墙的就自己配置吧</span></span><br></pre></td></tr></table></figure><h1>客户端配置</h1><ul><li>安装软件</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y nfs-utils</span><br></pre></td></tr></table></figure><ul><li>设置nfs挂载目录</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir /mnt/nfs-data</span><br></pre></td></tr></table></figure><ul><li>检查server的nfs共享目录</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">showmount -e 192.168.42.141</span><br></pre></td></tr></table></figure><ul><li>手动挂载</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mount 192.168.42.141:/home/nfs-server /mnt/nfs-data</span><br></pre></td></tr></table></figure><ul><li>查看挂载</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">df -Th</span><br></pre></td></tr></table></figure><ul><li>写入fstab</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">写入fstab设置开机自动挂载</span></span><br><span class="line">/mnt/nfs-server /mnt/nfs-data nfs defaults,_netdev 0 0 </span><br></pre></td></tr></table></figure><ul><li>测试fstab</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">先卸载手动挂载的</span></span><br><span class="line">umount /mnt/nfs-data</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">执行mount -a</span></span><br><span class="line">mount -a</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">查看挂载</span></span><br><span class="line">df -Th</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">描述</summary>
<category term="安装部署" scheme="https://www.dddachui.top/categories/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"/>
<category term="安装部署" scheme="https://www.dddachui.top/tags/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2/"/>
</entry>
<entry>
<title>Linux快速查找库文件位置</title>
<link href="https://www.dddachui.top/posts/3a97f081.html"/>
<id>https://www.dddachui.top/posts/3a97f081.html</id>
<published>2023-03-26T11:46:38.000Z</published>
<updated>2023-03-26T11:49:54.089Z</updated>
<content type="html"><![CDATA[<p>ldconfig -p | grep lib_name</p><p>ldconfig -p 会打印出当前系统已经安装的动态库信息,然后使用 grep 找你的 lib 即可<br><a href="https://blog.csdn.net/bjbz_cxy/article/details/108517003">https://blog.csdn.net/bjbz_cxy/article/details/108517003</a></p>]]></content>
<summary type="html">描述</summary>
<category term="知识点" scheme="https://www.dddachui.top/categories/%E7%9F%A5%E8%AF%86%E7%82%B9/"/>
<category term="库文件" scheme="https://www.dddachui.top/tags/%E5%BA%93%E6%96%87%E4%BB%B6/"/>
</entry>
<entry>
<title>GRUB了解</title>
<link href="https://www.dddachui.top/posts/1be27d0f.html"/>
<id>https://www.dddachui.top/posts/1be27d0f.html</id>
<published>2023-03-26T11:46:27.000Z</published>
<updated>2023-03-26T11:49:24.473Z</updated>
<content type="html"><![CDATA[<h1>什么是GRUB</h1><ol><li>一个来自GNU的多操作系统启动程序</li><li>计算机读取到第一个扇区的512字节找到gurb之后,由用户选择哪个系统</li></ol><h1>boot下文件</h1><ol><li>vmlinux文件</li><li>initramfs虚拟文件系统<br>linux内核启动前,GRUB会将虚拟文件系统加载到内存,内核启动时,会在访问真正的根文件系统之前先访问该内存中的虚拟文件系统,虚拟文件系统的目的是为访问真正的根文件扫清障碍,最主要的目的是加载根文件系统存储介质的驱动模块</li></ol><h1>GRUB用法</h1><ul><li>安装GRUB</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grub2-install /dev/sda</span><br></pre></td></tr></table></figure><ul><li>生成配置文件</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grub2-mkconfig -o /boot/grub2/grub.cfg</span><br></pre></td></tr></table></figure><ul><li>常用命令</li></ul><ol><li>insmod 插入模块</li><li>lsmod 显示已经加载的</li><li>set</li></ol><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">set root=(hd0,msdos1) #设置根目录</span><br><span class="line">set default=0 #设置默认菜单</span><br><span class="line">set timout=5 #设置超时</span><br><span class="line">set prefix=(hd0,msdos1)/EFI/grub</span><br></pre></td></tr></table></figure><ol start="4"><li>linux 加载linux内核</li><li>initrd 加载初始化RAM数据模块</li><li>boot</li></ol>]]></content>
<summary type="html">描述</summary>
<category term="知识点" scheme="https://www.dddachui.top/categories/%E7%9F%A5%E8%AF%86%E7%82%B9/"/>
<category term="grub" scheme="https://www.dddachui.top/tags/grub/"/>
</entry>
<entry>
<title>grub的相关操作</title>
<link href="https://www.dddachui.top/posts/b72ca0dc.html"/>
<id>https://www.dddachui.top/posts/b72ca0dc.html</id>
<published>2023-03-26T11:46:04.000Z</published>
<updated>2023-03-26T11:49:04.742Z</updated>
<content type="html"><![CDATA[<h1>grubby操作</h1><ul><li>查看默认引导内核</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grubby --default-kernel</span><br></pre></td></tr></table></figure><ul><li>查看所有内核</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grubby --info=ALL</span><br></pre></td></tr></table></figure><ul><li>修改</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grubby --set-default /boot/vmlinuz-4.18.0-80.11.2.el8_0.x86_64\</span><br></pre></td></tr></table></figure><h1>查看可引导的内核数量</h1><ul><li>UEFI</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">awk -F\' '$1=="menuentry " {print $2}' /boot/efi/EFI/kylin/grub.cfg</span><br></pre></td></tr></table></figure><ul><li>LEGACY</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat /boot/grub2/grub.cfg |grep menuentry</span><br></pre></td></tr></table></figure><h1>修改引导顺序</h1><ul><li>使用命令修改</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grub2-set-default 'KylinSec OS Linux (6.2.0-rc1) 3 (Core)'</span><br></pre></td></tr></table></figure><ul><li>使用数字修改</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grub2-set-default 0</span><br></pre></td></tr></table></figure><ul><li>查看修改启动项的结果</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grub2-editenv list</span><br></pre></td></tr></table></figure><ul><li>生成grub.cfg</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">uefi</span></span><br><span class="line">grub2-mkconfig -o /boot/efi/EFI/kylin/grub.cfg </span><br></pre></td></tr></table></figure><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">bios</span></span><br><span class="line">grub2-mkconfig -o /boot/grub2/grub.cfg</span><br></pre></td></tr></table></figure><h1>查看vmlinux参数</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grubby --info=/boot/vmlinuz-6.2.0-rc1</span><br></pre></td></tr></table></figure><h1>centos6的修改</h1><ol><li>查看/etc/grub.conf文件,确认系统内核的情况,如下图所示系统存在2个内核的现象。从上往下内核版本依次是2.6.32-573.18.1.el6.x86_64和2.6.32-431.23.3.el6.x86_64。</li><li>在grub.conf文件中决定开机使用哪个内核版本做启动的参数是default,默认值为0,代表从最新的内核启动。代表启动的内核版本从上往下依次是0、1、2等。</li><li>如果要选择从旧版内核,即系统最开始的内核启动,则把default值改为1 ,然后重启服务器从新的内核进行引导</li></ol>]]></content>
<summary type="html">描述</summary>
<category term="知识点" scheme="https://www.dddachui.top/categories/%E7%9F%A5%E8%AF%86%E7%82%B9/"/>
<category term="grub" scheme="https://www.dddachui.top/tags/grub/"/>
</entry>
<entry>
<title>linux统计实时网速的方法</title>
<link href="https://www.dddachui.top/posts/a9e5246.html"/>
<id>https://www.dddachui.top/posts/a9e5246.html</id>
<published>2023-03-26T10:33:58.000Z</published>
<updated>2023-03-26T10:41:02.204Z</updated>
<content type="html"><![CDATA[<h1>noload</h1><p>通过nload命令来统计网速<br>-t 刷新时间间隔 500ms<br>-u b/k/m/g 网速单位 依次字节/KB/MB/GB</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nload eth0 -u g -m </span><br></pre></td></tr></table></figure><h1>sar</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sar -n DEV 1 100</span><br></pre></td></tr></table></figure><h1>ifconfig</h1><p>RX: 接收流量<br>TX: 发送流量<br>计算方法:(<strong>KB</strong> = 数值/1000) (<strong>MB</strong> = 数值/100000)</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">watch -n 1 ifconfig </span><br></pre></td></tr></table></figure><h1>iftop</h1>]]></content>
<summary type="html">描述</summary>
<category term="网络管理" scheme="https://www.dddachui.top/categories/%E7%BD%91%E7%BB%9C%E7%AE%A1%E7%90%86/"/>
<category term="网速" scheme="https://www.dddachui.top/tags/%E7%BD%91%E9%80%9F/"/>
</entry>
<entry>
<title>网络连接数量查看</title>
<link href="https://www.dddachui.top/posts/acb02ade.html"/>
<id>https://www.dddachui.top/posts/acb02ade.html</id>
<published>2023-03-26T10:33:45.000Z</published>
<updated>2023-03-26T10:41:14.634Z</updated>
<content type="html"><![CDATA[<h2 id="查看哪些IP连接本机">查看哪些IP连接本机</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">netstat -an</span><br></pre></td></tr></table></figure><h2 id="查看TCP连接数">查看TCP连接数</h2><ul><li>统计80端口连接数</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">netstat -nat|grep -i "80"|wc -l</span><br></pre></td></tr></table></figure><ul><li>统计httpd协议连接数</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -ef|grep httpd|wc -l</span><br></pre></td></tr></table></figure><ul><li>统计已连接上的,状态为“established</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">netstat -na|grep ESTABLISHED|wc -l</span><br></pre></td></tr></table></figure><ul><li>查出哪个IP地址连接最多,将其封了</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">netstat -na|grep ESTABLISHED|awk {print $5}|awk -F: {print $1}|sort|uniq -c|sort -r +0n</span><br><span class="line">netstat -na|grep SYN|awk {print $5}|awk -F: {print $1}|sort|uniq -c|sort -r +0n</span><br></pre></td></tr></table></figure><ul><li>查看apache前并发访问数</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">netstat -an | grep ESTABLISHED | wc -l</span><br></pre></td></tr></table></figure><ul><li>查看有多少个进程数</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps aux|grep httpd|wc -l</span><br></pre></td></tr></table></figure><h1>字段解释</h1><p>TIME_WAIT 8947 等待足够的时间以确保远程TCP接收到连接中断请求的确认<br>FIN_WAIT1 15 等待远程TCP连接中断请求,或先前的连接中断请求的确认<br>FIN_WAIT2 1 从远程TCP等待连接中断请求<br>ESTABLISHED 55 代表一个打开的连接<br>SYN_RECV 21 再收到和发送一个连接请求后等待对方对连接请求的确认<br>CLOSING 2 没有任何连接状态<br>LAST_ACK 4 等待原来的发向远程TCP的连接中断请求的确认</p><h1>TCP连接状态详解</h1><p>LISTEN: 侦听来自远方的TCP端口的连接请求<br>SYN-SENT: 再发送连接请求后等待匹配的连接请求<br>SYN-RECEIVED:再收到和发送一个连接请求后等待对方对连接请求的确认<br>ESTABLISHED: 代表一个打开的连接<br>FIN-WAIT-1: 等待远程TCP连接中断请求,或先前的连接中断请求的确认<br>FIN-WAIT-2: 从远程TCP等待连接中断请求<br>CLOSE-WAIT: 等待从本地用户发来的连接中断请求<br>CLOSING: 等待远程TCP对连接中断的确认<br>LAST-ACK: 等待原来的发向远程TCP的连接中断请求的确认<br>TIME-WAIT: 等待足够的时间以确保远程TCP接收到连接中断请求的确认<br>CLOSED: 没有任何连接状态</p>]]></content>
<summary type="html">描述</summary>
<category term="网络管理" scheme="https://www.dddachui.top/categories/%E7%BD%91%E7%BB%9C%E7%AE%A1%E7%90%86/"/>
<category term="网络连接数" scheme="https://www.dddachui.top/tags/%E7%BD%91%E7%BB%9C%E8%BF%9E%E6%8E%A5%E6%95%B0/"/>
</entry>
<entry>
<title>网卡改名脚本使用</title>
<link href="https://www.dddachui.top/posts/74b3b75a.html"/>
<id>https://www.dddachui.top/posts/74b3b75a.html</id>
<published>2023-03-26T10:33:25.000Z</published>
<updated>2023-03-26T10:42:17.495Z</updated>
<content type="html"><![CDATA[<h1>问题</h1><ul><li>网卡名要按照客户需求改</li></ul><h1>解决</h1><h2 id="1-修改grub">1.修改grub</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/default/grub</span><br></pre></td></tr></table></figure><ul><li>添加 net.ifnames=1 biosdevname=0 如下图所示</li></ul><p><img src="images/%E5%9B%BE%E5%BA%93/image-20220331170233957.png" alt="image-20220331170233957"></p><h2 id="2-重建">2.重建</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">grub2-mkconfig -o /boot/grub2/grub.cfg</span><br></pre></td></tr></table></figure><p><img src="images/%E5%9B%BE%E5%BA%93/image-20220331170404356.png" alt="image-20220331170404356"></p><h2 id="3-执行脚本">3.执行脚本</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./ifcfg_cluster_manage create /var/log/ifcfg_cluster_manage.log</span><br></pre></td></tr></table></figure><ul><li>在/etc/udev/rules.d/会生成70-persistent-net.rules配置,修改网卡名和/etc/sysconfig/network-scripts/下面的配置一致就可以了</li></ul>]]></content>
<summary type="html"><h1>问题</h1>
<ul>
<li>网卡名要按照客户需求改</li>
</ul>
<h1>解决</h1>
<h2 id="1-修改grub">1.修改grub</h2>
<figure class="highlight shell"><table><tr><td class</summary>
<category term="网络管理" scheme="https://www.dddachui.top/categories/%E7%BD%91%E7%BB%9C%E7%AE%A1%E7%90%86/"/>
<category term="网卡改名" scheme="https://www.dddachui.top/tags/%E7%BD%91%E5%8D%A1%E6%94%B9%E5%90%8D/"/>
</entry>
<entry>
<title>网卡多队列</title>
<link href="https://www.dddachui.top/posts/2e0e8049.html"/>
<id>https://www.dddachui.top/posts/2e0e8049.html</id>
<published>2023-03-26T10:33:12.000Z</published>
<updated>2023-03-26T10:42:44.100Z</updated>
<content type="html"><![CDATA[<p><a href="https://www.bbsmax.com/A/6pdDbDgkJw/">https://www.bbsmax.com/A/6pdDbDgkJw/</a><br><a href="https://www.cnblogs.com/mauricewei/p/10502300.html">https://www.cnblogs.com/mauricewei/p/10502300.html</a></p><h1>什么是网卡多队列</h1><p>如果在多核 CPU 的服务器上,网卡内部会有多个 Ring Buffer,NIC 负责将传进来的数据分配给不同的 Ring Buffer,同时触发的 IRQ 也可以分配到多个 CPU 上,这样存在多个 Ring Buffer 的情况下 Ring Buffer 缓存的数据也同时被多个 CPU 处理,就能提高数据的并行处理能力</p><p>通常情况下,一张网卡会有一个队列用来接发收网络数据包,我们所说的一个队列你也可以理解成一个处理数据包的进程。</p><p>但是随着时代的发展,网卡支持的流量带宽越来越大,如果还是使用一个队列来接收网络数据包,必然容易造成数据包阻塞和单cpu处理不过来。于是出现了一批高端的智能网卡,这些网卡可以支持使用多个队列来接发收数据包。比如1822网卡</p><p>队列个数也可以根据情况设置,一个队列可以理解是一个处理数据包的进程,多个队列对应多个进程,这些进程可以分散到不同的cpu去处理,这样就缓解了单cpu的执行压力。</p><p>哪么网卡收到数据包后交给哪个队列处理呢?网卡驱动会根据数据包的源目的IP等五元组信息计算一个hash值,然后交由对应的队列处理。</p><h1>查看网卡是否支持</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ethtool -l eth0</span><br></pre></td></tr></table></figure><ul><li>如下</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">[root@localhost ~]# ethtool -l eth0</span><br><span class="line">Channel parameters for eth0:</span><br><span class="line">Pre-set maximums:</span><br><span class="line">RX: 0</span><br><span class="line">TX: 0</span><br><span class="line">Other: 0</span><br><span class="line">Combined: 2 #大于1 表示支持多队列</span><br><span class="line">Current hardware settings:</span><br><span class="line">RX: 0</span><br><span class="line">TX: 0</span><br><span class="line">Other: 0</span><br><span class="line">Combined: 2 #当前的多队列数量,大于1标识开启了</span><br></pre></td></tr></table></figure><h1>调整</h1><ul><li><h3 id="调整-Ring-Buffer-队列数量">调整 Ring Buffer 队列数量</h3></li></ul><p>注意,设置的队列数的前提是网卡首先要支持多队列,且不能超过网卡支持的最大的队列数。当网卡驱动比较老旧的时候,也有可能会设置失败,建议将网卡驱动先升级至最新版本</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ethtool -L eth1-combined 16</span><br></pre></td></tr></table></figure><ul><li><h3 id="调整-Ring-Buffer-队列大小">调整 Ring Buffer 队列大小</h3></li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">ethtool -G eth0 rx 4096</span><br><span class="line">````</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">网卡收到的数据包统计</span></span><br><span class="line">- ### 网卡收到的数据包统计</span><br><span class="line">```shell</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">RX 就是收到数据,TX 是发出数据</span></span><br><span class="line">ethtool -S em1 | more</span><br></pre></td></tr></table></figure><ul><li><h3 id="带有-drop-字样的统计和-fifo-errors-的统计">带有 drop 字样的统计和 fifo_errors 的统计</h3></li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">发送队列和接收队列 drop 的数据包数量显示在这里。并且所有 queue_drops 加起来等于 rx_fifo_errors。所以总体上能通过 rx_fifo_errors 看到 Ring Buffer 上是否有丢包。如果有的话一方面是看是否需要调整一下每个队列数据的分配,或者是否要加大 Ring Buffer 的大小</span></span><br><span class="line">ethtool -S em1 | grep -iE "error|drop"</span><br></pre></td></tr></table></figure><ul><li>查看ring buf大小</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">RX 和 TX 最大是 4096,当前值为 256 。队列越大丢包的可能越小,但数据延迟会增加</span></span><br><span class="line">ethtool -g eth0</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">结果如下</span></span><br><span class="line">Ring parameters for eth0:</span><br><span class="line">Pre-set maximums:</span><br><span class="line">RX: 2048</span><br><span class="line">RX Mini: 0</span><br><span class="line">RX Jumbo: 0</span><br><span class="line">TX: 2048</span><br><span class="line">Current hardware settings:</span><br><span class="line">RX: 2048</span><br><span class="line">RX Mini: 0</span><br><span class="line">RX Jumbo: 0</span><br><span class="line">TX: 2048</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">描述</summary>
<category term="网络管理" scheme="https://www.dddachui.top/categories/%E7%BD%91%E7%BB%9C%E7%AE%A1%E7%90%86/"/>
<category term="多队列" scheme="https://www.dddachui.top/tags/%E5%A4%9A%E9%98%9F%E5%88%97/"/>
</entry>
<entry>
<title>端口转发</title>
<link href="https://www.dddachui.top/posts/c0e91c93.html"/>
<id>https://www.dddachui.top/posts/c0e91c93.html</id>
<published>2023-03-26T10:32:53.000Z</published>
<updated>2023-03-26T10:43:04.509Z</updated>
<content type="html"><![CDATA[<p>有时,两个主机A、C之间网络并不互通,但A和B互通,B和C互通,这种情况下,我们可以利用B主机做一个端口转发,使得主机A可以访问主机C上的网络服务。</p><p>能够实现端口转发的软件有很多,如iptables、socat、portmap、rinetd等,而ssh也是常见的一个,用法如下:</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">ssh本地端口转发,在A机器上执行,会在A机开启2001端口,并将此端口数据发到B机,B机又转发到C机的80端口</span></span><br><span class="line">ssh -fgN -L2001:host_c:80 work@host_b</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">ssh远端端口转发,在B机器上执行,在A机开启22333端口(由A机sshd服务打开),将A机22333端口流量通过B机(中转机)转到C机的80端口上</span></span><br><span class="line">ssh -fgN -R 22333:host_c:80 work@host_a</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">ssh远端动态端口转发,在B机器上执行,会在A机开启2222端口开放socks代理服务,被代理的数据会发到B机,B机又转发到任何B机能访问的网络服务上</span></span><br><span class="line">ssh -fgN -R 2222 work@host_a</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">ssh本地动态端口转发,在A机器上执行,会在A机开启2222端口开放socks代理服务,被代理的数据会发到B机,B机又转发到任何B机能访问的网络服务上</span></span><br><span class="line">ssh -Nfg -D 2222 work@host_b</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">A机通过本机socks代理,登录到C机</span></span><br><span class="line">ssh -o ProxyCommand='ncat --proxy 127.0.0.1:2222 --proxy-type socks5 %h %p' work@host_c</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">A机通过B机ssh登录C机,其实就是两次ssh登录过程</span></span><br><span class="line">ssh -t work@host_b 'ssh work@host_c'</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">描述</summary>
<category term="网络管理" scheme="https://www.dddachui.top/categories/%E7%BD%91%E7%BB%9C%E7%AE%A1%E7%90%86/"/>
<category term="端口转发" scheme="https://www.dddachui.top/tags/%E7%AB%AF%E5%8F%A3%E8%BD%AC%E5%8F%91/"/>
</entry>
</feed>