CI/CD,DevOps介绍
- 持续集成(Continuous Integration,CI):
代码合并,构建,部署,测试都在一起,不断地执行这个过程,并对结果反馈 - 持续交付(Continuous Delivery,CD):
部署到生产环境,给用户使用 - 持续部署(Continuous Deployment,CD):
部署到生产环境
部署git版本远程仓库
[root@localhost ~]# useradd git
[root@localhost ~]# passwd git #密码是123456
[root@localhost ~]# su git #切换到git用户下
[git@localhost ~]$ mkdir repos #创建git仓库
[git@localhost ~]$ cd repos/
[git@localhost repos]$ mkdir app.git #创建app项目目录
[git@localhost repos]$ pwd
/home/git/repos
[git@localhost repos]$ cd app.git/
[git@localhost app.git]$ pwd
/home/git/repos/app.git
[git@localhost app.git]$ git --bare init
重新初始化现存的 Git 版本库于 /home/git/repos/app.git/
[git@localhost app.git]$ ls
branches config description HEAD hooks info objects refs
[git@localhost app.git]$ git status
fatal: This operation must be run in a work tree
在Jenkins服务器进行git代码远程推送测试
[root@localhost ~]# yum install -y git #安装git
#创建一个目录,尝试git clone 远程git服务器仓库代码
[root@localhost zxw]# git clone git@192.168.182.149:/home/git/repos/app.git
正克隆到 'app'...
The authenticity of host '192.168.182.149 (192.168.182.149)' can't be established.
ECDSA key fingerprint is SHA256:/E5HslaJaFMmTl9YKhsyGaIdAt62U9J/yOYz+1vZYqI.
ECDSA key fingerprint is MD5:82:0e:f1:af:51:69:66:0a:f3:6b:3d:b8:66:26:f5:31.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.182.149' (ECDSA) to the list of known hosts.
git@192.168.182.149's password: #输入远程服务器git用户的登录密码
warning: 您似乎克隆了一个空版本库。
[root@localhost zxw]# ls
app
#进行代码提交
[root@localhost zxw]# cd app/
[root@localhost app]# ls
[root@localhost app]# echo "welcome to yunjisuan" >> test #重定向的同时创建这个文件
[root@localhost app]# cat test
welcome to yunjisuan
[root@localhost app]# git add * #将文件添加到本地暂存区
[root@localhost app]# 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@localhost.(none)')
#配置git全局配置
[root@localhost app]# git config --global user.email "2420813702@qq.com"
[root@localhost app]# git config --global user.name "zxw"
#进行代码提交测试
[root@localhost app]# git commit -m "提交测试"
[master(根提交) 0912853] 提交测试
1 file changed, 1 insertion(+)
create mode 100644 test
#添加远程仓库地址
[root@localhost app]# git remote add origin git@192.168.182.149:/home/git/repos/app.git
fatal: 远程 origin 已经存在。
[root@localhost app]# git remote -v #发现已经添加过了(之前clone时自动添加的)
origin git@192.168.182.149:/home/git/repos/app.git (fetch)
origin git@192.168.182.149:/home/git/repos/app.git (push)
#将代码推送到远程仓库的master分支
[root@localhost app]# git push -u origin master
git@192.168.182.149's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 234 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.182.149:/home/git/repos/app.git
* [new branch] master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。
[root@localhost app]# git push -u origin master
git@192.168.182.149's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 234 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.182.149:/home/git/repos/app.git
* [new branch] master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。
#查看分支情况
[root@localhost app]# git branch
* master #本地当前所处的分支
在Jenkins服务器进行SSH免秘钥操作
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Fs/WiECFiLyWFL9K7byWdBKEe0VVtooMOLrNKD2o3Vo root@localhost
The key's randomart image is:
+---[RSA 2048]----+
| ..+ oo+o.o |
| =oo.o . . |
| .o=o.. . . |
| .=oo+ o * o |
|....o.o S = . |
| O +o .. . |
|= *.E+ |
|o. +o. |
|. ooo |
+----[SHA256]-----+
#进行公钥分发
[root@localhost ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub git@192.168.182.149
/usr/bin/ssh-copy-id: INFO: S