Devops介绍及git安装部署--02

目录

1. Devops介绍

01. 运维介绍

一般来说,运维工程师在一家企业里属于个位数的岗位,甚至只有一个。面对生产中NNN台服务器,NN个人员,工作量也是非常大的。

MTBF、 MTTR 、MTTF 详解

MTBF (Mean Time Between Failures) =平均故障间隔时间 MTTF

MTTF (Mean Time To Failure) =平均故障时间 

MTTR (Mean Time To Repair) =平均修复时间

3个9:(1-99.9%)*365*24=8.76小时,表示该软件系统在连续运行1年时间里最多可能的业务中断时间是8.76小时。
4个9:(1-99.99%)*365*24=0.876小时=52.6分钟,表示该软件系统在连续运行1年时间里最多可能的业务中断时间是52.6分钟。
5个9:(1-99.999%)*365*24*60=5.26分钟,表示该软件系统在连续运行1年时间里最多可能的业务中断时间是5.26分钟。
6个9:(1-99.9999%)*365*24*60*60=31秒

代码上线流程图


运维工程师三大核心职能

02. Devops是什么

开发 development
运维 operations

03. Devops能干嘛

提高产品质量

1 自动化测试2 持续集成3 代码质量管理工具4 程序员鼓励师

04. Devops如何实现

既然这么好?为什么有些公司没有设计架构规划-代码的存储-构建-测试、预生产、部署、监控

2. Git版本控制系统

01. 版本控制系统简介

vcs version control system

版本控制系统是一种记录一个或若干个文件内容变化,以便将来查阅特定版本内容情况的系统
记录文件的所有历史变化
随时可恢复到任何一个历史状态
多人协作开发

02. 为什么需要版本控制系统

03. 常见版本管理工具

SVN集中式的版本控制系统,只有一个中央数据仓库,如果中央数据仓库挂了或者不可访问,所有的使用者无法使用SVN,无法进行提交或备份文件。

04. 牛逼的人不需要解释

这句话被Linux展现的淋漓尽致

3. Git安装

01. 系统环境准备

[root@git ~]# cat /etc/redhat-release    
#查看系统版本
CentOS Linux release 7.6.1810 (Core)

[root@git ~]# uname -r    
#查看内核版本
3.10.0-957.el7.x86_64
[root@git ~]# getenforce    
#确认Selinux关闭状态Disabled
[root@git ~]# systemctl status firewalld     
#关闭防火墙
firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)Active: inactive (dead)Docs: man:firewalld(1)

02. Git安装部署

[root@git ~]# yum install git -y    #安装Git
[root@git ~]# git config
--global use global config file        #使用全局配置文件
--system use system config file        #使用系统级配置文件
--local use repository config file    #使用版本库级配置文件

 #配置git使用用户
[root@git ~]# git config --global user.name "gjy"
#配置git使用邮箱
[root@git ~]# git config --global user.email "861962063@qq.com"
#语法高亮
[root@git ~]# git config --global color.ui true
#检查结果
[root@git ~]# git config --list
user.name=gjy
user.email=861962063@qq.com
color.ui=true

#查看隐藏文件
[root@git ~]# ll -a
total 40
dr-xr-x---.  2 root root  187 Nov 26  2019 .
dr-xr-xr-x. 17 root root  224 Aug  2 04:55 ..
-rw-------.  1 root root 1430 Aug  2 04:57 anaconda-ks.cfg
-rw-------.  1 root root 2561 Nov 25  2019 .bash_history
-rw-r--r--.  1 root root   18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root  176 Dec 29  2013 .bash_profile
-rw-r--r--.  1 root root  176 Dec 29  2013 .bashrc
-rw-r--r--.  1 root root  100 Dec 29  2013 .cshrc
-rw-r--r--   1 root root   64 Nov 26  2019 .gitconfig
-rwxr-xr-x.  1 root root  473 Aug  1 20:44 host_ip.sh
-rw-r--r--.  1 root root  129 Dec 29  2013 .tcshrc
-rw-------   1 root root 1394 Nov 26  2019 .viminfo

[root@git ~]# cat .gitconfig 
[user]
    name = gjy
    email = 861962063@qq.com
[color]
    ui = true

03. Git初始化

#初始化工作目录、对已存在的目录或者对已存在的目录都可进行初始化
#创建一个仓库目录
[root@git ~]# mkdir git_data
[root@git ~]# cd git_data/
#初始化
[root@git ~/git_data]# git init
Initialized empty Git repository in /root/git_data/.git/

#查看工作区状态
[root@git git_data]# git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

[root@git git_data]# ll .git/
total 12
drwxr-xr-x 2 root root   6 Nov 25 16:50 branches
-rw-r--r-- 1 root root  92 Nov 25 16:50 config
-rw-r--r-- 1 root root  73 Nov 25 16:50 description
-rw-r--r-- 1 root root  23 Nov 25 16:50 HEAD
drwxr-xr-x 2 root root 242 Nov 25 16:50 hooks
drwxr-xr-x 2 root root  21 Nov 25 16:50 info
drwxr-xr-x 4 root root  30 Nov 25 16:50 objects
drwxr-xr-x 4 root root  31 Nov 25 16:50 refs

#隐藏文件介绍:
branches         #分支目录
config           #定义项目特有的配置选项
description      #仅供git web程序使用
HEAD             #指示当前的分支
hooks            #包含git钩子文件
info             #包含一个全局排除文件(exclude文件)
objects          #存放所有数据内容,有info和pack两个子文件夹
refs             #存放指向数据(分支)的提交对象的指针
index             #保存暂存区信息,在执行git init的时候,这个文件还没有

4. Git常规使用

01. 创建数据-提交数据

02. Git四种状态

未跟踪的 、未修改的 、 已修改的 、 暂存区

03. Git基础命令

git 改名
git mv a a.txt
git commit  -m "rename a a.txt"

git比对内容
git diff 比对工作目录和暂存区的不同
git diff --cached 比对暂存区和本地仓库的不同

git 查看历史操作信息
git  log 查看历史提交记录
git log --oneline 一条显示提交的历史记录
git log --oneline --decorate 查看当时的指针
git reset --hard e723hh5 回滚代码至某个版本
git reflog 查看所有的历史提交记录

1) 测试

#查看状态
[root@git git_data]# git status
# On branch master     #位于分支 master
#
# Initial commit     #初始提交
#
nothing to commit (create/copy files and use "git add" to track)    #无文件要提交(创建/拷贝文件并使用 "git add" 建立跟踪)

#创建测试文件
root@git git_data]# touch a b c
[root@git git_data]# ll
total 0
-rw-r--r-- 1 root root 0 Nov 25 17:00 a
-rw-r--r-- 1 root root 0 Nov 25 17:00 b
-rw-r--r-- 1 root root 0 Nov 25 17:00 c

[root@git git_data]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   a
#   b
#   c
nothing added to commit but untracked files present (use "git add" to track)

#git add a 把文件提交到了暂存区
[root@git git_data]# git add a

[root@git git_data]# ll .git/
total 16
drwxr-xr-x 2 root root   6 Nov 25 16:50 branches
-rw-r--r-- 1 root root  92 Nov 25 16:50 config
-rw-r--r-- 1 root root  73 Nov 25 16:50 description
-rw-r--r-- 1 root root  23 Nov 25 16:50 HEAD
drwxr-xr-x 2 root root 242 Nov 25 16:50 hooks
-rw-r--r-- 1 root root  96 Nov 25 17:03 index
drwxr-xr-x 2 root root  21 Nov 25 16:50 info
drwxr-xr-x 5 root root  40 Nov 25 17:03 objects
drwxr-xr-x 4 root root  31 Nov 25 16:50 refs

[root@git git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   a      #发现一个新的文件
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   b
#   c

#查看提交的内容
#使用git add . 或者 * 添加目录中所有改动过的文件
[root@git git_data]# git add .
[root@git git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   a
#   new file:   b
#   new file:   c
#

2)删除的方式

#1.只是删除缓存中的
[root@git git_data]# git rm --cached c
rm 'c'
[root@git git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   a
#   new file:   b
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   c
#2.删除工作目录文件
[root@git git_data]# rm -f c 
[root@git git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   a
#   new file:   b
#

或者:
#把暂停区和工作目录同时删除
[root@git git_data]# git rm -f b
rm 'b'
[root@git git_data]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   a
#

3)文件比对

#提交到本地仓库
[root@git git_data]# git commit -m "create a b"
[master (root-commit) da7ed82] create a b
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a
 create mode 100644 b
[root@git git_data]# git status
# On branch master
nothing to commit, working directory clean

#文件比对
[root@git git_data]# echo '1111' >>a
#比对工作目录跟暂存区的不同
[root@git git_data]# git diff a 
diff --git a/a b/a
index e69de29..5f2f16b 100644
--- a/a
+++ b/a
@@ -0,0 +1 @@
+1111
#提交到暂存区后,再次比对,没有变化
[root@git git_data]# git add .
[root@git git_data]# git diff a 
#比对暂存区和本地仓库的区别
[root@git git_data]# git diff --cached
diff --git a/a b/a
index e69de29..5f2f16b 100644
--- a/a
+++ b/a
@@ -0,0 +1 @@
+1111
#提交到本地仓库
[root@git git_data]# git commit -m 'modify a'
[master e20b4f9] modify a
 1 file changed, 1 insertion(+)
 #再次比对,没有变化
[root@git git_data]# git diff --cached

4)覆盖

#暂存区中的内容覆盖到工作目录
[root@git git_data]# echo 2222 >> a
[root@git git_data]# git diff a 
diff --git a/a b/a
index 5f2f16b..4f142ee 100644
--- a/a
+++ b/a
@@ -1 +1,2 @@
 1111
+2222
#从暂存区中的文件覆盖到工作目录
[root@git git_data]# git checkout -- a
[root@git git_data]# git diff
[root@git git_data]# cat a
1111

5)代码已经添加到暂存区,发现写错了

[root@git git_data]# echo 2222 >> a
[root@git git_data]# git add .
[root@git git_data]# git diff a
[root@git git_data]# cat a
1111
2222
[root@git git_data]# git diff --cached
diff --git a/a b/a
index 5f2f16b..4f142ee 100644
--- a/a
+++ b/a
@@ -1 +1,2 @@
 1111
+2222
#将本地仓库的文件覆盖暂存区
[root@git git_data]# git reset HEAD a
Unstaged changes after reset:
M   a
[root@git git_data]# git diff --cached
[root@git git_data]# git diff 
diff --git a/a b/a
index 5f2f16b..4f142ee 100644
--- a/a
+++ b/a
@@ -1 +1,2 @@
 1111
+2222

[root@git git_data]# git checkout a
[root@git git_data]# git diff 
[root@git git_data]# cat a
1111

6) 将代码提交到本地仓库,发现写错了

#将代码提交到本地仓库,发现写错了
[root@git git_data]# echo 2222 >> a
[root@git git_data]# git commit -am "modify 222 a"
[master b7818c5] modify 222 a
 1 file changed, 1 insertion(+)
[root@git git_data]# git diff
[root@git git_data]# git diff --cached
[root@git git_data]# cat a
1111
2222
#查看git的提交记录
#用1行内容来表示记录
[root@git git_data]# git log --oneline
b7818c5 modify 222 a
e20b4f9 modify a
da7ed82 create a b
#显示提交的指针方向
[root@git git_data]# git log --oneline --decorate
b7818c5 (HEAD, master) modify 222 a
e20b4f9 modify a
da7ed82 create a b
[root@git git_data]# cat a
1111
2222
[root@git git_data]# echo 3333 >> a
[root@git git_data]# git commit -am "modify 3333 a"
[master c949243] modify 3333 a
 1 file changed, 1 insertion(+)
[root@git git_data]# git log --oneline --decorate
c949243 (HEAD, master) modify 3333 a
b7818c5 modify 222 a
e20b4f9 modify a
da7ed82 create a b
[root@git git_data]# git reset --hard da7ed82
HEAD is now at da7ed82 create a b
[root@git git_data]# cat a

#突然发现恢复错了
[root@git git_data]# git reflog --oneline
da7ed82 HEAD@{0}: reset: moving to da7ed82
c949243 HEAD@{1}: commit: modify 3333 a
b7818c5 HEAD@{2}: commit: modify 222 a
e20b4f9 HEAD@{3}: commit: modify a
da7ed82 HEAD@{4}: commit (initial): create a b
[root@git git_data]# git reset --hard b7818c5
HEAD is now at b7818c5 modify 222 a
[root@git git_data]# cat a
1111
2222

Git服务程序中有一个叫做HEAD的版本指针,当用户申请还原数据时,其实就是将HEAD指针指向到某个特定的提交版本,但是因为Git是分布式版本控制系统,为了避免历史记录冲突,故使用了SHA-1计算出十六进制的哈希字串来区分每个提交版本,另外默认的HEAD版本指针会指向到最近的一次提交版本记录

[root@git ~/git_data]# git reset --hard 18c89e4
HEAD is now at 18c89e4 modified a

刚刚的操作实际上就是改变了一下HEAD版本指针的位置,就是你将HEAD指针放在那里,那么你的当前工作版本就会定位在那里,要想把内容再还原到最新提交的版本,先看查看下提交版本号

打开发现回退错了,应该回退到bbb版本

#打开发现回退错了,应该回退到bbb版本
[root@git ~/git_data]# cat aaaa
#这时候查看log没有commit bbb的历史了
[root@git ~/git_data]# git log --oneline
18c89e4 modified a
1a85735 rename a.txt
a64e0f41 commit a.txt
c6b0ac2 new file a

竟然没有了add bbb这个提交版本记录?原因很简单,因为我们当前的工作版本是历史的一个提交点,这个历史提交点还没有发生过add bbb 更新记录,所以当然就看不到了,要是想"还原到未来"的历史更新点,可以用git reflog命令来查看所有的历史记录:

#使用git reflog 可查看总历史内容
[root@git ~/git_data]# git reflog
18c89e4 HEAD@{0}: reset: moving to 18c89e4
cc5c366 HEAD@{1}: commit: add ccc
6118c8d HEAD@{2}: commit: add bbb
18c89e4 HEAD@{3}: commit: modified a
1a85735 HEAD@{4}: commit: rename a.txt
a64e0f41 HEAD@{5}: commit: commit a.txt
c6b0ac2 HEAD@{6}: commit (initial): new file a
#然后使用reset回到bbb的版本内容下
[root@git ~/git_data]# git reset --hard 6118c8d
HEAD is now at 6118c8d add bbb
[root@git ~/git_data]# cat a
aaa
bbb

原文地址:https://www.cnblogs.com/gongjingyun123--/p/11969713.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


前言我们于2022年5月宣布推出 AmazonDevOpsGuruforServerless ,这是面向AmazonDevOpsGuru https://aws.amazon.com/devops-guru/的全新功能。通过此功能,开发人员能够提高无服务器应用程序的运行性能和可用性。该产品链接可点击:https://aws.amazon.com/devops-guru/fe
GIT、GITLAB、GITHUB、GITLIBGit是一款免费、开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。Git是一个开源的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。Github - 一个网站,提供给用户空间创建git仓储,保存用户的一些数据文档或者代码等作为开源代码库以及版本控制系统,Github目前拥有140多万开发者用户。随着越来越...
初识JFrog Artifactory背景在软件项目开发中,一个项目常常依赖于大量的外部库,而这些外部库又在不断的进行版本更新,特别是在当前微服务开发越来越流行的情况下,一个服务依赖于多个服务,如何管理依赖库以及依赖版本,确保开发有序进行呢?JFrog ArtiFactoryArtiFactory是一款二进制存储管理工具,用来管理构建构建工具(如:gradle)等所依赖的二进制仓库,以方...
在删除文件夹的时候,可能会遇到文件夹正在使用,操作无法完成,因为其中的文件,或文件夹已在另一个程序中打开,请关闭该文件夹或或文件,然后重试。这类无法关闭删除文件夹的情况,如下图所示。 解决这个的关键是,找到是哪个程序在使用该文件夹,把这个程序关闭掉就行了。 但有时说实在的并不好找。 下面来介绍一个方便的找到这些程序的方法。 首先按ctrl+shitf+esc快捷键,打开任务管理器。然后...
xcopy 若目标盘上不存在此子目录,而在目标盘的结束符又不以&amp;amp;quot;&amp;amp;quot;为结束,则将提示:does destination specify a file name or directory name on the target[f=file,d=directory]?在目标盘上创建文件[按下]还是创建子目录[按下d] ?应选择d键如何在命令中指定copy的是一个文件或者目录?而不用再手动输入F或...
DevOps软件开发工艺解读随着业务复杂化和人员的增加,开发人员和运维人员逐渐演化成两个独立的部门,他们工作地点分离,工具链不同,业务目标也有差异,这使得他们之间出现一条鸿沟。而发布软件就是将一个软件想从鸿沟的这边送去那边,这之中困难重重。另一方面,行业竞争更加激烈,无论是客户还是公司自身,都要求软件能快速发布,频繁修改,而上边所说的这种隔阂,阻碍了开发团队的生产力,成了企业亟待解决的难题。面对...
创建任务创建任务比较简单,这里我们创建自由风格项目:General信息这里填写项目或任务的基本信息,如下:GitBucket这里我们用到的就以下两点,一个是参数化构建:构建的时候可以指定部分参数,比如这里我们这里指定要构建的分支作参数,第二个是丢弃旧的构建:这样每次构建都会丢弃之前历史构建,防止jenkins构建项目过多导致内存泄漏等问题:源码管理源码管理主要是填写我们要构建的...
一、在任务设置-构建触发器模块,选中“Build periodically”二、然后在日程表里输入你的定时构建时间,输入的时间语法参考如下:1、时间字段遵循cron的语法,每行由TAB或空格分隔的5个字段组成:MINUTE HOUR DOM MONOW DOW - 分钟:小时内的分钟数(0-59) - 小时 :一天中的小时(0-23) - DOM:月份的日子(1-31) ...
DevOps进阶(九)使用assembly plugin实现自定义打包assembly plugin的使用方式比较简单,主要有:1. 修改pom.xml pom.xml中设置如下:&amp;amp;lt;build&amp;amp;gt; &amp;amp;lt;plugins&amp;amp;gt; &amp;amp;lt;plugin&amp;amp;gt; &amp;amp;lt;artifactId&amp;amp;g
&amp;amp;lt;h2 id=&amp;quot;1-操作环境&amp;quot;&amp;amp;gt;&amp;amp;lt;strong&amp;amp;gt;1. 操作环境&amp;amp;lt;/strong&amp;amp;gt;&amp;amp;lt;/h2&amp;amp;gt;1. Windows:win72. JenkinsJenkins 1.6193. JavaJDK_1.7.0_64bit.exe4. Tomcatapache-tomcat-8.
在使用linux时,经常需要进行文件查找。其中查找的命令主要有find和grep。两个命令是有区的。区别:(1)find命令是根据文件的属性进行查找,如文件名,文件大小,所有者,所属组,是否为空,访问时间,修改时间等。(2)grep是根据文件的内容进行查找,会对文件的每一行按照给定的模式(patter)进行匹配查找。一.find命令基本格式:find path expres......
走近DevOps工程师我们之前已经听到很多谈论DevOps和DevOps世界的最新趋势的事情,但是就DevOps工程师本身,到底干些什么呢?在最纯粹的存在形式上来说,DevOps工程师是为了加快开发和运营团队之间的交付效率而存在的桥梁。DevOps工程师在软件生命周期中能带来什么?在传统的交付周期中,软件开发人员会在经年累月的编写代码后,将软件交给QA团队进行测试,然后将最终版本交给运营...
1、关闭Jenkins 只需要在访问jenkins服务器的网址url地址后加上exit。例如我jenkins的地址http://localhost:8080/,那么我只需要在浏览器地址栏上敲下http://localhost:8080/exit 网址就能关闭jenkins服务.2、重启Jenkieshttp://localhost:8080/restart3、重新加载配置信息http...
&amp;nbsp; &amp;nbsp;我们在执行Jenkins的项目构建的时候一般都是通过web管理界面中的”构建”来执行项目构建操作,但是除此之外我们还可以通过项目配置中的”构建触发器”来触发构建操作,其中”构建触发器”有一种方式是通过配置令牌远程触发项目构建;要启用Token(令牌)远程触发项目构建首先要保证Jenkins服务安装了build-token-root&amp;nbsp;插件,...
maven三种打包插件maven有多种可以打包的插件,如下: plugin function 官网 maven-jar-plugin maven 默认打包插件,用来创建 project jar maven-shade-plugin 用来打可执行包,executable(fat) jar http://maven.apache.org/plug...
Linux下查看和添加环境变量$PATH:决定了shell将到哪些目录中寻找命令或程序,PATH的值是一系列目录,当您运行一个程序时,Linux在这些目录下进行搜寻编译链接。编辑你的 PATH 声明,其格式为:PATH=$PATH:&amp;lt;PATH 1&amp;gt;:&amp;lt;PATH 2&amp;gt;:&amp;lt;PATH 3&amp;gt;:------:你可以自己加上指定的路径,中间用冒号隔开。环境变量更改后......
贾磊:高级质量经理&敏捷教练曾就职于外企、国企、大型上市企业等,担任过测试工程师、测试经理、项目经理、敏捷教练、质量总监、高级质量经理等岗位。是一名敏捷变革的爱好者和践行者。爱好网球、羽毛球。正文原文链接:https://www.scaledagileframework.com/continuous-explorati
在IT流行语的字母组合中,DevSecOps是一个很容易让人混淆的缩写。DevSecOps是一个特定工具吗?是否有DevSecOps流程或最佳实践?DevSecOps应该成为内部IT部门的优先事项,还是更广泛的公司理念?如果一个公司已经利用了DevOps的流程和技术栈,那么它应该升级到DevSecOps吗?或者这只
企业项目开发流程商城1.1B2C直销商城商家与会员直接交易(BusinessToCustomer)1.2B2B批发商城商家与商家直接交易1.3B2B2C购物平台商家和会员在另一个商家提供的平台上面进行交易1.4C2B定制商城会员向商家发起定制商品的需求,商家去完成。1.5O2O线上线下
jenkins清除工作空间报错 错误如下: Error:WipeOutWorkspaceblockedbySCM   解决方法:进入jenkins服务器,进入workspace,手动rmcd/var/jenkins_home/workspace  ===================注释==================如果你的启动命令如下:【进行了外部目录的挂载