设为首页 收藏本站
查看: 1132|回复: 0

[经验分享] 持续集成教程 Devops,Git,Github,Gitlab的安装使用

[复制链接]
YunVN网友  发表于 2019-4-17 15:13:50 |阅读模式
1. Git
  gitHub官网

1.1. devops介绍

1.1.1. Devops是什么?



开发  development
运维  operations
1.1.2. Devops能干嘛?

提高产品质量
1  自动化测试
2 持续集成
3 代码质量管理工具
4 程序员鼓励师
1.1.3. Devops如何实现?

设计架构规划——代码的存储——构建——测试、预生产、部署、监控。
2. Git版本控制系统

2.1. 版本控制简介
  详细介绍


2.2. 为什么要用版本系统
  参考查看之处!!

2.2.1. 协同合作

试想一下,如果没有版本控制系统,当你需要处理那些共享文件夹中的文件时,你必须告知办公室里的所有人,你正在对哪些文件进行编辑;与此同时,其他人必须要避免与操作相同的文件。这是一个不现实和完全错误的流程。当你花了很长时间完成你的编辑后,可能这些文件早已经被团队里的其他开发成员修改或者删除了。
如果使用了版本控制系统,每一个团队成员都可以在任何时间对任何文件毫无顾虑的进行修改,版本控制系统可以把之后所有的改动合并成一个共同的版本,不论是一个文件还是整个项目。这个共同的中心平台就是我们的版本控制系统。
使用版本控制还有更多优点,这就要取决于你自己或者你的开发团队了。
2.2.2. 版本存储(正确的)

2.2.3. 恢复之前的版本

2.2.4. 了解发什么什么

2.2.5. 备份
[img]_v_images/1542284![](https://s1.运维网.com/images/blog/201811/15/ff3e8453454422a5ddb9d22a86c7d183.png[/img]


2.2.6. 常见的版本管理工具
  简单介绍了解



林纳斯托瓦次在一周之内写出了Git
2.2.7. 牛逼的人不需要解释这句话被LINUX淋漓尽致的展现出来。

3. git的安装

3.1. git安装

安装环境前的准备
root@git-git~]# cat /etc/redhat-release #查看系统版本
CentOS Linux release 7.1.1503 (Core)
[root@git-git ~]# uname -r #查看内核版本
3.10.0-229.el7.x86_64
[root@git-git ~]# getenforce #确认Selinux关闭状态
Disabled
[root@git-git ~]# systemctl stop firewalld #关闭防火墙
[root@git-git ~]# yum install git
# 安装Git
[root@git ~]# git config
--global 使用全局配置文件
--system 使用系统级配置文件
--local 使用版本库级配置文件
[root@git-git ~]# git config –-global user.name “wangweigang”
# 配置git使用用户
[root@git-git ~]# git config –-global user.email “1602031534@qq.com”   ###这写自己的邮箱
# 配置git使用邮箱
[root@git-git ~]# git config –-global color.ui true
# 语法高亮
[root@git-git ~]# git config –-list
user.name=wangweigang
user.email=1602031534@qq.com
color.ui=true
[root@git ~]# cat .gitconfig
[user]
name = wangweigang
email =1602031534@qq.com
[color]
ui = true
3.2. git初始化

初始化工作目录、对已存在的目录或者对已存在的目录都可进行初始化
mkdir git_data
cd git_data
# 初始化
git init
# 查看工作区状态
git status
#3. 位于分支 master
#
#3. 初始提交
#
无文件要提交(创建/拷贝文件并使用 "git add" 建立跟踪)
生成仓库目录介绍
3.2.1. 隐藏文件介绍 ll .git/

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

3.3.1. 创建数据库


[root@git git_data]# touch a b c
[root@git git_data]# git status
[root@git git_data]# git add a   git rm  --cache a(撤回) git rm -f  a(删除)
[root@git git_data]# git status
[root@git git_data]# git commit -m "add file a"
[master(根提交) 2a22d49] add file a
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a
[root@git git_data]# git status    “a”不在了,暂存在缓存区
3.4. git四种状态

git查阅文档


[root@git git_data]# git mv test test.txt
[root@git git_data]# git diff test
git diff --cached test.txt   查看文件缓存
[root@git git_data]# git commit -m "add abe"   添加内容倒库
git diff --cached test.txt   再次执行缓存,不会再显示。
[root@git git_data]# git commit -am "add test file abe"   -a先添加到暂存区域
git log   
git log --oneline     一行简单的commit信息
ff6606e add abe
785d1c8 add test.txt file abc
3bd47ec add file b
c3cdb56 add file b
2a22d49 add file a
[root@git git_data]# git log --oneline --decorate  //显示当前指针指向哪里,默认指向最后一次。
ff6606e (HEAD, master) add abe
785d1c8 add test.txt file abc
3bd47ec add file b
c3cdb56 add file b
2a22d49 add file a
[root@git git_data]# git log -p  #显示具体内容变化
[root@git git_data]# git log -1  #只显示1条信息,显示几条数字变几
3.5. 回滚

[root@git git_data]# git log --oneline
96929d4 add ddd
ff6606e add abe
785d1c8 add test.txt file abc
3bd47ec add file b
c3cdb56 add file b
2a22d49 add file a
[root@git git_data]# git reset --hard 3bd47ec  //哈西字符串
HEAD 现在位于 3bd47ec add file b
假如回滚错了,回滚所有
[root@git git_data]# git reflog
3bd47ec HEAD@{0}: reset: moving to 3bd47ec
96929d4 HEAD@{1}: commit: add ddd
ff6606e HEAD@{2}: commit: add abe
785d1c8 HEAD@{3}: commit: add test.txt file abc
3bd47ec HEAD@{4}: commit: add file b
c3cdb56 HEAD@{5}: commit: add file b
2a22d49 HEAD@{6}: commit (initial): add file a
会滚到最开始的操作
*[root@git git_data]# git reflog *
3bd47ec HEAD@{0}: reset: moving to 3bd47ec**     //这个是回滚操作的信息
96929d4 HEAD@{1}: commit: add ddd**
ff6606e HEAD@{2}: commit: add abe
785d1c8 HEAD@{3}: commit: add test.txt file abc
3bd47ec HEAD@{4}: commit: add file b
c3cdb56 HEAD@{5}: commit: add file b
2a22d49 HEAD@{6}: commit (initial): add file a
*[root@git git_data]# git reset --hard 96929d4*
HEAD 现在位于 96929d4 add ddd
3.6. git分支

查看分支
[root@git git_data]# git log --oneline --decorate
96929d4 (HEAD, master) add ddd
ff6606e add abe
785d1c8 add test.txt file abc
3bd47ec add file b
c3cdb56 add file b
2a22d49 add file a
[root@git git_data]# git branch   # 查看分支
* master
[root@git git_data]# git  branch  testing   创建分支
[root@git git_data]# git branch       查看
* master
testing
[root@git git_data]# git checkout testing   切换分支
切换到分支 'testing'
[root@git git_data]# git branch             查看当前是testing
master
* testing
3.7. 合并分支

3.7.1. 写法有点糙

[root@git git_data]# git branch      确保在HEAD指针在master
* master
test
testing
[root@git git_data]# git merge test         合并test
[root@git git_data]# git branch -d  testing        删除分支
git merge testing -m "merge testing"      合并分支冲突解决  假如分支和主干之间的代码发生冲突,需要在冲突的文件修改保存。
3.7.2. 详细的合并方法

[root@git git_data]# git merge testing # 提示输入描述信息 相当于git的-m参数
[root@git git_data]# git log --oneline --decorate
3258705 (HEAD, master) Merge branch 'testing'
f5ae1d8 commit master
ad4f25a (testing) commit test
dbead4c add bbb
4c57a60 modified a
5692532 rename a.txt a
7adfca0 commit a.txt
b4017a8 commit


冲突合并
[root@git git_data]# echo "master" >> a
[root@git git_data]# git commit -am "modified a master"
[root@git git_data]# git checkout testing
切换到分支 'testing'
[root@git git_data]# git branch
master
* testing
[root@git git_data]# cat a
aaa
bbb
[root@git git_data]# echo "testing" >>a
[root@git git_data]# git commit -am "modified a on testing branch"
[root@git git_data]# git checkout master
[root@git git_data]# git merge testing
自动合并 a
冲突(内容):合并冲突于 a
自动合并失败,修正冲突然后提交修正的结果。
[root@git git_data]# cat a # 冲突的文件自动标识到文件里,手动更改冲突要保留的代码
[root@git git_data]# git commit -am "merge testing to master" # 进行提交即可
[root@git git_data]# git log --oneline --decorate
bba413d (HEAD, master) merge testing to master
34d7a55 (testing) modified a on testing branch
ec1a424 modified a master
3258705 Merge branch 'testing'
f5ae1d8 commit master
ad4f25a commit test
删除分支-d参数
[root@git git_data]# git branch -d testing
已删除分支 testing(曾为 34d7a55)。
[root@git git_data]# git branch
* master
3.8. git标签的使用

标签也是指向了一次commit提交,是一个里程碑式的标签,回滚打标签直接加标签号,不需要加唯一字符串不好记
[root@git git_data]# git tag -a v1.0 -m "aaa bbb master tesing version v1.0" # -a指定标签名字 -m
指定说明文字
[root@git git_data]# git tag
v1.0
[root@git git_data]# git tag -a v2.0 dbead4c -m "add bbb version v2.0" # 指定某一次的提交为标签
[root@git git_data]# git show v1.0 # 查看v1.0的信息 git show 加标签查看
[root@git git_data]# git reset --hard v2.0 # 直接还原数据到v2.0
HEAD 现在位于 dbead4c add bbb
[root@git git_data]# ll
总用量 4
-rw-r--r-- 1 root root 8 8月 23 11:26 a
-rw-r--r-- 1 root root 0 8月 23 11:25 b
[root@git git_data]# git tag -d v2.0 # 删除标签 -d
4. githup使用----远程仓库

Github顾名思义是一个Git版本库的托管服务,是目前全球最大的软件仓库,拥有上百万的开发者用户,也是软件开发和
寻找资源的最佳途径,Github不仅可以托管各种Git版本仓库,还拥有了更美观的Web界面,您的代码文件可以被任何人
克隆,使得开发者为开源项贡献代码变得更加容易,当然也可以付费购买私有库,这样高性价比的私有库真的是帮助到
了很多团队和企业
1、注册用户 # 课前注册好用户
2、配置ssh-key
3、创建项目
4、克隆项目到本地
5、推送新代码到githu


[root@git git_data]# git remote
origin
克隆http到本地进行测试
cd /tmp/
git clone https://github.com/oldboylzy/git_test.git
低版本的系统存在版本问题提示
fatal: unable to access 'https://github.com/oldboylzy/oldboy.git/': Peer reports incompatible or
unsupported protocol version
yum update -y nss curl libcurl #升级版本即可
[root@git git_test]# touch d
[root@git git_test]# git add .
[root@git git_test]# git commit -m "add d"
[root@git git_test]# git push -u origin master
[root@git git_data]# cd /root/git_data/
[root@git git_data]# git pull # 拉取远程仓库最新代码、然后进行上传
5. gitlap安装
  查阅centos7及其他的文档

5.1. GitLab简介

GitLab 是一个用于仓库管理系统的开源项目。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。可通过
Web界面进行访问公开的或者私人项目。它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队
对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进
行交流。它还提供一个代码片段收集功能可以轻松实现代码复用
5.2. 安装插件

[root@git git_data]# yum install -y curl policycoreutils-python openssh-server
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh
5.3. 下载啊hitlab软件包

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/
rpm -ivh gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm
vim /etc/gitlab/gitlab.rb                   #  gitlab 配置文件
更改url地址为本机IP地址 external_url 'http://10.0.0.203'
5.4. 详细的文件(比较费时间但初学者非常适合)

国内镜像:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/
安装环境:
1、 CentOS 6或者7
2、 2G内存(实验)生产(至少4G)
3、 安装包:gitlab-ce-10.2.2-ce
4、 禁用防火墙,关闭selinux
https://about.gitlab.com/installation/#centos-7 # git官网
yum install -y curl policycoreutils-python openssh-server # 安装依赖
cd /home/oldboy/tools
rz -bye gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm # 上传gitlab安装包 下载方式可通过国内
清华源gitlab-ce社区版本下载
vim /etc/gitlab/gitlab.rb # gitlab 配置文件
更改url地址为本机IP地址 external_url 'http://10.0.0.200'  ##这里修改为当前自己主机的外网ip地址。。
gitlab-ctl reconfigure # 更改配置文件后需重新配置
/opt/gitlab/ # gitlab的程序安装目录
/var/opt/gitlab # gitlab目录数据目录
/var/opt/gitlab/git-dfata # 存放仓库数据
gitlab-ctl status # 查看目前gitlab所有服务运维状态
gitlab-ctl stop # 停止gitlab服务
gitlab-ctl stop nginx # 单独停止某个服务
gitlab-ctl tail # 查看所有服务的日志
通过浏览器输入IP地址进行访问gitlab
10.0.0.203
Gitlab的服务构成:
nginx: 静态web服务器
gitlab-workhorse: 轻量级的反向代理服务器
logrotate:日志文件管理工具
postgresql:数据库
redis:缓存数据库
sidekiq:用于在后台执行队列任务(异步执行)。(Ruby)
unicorn:An HTTP server for Rack applications,GitLab Rails应用是托管在这个服务器上面的。(Ruby Web
Server,主要使用Ruby编写)
5.5. gitlab汉化:

1、下载汉化补丁
git clone https://gitlab.com/xhang/gitlab.git
2、查看全部分支版本
git branch -a
3、对比版本、生成补丁包
git diff remotes/origin/10-2-stable remotes/origin/10-2-stable-zh > ../10.2.2-zh.diff
4、停止服务器
gitlab-ctl stop
5、打补丁
patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < /tmp/10.2.2-zh.diff
6、启动和重新配置
gitlab-ctl start
gitlab-ctl reconfigure
5.6. gitlab的使用

输入url登录
1、配置外观
管理区域-外观
2、关闭自动注册-可根据实际需求操作
管理区域-设置-关闭自动注册
3、创建组-用户-项目
创建组
![](


设置组名称、描述等创建群组


创建用户







6、登陆dev用户测试是否能看到空的git-test仓库
7、添加ssh-keys到gitlab 注:一个服务器的key只能添加到一个gitlab服务器上,一个用户可以添加多个key
ssh-keygen -t rsa
8、添加远程仓库、推送本地代码到远程仓库
git remote add origin git@10.0.0.203:oldboy/get_test.git # 添加远程仓库
git remote rename origin old-origin # 远程 origin 如果已经存在则重新命名或者新添加仓库名称不

git push -u origin --all # 推送代码到远程仓库
9、克隆代码到另外一台主机
如果不做认证会让输入gitlab的密码、我们使用key进行认证
ssh-keygen -t rsa
把公钥复制到dev用户下进行测试
然后在克隆代码
git clone git@10.0.0.203:oldboy/get_test.git
10. gitlab备份
测试推送代码到dev下
git branch dev
git checkout dev
touch dev
git add .
git commit -m "add dev"
git push -u origin dev # 推送dev分支到远程仓库
提×××并请求进行分支合并到master主分支
合并后在gitlab服务端master上没有dev、要先进行pull
cd /root/git_data
git pull
11、设置保护主分支


测试dev分支推送代码则显示为拒绝,如果还是可以推送请查看配置保护分支选项
[root@web01 get_test]# git checkout master
[root@web01 get_test]# git merge dev
[root@web01 get_test]# git push -u origin master
12、返回master端测试推送,由于其他分支进行推送,和master端内容不一致,所以无法进行推送,使用git pull把
代码拉取到本地,或者git fetch 把代码拉取到本地仓库后进行合并(注意:git pull = git tetch+git merge)
5.7. gitlab备份

对gitlab进行备份将会创建一个包含所有库和附件的归档文件。对备份的恢复只能恢复到与备份时的gitlab相同的版
本。将gitlab迁移到另一台服务器上的最佳方法就是通过备份和还原。
gitlab提供了一个简单的命令行来备份整个gitlab,并且能灵活的满足需求。
备份文件将保存在配置文件中定义的backup_path中,文件名为TIMESTAMP_gitlab_backup.tar,TIMESTAMP为备份时
的时间戳。TIMESTAMP的格式为:EPOCH_YYYY_MM_DD_Gitlab-version。
如果自定义备份目录需要赋予git权限
配置文件中加入
gitlab_rails['backup_path'] = '/data/backup/gitlab'
gitlab_rails['backup_keep_time'] = 604800 备份保留的时间(以秒为单位,这个是七天默认值),
mkdir /data/backup/gitlab
chown -R git.git /data/backup/gitlab
完成后执行gitlab-ctl reconfigure



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-828250-1-1.html 上篇帖子: 六个问题搞定DevOps面试 下篇帖子: 我们离DevOps有多远
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表