gkoufie1/devops-incident-response-project

GitHub: gkoufie1/devops-incident-response-project

基于 Linux/AWS 的 DevOps 事件响应实战实验室,通过模拟五种典型生产故障并提供诊断手册与自动化修复脚本来培养运维排障能力。

Stars: 0 | Forks: 0

# DevOps 事件响应实验室 一个基于 Linux/AWS 的动手实验,模拟了五种生产环境事件类型 —— 包含模拟脚本、诊断操作手册(runbook)、修复自动化以及健康检查套件。 **目标环境:** AWS Ubuntu EC2(t2.micro 或 t3.small),通过 MobaXterm 使用 SSH 访问。 ## 本实验涵盖的内容 | 模块 | 事件类型 | 展示的技能 | |---|---|---| | 1 | 磁盘已满 | `df`, `du`, `find`, logrotate, journalctl | | 2 | 服务故障 | `nginx -t`, `journalctl`, `systemctl`, 配置管理 | | 3 | 网络故障 | `iptables`, `ss`, `ip`, AWS 安全组排查 | | 4 | SSH 故障 | `sshd -t`, `sshd_config`, auth 日志, EC2 恢复路径 | | 5 | CPU 飙高 | `ps`, `pidstat`, `sar`, `htop`, 进程管理 | ## 仓库结构 ``` devops-incident-response-project/ ├── scripts/ │ ├── setup_lab.sh # Install and configure the lab environment │ ├── simulate_disk_full.sh # Create large fake log files │ ├── fix_disk_full.sh # Clean up disk and compress logs │ ├── simulate_broken_service.sh # Inject invalid nginx config directive │ ├── fix_broken_service.sh # Restore nginx from backup │ ├── simulate_network_issue.sh # Block port 80 with iptables │ ├── fix_network_issue.sh # Remove iptables rule │ ├── simulate_ssh_failure_safe.sh # Disable SSH auth methods safely │ ├── fix_ssh_failure.sh # Restore sshd_config from backup │ ├── simulate_high_cpu.sh # Spawn stress CPU workers │ └── fix_high_cpu.sh # Kill stress processes ├── docs/ │ ├── 01-disk-full-runbook.md │ ├── 02-broken-service-runbook.md │ ├── 03-networking-runbook.md │ ├── 04-ssh-failure-runbook.md │ ├── 05-high-cpu-runbook.md │ └── incident-report-template.md ├── configs/ │ ├── nginx/devops-lab.conf │ ├── prometheus/prometheus.yml │ ├── logrotate/devops-lab │ └── ansible/ │ ├── inventory.ini │ └── basic-health-check.yml ├── tests/ │ └── health_check.sh └── assets/ └── architecture.txt ``` ## 快速开始 使用 MobaXterm 通过 SSH 登录到你的 EC2 实例,然后: ``` sudo apt update -y sudo apt install -y git curl wget vim htop net-tools dnsutils traceroute tcpdump lsof sysstat stress logrotate unzip git clone https://github.com/gkoufie1/devops-incident-response-project.git cd devops-incident-response-project chmod +x scripts/*.sh tests/health_check.sh sudo ./scripts/setup_lab.sh ``` 验证: ``` curl http://localhost systemctl status nginx --no-pager ``` ## 实验模块 每个模块遵循相同的模式:**模拟 → 诊断 → 修复 → 记录** ### 模块 1 — 磁盘已满 ``` sudo ./scripts/simulate_disk_full.sh df -h && du -sh /var/log/devops-lab/* sudo ./scripts/fix_disk_full.sh ``` 操作手册:[docs/01-disk-full-runbook.md](docs/01-disk-full-runbook.md) ### 模块 2 — 服务故障 ``` sudo ./scripts/simulate_broken_service.sh sudo nginx -t && journalctl -u nginx -n 50 --no-pager sudo ./scripts/fix_broken_service.sh ``` 操作手册:[docs/02-broken-service-runbook.md](docs/02-broken-service-runbook.md) ### 模块 3 — 网络故障 ``` sudo ./scripts/simulate_network_issue.sh sudo iptables -L -n -v && ss -tulpn sudo ./scripts/fix_network_issue.sh ``` 操作手册:[docs/03-networking-runbook.md](docs/03-networking-runbook.md) ### 模块 4 — SSH 故障 ``` sudo ./scripts/simulate_ssh_failure_safe.sh # 打开第二个 MobaXterm 会话进行测试 — 它将会失败 sudo ./scripts/fix_ssh_failure.sh ``` 操作手册:[docs/04-ssh-failure-runbook.md](docs/04-ssh-failure-runbook.md) ### 模块 5 — CPU 飙高 ``` sudo ./scripts/simulate_high_cpu.sh htop && ps aux --sort=-%cpu | head sudo ./scripts/fix_high_cpu.sh ``` 操作手册:[docs/05-high-cpu-runbook.md](docs/05-high-cpu-runbook.md) ## 健康检查 ``` sudo ./tests/health_check.sh ``` 检查磁盘、nginx、HTTP 响应、监听端口和防火墙规则。 ## 推荐的 AWS EC2 设置 - **AMI:** Ubuntu Server 22.04 LTS - **实例类型:** t2.micro(免费套餐)或 t3.small - **存储:** 20 GB gp3 - **安全组入站规则:** | 端口 | 协议 | 来源 | |------|----------|--------| | 22 | TCP SSH | 仅限你的 IP | | 80 | TCP HTTP | 0.0.0.0/0 | | 9090 | TCP | 仅限你的 IP(Prometheus) | 切勿将 SSH 端口 22 暴露给 `0.0.0.0/0`。 ## 监控技术栈 - **Prometheus** 抓取自身指标(`localhost:9090`),并通过 **node_exporter**(`localhost:9100`)抓取节点指标 - **node_exporter** 由 `setup_lab.sh` 自动安装 - 配置文件:[configs/prometheus/prometheus.yml](configs/prometheus/prometheus.yml) ## 安全提示 - 请勿在生产系统上运行这些脚本。 - 所有模拟脚本都是幂等的 —— 它们会在更改之前检查状态。 - 对于 SSH 模块,请始终保持至少一个活动的会话作为恢复路径。 - `.pem` 密钥文件已通过 `.gitignore` 排除在 git 之外。 ## 作品集面试要点 使用此项目来展示: - 你如何检测、排查并解决真实的基础设施事件 - 你如何编写运维操作手册和 RCA 文档 - 你如何使用 Bash 自动执行可重复的修复任务 - 你如何强化 SSH 访问安全并保护基础设施 - 你如何利用健康检查和监控来降低 MTTR - 你如何区分服务层故障和网络层故障
标签:API令, AWS, DPI, 应用安全, 故障排查, 系统提示词, 系统运维, 自动化运维, 自定义请求头