目录
一、CICD是什么
1.1 持续集成(Continuous Integration)
1.2 持续部署(Continuous Deployment)
1.3 持续交付(Continuous Delivery)
二、git工具使用
2.1 git简介
2.2 git的工作流程
2.3 部署git
2.3.1 安装git
2.3.2 初始化
2.3.3 git的使用方法
2.3.3.1 常用方法
2.3.3.2 git对于文件如何忽略
三、gitlab代码仓库
3.1 gitlab简介
3.2 gitlab 的部署实施
3.2.1 部署gitlab
3.2.2 配置gitlab
3.2.3 登陆gitlab
3.2.4 在gitlab中新建项目
四、Jenkins
4.1 Jenkins简介
4.2 部署Jenkins
4.3 jenkins 与gitlab的整合
一、CICD是什么
CI/CD是指持续集成(Continuous Integration)和持续部署(Continuous Deployment)或持续交付(Continuous Delivery)
1.1 持续集成(Continuous Integration)
持续集成是一种软件开发实践,团队成员频繁地将他们的工作集成到共享的代码仓库中。其主要特点包括:
-
频繁提交代码:开发人员可以每天多次提交代码,确保代码库始终保持最新状态。
-
自动化构建:每次提交后,自动触发构建过程,包括编译、测试、静态分析等。
-
快速反馈:如果构建失败或测试不通过,能够快速地向开发人员提供反馈,以便及时修复问题。
1.2 持续部署(Continuous Deployment)
持续部署是在持续集成的基础上,将通过所有测试的代码自动部署到生产环境中。其特点如下:
-
自动化流程:从代码提交到生产环境的部署完全自动化,无需人工干预。
-
高频率部署:可以实现频繁的部署,使得新功能能够快速地提供给用户。
-
风险控制:需要有强大的测试和监控体系来确保部署的稳定性和可靠性。
1.3 持续交付(Continuous Delivery)
持续交付与持续部署类似,但不一定自动部署到生产环境,而是随时可以部署。其重点在于确保软件随时处于可发布状态。
CI/CD 的好处包括:
-
提高开发效率:减少手动操作和等待时间,加快开发周期。
-
尽早发现问题:通过频繁的集成和测试,问题能够在早期被发现和解决。
-
降低风险:减少了大规模部署时可能出现的问题,提高了软件的质量和稳定性。
-
增强团队协作:促进团队成员之间的沟通和协作,提高团队的整体效率。
常见的 CI/CD 工具包括 Jenkins、GitLab CI/CD、Travis CI 等。这些工具可以帮助团队实现自动化的构建、测试和部署流程。
二、git工具使用
2.1 git简介
Git 是一个分布式版本控制系统,被广泛用于软件开发中,以管理代码的版本和变更。 主要特点:
-
分布式
-
每个开发者都有完整的代码仓库副本,这使得开发者可以在离线状态下进行工作,并且在网络出现问题时也不会影响开发。
-
即使中央服务器出现故障,开发者仍然可以在本地进行开发和查看项目历史。
-
-
高效的分支管理
-
Git 中的分支创建和切换非常快速和简单。开发人员可以轻松地创建新的分支来进行新功能的开发或修复 bug,而不会影响主分支。
-
合并分支也相对容易,可以使用多种合并策略来满足不同的需求。
-
-
快速的版本回退
-
如果发现某个版本存在问题,可以快速回退到之前的版本。
-
可以查看每个版本的详细变更记录,方便了解代码的演进过程。
-
-
强大的提交管理
-
每个提交都有一个唯一的标识符,可以方便地引用和查看特定的提交。
-
提交可以包含详细的提交信息,描述本次提交的更改内容。
-
-
支持协作开发
-
开发者可以将自己的更改推送到远程仓库,供其他开发者拉取和合并。
-
可以处理多个开发者同时对同一文件进行修改的情况,通过合并冲突解决机制来确保代码的完整性。
-
Git必看秘籍:https://git-scm.com/book/zh/v2
2.2 git的工作流程
Git 有三种状态:已提交(committed)、已修改(modified) 和 已暂存(staged)。
-
已修改表示修改了文件,但还没保存到数据库中。
-
已暂存表示对一个已修改文件的当前版本做了标记,使之包含在下次提交的快照中。
-
已提交表示数据已经安全地保存在本地数据库中。
这会让我们的 Git 项目拥有三个阶段:工作区、暂存区以及 Git 目录。
2.3 部署git
2.3.1 安装git
[root@getlab-node1 ~]# dnf install git -y设定命令补全功能:
[root@getlab-node1 ~]# echo "source /usr/share/bash-completion/completions/git" >> ~/.bashrc
[root@getlab-node1 ~]# source ~/.bashrc
[root@getlab-node1 ~]#
2.3.2 初始化
获取 Git 仓库通常有两种方式:
-
将尚未进行版本控制的本地目录转换为 Git 仓库。
-
从其它服务器克隆 一个已存在的 Git 仓库。比如: git clone
初始化版本库
[root@getlab-node1 ~]# mkdir xiaoding
[root@getlab-node1 ~]# cd xiaoding/
[root@getlab-node1 xiaoding]#
[root@getlab-node1 xiaoding]#
[root@getlab-node1 xiaoding]# git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /root/xiaoding/.git/
[root@getlab-node1 xiaoding]# ls -a
. .. .git
[root@getlab-node1 xiaoding]#
[root@getlab-node1 xiaoding]# ls .git/
branches config description HEAD hooks info objects refs
[root@getlab-node1 xiaoding]# 设定用户信息:
[root@getlab-node1 xiaoding]# git config --global user.name "xiaoding"
[root@getlab-node1 xiaoding]# git config --global user.email "xiaoding@xiaoding.org"
[root@getlab-node1 xiaoding]# 查看当前文件状态:
[root@getlab-node1 xiaoding]# git status
On branch masterNo commits yetnothing to commit (create/copy files and use "git add" to track)
[root@getlab-node1 xiaoding]# [root@CICD-node1 timinglee]# git status -s #简化输出
2.3.3 git的使用方法
2.3.3.1 常用方法
[root@getlab-node1 xiaoding]# echo xiaoding > README.md
[root@getlab-node1 xiaoding]# git status
On branch masterNo commits yetUntracked files:(use "git add <file>..." to include in what will be committed)README.mdnothing added to commit but untracked files present (use "git add" to track)
[root@getlab-node1 xiaoding]# git status -s
?? README.md #?? 新建文件未添加到版本库
[root@getlab-node1 xiaoding]# git add README.md
[root@getlab-node1 xiaoding]# git status -s
A README.md #A 已添加到暂存区
[root@getlab-node1 xiaoding]#提交暂存区的数据:
[root@getlab-node1 xiaoding]# git commit -m "add README.md"
[master (root-commit) 52a1911] add README.md1 file changed, 1 insertion(+)create mode 100644 README.md
[root@getlab-node1 xiaoding]# git status -s #无任何显示,标识已经提交到版本库
[root@getlab-node1 xiaoding]#再次修改:
[root@getlab-node1 xiaoding]# vim README.md xiaoding
xiaoding[root@getlab-node1 xiaoding]# git status -sM README.md #右M 表示文件在工作区被修改
[root@getlab-node1 xiaoding]#撤销修改:
[root@getlab-node1 xiaoding]# git checkout -- README.md
[root@getlab-node1 xiaoding]# cat README.md
xiaoding
[root@getlab-node1 xiaoding]#重新修改:
[root@getlab-node1 xiaoding]# echo timinglee> README.md
[root@getlab-node1 xiaoding]# git add README.md
[root@getlab-node1 xiaoding]# git statrus -s
git: 'statrus' is not a git command. See 'git --help'.The most similar command isstatus
[root@getlab-node1 xiaoding]# git status -s
M README.md #左M表示文件已经在版本库中并被跟踪,
[root@getlab-node1 xiaoding]# 从暂存区撤销:
[root@getlab-node1 xiaoding]# git restore --staged README.md
[root@getlab-node1 xiaoding]# git status -sM README.md
[root@getlab-node1 xiaoding]# 重新提交:
[root@getlab-node1 xiaoding]# git add README.md
[root@getlab-node1 xiaoding]# git status -s
M README.md
[root@getlab-node1 xiaoding]# 更新文件:
[root@getlab-node1 xiaoding]# echo timingding >> README.md
[root@getlab-node1 xiaoding]# git add README.md
[root@getlab-node1 xiaoding]# echo timingding >> README.md
[root@getlab-node1 xiaoding]# git status -s
MM README.md #MM表示有一部分在暂存区,还有一部分没有提交
[root@getlab-node1 xiaoding]#如果现在提交只能提交在暂存区中的部分:
[root@getlab-node1 xiaoding]# git commit -m "update v2"
[master 5b49e73] update v21 file changed, 2 insertions(+), 1 deletion(-)
[root@getlab-node1 xiaoding]# git status -sM README.md #右M还在
[root@getlab-node1 xiaoding]#查看已暂存和未暂存的修改变化:
[root@getlab-node1 xiaoding]# echo timingding >> README.md
[root@getlab-node1 xiaoding]# git diff
diff --git a/README.md b/README.md
index 065bdae..e683b61 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,4 @@timingleetimingding
+timingding
+timingding
[root@getlab-node1 xiaoding]# 跳过使用暂存区,只能在提交过的在版本库中存在的文件使用如果文件状态是“??”不能用此方法:
[root@getlab-node1 xiaoding]# git commit -a -m "update v3"
[master ab608f4] update v31 file changed, 2 insertions(+)
[root@getlab-node1 xiaoding]#撤销工作区中删除动作:
[root@getlab-node1 xiaoding]# touch ding.txt
[root@getlab-node1 xiaoding]# git add ding.txt
[root@getlab-node1 xiaoding]# git commit -m "add ding.txt"
[master 825b0dc] add ding.txt1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 ding.txt
[root@CICD-node1 xiaoding]# git status -sD ding.txt #右D表示文件在工作区被删除[root@CICD-node1 xiaoding]# git checkout -- ding.txt
[root@CICD-node1 xiaoding]# ls
dir1 ding.txt README.md从版本库中删除文件:
[root@getlab-node1 xiaoding]# git rm ding.txt
rm 'ding.txt'
[root@getlab-node1 xiaoding]# git status -s
D ding.txt #左D表示文件删除动作被提交到暂存区
[root@getlab-node1 xiaoding]#[root@getlab-node1 xiaoding]# git commit -m "delete ding.txt"
[master 08e9d47] delete ding.txt1 file changed, 0 insertions(+), 0 deletions(-)delete mode 100644 ding.txt
[root@getlab-node1 xiaoding]# git status -s
[root@getlab-node1 xiaoding]# 恢复从版本库中被删除的文件:
[root@getlab-node1 xiaoding]# git log #查看日志操作
commit 08e9d470a436a6fc3a9e6977ccccd78d149fa133 (HEAD -> master)
Author: xiaoding <xiaoding@xiaoding.org>
Date: Thu Sep 12 01:57:23 2024 -0400delete ding.txtcommit 825b0dc35ccd9a2984cb171b953373a1fee5e5bf
Author: xiaoding <xiaoding@xiaoding.org>
Date: Thu Sep 12 01:53:27 2024 -0400add ding.txtcommit ab608f43483f5c302669f26b43dae6f9540d8cbe
Author: xiaoding <xiaoding@xiaoding.org>
Date: Thu Sep 12 01:52:07 2024 -0400update v3commit 5b49e7340133e64b8f7d35b073524206cf456558
Author: xiaoding <xiaoding@xiaoding.org>
Date: Thu Sep 12 01:50:39 2024 -0400update v2commit 52a1911629f9c5a6862310732387bfa43002eda8
Author: xiaoding <xiaoding@xiaoding.org>
Date: Thu Sep 12 01:42:14 2024 -0400add README.md
[root@getlab-node1 xiaoding]# [root@getlab-node1 xiaoding]# git reflog #查看提交动作
08e9d47 (HEAD -> master) HEAD@{0}: commit: delete ding.txt
825b0dc HEAD@{1}: commit: add ding.txt
ab608f4 HEAD@{2}: commit: update v3
5b49e73 HEAD@{3}: commit: update v2
52a1911 HEAD@{4}: commit (initial): add README.md
[root@getlab-node1 xiaoding]# 版本回退到删除之前:
[root@getlab-node1 xiaoding]# git reset --hard 825b0dc
HEAD is now at 825b0dc add ding.txt
[root@getlab-node1 xiaoding]# ls
ding.txt README.md
[root@getlab-node1 xiaoding]#
2.3.3.2 git对于文件如何忽略
在做软件开发时对源码编译会产生一些临时文件,我们在提交时需要忽略这些临时文件
[root@getlab-node1 xiaoding]# mkdir dir1/
[root@getlab-node1 xiaoding]# touch dir1/.file2
[root@getlab-node1 xiaoding]# git status -s
?? dir1/
[root@getlab-node1 xiaoding]# [root@getlab-node1 xiaoding]# echo .file1 > .gitignore
[root@getlab-node1 xiaoding]# git status -s
?? .gitignore
?? dir1/
[root@getlab-node1 xiaoding]#
[root@getlab-node1 xiaoding]# echo ".*" > .gitignore
[root@getlab-node1 xiaoding]# git status -s
[root@getlab-node1 xiaoding]#
三、gitlab代码仓库
3.1 gitlab简介
-
GitLab 是一个用于仓库管理系统的开源项目,使用 Git 作为代码管理工具,并在此基础上搭建起来的 web 服务。
-
GitLab 具有很多功能,比如代码托管、持续集成和持续部署(CI/CD)、问题跟踪、合并请求管理等。它可以帮助开发团队更好地协作开发软件项目,提高开发效率和代码质量。
官网:https://about.gitlab.com/install/
中文站点: GitLab下载安装_GitLab安装和配置_GitLab最新中文官网免费版下载-极狐GitLab
官方包地址:gitlab/gitlab-ce - Packages · packages.gitlab.com
3.2 gitlab 的部署实施
3.2.1 部署gitlab
部署gitlab需要内存大于4G
[root@getlab-node1 ~]# yum install -y curl policycoreutils-python openssh-server perl[root@getlab-node1 ~]# dnf install gitlab-ce-17.1.6-ce.0.el9.x86_64.rpm
3.2.2 配置gitlab
修改配置文件:
[root@getlab-node1 ~]# cd /etc/gitlab/
[root@getlab-node1 gitlab]# ls
gitlab.rb
[root@getlab-node1 gitlab]# vim gitlab.rb 32 external_url 'http://172.25.254.50'修改配置文件后需利用gitlab-crt来生效:
[root@getlab-node1 ~]# gitlab-ctl reconfigure
3.2.3 登陆gitlab
用户名默认为 root
。如果在安装过程中指定了初始密码,则用初始密码登录,如果未指定密码,则系统会随机生成一个密码并存储在 /etc/gitlab/initial_root_password
文件中, 查看随机密码并使用 root
用户名登录。
注意:出于安全原因,24 小时后,/etc/gitlab/initial_root_password
会被第一次 gitlab-ctl reconfigure
自动删除,因此若使用随机密码登录,建议安装成功初始登录成功之后,立即修改初始密码。
原始密码:
[root@getlab-node1 gitlab]# cat /etc/gitlab/initial_root_password
# WARNING: This value is valid only in the following conditions
# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
# 2. Password hasn't been changed manually, either via UI or via command line.
#
# If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.Password: EjhFCCHKf6M8GNd7BlN2CFmmVO+OBp0k1rVbDSADII0=# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
[root@getlab-node1 gitlab]#
登录:
设置语言:
设置密码:
3.2.4 在gitlab中新建项目
生成密钥;
生成密钥:
[root@getlab-node1 gitlab]# 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:UOjJbI7p9lgSTHSdu8gb8o4VEyTE/fyEKvWJpmOJ9qU root@getlab-node1
The key's randomart image is:
+---[RSA 3072]----+
| o+.oo.. |
| ..+o.o |
| .+o+ o |
| o Bo= . |
| oBo=S= |
| =.Oo+ . |
| o.B+o |
| o BOo |
| . +E+o |
+----[SHA256]-----+
[root@getlab-node1 gitlab]#[root@getlab-node1 ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQClo5h0ljRd8j4mCXfxMxDdk7rpUVXF5iqJrAoLODBTuZephBHM79Xn3n8Bwn5qfhVgwTto5ABCkdygAwAqTtf1VtSuS5Na2sAZX91l7L7evqgyunwvmynZFrrC+b3FSGbSV8w93+kVgSOCBZpDabSRNjIHnxsDjqBj4Jg2M5TB9LOq9BDEmTJgveaNayaB1cGNNC0cmVoghENApvShJbbMNhF9PcKmORBVfabqCKj8qI34j7Ofu0MaXqSkE3tHDrY15R2e2CMbg5tI5KyvbjEjLdQ0IlOKienlBnSkWnbf39aSDmDAgUZVOQMjwBfA6IxT3ruMvTm3XlSWlx9Cf33JfknH1M/ami7HMS/JdoENgwcLfQGjWHB098jXsW32FuEqyiNgj9v+yRpyXToBaWKaC/9x3YNZyoe4sZU0fSo0pwGIb7bm+XU1Wl/EemvY8wEm8dKCiO02/8F+y7G1TKoVIE3HDstcFzsIfbWXAN98TpPmIVrUi8aSUJtuLIxmIeU= root@getlab-node1
[root@getlab-node1 ~]#
上传公钥到gitlab中:
下载项目:
下载项目:
[root@getlab-node1 ~]# git clone git@172.25.254.50:root/timingding.git
Cloning into 'timingding'...
The authenticity of host '172.25.254.50 (172.25.254.50)' can't be established.
ED25519 key fingerprint is SHA256:JAc5p6OZrNZsG8UQHYDL8RDEOeKmzy1IWQlXlmvsuSw.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '172.25.254.50' (ED25519) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0
Receiving objects: 100% (3/3), done.
[root@getlab-node1 ~]# [root@getlab-node1 ~]# ls -R./xiaoding:
ding.txt dir1 README.md./xiaoding/dir1:
[root@getlab-node1 ~]# [root@getlab-node1 ~]# cd timingding/
[root@getlab-node1 timingding]# ls
README.md
[root@getlab-node1 timingding]# git remote -v
origin git@172.25.254.50:root/timingding.git (fetch)
origin git@172.25.254.50:root/timingding.git (push)
[root@getlab-node1 timingding]# 文件提交:[root@gitlab-node1 timingding]# git config --global user.email "timingding@timingding.org" #创建邮箱
[root@gitlab-node1 timingding]# git config --global user.name "timingding" #创建用户名[root@getlab-node1 timingding]# echo timingding > timingding
[root@getlab-node1 timingding]# git add timingding
[root@getlab-node1 timingding]# git commit -m "add timingding"
[main e30c821] add timingding1 file changed, 1 insertion(+)create mode 100644 timingding
[root@getlab-node1 timingding]# git push -u origin main
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 278 bytes | 278.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To 172.25.254.50:root/timingding.git8a1a315..e30c821 main -> main
branch 'main' set up to track 'origin/main'.
[root@getlab-node1 timingding]#
四、Jenkins
4.1 Jenkins简介
-
Jenkins是开源CI&CD软件领导者, 提供超过1000个插件来支持构建、部署、自动化, 满足任何项目的需要。
-
Jenkins用Java语言编写,可在Tomcat等流行的servlet容器中运行,也可独立运行
CI(Continuous integration持续集成)持续集成强调开发人员提交了新代码之后,立刻进行构建、(单元)测试。
CD(Continuous Delivery持续交付) 是在持续集成的基础上,将集成后的代码部署到更贴近真实运行环境(类生产环境)中
4.2 部署Jenkins
软件下载:Download and deploy
jenkins需要部署在新的虚拟机中
jenkins需要部署在新的虚拟机中,建议最少4G内存,4核心cpu
#安装依赖包
[root@jenkins-node1 ~]# yum install fontconfig java-17-openjdk git#安装jenkins
[root@jenkins-node1 ~]# dnf install jenkins-2.462.2-1.1.noarch.rpm -y#启动jenkins
[root@jenkins-node1 ~]# systemctl enable --now jenkins.service
Created symlink /etc/systemd/system/multi-user.target.wants/jenkins.service → /usr/lib/systemd/system/jenkins.service.
[root@jenkins-node1 ~]# 查看原始密码:
[root@jenkins-node1 ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
d1eadf188d2249cb8b6634f7941052ef
[root@jenkins-node1 ~]#
部署插件:
修改密码:
4.3 jenkins 与gitlab的整合
这个错误的原因是因为本机没有gitlab上的sshkey:
生成密钥:
[root@jenkins-node1 ~]# 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:0tQPkSa36S37pL9+uw2t1Lt/0F2r2BWwXKtfTQxsrns root@jenkins-node1
The key's randomart image is:
+---[RSA 3072]----+
| .. . |
| ..+. .+. |
| .+oo.o+o.|
| o oo o.o+|
| . S. ....o*|
| . o o..==|
| o+.*.+|
| .+.+E=o|
| .+=++=*|
+----[SHA256]-----+
[root@jenkins-node1 ~]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC7NfXD9pWYs4VcxxjwRj1lJm9vr+qywS08OnkWErLA8S2OuaXFs4+8ST6JKE+tm0p+lxWe3vJoZL5FRTDvyRVEF7W8AmAC02fBRrtX28pTiby6OAJTQpy8IhCyasdv0s1xTzCXBVAqECF54IT85CIPmO85DzidbTM8kh1jqPjQM+Q9jtEUq6WJb05j7b3DhEwnZeO4mNYGhueeFNR36yHaL1WIVnbHGAq3NrExz/pLfje5YIILYfbCeK1yc3EVssqQ1ZY/1peo5ywE1DZF0dZwdXbkhXQ7TeWxfZaxLP8IwRnwHFDKF/xTlDIyCa7BRZcb4JWMTtNdFvlUWuD2Va4geXz56uQNjYUO5c3DklY4/OIAxVXO8HhkN+JIduL3byzv28w9KDttJgK+IAvIY67P7B2ueOdBMiK8VjDIy8wEJUArbqE2Con4xy5bn1VUYQfMtJtd57PKqq5D/n4uUKG91ippGMveBnu4mpCZu3Y7n/c+1/Qcb/YqkfhvCUcb3Oc= root@jenkins-node1
[root@jenkins-node1 ~]#
到gitlab上面添加jenkins的密钥:
把此密钥添加到gitlab上即可
添加密钥凭据
添加私钥:
[root@jenkins-node1 ~]# cd .ssh/
[root@jenkins-node1 .ssh]# ls
id_rsa id_rsa.pub
[root@jenkins-node1 .ssh]# cat id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
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
-----END OPENSSH PRIVATE KEY-----
[root@jenkins-node1 .ssh]#
添加完成后报错依然存在,因为ssh首次连接主机是需要签名认证,需要手动输入yes
还有两太主机之间一定要做好解析
可以在这里连接输入yes:
不想输入yes,可以修改配置:
[root@jenkins-node1 .ssh]# vim /etc/ssh/ssh_configHost *StrictHostKeyChecking no
# ForwardX11 no
# PasswordAuthentication yes
# HostbasedAuthentication no[root@jenkins-node1 .ssh]# ssh -l root 172.25.254.50
Warning: Permanently added '172.25.254.50' (ED25519) to the list of known hosts.
root@172.25.254.50's password:
Activate the web console with: systemctl enable --now cockpit.socketRegister this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Thu Sep 12 05:49:00 2024 from 172.25.254.1
[root@gitlab-node1 ~]#
现在就没有报错了
此时就构成了简单的持续集成和交互