Skip to content

Commit 7e9d602

Browse files
committed
ops/service: Split "init process" to new page
1 parent 2477746 commit 7e9d602

5 files changed

Lines changed: 58 additions & 32 deletions

File tree

docs/advanced/hpc/scheduler.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ icon: fontawesome/solid/tasks
5454
??? tip "munge 测试"
5555

5656
可通过以下命令测试 munge 是否配置正确:
57-
57+
5858
```text
5959
harry@foo:~$ echo 'Hello World' | munge | ssh bar unmunge
6060
STATUS: Success (0)
@@ -68,15 +68,15 @@ icon: fontawesome/solid/tasks
6868
UID: harry (1000)
6969
GID: harry (1000)
7070
LENGTH: 12
71-
71+
7272
Hello World
7373
```
7474

7575
统一的文件系统(如 NFS 或分布式文件系统)、网络配置和用户管理(如 LDAP)并非部署任何作业调度系统的强制要求,但通常是高性能计算集群的基础设施。请参阅本项目中的其他文档对此部分进行配置。
7676

7777
### Slurm 配置文件 {#slurm-config-files}
7878

79-
Slurm 需要的所有配置文件均存储在 `/etc/slurm` 下,管理员**务必**时刻保证集群中所有节点上文件内容一致(Slurm 会检查 hash),否则可能导致不可预期的错误。目前推荐的方式是使用 Configless Slurm(见后文),仅在管理节点上维护配置文件,其他节点实时进行拉取,以减少管理负担。
79+
Slurm 需要的所有配置文件均存储在 `/etc/slurm` 下,管理员**务必**时刻保证集群中所有节点上文件内容一致(Slurm 会检查 hash),否则可能导致不可预期的错误。目前推荐的方式是使用 [Configless Slurm](#configless-slurm),仅在管理节点上维护配置文件,其他节点实时进行拉取,以减少管理负担。
8080

8181
Debian 打包的 Slurm 没有提供默认配置文件,可通过官方的 [Configuration Tool](https://slurm.schedmd.com/configurator.html) 生成 `slurm.conf`,并根据实际情况进行修改。一些关键的配置项包括:
8282

@@ -182,7 +182,7 @@ Slurm 的权限管理依赖于其账户数据库,因此需要 slurmdbd 的支
182182
* `normal` 是所有选课学生,优先级系数为 5,每个任务最多使用 112 个 CPU 核心,最长运行时间为 2 分钟,每个用户最多同时提交 5 个任务,超过限制的任务会被拒绝。
183183
* `lab-ta` 是课程助教,优先级系数为 10,没有其他限制。
184184
* `lab-out` 为其他用户,优先级系数为 0,每个任务最长运行时间为 5 分钟,每个用户最多同时提交 3 个任务,超过限制的任务会被拒绝。
185-
185+
186186
此集群 `slurm.conf` 中的优先级相关配置是:
187187

188188
```ini
@@ -231,26 +231,26 @@ Slurm 的权限管理依赖于其账户数据库,因此需要 slurmdbd 的支
231231
232232
在作者管理的集群上,sshd 的 PAM 配置如下:
233233
234-
```text
234+
```shell
235235
# PAM configuration for the Secure Shell service
236-
236+
237237
# Standard Un*x authentication.
238238
@include common-auth
239-
239+
240240
# Disallow non-root logins when /etc/nologin exists.
241241
account sufficient pam_listfile.so item=user sense=allow file=/etc/ssh/allowed_users onerr=fail
242242
account sufficient pam_listfile.so item=user sense=allow file=/etc/ssh/allowed_groups onerr=fail
243243
-account required pam_slurm_adopt.so action_adopt_failure=deny action_generic_failure=deny
244244
account required pam_nologin.so
245-
245+
246246
# Uncomment and edit /etc/security/access.conf if you need to set complex
247247
# access limits that are hard to express in sshd_config.
248248
# account required pam_access.so
249-
249+
250250
# Standard Un*x authorization.
251251
@include common-account
252252
```
253-
253+
254254
`/etc/ssh/allowed_users` 和 `/etc/ssh/allowed_groups` 额外列出了允许登录的用户和用户组,无论它们是否有正在运行的作业。作者还配置了更严格的 `action_adopt_failure=deny` 选项,进一步防止有用户进程残留。
255255
256256
### Configless Slurm
@@ -261,26 +261,26 @@ Slurm 的权限管理依赖于其账户数据库,因此需要 slurmdbd 的支
261261
262262
1. 在 `slurm.conf` 中配置 `SlurmctldParameters=enable_configless` 并重启 slurmctld;
263263
2. 使得 slurmd 能找到 slurmctld:可以通过 DNS SRV 记录或者启动时传递 `--conf-server` 参数,或者传递 `SLURM_CONF_SERVER` 环境变量;
264-
3. 如果使用 SRV 记录,需要保证 slurmd 启动时本地没有任何配置(因为 [搜索顺序](https://slurm.schedmd.com/configless_slurm.html#NOTES) 中 SRV 记录优先级最低)。
264+
3. 如果使用 DNS SRV 记录,需要保证 slurmd 启动时本地没有任何配置(因为 [搜索顺序](https://slurm.schedmd.com/configless_slurm.html#NOTES) 中 DNS SRV 记录优先级最低)。
265265
266266
简单起见,可以选择传参的方案,即在所有安装 slurmd 的节点上修改 `/etc/default/slurmd`,在 `SLURMD_OPTIONS` 中添加:
267267
268-
```text
268+
```shell
269269
SLURMD_OPTIONS="--conf-server your_ctl_server:6817"
270270
```
271271

272272
(此部分可选)保险起见,还可以通过 systemd 对 slurmd 隐藏整个 `/etc/slurm` 的文件夹,避免潜在的冲突/混淆问题。运行 `systemctl edit slurmd`,增加:
273273

274-
```init
274+
```ini
275275
[Service]
276276
TemporaryFileSystem=/etc/slurm
277277
```
278278

279-
??? tip "trixie 前的特殊配置"
279+
??? tip "Trixie 前的特殊配置"
280+
281+
较旧(Debian Trixie 前)的 `slurmd.service` 中含有多余的 `ConditionPathExists=/etc/slurm/slurmd.conf`,需要一并覆盖清除,否则会导致无配置的情况下,服务无法正常启动:
280282

281-
较旧(trixie 前)的 `slurmd.service` 中含有多余的 `ConditionPathExists=/etc/slurm/slurmd.conf`,需要一并覆盖清除,否则会导致无配置的情况下,服务无法正常启动:
282-
283-
```init
283+
```ini
284284
[Unit]
285285
ConditionPathExists=
286286
```
@@ -309,7 +309,7 @@ systemctl enable --now sackd
309309

310310
目前 Slurm 对容器的支持仍然比较初级,配置较为晦涩难懂(如对共享文件系统有更复杂的要求),且对不同的容器运行时支持程度不一,限制较多。作者尚未成功配置过此功能,建议有兴趣的读者仔细阅读官方文档,谨慎部署。
311311

312-
### Slurm Restful API (slurmrestd)
312+
### Slurm Restful API (slurmrestd) {#slurmrestd}
313313

314314
通过运行 slurmrestd 守护进程,可以为 Slurm 提供基于 RESTful 的 API 接口,方便用户和管理员通过 HTTP 请求与 Slurm 进行结构化的数据交互,而无需拼接命令、解析文本。很多图形化的作业提交平台正是基于此接口实现的。
315315

docs/ops/booting.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
icon: material/power
3+
---
4+
5+
# 启动程序
6+
7+
!!! warning "本文编写中"
8+
9+
## BIOS 与 UEFI
10+
11+
## Bootloader
12+
13+
### GRUB
14+
15+
### systemd-boot
16+
17+
## initramfs
18+
19+
### UKI
20+
21+
## init 进程
22+
23+
`init` 进程是 Linux 启动时运行的第一个进程,负责启动系统的各种服务并最终启动 shell。传统的 init 程序位于 `/sbin/init`,而现代发行版中它一般是指向 `/lib/systemd/systemd` 的软链接,即由 systemd 作为 PID 1 运行。
24+
25+
PID 1 在 Linux 中有一些特殊的地位:
26+
27+
- 不受 `SIGKILL``SIGSTOP` 信号影响,不能被杀死或暂停。类似地,即使收到了其他未注册的信号,默认行为也是忽略,而不是结束进程或挂起。
28+
- 当其他进程退出时,这些进程的子进程会由 PID 1 接管,因此 PID 1 需要负责回收(`wait(2)`)这些僵尸进程。
29+
30+
### systemd
31+
32+
### 其他 init 系统

docs/ops/network-service/nginx.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ TLS 是一种加密通信协议,用于保护客户端和服务器之间的通
586586
/// caption
587587
图片来自 [If OpenSSL were a GUI](https://smallstep.com/blog/if-openssl-were-a-gui/)
588588
///
589-
589+
590590
因此这里推荐使用 [mkcert](https://github.com/FiloSottile/mkcert) 用于快速测试。安装 `mkcert` 包后可以直接让它生成指定域名的证书,它会自动生成对应的 CA 证书:
591591

592592
```console
@@ -622,6 +622,8 @@ TLS 是一种加密通信协议,用于保护客户端和服务器之间的通
622622
openssl verify -CAfile ca.crt cert.crt
623623
```
624624

625+
另外,[xca](https://www.hohnstaedt.de/xca/) 是一个 GUI 的证书管理程序,相比于命令行工具更容易上手。
626+
625627
以下假设你的证书保存在 `/etc/nginx/ssl/example.com.crt``/etc/nginx/ssl/example.com.key`
626628

627629
!!! tip "证书格式"

docs/ops/service.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ icon: material/room-service
1414

1515
早期(2014 年以前)还有 SysVinit 和 Upstart 等,但现在已经很少见了。SysVinit 还有一个现代化的替代品,叫做 OpenRC。
1616

17-
## Init
18-
19-
Init 进程是 Linux 启动时运行的第一个进程,负责启动系统的各种服务并最终启动 shell。传统的 init 程序位于 `/sbin/init`,而现代发行版中它一般是指向 `/lib/systemd/systemd` 的软链接,即由 systemd 作为 PID 1 运行。
20-
21-
PID 1 在 Linux 中有一些特殊的地位:
22-
23-
- 不受 `SIGKILL``SIGSTOP` 信号影响,不能被杀死或暂停。类似地,即使收到了其他未注册的信号,默认行为也是忽略,而不是结束进程或挂起。
24-
- 当其他进程退出时,这些进程的子进程会由 PID 1 接管,因此 PID 1 需要负责回收(`wait(2)`)这些僵尸进程。
25-
2617
## Systemd 与服务 {#systemd-and-service}
2718

2819
Systemd 是一大坨软件,包括服务管理(PID 1)、日志管理(systemd-journald)、网络管理(systemd-networkd)、本地 DNS 缓存(systemd-resolved)、时间同步(systemd-timesyncd)等,本文主要关心服务管理和日志管理。
@@ -113,7 +104,7 @@ WantedBy=multi-user.target
113104
!!! tip "查询手册"
114105

115106
Unit 配置中不同的字段分布在 systemd 不同的手册页中。其中 `[Unit]` 和 `[Install]` 部分的字段可以在 [`systemd.unit(5)`][systemd.unit.5] 中找到。
116-
107+
117108
对于服务,`[Service]` 中的字段大部分在 [`systemd.service(5)`][systemd.service.5] 中,但其中与运行环境有关的会在 [`systemd.exec(5)`][systemd.exec.5] 中,与程序资源限制相关的会在 [`systemd.resource-control(5)`][systemd.resource-control.5] 中,与退出/杀死服务相关的会在 [`systemd.kill(5)`][systemd.kill.5] 中。
118109

119110
对于定时器,`[Timer]` 部分的字段可以在 [`systemd.timer(5)`][systemd.timer.5] 中找到。
@@ -276,7 +267,7 @@ Service 也就是我们最常见的服务,它的配置文件中有一个 `[Ser
276267
- `[Unit]` 部分指定的 `After=remote-fs.target nss-user-lookup.target` 表示 cron 会在系统达到这两个 target 之后才启动,即远程文件系统挂载完成和用户信息服务(`getent passwd` 等命令可用)都已经启动。
277268
- `EnvironmentFile=-/etc/default/cron` 表示会读取 `/etc/default/cron` 文件中的环境变量。开头的 `-` 表示如果这个文件不存在,则直接忽略。
278269
- `ExecStart=/usr/sbin/cron -f -P $EXTRA_OPTS` 指定了服务的启动命令,其中 `$EXTRA_OPTS` 是从上面的文件中读取的环境变量。
279-
270+
280271
!!! tip
281272

282273
通常情况下我们建议对命令使用绝对路径,因为 systemd 启动服务时并不会使用系统配置的 `$PATH` 环境变量,而是使用一个硬编码的列表。
@@ -689,7 +680,7 @@ ForwardToSyslog=yes
689680
!!! note "systemd-journal-{upload,remote,gatewayd}"
690681

691682
事实上,systemd-journal 也提供了远程通过网络传输日志的独立服务(由 `systemd-journal-remote` 包提供),其中 systemd-journal-gatewayd 提供了访问日志的 HTTP API 服务,systemd-journal-remote 运行在日志接收端,systemd-journal-upload 运行在发送端。
692-
683+
693684
但是在 Debian 下存在一个严重的问题:由于 systemd 与 TLS 相关的代码从 GnuTLS 迁移到了 OpenSSL,并且 Debian 不希望同时使用多个 TLS 库构建 systemd,因此在构建时关闭了 GnuTLS 的支持。但是 systemd-journal-remote 依赖于 [libmicrohttpd](https://www.gnu.org/software/libmicrohttpd/),其依赖于 GnuTLS。这导致了 Debian 构建的 systemd-journal-remote 不支持 HTTPS 加密传输日志,带来了安全风险。
694685

695686
详情可参考 [Debian bug #1100729](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1100729)。
@@ -779,7 +770,7 @@ systemd 中每个 session 都会启动一个用户级别的 systemd 进程,用
779770
`systemctl`、`journalctl` 等命令依赖于 DBus 总线与 systemd 通信。对于用户 session 来说,则依赖于 session 的 DBus 服务正常工作(一般路径为 `/run/user/<用户 PID>/bus`)。
780771

781772
在命令行下需要切换用户的场合中,如果需要使用用户级别的 systemd,推荐的做法是使用以下命令:
782-
773+
783774
- `machinectl shell username@`
784775
- `run0`(需要很新的发行版,如 Debian 13)
785776

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ nav:
103103
- ops/index.md
104104
- 检查单: ops/checklist.md
105105
- 服务器介绍: ops/server.md
106+
- 系统启动程序: ops/booting.md
106107
- 包管理系统: ops/package.md
107108
- 服务与日志管理: ops/service.md
108109
- 存储系统:

0 commit comments

Comments
 (0)