DevOps
第1章 什么是DevOps
开发 development
运维 operations
1.1 DevOps能做什么?
提高产品质量
1 自动化测试
2 持续集成
3 代码质量管理工具
4 程序员鼓励师
1.2 Devops如何实现
既然这么好?为什么有些公司没有
设计架构规划‐代码的存储‐构建‐测试、预生产、部署、监控
第2章 Git版本控制系统
2.1 版本控制系统简介
一个标准的版本控制系统 Version Control System (VCS),通常需要有以下功能:
- 能够创建 Repository (仓库),用来保存代码
- 协同开发时方便将代码分发给团队成员
- 记录每次修改代码的内容、时间、原因等信息
- 能够创建 Branch (分支),可以根据不同的场景进行开发
- 能够创建 Tag (标签),建立项目里程碑
2.2 为什么需要版本控制
在软件开发过程,每天都会产生新的代码,代码合并的过程中可能会出现如下问题:
- 代码被覆盖或丢失
- 代码写的不理想希望还原之前的版本
- 希望知道与之前版本的差别
- 是谁修改了代码以及为什么修改
- 发版时希望分成不同的版本(测试版、发行版等)
因此,我们希望有一种机制,能够帮助我们:
- 可以随时回滚到之前的版本
- 协同开发时不会覆盖别人的代码
- 留下修改记录,以便随时查看
- 发版时可以方便的管理不同的版本
2.3 常见版本管理工具
Cvs:是一个C/S系统,是一个常用的代码版本控制软件。主要在开源软件管理中使用。多个开发人员通过一个中心版本控制系统来记录文件版本,从而达到保证文件同步的目的。是一种很古老的版本控制工具了,但是是很典型的集中式版本控制工具
SVN: 是一个开放源代码的版本控制系统,相较于RCS、CVS,它采用了分支管理系统,它的设计目标就是取代CVS。可以说是集中式版本控制的集大成者
Git: 是一个开源的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。是一种分布式的版本控制工具
GitHub:gitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名gitHub。
2个概念:
分布式版本控制:分布式的版本控制就是每个人都可以创建一个独立的代码仓库用于管理,各种版本控制的操作都可以在本地完成。每个人修改的代码都可以推送合并到另外一个代码仓库中。
集中式版本控制:只有一个中央控制,所有的开发人员都必须依赖于这个代码仓库。每次版本控制的操作也必须链接到服务器才能完成。所以很多公司喜欢用集中式的版本控制是为了更好的控制代码。如果个人开发,就可以选择Git这种分布式的。并不存在那个更加好或者其他的。
第3章 Git安装部署
3.1 系统环境准备
1 2 3 4 5 6 7
| [root@gitlab-200 ~] CentOS Linux release 7.4.1708 (Core) [root@gitlab-200 ~] 3.10.0-693.el7.x86_64 [root@gitlab-200 ~] Disabled [root@gitlab-200 ~]
|
3.2 安装部署
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| [root@gitlab-200 ~] [root@git ~] ‐‐global ‐‐system ‐‐local [root@gitlab-200 ~]
[root@gitlab-200 ~]
[root@gitlab-200 ~]
[root@gitlab-200 ~] user.name=wufei user.email=wufei008@qq.com color.ui=true [root@gitlab-200 ~] [user] name = wufei email = wufei008@qq.com [color] ui = true
|
3.3 Git初始化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| [root@gitlab-200 ~] [root@gitlab-200 ~] [root@gitlab-200 /git_date] [root@gitlab-200 /git_date]
[root@gitlab-200 /git_date] .git/ ├── branches ├── COMMIT_EDITMSG ├── config ├── description ├── HEAD ├── hooks ├── index ├── info ├── logs ├── objects ├── ORIG_HEAD └── refs
|
3.4 Git常规使用
3.4.1 创建数据-提交数据

3.4.2 git四种状态
git库所在的文件夹中的文件大致有4种状态
- Untracked: 未跟踪, 此文件在文件夹中, 但并没有加入到git库, 不参与版本控制. 通过
git add
状态变为Staged
.
- Unmodify: 文件已经入库, 未修改, 即版本库中的文件快照内容与文件夹中完全一致. 这种类型的文件有两种去处, 如果它被修改, 而变为
Modified
. 如果使用git rm
移出版本库, 则成为Untracked
文件
- Modified: 文件已修改, 仅仅是修改, 并没有进行其他的操作. 这个文件也有两个去处, 通过
git add
可进入暂存staged
状态, 使用git checkout
则丢弃修改过, 返回到unmodify
状态, 这个git checkout
即从库中取出文件, 覆盖当前修改
- Staged: 暂存状态. 执行
git commit
则将修改同步到库中, 这时库中的文件和本地文件又变为一致, 文件为Unmodify
状态. 执行git reset HEAD filename
取消暂存, 文件状态为Modified

3.4.3 git基础命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| [root@gitlab-200 /git_date]
nothing to commit, working directory clean
[root@gitlab-200 /git_date] [root@gitlab-200 /git_date]
[root@gitlab-200 /git_date] [root@gitlab-200 /git_date]
[root@gitlab-200 /git_date]
1.先从暂存区撤回到工作区、然后直接删除文件 git rm ‐‐cached c rm ‐f c 2.直接从暂存区域同工作区域一同删除文件命令 git rm -f b [root@gitlab-200 /git_date]
1. [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] 2.直接用git命令重命名 [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] [root@gitlab-200 /git_date]
[root@gitlab-200 /git_date]
[root@gitlab-200 /git_date]
[root@gitlab-200 /git_date]
[root@gitlab-200 /git_date]
git commit
[root@gitlab-200 /git_date] commit f3a56773c5c08cbffcb4fe331696a2725c03b3c9 Merge: 4c81d52 9ff69f6 Author: wufei <wufei008@qq.com> Date: Tue Sep 3 01:10:10 2019 +0800
merge [root@gitlab-200 /git_date] f3a5677 merge 9ff69f6 xxx 4c81d52 xxx [root@gitlab-200 /git_date] f3a5677 (HEAD, tag: v2.0, origin/master, testing, master) merge 9ff69f6 xxx 4c81d52 xxx [root@gitlab-200 /git_date] [root@gitlab-200 /git_date]
|
恢复历史数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| 1.只更改了当前目录 [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] 2.修改了本地目录且同时提交到 了暂存区 [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] 3.修改了工作目录后提交到了暂存区和本地仓库后进行数据恢复 echo bbb >>a git commit ‐m "add bbb" echo ccc >> a git commit ‐am "add ccc" [root@gitlab-200 /git_date] [root@gitlab-200 /git_date]
git reflog
|
3.4.4 git分支
分支
即是平行空间
,假设你在为某个手机系统研发拍照功能,代码已经完成了80%,但如果将这不完整的代码直接提交到git仓库中,又有可能影响到其他人的工作,此时我们便可以在该软件的项目之上创建一个名叫”拍照功能”的分支,这种分支只会属于你自己,而其他人看不到,等代码编写完成后再与原来的项目主分支合并下即可,这样即能保证代码不丢失,又不影响其他人的工作。
一般在实际的项目开发中,我们要尽量保证master分支是非常稳定的,仅用于发布新版本,平时不要随便直接修改里面的数据文件,而工作的时候则可以新建不同的工作分支,等到工作完成后在合并到master分支上面,所以团队的合作分支看起来会像上面图那样。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| [root@gitlab-200 /git_date] f3a5677 (HEAD, tag: v2.0, origin/master, testing, master) merge 9ff69f6 xxx 4c81d52 xxx 7353a92 Merge branch 'testing' 7363b5e add newfile master.txt 7768c8d add newfile test.txt 061d4cf (tag: v1.0) newfile b.txt
git branch testing git branch -d testing git checkout testing git checkout -b testing [root@gitlab-200 /git_date] * master testing [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] [root@gitlab-200 /git_date] touch master git add . git commit ‐m "commit master"
|
合并分支
1 2 3 4
| git merge testing git log ‐‐oneline ‐‐decorate
git branch ‐d testing
|
3.4.5 git标签使用
1 2 3 4 5 6 7 8 9
| git tag ‐a v1.0 ‐m "aaa bbb master tesing version v1.0"
git tag git tag ‐a v2.0 dbead4c ‐m "add bbb version v2.0"
git show v1.0 git reset ‐‐hard v2.0 git tag ‐d v2.0
|
第4章 github使用
Github
顾名思义是一个Git版本库的托管服务,是目前全球最大的软件仓库,拥有上百万的开发者用户,也是软件开发和寻找资源的最佳途径,Github
不仅可以托管各种Git版本仓库,还拥有了更美观的Web界面,您的代码文件可以被任何人克隆,使得开发者为开源项贡献代码变得更加容易,当然也可以付费购买私有库,这样高性价比的私有库真的是帮助到了很多团队和企业
- 注册用户
- 配置ssh‐key
- 创建项目
- 克隆项目到本地
- 推送新代码到github
1 2 3 4 5 6 7
| git remote add origin git@github.com:wf3512638/git_data.git git remote remove origin 删除远程仓库 [root@gitlab-200 /git_data] origin yum update ‐y nss curl libcurl git push ‐u origin master git pull
|