Skip to content

Commit 9b69a9f

Browse files
author
pptfz
committed
更新containerd笔记
1 parent fa2f474 commit 9b69a9f

5 files changed

Lines changed: 496 additions & 45 deletions

File tree

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# Rocky Linux 10 时间同步与虚拟机休眠时间漂移问题笔记
2+
3+
## 一、背景说明
4+
5+
在 Rocky Linux 10 中,系统**默认不再提供 `ntpdate` 命令**,时间同步统一由 **chrony(chronyd / chronyc)** 负责。
6+
7+
**虚拟机环境**(如 Parallels Desktop、VMware、VirtualBox)中,如果 **宿主机进入休眠 / 挂起**
8+
9+
- 虚拟机 CPU 会被暂停
10+
- 虚拟机内部时间不再流逝
11+
- 唤醒后,虚拟机时间仍停留在休眠前
12+
13+
这在 K8s 节点、数据库、日志系统中会引发严重问题。
14+
15+
---
16+
17+
## 二、问题现象
18+
19+
典型表现:
20+
21+
- 宿主机真实时间:`2025-12-18`
22+
- 虚拟机时间仍为:`2025-12-17`
23+
- `chronyc -a makestep` 返回 `200 OK`,但时间未修正
24+
- cron 中已配置时间同步任务,但无效
25+
26+
---
27+
28+
## 三、根本原因分析
29+
30+
### 1. 虚拟机休眠导致时钟冻结
31+
32+
宿主机休眠期间:
33+
- 虚拟机 vCPU 停止
34+
- guest OS 内核时钟冻结
35+
- 唤醒后不会自动追赶真实时间
36+
37+
---
38+
39+
### 2. Rocky 10 中 chrony 的默认行为
40+
41+
chrony 的设计原则:
42+
43+
- **小偏差**:平滑调整(slew)
44+
- **大偏差**:只在特定条件下跳变(step)
45+
46+
Rocky 10 默认配置:
47+
```conf
48+
makestep 1.0 3
49+
```
50+
51+
含义:
52+
- 偏差 > 1 秒才允许 step
53+
- **只在前 3 次时间更新时允许 step**
54+
55+
👉 系统运行一段时间后,即使时间差一天,也**禁止自动 step**
56+
57+
---
58+
59+
## 四、为什么 `ntpdate` 不存在了
60+
61+
- RHEL 9 / Rocky 9+ 开始 **彻底移除 ntpdate**
62+
- 原因:
63+
- ntpdate 会粗暴修改系统时间
64+
- 与现代时间同步机制冲突
65+
- 官方替代方案:
66+
- `chronyc makestep`
67+
- `chronyc burst`
68+
69+
---
70+
71+
## 五、关键命令解释(核心)
72+
73+
### 1️⃣ `chronyc -a 'burst 4/4'`
74+
75+
作用:
76+
- 立即向 NTP 服务器发送一组请求
77+
- 强制获取**最新真实时间**
78+
79+
适用场景:
80+
- 虚拟机刚从休眠唤醒
81+
- chrony 尚未更新 offset
82+
83+
---
84+
85+
### 2️⃣ `chronyc -a makestep`
86+
87+
作用:
88+
- 当时间偏差过大时
89+
- **直接跳变系统时间(step)**
90+
91+
说明:
92+
- 管理员手动执行的 makestep
93+
- **不受 `chrony.conf` 中 step 次数限制**
94+
95+
---
96+
97+
### 3️⃣ 组合拳(推荐记住)
98+
99+
```bash
100+
chronyc -a 'burst 4/4' && chronyc -a makestep
101+
```
102+
103+
👉 专治:
104+
- 虚拟机休眠
105+
- 快照恢复
106+
- 时间冻结
107+
108+
---
109+
110+
## 六、正确的 chrony 配置(强烈推荐)
111+
112+
### 修改配置文件
113+
114+
```bash
115+
vi /etc/chrony.conf
116+
```
117+
118+
将:
119+
```conf
120+
makestep 1.0 3
121+
```
122+
123+
改为:
124+
```conf
125+
makestep 1.0 -1
126+
```
127+
128+
含义:
129+
- 偏差 > 1 秒就 step
130+
- **系统运行期间始终允许 step**
131+
132+
---
133+
134+
### 重启服务
135+
136+
```bash
137+
systemctl restart chronyd
138+
```
139+
140+
---
141+
142+
## 七、cron 时间同步的正确姿势
143+
144+
### ❌ 不推荐
145+
146+
```cron
147+
*/10 * * * * chronyc -a makestep
148+
```
149+
150+
原因:
151+
- makestep 不会主动拉取最新时间
152+
- offset 过期时可能什么都不做
153+
154+
---
155+
156+
### ✅ 推荐(兜底方案)
157+
158+
```cron
159+
*/10 * * * * /usr/bin/chronyc -a 'burst 4/4' && /usr/bin/chronyc -a makestep >/dev/null 2>&1
160+
```
161+
162+
说明:
163+
- burst 先获取真实时间
164+
- makestep 再决定是否跳变
165+
166+
---
167+
168+
## 八、虚拟化平台时间同步(可选但推荐)
169+
170+
**Parallels Desktop** 为例:
171+
172+
- 虚拟机设置 → Options → Time
173+
- 勾选:**Sync time with host**
174+
175+
并在虚拟机中确认:
176+
```bash
177+
systemctl status prl-tools
178+
```
179+
180+
---
181+
182+
## 九、常用排查命令
183+
184+
```bash
185+
chronyc tracking
186+
timedatectl
187+
```
188+
189+
重点关注:
190+
- `System clock synchronized: yes`
191+
- `System time` 偏差是否接近 0
192+
193+
---
194+
195+
## 十、最佳实践总结
196+
197+
- Rocky Linux 10 **不使用 ntpdate**
198+
- chrony 是唯一官方时间同步方案
199+
- 虚拟机环境 **必须允许 makestep 永久在线**
200+
- 推荐配置:
201+
```conf
202+
makestep 1.0 -1
203+
```
204+
- 遇到时间冻结:
205+
```bash
206+
chronyc -a 'burst 4/4' && chronyc -a makestep
207+
```
208+
209+
---
210+
211+
## 一句话结论(面试 / 笔记版)
212+
213+
> Rocky Linux 10 使用 chrony 替代 ntpdate,虚拟机休眠会导致系统时钟冻结,需通过 `makestep 1.0 -1` 或 burst + makestep 强制修正时间,否则 chrony 默认禁止大幅时间跳变。

docs/云原生/k8s/k8s资源/服务、负载均衡和联网/ingress/ingress-nginx/ingress-nginx安装.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ helm pull ingress-nginx/ingress-nginx
106106
解压缩
107107

108108
```shell
109-
tar xf ingress-nginx-4.8.4.tgz && cd ingress-nginx
109+
tar xf ingress-nginx-4.14.1.tgz && cd ingress-nginx
110110
```
111111

112112

docs/云原生/k8s/云原生网关/Envoy Gateway/Envoy Gateway使用.md

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,31 @@
22

33
## 创建GatewayClass
44

5+
[GatewayClass](https://gateway-api.sigs.k8s.io/api-types/gatewayclass/)
6+
57
:::tip 说明
68

79
`GatewayClass``Envoy Gateway` 的入口控制器
810

11+
12+
13+
官方示例 `GatewayClass` 配置
14+
15+
```yaml
16+
apiVersion: gateway.networking.k8s.io/v1
17+
kind: GatewayClass
18+
metadata:
19+
name: eg
20+
spec:
21+
controllerName: gateway.envoyproxy.io/gatewayclass-controller
22+
```
23+
924
:::
1025
26+
27+
28+
创建GatewayClass
29+
1130
```yaml
1231
cat > GatewayClass.yaml << EOF
1332
apiVersion: gateway.networking.k8s.io/v1
@@ -25,6 +44,31 @@ EOF
2544

2645
## 创建Gateway
2746

47+
[Gateway](https://gateway-api.sigs.k8s.io/api-types/gateway/)
48+
49+
:::tip 说明
50+
51+
官方示例 `Gateway` 配置
52+
53+
```yaml
54+
apiVersion: gateway.networking.k8s.io/v1
55+
kind: Gateway
56+
metadata:
57+
name: eg
58+
spec:
59+
gatewayClassName: eg
60+
listeners:
61+
- name: http
62+
protocol: HTTP
63+
port: 80
64+
```
65+
66+
:::
67+
68+
69+
70+
创建Gateway
71+
2872
```yaml
2973
cat > Gateway.yaml << EOF
3074
apiVersion: gateway.networking.k8s.io/v1
@@ -57,11 +101,59 @@ pptfz pptfz 10.0.0.231 False 8s
57101

58102
gateway创建完后会自动创建LoadBalancer类型的sec
59103

104+
:::tip 说明
105+
106+
svc的命名规则是 `envoy-<gateway-namespace>-<gateway-name>-<随机后缀>`
107+
108+
:::
109+
60110
```shell
61-
$ k get svc
111+
$ k get svc
62112
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
63-
envoy-envoy-gateway-system-pptfz-a1c63820 LoadBalancer 10.103.151.34 10.0.0.231 80:30626/TCP 12s
113+
envoy-envoy-gateway-system-pptfz-a1c63820 LoadBalancer 10.109.214.77 10.0.0.230 80:30828/TCP 5s
114+
envoy-gateway ClusterIP 10.96.250.227 <none> 18000/TCP,18001/TCP,18002/TCP,19001/TCP,9443/TCP 8m20s
115+
```
116+
117+
118+
119+
## 创建HTTPRoute
120+
121+
[HTTPRoute](https://gateway-api.sigs.k8s.io/api-types/httproute/)
122+
123+
:::tip 说明
124+
125+
官方示例 `HTTPRoute` 配置
126+
127+
```yaml
128+
apiVersion: gateway.networking.k8s.io/v1
129+
kind: HTTPRoute
130+
metadata:
131+
name: backend
132+
spec:
133+
parentRefs:
134+
- name: eg
135+
hostnames:
136+
- "www.example.com"
137+
rules:
138+
- backendRefs:
139+
- group: ""
140+
kind: Service
141+
name: backend
142+
port: 3000
143+
weight: 1
144+
matches:
145+
- path:
146+
type: PathPrefix
147+
value: /
64148
```
65149
150+
:::
151+
152+
153+
154+
创建HTTPRoute
66155
156+
```yaml
157+
158+
```
67159

0 commit comments

Comments
 (0)