This commit is contained in:
许大仙 2024-08-26 16:18:00 +08:00
parent c1279aea38
commit 0cdb275b12
15 changed files with 137 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1854,3 +1854,60 @@ cp perf /usr/bin/
![](./assets/174.png)
## 8.7 WSL 启用 systemd
### 8.7.1 概述
* 根据 [systemd.io](https://systemd.io/)“systemd 是 Linux 系统的基本构建基块套件。 它提供一个系统和服务管理器,该管理器作为 PID 1 运行并启动系统的其余部分。”
* Systemd 主要是一个 init 系统和服务管理器,它包括按需启动守护程序、装载和自动装载点维护、快照支持以及使用 Linux 控制组进行跟踪等功能。
* 大多数主要的 Linux 发行版现在都运行 systemd因此在 WSL 上启用它可使体验更接近于使用裸机 Linux。
> [!NOTE]
>
> 默认情况下,在 WSL2 中,只有 Ubuntu 才会将 systemd 作为 pid-1 的守护进程启动整个 WSL2而其余的 Linux 的守护进程并不是这样的。
* 检查进程树,判断 systemd 是否正在运行:
```shell
ps -p 1 -o comm= # 如果显示 systemd ,则表示 systemd 正在运行
```
![](./assets/175.gif)
### 8.7.2 操作步骤
* ① 查询 WSL2 的版本,确保 WSL2 的版本为 `0.67.6` 或更高版本:
```shell
# 如果未满足要求,则使用 wsl --update 更新 WSL2 版本
wsl --version # 在 win 中的 cmd 或 PowerShell
```
![](./assets/176.png)
* ② 向 `/etc/wsl.conf` 配置文件中写入以下内容:
```shell
cat <<EOF | tee /etc/wsl.conf
[boot]
systemd=true
EOF
```
![](./assets/177.gif)
* ③ 重启 WSL 实例:
```shell
wsl --shutdown # 在 win 中的 cmd 或 PowerShell
```
![](./assets/178.gif)
* ④ 查看是否启用成功:
```shell
ps -p 1 -o comm=
```
![](./assets/179.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -2352,3 +2352,83 @@ man ascii
![](./assets/44.png)
## 3.2 WSL2 中设置默认编码为中文
### 3.2.1 概述
* 查看 WSL2 的 Linux 发行版的默认编码:
```shell
echo $LANG
```
![](./assets/45.gif)
> [!NOTE]
>
> `C.UTF-8` 是一种字符编码设置,结合了 `C` 区域设定和 `UTF-8` 字符编码。
>
> * ① **C 区域设定**:这是一个标准的、最小化的区域设置,通常用于系统默认的语言环境。`C` 区域设定下,所有字符都被认为是 ASCII 字符集的一部分,这意味着仅支持基本的英文字符和符号。在 `C` 区域设定中,字符串的排序和比较是基于简单的二进制值比较,这与本地化的语言设置相比相对简单。
> * ② **UTF-8 编码**UTF-8 是一种变长的字符编码方式,可以编码所有的 Unicode 字符。它是一种广泛使用的字符编码,能够支持多种语言和符号。每个 UTF-8 字符可以由1到4个字节表示这使得它兼容 ASCII对于标准 ASCII 字符UTF-8 只使用一个字节)。
>
> 因此,`C.UTF-8` 结合了 `C` 区域设定和 UTF-8 字符编码的优势。使用 `C.UTF-8` 时,系统默认语言环境保持简单和高效,同时支持更广泛的字符集,特别是多语言和非英语字符。这样可以在需要兼容性的同时,提供对全球化字符的支持。
### 3.2.2 AlmaLinux9 设置默认编码
* ① 搜索中文语言包:
```shell
dnf search locale zh
```
![](./assets/46.gif)
* ② 安装中文语言包:
```shell
dnf -y install glibc-langpack-zh
```
![](./assets/47.gif)
* ③ 切换语言环境为中文:
```shell
localectl set-locale LANG=zh_CN.UTF-8
```
![](./assets/48.gif)
* ④ 手动加载配置文件,使其生效:
```shell
source /etc/locale.conf
```
![](./assets/49.gif)
### 3.2.3 Ubuntu 22.04 设置默认编码
* ① 安装中文语言包:
```shell
sudo apt update -y && apt install language-pack-zh-hans -y
```
![](./assets/50.gif)
* ② 切换环境为中文:
```shell
update-locale LANG=zh_CN.UTF-8 LANGUAGE=zh_CN:zh
```
![](./assets/51.gif)
* ③ 手动加载配置文件,使其生效:
```shell
source /etc/default/locale
```
![](./assets/52.gif)