工程化与 DevOps
Maven、Git、Linux — 从写代码到工程化交付。
Maven
坐标与仓库
GAV 坐标:groupId + artifactId + version 唯一标识一个依赖 本地仓库:~/.m2/repository 中央仓库:repo1.maven.org 私服:公司内部 Nexus / Artifactory
依赖管理
dependencies:直接依赖 dependencyManagement:仅声明版本,子模块按需引入 传递依赖:A 依赖 B,B 依赖 C → A 自动获得 C 版本冲突解决:路径最近者优先、声明优先
依赖范围 (Scope)
compile:默认,编译 + 测试 + 运行 provided:编译 + 测试,运行时由容器提供(如 Servlet API) runtime:测试 + 运行,编译不需要(如 JDBC 驱动) test:仅测试(如 JUnit)
生命周期
clean:清理 target default:compile → test → package → install → deploy site:生成项目文档 插件:maven-compiler-plugin, maven-surefire-plugin 等
Git
基础操作
git init / clone git add . / git commit -m "msg" git status / git log --oneline git diff / git diff --staged
分支管理
git branch / git checkout -b feature git merge / git rebase git stash / git stash pop .gitignore 忽略文件
远程协作
git remote add origin url git push -u origin main git pull = fetch + merge PR / MR:代码评审后合并
Linux
基本命令
文件操作:ls, cd, pwd, mkdir, rm, cp, mv, touch, cat, more, tail 权限管理:chmod, chown, chgrp 用户管理:useradd, passwd, su, sudo 网络:ping, netstat, curl, wget
CentOS 7 虚拟机配置
虚拟机安装与网络配置(NAT / 桥接) 关闭防火墙:systemctl stop firewalld 配置静态 IP 安装 JDK、MySQL、Redis 等环境
服务管理
systemctl start/stop/restart/status 服务名 systemctl enable/disable 服务名(开机自启) journalctl -u 服务名(查看日志)
Shell 脚本
#!/bin/bash 声明 变量:name="value"(等号两边无空格) 条件:if [ condition ]; then ... fi 循环:for i in list; do ... done 函数:function name()
Docker
核心概念
镜像 (Image):只读模板,包含运行环境 容器 (Container):镜像的运行实例 仓库 (Registry):存储和分发镜像(Docker Hub)
常用命令
docker pull / push / images / rmi docker run -d -p 8080:8080 --name myapp image docker ps / docker stop / docker rm docker exec -it container bash docker logs container
Dockerfile
FROM:基础镜像 COPY / ADD:复制文件 RUN:执行命令 EXPOSE:声明端口 CMD / ENTRYPOINT:启动命令 docker build -t name:tag .