mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-03-26 19:55:23 +00:00
Add blank lines around headers
This commit is contained in:
@@ -48,6 +48,7 @@ scrape_configs:
|
||||
rule_files:
|
||||
- /etc/prometheus/rules.yml
|
||||
```
|
||||
|
||||
#### 2. 编写 Docker Compose 文件
|
||||
|
||||
创建 `compose.yaml` (或 `docker-compose.yml`):
|
||||
@@ -105,6 +106,7 @@ networks:
|
||||
volumes:
|
||||
prometheus_data:
|
||||
```
|
||||
|
||||
#### 3. 启动服务
|
||||
|
||||
```bash
|
||||
|
||||
@@ -71,6 +71,7 @@ volumes:
|
||||
networks:
|
||||
logging:
|
||||
```
|
||||
|
||||
#### 2. 配置 Fluentd
|
||||
|
||||
创建 `fluentd/conf/fluent.conf`:
|
||||
@@ -101,6 +102,7 @@ networks:
|
||||
</store>
|
||||
</match>
|
||||
```
|
||||
|
||||
#### 3. 配置应用容器使用 fluentd 驱动
|
||||
|
||||
启动一个测试容器,指定日志驱动为 `fluentd`:
|
||||
|
||||
@@ -91,6 +91,7 @@ done
|
||||
# MEM % 接近 100%:容器即将 OOM,需要增加内存或排查内存泄漏
|
||||
# 如果 NET I/O 中 dropped 为非零:网络拥塞或丢包
|
||||
```
|
||||
|
||||
### 19.3.3 cAdvisor 容器监控系统
|
||||
|
||||
cAdvisor 是 Google 开发的容器监控工具,提供比 `docker stats` 更详细的性能数据。
|
||||
@@ -150,6 +151,7 @@ scrape_configs:
|
||||
- targets: ['localhost:8080']
|
||||
metrics_path: '/metrics'
|
||||
```
|
||||
|
||||
### 19.3.4 Prometheus 容器监控配置
|
||||
|
||||
使用 Prometheus 和 node-exporter 进行长期的容器性能监控。
|
||||
@@ -275,6 +277,7 @@ container_memory_cache_bytes / container_memory_usage_bytes
|
||||
# 按镜像统计容器数
|
||||
count(container_memory_usage_bytes) by (image)
|
||||
```
|
||||
|
||||
### 19.3.5 容器 OOM 排查与内存限制调优
|
||||
|
||||
#### OOM 问题诊断
|
||||
@@ -293,6 +296,7 @@ docker logs <container_id> 2>&1 | grep -i "out of memory\|oom"
|
||||
dmesg | grep -i "oom\|kill"
|
||||
journalctl -u docker -n 100 | grep -i "oom"
|
||||
```
|
||||
|
||||
#### 内存泄漏检测
|
||||
|
||||
使用专项工具分析应用内存使用:
|
||||
@@ -347,6 +351,7 @@ jstat -gc <pid> 1000 # 每秒采样一次
|
||||
# S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU
|
||||
# 6144 6144 0 6144 39424 12288 149504 84320 50552 47689 6464 5989
|
||||
```
|
||||
|
||||
#### 内存限制最佳实践
|
||||
|
||||
```bash
|
||||
@@ -385,6 +390,7 @@ services:
|
||||
memory: 2G
|
||||
memory_reservation: 1G # 预留 1GB,允许突发到 2GB
|
||||
```
|
||||
|
||||
### 19.3.6 镜像体积优化与多阶段构建
|
||||
|
||||
#### 镜像体积分析工具
|
||||
@@ -411,6 +417,7 @@ chmod +x hadolint
|
||||
# 检查 Dockerfile 最佳实践
|
||||
./hadolint Dockerfile
|
||||
```
|
||||
|
||||
#### 多阶段构建最佳实践
|
||||
|
||||
**Go 应用的最小化镜像构建:**
|
||||
@@ -528,6 +535,7 @@ EXPOSE 5000
|
||||
|
||||
CMD ["python", "app.py"]
|
||||
```
|
||||
|
||||
#### 镜像体积优化检查清单
|
||||
|
||||
```bash
|
||||
@@ -558,6 +566,7 @@ RUN apt-get update && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
```
|
||||
|
||||
### 19.3.7 常见性能问题及解决方案
|
||||
|
||||
**问题 1: 容器频繁被 OOM 杀死**
|
||||
|
||||
Reference in New Issue
Block a user