CodeRoadMap
首页路线题库资源库文章社区
CodeRoadMap

程序员的学习成长路线图。内容免费开放,登录后可同步路线图与课时进度。

由 程序员柏风 独立维护 · 关于作者

学习

  • 路线图
  • 课程
  • 面试题
  • 文章
  • 我

更多

  • 资源
  • 社区
  • 关于作者
  • 内容说明

© 2026 CodeRoadMap

津ICP备2026012044号-1·津公网安备12011002026155号·coderoadmap@126.com
DevOps 网络与邮件/课时/版本控制回顾
RawBlame
课时目录12 节

DevOps 网络与邮件

  1. 01网络与运维基础
  2. 02OSI 与分层
  3. 03SSH 远程管理
  4. 04FTP 与 SFTP
  5. 05SMTP 发信
  6. 06IMAP 与 POP3
  7. 07邮件认证
  8. 08编辑器与文本处理
  9. 09版本控制回顾
  10. 10编程语言选型
  11. 11邮件运维排障
  12. 12综合练习

版本控制回顾

version-control-systems;衔接 git-essentials。

20 分钟

版本控制:Git 与运维配置管理

Infrastructure as Code 时代,Nginx 配置、Postfix 模板、DNS 变更脚本、部署 playbook 都应纳入版本控制。本课在 git-essentials 基础上,聚焦 运维场景的 Git 工作流——与开发共用仓库还是独立 infra 仓、如何 review 配置变更、如何与 CI/CD 联动。服务器操作见 linux-essentials,网络与端口见 networking-essentials,DNS 记录见 dns-essentials,远程操作见 dnm-ssh,编辑器见 dnm-editors。

学习目标

  • 建立 infra 配置仓库 的目录结构与分支策略
  • 用 Git 管理 Postfix/Nginx 配置变更并 trace 历史
  • 理解 配置 drift 与 Git 作为「期望状态」源的意义

运维仓库结构示例

infra/
├── nginx/
│   ├── sites-available/
│   └── snippets/
├── postfix/
│   ├── main.cf
│   └── master.cf
├── dovecot/
│   └── conf.d/
├── dns/
│   └── example.com.zone.txt
├── scripts/
│   ├── deploy.sh
│   └── backup-mail.sh
└── README.md

与 git-essentials 的 feature branch 一致:一个分支一个故事。

基本工作流

git clone git@github.com:org/infra.git
cd infra

git checkout -b feat/postfix-relay-sendgrid
vim postfix/main.cf
# 修改 relayhost

git diff
git add postfix/main.cf
git commit -m "postfix: switch relay to SendGrid on port 587"
git push -u origin feat/postfix-relay-sendgrid
# 开 PR,同事 review 后 merge

PR 描述应含:影响范围、回滚步骤、是否需 systemctl reload。

部署:从 Git 到服务器

# 服务器上 /opt/infra 为 clone
cd /opt/infra
git pull origin main

# 同步配置(示例)
sudo cp postfix/main.cf /etc/postfix/main.cf
sudo postfix check && sudo systemctl reload postfix

# 或 rsync / 软链 / Ansible(进阶见 devops-cloud-essentials)
# deploy.sh 示意
#!/bin/bash
set -euo pipefail
cd /opt/infra
git pull --ff-only origin main
sudo cp postfix/main.cf /etc/postfix/main.cf
sudo postfix check
sudo systemctl reload postfix
echo "Postfix config deployed: $(git rev-parse --short HEAD)"

脚本本身也在 Git 里——改 deploy 逻辑也要 PR。

敏感信息处理

❌ 不要✅ 应该
把 SMTP 密码 commit 进仓库用环境变量 / Ansible Vault / 密钥管理器
私钥进 repo.gitignore + ssh-add 或 CI secret
明文 .env.env.example 进 Git,.env 忽略
# .gitignore
.env
*.pem
*.key
postfix/sasl_passwd

参考 git-essentials 与 sec-secrets。

配置 drift 检测

# 服务器当前配置 vs Git 期望
diff /etc/postfix/main.cf /opt/infra/postfix/main.cf

# 或用 git 在服务器上直接看
cd /opt/infra && git status   # 若有人手改 /etc 再 cp 回来,应有 diff

Git 是 single source of truth;手改 /etc 不回流 = 技术债。

与 DNS 变更协作

MX/SPF/DKIM 记录变更:

  1. 改 dns/example.com.zone.txt
  2. PR + review
  3. merge 后在 DNS 控制台应用(或 API/terraform)
  4. dig 验证(dns-essentials)

练习

  • 初始化一个 infra 仓库,纳入一份 Nginx 或 Postfix 配置样例
  • 走一遍 feature branch → commit → push → PR 描述(可自审)
  • 写 deploy.sh 脚本:git pull + 复制配置 + reload 服务

小结

运维 Git = 配置的版本化、可 review、可回滚。 与开发共用规范,敏感信息不进库。下一课讲脚本编程——把重复运维动作自动化。

加载本节练习…
← 上一课编辑器与文本处理下一课 →编程语言选型