Git+制作rpm

什么是版本控制

  • 你可以把一个版本控制系统(简称VCS)理解为一个“备份数据库”,在需要的时候,它可以帮你完整地保存一个项目的快照。当你需要查看一个之前的快照(称为“版本” )时,版本控制系统可以显示出当前版本与上一个版本之间的所有替换的细节。
  • 版本控制是一种备份一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统。
  • Git就是一个版本控制软件

版本库

典型的客户/服务器系统
版本库是版本控制的核心
任意数量客户端
客户端通过写数据分享代码

分布式版本控制

集中式版本控制系统

  • 开发者之间共用一个仓库(repository)
  • 所有操作需要联网

分布式版本控制系统

  • 每个开发者都是一个仓库的完整克隆,每个人都是服务器
  • 支持断网操作

Git基本概念

  • git仓库
    保存所有数据的地方
  • 工作区
    从仓库中提取出来的文件,放在磁盘上供你使用或修改
  • 暂存区
    就是一个文件.索引文件,保存了下次将提交的文件列表信息

Git的作用

追踪文件的变更。它将什么时候、什么人更改了文件的什么内容等信息忠实地了已录下来。
每一次文件的改变,文件的版本号都将增加。
除了记录版本变更外,版本控制的另一个重要功能是并行开发。
软件开发往往是多人协同作业,版本控制可以有效地解决版本的同步以及不同开发者之间的开发通信问题,提高协同开发的效率。
并行开发中最常见的不同版本软件的错误(Bug)修正问题也可以通过版本控制中分支与合并的方法有效地解决。

Git的工作流程

在这里插入图片描述

工作区就是一个目录
所有的修改都是在这个目录中
工作区这个目录存放的永远都是最新的文件
工作区里的文件不能直接提交到Git仓库
git仓库是一个隐藏的目录
是用来备份历史记录
暂存区只存放被修改的文件名

版本控制软件

集中式版本控制软件

  • CVS
  • SVN
    分布式版本控制软件
  • Git (免费)
  • BitKeeper (收费)

Git基本操作

问题:
要求先快速搭建好一台Git服务器,并测试该版本控制软件,要求如下:
安装Git软件
创建版本库
客户端克隆版本仓库到本地
本地工作目录修改数据
提交本地修改到服务器

实验如图所示:
在这里插入图片描述

步骤一:部署Git服务器(192.168.2.100作为远程git服务器)

  • 服务器是一台多人协作的中心服务器
  • init初始化一个仓库 (没有具体数据)
1.yum安装Git
[root@web1 ~]# yum -y install git
2.初始化一个仓库
[root@web1 ~]# git init /var/git  --bare
初始化空的 Git 版本库于 /var/git/
[root@web1 ~]# ls /var/git
branches  config  description  HEAD  hooks  info  objects  refs
注: 这样一个Git服务器就做完了
##--bare 代表空仓库

客户端访问方式

本地访问:
[root@web2 ~]# git clone file:///git仓库
远程访问:
[root@web2 ~]# git clone 用户名@服务器IP:/git仓库
web:
服务器需要额外配置web服务器
客户端可以浏览器访问
[root@web2 ~]# git clone http://服务器IP/git仓库
[root@web2 ~]# git clone httpsL//服务器IP/git仓库

步骤二:客户端测试(192.168.2.200作为客户端主机)
使用git常用指令列表如表
在这里插入图片描述

Git的命令

最常用的 git 命令有:
   add        添加文件内容至索引
   bisect     通过二分查找定位引入 bug 的变更
   branch     列出、创建或删除分支
   checkout   检出一个分支或路径到工作区
   clone      克隆一个版本库到一个新目录
   commit     记录变更到版本库
   diff       显示提交之间、提交和工作区之间等的差异
   fetch      从另外一个版本库下载对象和引用
   grep       输出和模式匹配的行
   init       创建一个空的 Git 版本库或重新初始化一个已存在的版本库
   log        显示提交日志
   merge      合并两个或更多开发历史
   mv         移动或重命名一个文件、目录或符号链接
   pull       获取并合并另外的版本库或一个本地分支
   push       更新远程引用和相关的对象
   rebase     本地提交转移至更新后的上游分支中
   reset      重置当前HEAD到指定状态
   rm         从工作区和索引中删除文件
   show       显示各种类型的对象
   status     显示工作区状态
   tag        创建、列出、删除或校验一个GPG签名的 tag 对象
  1. clone克隆服务器仓库到本地。
[root@web2 ~]# yum -y install git
[root@web2 ~]# git clone root@192.168.2.100:/var/git
正克隆到 'git'...
Warning: Permanently added '192.168.2.100' (ECDSA) to the list of known hosts.
root@192.168.2.100's password: 
warning: 您似乎克隆了一个空版本库。
[root@web2 ~]# cd git
[root@web2 git]# ls -a
.  ..  .git
[root@web2 git]# cd ./git
-bash: cd: ./git: 没有那个文件或目录
[root@web2 git]# cd .git
[root@web2 .git]# ls
branches        config       HEAD   index  logs     refs
COMMIT_EDITMSG  description  hooks  info   objects

2)本地工作区对数据进行增删改查(必须要先进入仓库再操作数据)。

[root@web2 git]# mkdir demo
[root@web2 git]# echo "任意" > init.txt
[root@web2 git]# ls
demo  init.txt

3) 查看仓库中数据的状态。

[root@web2 git]# git status
# 位于分支 master
#
# 初始提交
#
# 未跟踪的文件:
#   (使用 "git add <file>..." 以包含要提交的内容)
#
#	init.txt
提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)

4) 将工作区的修改提交到暂存区。

[root@web2 git]# git add .  ##备份资料到暂存区

5 ) 将暂存区修改提交到本地仓库。

[root@web2 git]# git commit -m "注释"  ##可以把所有修改的文件传到git仓库
##会报错!!!

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"  ##提示要输入的信息
  git config --global user.name "Your Name"    ##提示要输入的信息

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'root@web2.(none)')
--------------------------------------------------------------------------------
##生产环境中请按照实际情况填写,此为案例:
##这两条命令只需要打一次就行了
##config修改git配置
##客户端用户标记信息(跟git账户和密码无关)
[root@web2 git]# git config --global user.email "you@example.com"  
[root@web2 git]# git config --global user.name "Your Name"
[root@web2 git]# git commit -m "注释"  ##再提交
[master(根提交) 416a0aa] 注释
 1 file changed, 1 insertion(+)
 create mode 100644 init.txt
[root@web2 git]# git status
# 位于分支 master
无文件要提交,干净的工作区

7) 将本地仓库中的数据推送到远程服务器(web2将数据推送到web1)。

[root@web2 git]# git push  ##提交到远程服务器
##会报错!!!
warning: push.default 未设置,它的默认值将会在 Git 2.0 由 'matching'
修改为 'simple'。若要不再显示本信息并在其默认值改变后维持当前使用习惯,
进行如下设置:

  git config --global push.default matching

若要不再显示本信息并从现在开始采用新的使用习惯,设置:

  git config --global push.default simple

参见 'git help config' 并查找 'push.default' 以获取更多信息。
('simple' 模式由 Git 1.7.11 版本引入。如果您有时要使用老版本的 Git,
为保持兼容,请用 'current' 代替 'simple' 模式)

root@192.168.2.100's password: 
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: 无法推送一些引用到 'root@192.168.2.100:/var/git'
--------------------------------------------------------------------------------
##此命令只输入一次即可
[root@web2 git]# git config --global push.default simple  ##按照提示输入
[root@web1 ~]# du -sh /var/git  ##查看远程服务器仓库的大小
56K	/var/git
[root@web2 git]# git push  ##再次提交
root@192.168.2.100's password:   ##输入服务器root密码
Counting objects: 3, done.
Writing objects: 100% (3/3), 220 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To root@192.168.2.100:/var/git
 * [new branch]      master -> master
[root@web1 ~]# du -sh /var/git  ##再次查看远程服务器仓库的大小
72K	/var/git
##熟悉Git操作后可以一开始就打上面案例中的config配置
##此为小白教程
  1. 将服务器上的数据更新到本地(web1的数据更新到web2)。
    备注:可能其他人也在修改数据并提交服务器,就会导致自己的本地数据为旧数据,使用pull就可以将服务器上新的数据更新到本地。
[root@web2 git]# git pull
root@192.168.2.100's password: 
Already up-to-date.
  1. 查看版本日志
[root@web2 git]# git log  ##显示详细日志
commit 416a0aa0cfffa2199081b34e751c78c58c181a8a  ##提交的版本id号
Author: Your Name <you@example.com>  ##什么人提交
Date:   Fri Jan 17 10:50:14 2020 +0800  ##什么时间提交
    注释    ##提交的注释,注释一般填写为什么修改,修改了哪些内容,方便以后查找
[root@web2 git]# git log --pretty=oneline
416a0aa0cfffa2199081b34e751c78c58c181a8a 注释  ##文件的版本号及注释
[root@web2 git]# git log --oneline
416a0aa 注释
[root@web2 git]# git reflog
416a0aa HEAD@{0}: commit (initial): 注释

客户端也可以使用图形程序访问服务器

Windows需要安装git和tortoiseGit。如图
在这里插入图片描述

Git进阶

HEAD指针操作

  • HEAD指针是一个可以在任何分支和版本移动的指针,通过移动指针我们可以将数据还原至任何版本。每做一次提交操作都会导致git更新一个版本,HEAD指针也跟着自动移动。

问题:
沿用练习一,学习操作HEAD指针,具体要求如下:
查看Git版本信息
移动指针
通过移动HEAD指针恢复数据

步骤一:HEAD指针基本操作
1)准备工作(多对数据仓库进行修改、提交操作,以产生多个版本)。

[root@web2 git]# echo "new file" > new.txt
[root@web2 git]# git add .
[root@web2 git]# git commit -m "add new.txt"
[master 565719e] add new.txt
 1 file changed, 1 insertion(+)
 create mode 100644 new.txt
[root@web2 git]# echo "first" >> new.txt
[root@web2 git]# git add .
[root@web2 git]# git commit -m "new.txt:first line"
[master 5dc6afb] new.txt:first line
 1 file changed, 1 insertion(+)
[root@web2 git]# echo "second" >> new.txt
[root@web2 git]# git add .
[root@web2 git]# git commit -m "new.txt:second"
[master c2992cf] new.txt:second
 1 file changed, 1 insertion(+)
[root@web2 git]# echo "third" >> new.txt
[root@web2 git]# git add .
[root@web2 git]# git commit -m "new.txt:third"
[master c0f361e] new.txt:third
 1 file changed, 1 insertion(+)
[root@web2 git]# git push
root@192.168.2.100's password: 
To root@192.168.2.100:/var/git
   416a0aa..c0f361e  master -> master
[root@web2 git]# echo "123" > num.txt
[root@web2 git]# git add .
[root@web2 git]# git commit -m "num.txt:123"
[master 0543b16] num.txt:123
 1 file changed, 1 insertion(+)
 create mode 100644 num.txt
[root@web2 git]# echo "456" > num.txt
[root@web2 git]# git add .
[root@web2 git]# git commit -m "num.txt:456"
[master 157cfcc] num.txt:456
 1 file changed, 1 insertion(+), 1 deletion(-)
[root@web2 git]# echo "789" > num.txt
[root@web2 git]# git add .
[root@web2 git]# git commit -m "num.txt:789"
[master d7293ba] num.txt:789
 1 file changed, 1 insertion(+), 1 deletion(-)
[root@web2 git]# git push
root@192.168.2.100's password: 
To root@192.168.2.100:/var/git
   c0f361e..d7293ba  master -> master
  1. 查看Git版本信息。
[root@web2 git]# git reflog
d7293ba HEAD@{0}: commit: num.txt:789
157cfcc HEAD@{1}: commit: num.txt:456
0543b16 HEAD@{2}: commit: num.txt:123
c0f361e HEAD@{3}: commit: new.txt:third
c2992cf HEAD@{4}: commit: new.txt:second
5dc6afb HEAD@{5}: commit: new.txt:first line
565719e HEAD@{6}: commit: add new.txt
416a0aa HEAD@{7}: commit (initial): 注释
##HEAD@{0}: 代表当前所在位置(版本)
[root@web2 git]# ls
demo  init.txt  new.txt  num.txt
[root@web2 git]# cat new.txt 
new file
first
second
third

3)移动HEAD指针,将数据还原到任意版本。
提示:当前HEAD指针为HEAD@{0}。

[root@web2 git]# git reset --hard 0543b  ##移动版本到HEAD@{2}位置
HEAD 现在位于 0543b16 num.txt:123
[root@web2 git]# ls
demo  init.txt  new.txt  num.txt
[root@web2 git]# cat num.txt 
123
##移动指针不是最终的目的,找回想要的数据才是最终的目的,最终还是要移回最新版本位置.
[root@web2 git]# git reflog  ##查看当前所在位置
0543b16 HEAD@{0}: reset: moving to 0543b  ##当前所在位置
d7293ba HEAD@{1}: commit: num.txt:789
157cfcc HEAD@{2}: commit: num.txt:456
0543b16 HEAD@{3}: commit: num.txt:123
c0f361e HEAD@{4}: commit: new.txt:third
c2992cf HEAD@{5}: commit: new.txt:second
5dc6afb HEAD@{6}: commit: new.txt:first line
565719e HEAD@{7}: commit: add new.txt
416a0aa HEAD@{8}: commit (initial): 注释
[root@web2 git]# git reset --hard 56571  ##移动指针到HEAD@{7}位置
HEAD 现在位于 565719e add new.txt
[root@web2 git]# ls
demo  init.txt  new.txt
[root@web2 git]# cat new.txt 
new file
--------------------------------------------------------------------------------
把历史版本拷贝到其他目录下
[root@web2 git]# cp new.txt  /tmp
[root@web2 git]# git push  ##不能在此提交
root@192.168.2.100's password: 
To root@192.168.2.100:/var/git
 ! [rejected]        master -> master (non-fast-forward)
error: 无法推送一些引用到 'root@192.168.2.100:/var/git'
提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。
提示:再次推送前,先与远程变更合并(如 'git pull')。详见
提示:'git push --help' 中的 'Note about fast-forwards' 小节。
[root@web2 git]# git reflog  ##查看日志
565719e HEAD@{0}: reset: moving to 56571
0543b16 HEAD@{1}: reset: moving to 0543b
d7293ba HEAD@{2}: commit: num.txt:789
157cfcc HEAD@{3}: commit: num.txt:456
0543b16 HEAD@{4}: commit: num.txt:123
c0f361e HEAD@{5}: commit: new.txt:third
c2992cf HEAD@{6}: commit: new.txt:second
5dc6afb HEAD@{7}: commit: new.txt:first line
565719e HEAD@{8}: commit: add new.txt
416a0aa HEAD@{9}: commit (initial): 注释
[root@web2 git]# git reset --hard d7293  ##移动指针到最新版本
HEAD 现在位于 d7293ba num.txt:789
[root@web2 git]# \cp  /tmp/new.txt new.txt  
[root@web2 git]# cat new.txt ##这样就能恢复数据
new file
[root@web2 git]# git push
root@192.168.2.100's password: 
To root@192.168.2.100:/var/git
   416a0aa..c0f361e  master -> master

Git分支

  • 分支可以让开发分多条主线同时进行,每条主线互不影响
  • 按功能模块分支,按版本分支
  • 分支也可以合并

Git分支操作

  • Git支持按功能模块、时间、版本等标准创建分支,分支可以让开发分多条主线同时进行,每条主线互不影响

常见的分支规范

  • MASTER分支(MASTER是主分支,是代码的核心)。
  • DEVELOP分支(DEVELOP最新开发成果的分支)。
  • RELEASE分支(为发布新产品设置的分支)。
  • HOTFIX分支(为了修复软件BUG缺陷的分支)。
  • FEATURE分支(为开发新功能设置的分支)。
  • Git默认会有一个master的分支

问题:
沿用上面的练习,学习操作Git分支,具体要求如下:
查看分支
创建分支
切换分支
合并分支
解决分支的冲突
如图:
在这里插入图片描述
步骤一:查看并创建分支
1)查看当前分支。

[root@web2 git]# git status  ##查看当前分支
# 位于分支 master  
无文件要提交,干净的工作区

[root@web2 git]# git branch -v  ##查看所有分支
* master d7293ba num.txt:789

2)创建分支。

[root@web2 git]# git branch hotfix   ##创建分支,名称可以随意起
[root@web2 git]# git branch feature  ##创建分支
[root@web2 git]# git branch -v  ##查看所有分支
  feature d7293ba num.txt:789
  hotfix  d7293ba num.txt:789
* master  d7293ba num.txt:789

步骤二:切换与合并分支

[root@web2 git]# git checkout hotfix  ##切换到hotfix分支
切换到分支 'hotfix'
[root@web2 git]# git branch -v
  feature d7293ba num.txt:789
* hotfix  d7293ba num.txt:789
  master  d7293ba num.txt:789

2)在新的分支上可以继续进行数据操作(增、删、改、查)。

[root@web2 git]# echo "fix a bug" >> new.txt
[root@web2 git]# git add .
[root@web2 git]# git commit -m "fix a bug"
[hotfix 517b54a] fix a bug
 1 file changed, 1 insertion(+)
[root@web2 git]# cat new.txt 
new file
first
second
third
fix a bug

3)将hotfix修改的数据合并到master分支。
注意,合并前必须要先切换到master分支,然后再执行merge命令。

[root@web2 git]# git checkout master  ##切回主分支
切换到分支 'master'
[root@web2 git]# cat new.txt  #默认master分支中没有hotfix分支中的数据
new file
first
second
third
[root@web2 git]# git merge hotfix  ##合并分支
更新 d7293ba..517b54a
Fast-forward
 new.txt | 1 +
 1 file changed, 1 insertion(+)
[root@web2 git]# cat new.txt  ##再查看一下
new file
first
second
third
fix a bug

步骤二:解决版本分支的冲突问题
1)在不同分支中修改相同文件的相同行数据,模拟数据冲突。

[root@web2 git]# git checkout hotfix  ##切换到分支hotfix
切换到分支 'hotfix'
[root@web2 git]# echo "AAA" > a.txt   ##创建一个文件
[root@web2 git]# git add .
[root@web2 git]# git commit -m "add a.txt by hotfix"  ##提交到本地仓库
[hotfix 00c1525] add a.txt by hotfix
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
[root@web2 git]# git checkout master  ##切回主分支
已经位于 'master'
您的分支领先 'origin/master' 共 1 个提交。
  (使用 "git push" 来发布您的本地提交)
[root@web2 git]# echo "BBB" > a.txt  ##创建相同文件
[root@web2 git]# git add .
[root@web2 git]# git commit -m "add a.txt by master"   ##提交到仓库
[master 5912609] add a.txt by master
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
[master 5912609] add a.txt by master
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
[root@web2 git]# git merge hotfix   ##合并报错
自动合并 a.txt
冲突(添加/添加):合并冲突于 a.txt
自动合并失败,修正冲突然后提交修正的结果。
##相同文件不同分支修改的都是同样内容就会发生冲突,需要人为解决
[root@web2 git]# vim a.txt  ##决定最终留下的内容
##修改前内容
<<<<<<< HEAD
BBB
=======
AAA
>>>>>>> hostfix
--------------------------------------------------------------------------------
##修改后内容
AAA
[root@web2 git]# git add .
[root@web2 git]# git commit -m "xxx"
[master 3dd02e1] xxx

总结:分支指针与HEAD指针的关系。
创建分支的本质是在当前提交上创建一个可以移动的指针
如何判断当前分支呢?答案是根据HEAD这个特殊指针
在这里插入图片描述

多分支提交的流程

  • 切换分支,只是移动HEAD指针
    在这里插入图片描述

多分支提交的流程(续1)

  • testing分支的提交,不会影响master
    在这里插入图片描述

多分支提交的流程(续2)

  • 切换回master分支
    在这里插入图片描述

多分支提交流程(续3)

  • master提交也不影响testing分支
    在这里插入图片描述

Git服务器

SSH协议

  • 密码认证访问
  • 服务器安装git
  • 使用git命令初始化版本仓库
  • 客户端使用SSH远程访问(可读写权限)

问题
沿用练习三,学习Git不同的服务器形式,具体要求如下:
创建SSH协议服务器
创建Git协议服务器
创建HTTP协议服务器

  • Git支持很多服务器协议形式,不同协议的Git服务器,客户端就可以使用不同的形式访问服务器。创建的服务器协议有SSH协议、Git协议、HTTP协议。

步骤一:SSH协议服务器(支持读写操作)
1)创建基于密码验证的SSH协议服务器(web1主机操作)。

[root@web1 ~]# git init --bare /var/git/base_ssh
Initialized empty Git repository in /var/git/base_ssh/

2)客户端访问的方式(web2主机操作)。

[root@web2 ~]# git clone root@192.168.2.100:/var/git/base_ssh
[root@web2 ~]# rm -rf base_ssh

3)客户端生成SSH密钥,实现免密码登陆git服务器(web2主机操作)。

[root@web2 ~]# ssh-keygen -f /root/.ssh/id_rsa -N ''
[root@web2 ~]# ssh-copy-id  192.168.2.100
[root@web2 ~]# git clone root@192.168.2.100:/var/git/base_ssh
[root@web2 ~]# git push

步骤二:Git协议服务器(只读操作的服务器)
1)安装git-daemon软件包(web1主机操作)。

[root@web1 ~]# yum -y install git-daemon.x86_64 

2)创建版本库(web1主机操作)

[root@web1 ~]# git init --bare /var/tian
初始化空的 Git 版本库于 /var/tian/

3)修改配置文件,启动git服务(web1主机操作)。

[root@web1 ~]# vim /usr/lib/systemd/system/git@.service
修改前内容如下:
ExecStart=-/usr/libexec/git-core/git-daemon --base-path=/var/lib/git 
--export-all --user-path=public_git --syslog --inetd –verbose
修改后内容如下:
ExecStart=-/usr/libexec/git-core/git-daemon --base-path=/var
--export-all --user-path=public_git --syslog --inetd –verbose
[root@web1 ~]# systemctl start git.socket  ##启动服务

4)客户端访问方式(web2主机操作)

[root@web2 ~]# git clone git://192.168.2.100/tian
正克隆到 'tian'...
warning: 您似乎克隆了一个空版本库。

步骤三:HTTP协议服务器(只读操作的服务器)
1)安装gitweb、httpd软件包(web1主机操作)。

[root@web1 ~]# yum -y install gitweb httpd

2)修改配置文件,设置仓库根目录(web1主机操作)。

[root@web1 ~]# vim +11 /etc/gitweb.conf
$projectroot = "/var";   ##添加一行

) 创建版本仓库(web1主机操作)

[root@web1 ~]# git init --bare /var/base
初始化空的 Git 版本库于 /var/base/

4)启动httpd服务器

[root@web1 ~]# systemctl start httpd

5)客户端访问方式(web2主机操作)
注意:调用虚拟机中的firefox浏览器,需要在远程时使用ssh -X 服务器IP,并且确保真实主机的firefox已经关闭。

root@web2 ~]# firefox http://192.168.2.100/git/
##在浏览器上就能看见创建的仓库及文件信息

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Github

  • GitHub是一个面向开源及私有软件项目的托管平台,因为只支持git作为唯一的版本库格式进行托管,故名GitHub
  • GitHub于2008年4月10日正式上线

步骤四:注册使用Github
1.登陆网站https://github.com,点击Sign up(注册),如图所示。
在这里插入图片描述
2.填写注册信息(用户名,邮箱,密码),如图所示。

在这里插入图片描述
3. 初始化操作,如图所示。
在这里插入图片描述
在这里插入图片描述
注意,初始化完成后,到邮箱中去激活Github账户。

  1. 创建仓库、使用仓库
    点击Start a project(如图所示)
    在这里插入图片描述
    填写项目名称(项目名称任意),如图所示。
    在这里插入图片描述
    往仓库中上传文件或新建文件,如图所示
    在这里插入图片描述
  2. 命令行操作(需要联网的主机,如真实机)
[root@pc001 ~]# yum -y install git
[root@pc001 ~]# git clone https://github.com/账户名称/仓库名称
#clone指令用于将服务器仓库中的资料打包下载到本地
[root@pc001 ~]# cd 仓库名称
[root@pc001 ~]# 任意修改文件,或新建文件
[root@pc001 ~]# git add .
#add添加新文件
[root@pc001 ~]# git commit -m "test"
[root@pc001 ~]# git push
#commit和push实现提交代码的功能
[root@pc001 ~]# git pull
#pull可以从githuab服务器拉取数据到本地

RPM打包


源码包:------->自己打成RPM
麻烦
新软件,可以自定义
./configure --with…

RPM包(Contos7)
简单,旧,不能自定义
yum #####################


应用场景

  • 官方未提供RPM
  • 官方RPM无法自定义
  • 大量源码包,希望提供统一的软件管理机制

打包流程
准备源码软件
安装rpm-build
编写编译配置文件
编译RPM包

制作nginx的RPM包

问题
本案例使用nginx-1.12.2版本的源码软件,生成对应的RPM包软件,具体要求如下:
软件名称为nginx
软件版本为1.12.2
RPM软件包可以查询描述信息
RPM软件包可以安装及卸载

安装rpm-build软件包,编写SPEC配置文件,创建新的RPM软件包。
配置文件中的描述信息如表:
在这里插入图片描述
步骤一:安装rpm-build软件
1)安装rpm-build软件包

[root@web1 ~]# yum -y install  rpm-build

2)生成rpmbuild目录结构

[root@web1 ~]# rpmbuild -ba xxxx     ##会报错,没有文件或目录
[root@web1 ~]# ls /root/rpmbuild     ##自动生成的目录结构
BUILD  BUILDROOT  RPMS  SOURCES  SPECS  SRPMS
##sources   放源码包的目录
##RPMS      rpm包放在这
##SPECS     写配置文件

3)准备工作,将源码软件复制到SOURCES目录

[root@web1 rpmbuild]# cp /opt/lnmp_soft/nginx-1.12.2.tar.gz /root/rpmbuild/SOURES

4)创建并修改SPEC配置文件

root@web1 ~]# vim /root/rpmbuild/SPECS/nginx.spec 
##打*号的内容要写对!!!
*Name:nginx       ##源码包软件名称  
*Version:1.12.2   ##源码包软件的版本号
Release:        1%{?dist}  ##RPM包版本号
Summary:this is a web server   ##RPM软件概述

#Group:      ##RPM包软件组   
License:GPL    ##软件协议
URL:www.douniwan.com  ##网址
*Source0:nginx-1.12.2.tar.gz   ##源码包文件全称

#BuildRequires:   ##制作RPM时的依赖关系
#Requires:         ## #安装RPM时的依赖关系

%description  ##RPM软件的详细描述
this is a web server tooooooooooooooo.
*%post   ##安装后脚本,及安装后执行
useradd -s /sbin/nologin tom     #非必需操作:安装后脚本(创建账户)
命令
......
%prep         ##安装前准备,解压
%setup -q       #自动解压源码包,并cd进入目录


%build       ##编译时需要执行的命令
*./configure --with-http_ssl_module  --user=tom
make %{?_smp_mflags}


%install   ##安装时需要执行的指令
make install DESTDIR=%{buildroot}

%clean     ##清理时需要执行的指令
%files     ##定义打包文件列表
%doc   
/usr/local/nginx/*        #对哪些文件与目录打包


%changelog      ##软件修改历史

步骤二:使用配置文件创建RPM包

[root@web1 ~]# yum -y install  gcc  pcre-devel openssl-devel

2)rpmbuild创建RPM软件包

[root@web1 ~]# rpmbuild -ba /root/rpmbuild/SPECS/nginx.spec
[root@web1 ~]# ls /root/rpmbuild/RPMS/x86_64/
nginx-1.12.2-1.el7.centos.x86_64.rpm  ##制作的RPM包
nginx-debuginfo-1.12.2-1.el7.centos.x86_64.rpm  ##源RPM包

步骤三:安装软件

使用spec文件编译RPM包
[root@web1 ~]# yum install /root/rpmbuild/RPMS/x86_64/nginx-1.12.2-10.x86_64.rpm 
[root@web1 ~]# rpm -qa |grep nginx
nginx-1.12.2-1.el7.centos.x86_64
[root@web1 ~]# ls /usr/local/nginx/
client_body_temp  fastcgi_temp  logs        sbin       uwsgi_temp
conf              html          proxy_temp  scgi_temp
[root@web1 SPECS]# yum info nginx.x86_64 
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
已安装的软件包
名称    :nginx
架构    :x86_64
版本    :1.12.2
发布    :1.el7.centos
大小    :797 k
源    :installed
简介    : this is a web server
网址    :www.douniwan.com
协议    : GPL
描述    : this is a web server tooooooooooooooo.
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值