Skip to content

Commit d4cda2d

Browse files
committed
chore: 整理Linux相关文章
1 parent 623f12b commit d4cda2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+193
-162
lines changed

.vitepress/config/sidebar/seo.sidebar.ts

-30
This file was deleted.

.vitepress/config/theme.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import type { DefaultTheme, PageData, TransformPageContext } from 'vitepress'
22
import { localSearchOptions } from './search/local-search'
3-
import { getSubdirNames, readFile } from '.vitepress/theme/utils'
3+
import { getSidebar, getSubdirNames, readFile } from '.vitepress/theme/utils'
44
import path from 'path'
55
import matter from 'gray-matter'
66
import { androidComposeSidebar } from './sidebar/android-compose.sidebar'
77
import { androidFaqSidebar } from './sidebar/android-faq.sidebar'
8-
import { seoSidebar } from './sidebar/seo.sidebar'
98
import { nestJsFaqSidebar } from './sidebar/nestjs-faq.sidebar'
109
import { nestJsBeginnerSidebar } from './sidebar/nestjs-beginner.sidebar'
1110
import { nestJsMasterSidebar } from './sidebar/nestjs-master.sidebar'
@@ -31,6 +30,11 @@ export const themeConfig: DefaultTheme.Config = {
3130
text: '如有不妥,请提PR修正,感谢!',
3231
},
3332
nav: [
33+
{
34+
text: 'Linux',
35+
activeMatch: '/linux/',
36+
link: '/linux/linux-newbie-ps-command/',
37+
},
3438
{
3539
text: 'NestJS',
3640
activeMatch: '/nestjs/*',
@@ -87,7 +91,8 @@ export const themeConfig: DefaultTheme.Config = {
8791
sidebar: {
8892
'/android/': androidComposeSidebar(),
8993
'/android/faq/': androidFaqSidebar(),
90-
'/seo/': seoSidebar(),
94+
'/seo/': getSidebar('seo'),
95+
'/linux/': getSidebar('linux'),
9196
// '/nestjs/faq': nestJsFaqSidebar(),
9297
'/nestjs/beginner': nestJsBeginnerSidebar(),
9398
'/nestjs/master': nestJsMasterSidebar(),

.vitepress/theme/utils.ts

+28
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { PageData, TransformPageContext } from 'vitepress'
22
import fs from 'fs'
33
import matter from 'gray-matter'
44
import { markdownToTxt } from 'markdown-to-txt'
5+
import path from 'path'
56

67
/**
78
* 生成文章描述信息
@@ -49,6 +50,33 @@ export function getSubdirNames(dirPath: string): string[] {
4950
.map((dirent) => dirent.name)
5051
}
5152

53+
export function getSidebar(sidebarDir: string) {
54+
const seoDir = path.join(__dirname, `../../${sidebarDir}/`)
55+
const subDirs = getSubdirNames(seoDir)
56+
const sidebar: any[] = []
57+
subDirs.forEach((subdirectory) => {
58+
const subdirectoryPath = path.join(seoDir, subdirectory)
59+
const indexPath = path.join(subdirectoryPath, 'index.md')
60+
const indexMdContent = readFile(indexPath)
61+
if (!indexMdContent) return
62+
const page: any = matter(indexMdContent)
63+
64+
if (page) {
65+
sidebar.push({
66+
text: page.data?.title,
67+
link: `/${sidebarDir}/${subdirectory}/`,
68+
order: page.data?.order ?? 9999,
69+
})
70+
} else {
71+
console.log(`${sidebarDir} Subdirectory: ${subdirectory}`)
72+
console.log(`Index.md not found in this ${sidebarDir} subdirectory.`)
73+
console.log('-----------------------')
74+
}
75+
})
76+
77+
return sidebar.sort((a, b) => a.order - b.order)
78+
}
79+
5280
export function readFile(filepath: string): string | null {
5381
if (fs.existsSync(filepath)) {
5482
const content = fs.readFileSync(filepath, 'utf-8')

blog/2021/04/linux-learning-top-command/index.md

-103
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
title: "Linux入门:查看系统进程TOP命令"
3+
date: "2021-04-03"
4+
categories:
5+
- "Linux教程"
6+
tags:
7+
- "Linux"
8+
coverImage: "How-To-Linux-TOP-Command.png"
9+
---
10+
11+
使用过Linux的朋友应该对`top`程序不会陌生,但是很多人并没有真正的把top用起来,有很多功能估计都没有使用到,这篇文章就分享下我在网站**运维服务器**过程中使用top的技巧。
12+
13+
## 使用top
14+
15+
首先我们要查看下top的版本,如果版本太低,有可能不支持下面介绍的一些功能,输入`top -v`看看自己的Linux安装的TOP程序是什么版本:
16+
```bash
17+
[root@SEOZEN ~]# top -v
18+
procps-ng version 3.3.10
19+
```
20+
在终端输入top应该可以看到类似下面界面的样式:
21+
22+
![Linux top界面](images/top界面.jpg)
23+
24+
这个界面包含两部分,分别是`系统摘要``进程列表`,我会详细的一行一行的介绍。
25+
26+
## 系统统计信息
27+
28+
### **第一行:概况**
29+
```bash
30+
top - 19:42:49 up 56 days, 5:30, 1 user, load average: 0.00, 0.01, 0.05
31+
```
32+
- `19:42:49`: 系统当前时间
33+
34+
- `up 56 days, 5:30`: 表示从服务器开机到现在一共运行的时间,这是是56天,19个小时42分49秒。
35+
36+
- `1 user`: 当前登录用户数
37+
38+
- `load average: 0.00, 0.01, 0.05`: 系统1分钟、5分钟、15分钟内的平均负载值,具体数值的含义和算法参考[这里](http://www.brendangregg.com/blog/2017-08-08/linux-load-averages.html)
39+
40+
### 第二行:进程计数
41+
```bash
42+
Tasks: 82 total, 1 running, 81 sleeping, 0 stopped, 0 zombie
43+
```
44+
- `total`:进程总数。
45+
- `running`:正在运行的进程数,对应状态TASK_RUNNING。
46+
- `sleeping`:睡眠的进程数,对应状态TASK_INTERRUPTIBLE和TASK_UNINTERRUPTIBLE。
47+
- `stopped`:停止的进程数,对应状态TASK_STOPPED。
48+
- `zombie`:僵尸进程数,对应状态TASK_ZOMBIE。
49+
50+
### **第三行:**CPU使用率(%Cpu(s))
51+
```bash
52+
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
53+
```
54+
- `us`:进程在用户空间(user space)消耗的CPU时间占比,不包含调整过优先级的进程。
55+
- `sy`:进程在内核空间(kernel space)消耗的CPU时间占比。
56+
- `ni`:手动调整过用户态优先级的(niced)进程的CPU时间占比。
57+
- `id`:空闲的(idle)CPU时间占比。
58+
- `wa`:等待(wait)I/O完成的CPU时间占比。
59+
- `hi`:处理硬中断(hardware interrupt)的CPU时间占比。
60+
- `si`:处理软中断(software interrupt)的CPU时间占比。
61+
- `st`:当Linux系统是在虚拟机中运行时,等待CPU资源的时间(steal time)占比。
62+
63+
### **第四、五行:物理内存和交换空间(Mem/Swap)**
64+
```bash
65+
KiB Mem : 964312 total, 85656 free, 687008 used, 191648 buff/cache
66+
```
67+
单位为KB,以物理内存为例:
68+
- `total`:内存总量。
69+
- `free`:空闲内存量。
70+
- `used`:使用中的内存量。
71+
- `buff/cache`:缓存和page cache占用的内存量。
72+
73+
## **进程详细信息**
74+
75+
这里显示的数据列是可以改的,默认会显示如图中的12列。其含义分别如下:
76+
- `PID`:进程ID。
77+
- `USER`:进程所有者的用户名。
78+
- `PR`:从系统内核角度看的进程调度优先级。
79+
- `NI`:进程的nice值,即从用户空间角度看的进程优先级。值越低,优先级越高。
80+
- `VIRT`:进程申请使用的虚拟内存量。
81+
- `RES`:进程使用的驻留内存(即未被swap out的内存)量。
82+
- `SHR`:进程使用的共享内存量。
83+
- `S`:进程状态可以为R=running,S=interruptible sleeping,D=uninterruptible sleeping,T=stopped,Z=zombie。
84+
- `%CPU`:进程在一个更新周期内占用的CPU时间比例。
85+
- `%MEM`:进程占用的物理内存比例。
86+
- `TIME+`:进程创建后至今占用的CPU时间长度。
87+
- `COMMAND`:运行进程使用的命令。
88+
89+
## TOP内的操作
90+
91+
- `上下移动`: 通过键盘上下箭头来移动显示其它进程的信息。
92+
93+
- `左右移动`: 通过键盘左右箭头来移动显示进程列信息可见性,如果有的行显示太长就可以通过这个操作查看。
94+
95+
- `改变数值单位`: 通过小写`e`和大写`E`来分别改变系统统计信息和进程详细信息的数值单位。
96+
97+
- `多cpu使用情况`: 如果你有不止一个cpu内核,可以通过按下`1`按钮来显示其它CPU信息,因为我的服务器就一个CPU内核,所以没得东西看。
98+
99+
- `切换CPU图表`: 按下`t`按钮来切换CPU实用的显示方式,挺有意思的自己可以试试。
100+
101+
- `切换内存/SWAP图表`: 按下`m`按键来切换内存和交换区的显示方式。
102+
103+
- `添加颜色显示`: 可以按下`z`来切换颜色显示程序进程信息。
104+
105+
- `高亮运行进程`: 按下键盘`y`来显示正在运行的进程。
106+
107+
- `高亮显示当前排序列`: 按下键盘`x`会高亮显示当前排序依据的列,默认是CPU列,可以能过按下如下大小字母来选择排序的表:
108+
109+
- **P:** The `%CPU` column.
110+
- **M:** The `%MEM` column.
111+
- **N:** The `PID` column.
112+
- **T:** The `TIME+` column.
113+
114+
- `切换command列显示`: 按下`c`按键可以切换command列的显示。
115+
116+
- `单独显示特定用户进程`: 按钮`u`按键,再输入用户名称就可以查看特定用户的进程信息。
117+
118+
- `设置进程的优先级`: 按下键盘中的`r`,再输入PID进可以设置进程的nice值了。
119+
120+
- `结束一个进程`: 按下键盘`k`,再输入PID结束一个进程。
121+
122+
基本使用差不多就上面这些,主要我们使用TOP程序来查看系统进程,来发现一些有问题的进程及时进行处理,保持服务器的速度和稳定,这对于我们做SEO优化来说是很重要的。
123+
124+
本文参考资料:
125+
126+
https://www.howtogeek.com/668986/how-to-use-the-linux-top-command-and-understand-its-output/
127+
128+
https://www.jianshu.com/p/a6e96c102881
129+
130+
https://blog.csdn.net/dxl342/article/details/53507673

blog/2021/08/linux-macos-increase-ssh-time/index.md linux/linux-macos-increase-ssh-time/index.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,41 @@ coverImage: "SSH-increase-timeout.png"
1414

1515
拿Debian 10服务器和MacOS系统举例,首先是**Debian服务器**端,我们需要打开文件:
1616

17-
```
17+
```bash
1818
sudo vim /etc/ssh/sshd_config
1919
```
2020

2121
打开之后,使用`/`搜索:
2222

23-
```
23+
```vim
2424
ClientAliveInterval
2525
ClientAliveCountMax
2626
```
2727

2828
这两个字段共同决定了客户端和服务器保持会话的超时时长,`ClientAliveInterval`字段是服务器间隔多少秒,向客户端发送心跳包,`ClientAliveCountMax`字段表示最大的发送尝试次数,比如我们要设置10分钟断开之内不好断开连接,可以设置成下面这样:
2929

30-
```
30+
```vim
3131
ClientAliveInterval 60
3232
ClientAliveCountMax 10
3333
```
3434

3535
修改保存,重新启动下SSH进程服务:
3636

37-
```
37+
```bash
3838
sudo systemctl restart sshd
3939
```
4040

4141
## 客户端SSH增加连接时长
4242

4343
同样是修改SSH配置文件,本地的配置文件MacOS:
4444

45-
```
45+
```bash
4646
sudo vim /etc/ssh/sshd_config
4747
```
4848

4949
拉到文件最底部,找到`Host` 字段:
5050

51-
```
51+
```vim
5252
ServerAliveInterval 1800
5353
ServerAliveCountMax 3
5454
```

0 commit comments

Comments
 (0)