|NO.Z.00049|——————————|^^ 部署 ^^|——|CI/CD&Jenkins_Harbor部署.V06|--------------------------------------------|部署_Git|Maven報錯處理|
阿新 • • 發佈:2022-03-28
[CloudNative:CI/CD&Jenkins_Harbor配置.V06] [Applications.CloudNative] [|CI/CD.git部署|Git測試|SSH免密連線|Maven報錯處理|]
一、CI/CD.Git服務部署
### --- Git服務部署:centos7.x 10.10.10.14 git 伺服器
~~~ 安裝Git伺服器端
[roo1t@git ~]# yum install -y git
### --- 建立Git使用者 ~~~ 建立git使用者並設定密碼為1qaz2wsx(為開發人員拉程式碼時設定的使用者) [root@git ~]# useradd git [root@git ~]# passwd git
二、安裝Git客戶端——IP:10.10.10.12,jenkins伺服器進行測試### --- 建立Git倉庫 ~~~ 配置完倉庫後,我們需要找一臺機器測試是否能夠成功從倉庫中拉取程式碼, ~~~ 或者上傳程式碼到該倉庫。 [root@git ~]# su - git // 切換到git使用者下 [git@git ~]$ mkdir easy-springmvc-maven.git/ // 在git使用者家目錄下建立一個repos目錄,repos目錄下建立各個專案的目錄 [git@git ~]$ cd easy-springmvc-maven.git/ [git@git easy-springmvc-maven.git]$ git --bare init // 初始化倉庫,如果不初始化,這僅僅就只是一個目錄 [git@git easy-springmvc-maven.git]$ ls -a . .. branches config description HEAD hooks info objects refs // 檢視初始化後倉庫資訊
### --- 安裝Git客戶端
~~~ 安裝 git 客戶端:拉取程式碼
[root@jenkins ~]# yum install -y git
三、Git測試### --- git.clone測試 ~~~ 測試clone遠端git倉庫 [root@jenkins ~]# git clone [email protected]:/home/git/easy-springmvc-maven.git [root@jenkins ~]# ls easy-springmvc-maven
### --- git.push測試
~~~ 第一次的話會有報錯警告,說讓配置郵箱和姓名。
~~~ 配置一下即可,或者直接執行給出的命令執行即可。
[root@jenkins easy-springmvc-maven]# touch index.html
[root@jenkins easy-springmvc-maven]# git add .
[root@jenkins easy-springmvc-maven]# git commit -m "jenkins"
### --- git.push測試
~~~ # Gitpush測試
[root@jenkins easy-springmvc-maven]# touch index.html
[root@jenkins easy-springmvc-maven]# git add .
[root@jenkins easy-springmvc-maven]# git config --global user.email "[email protected]"
[root@jenkins easy-springmvc-maven]# git config --global user.name "yanqi"
[root@jenkins easy-springmvc-maven]# git commit -m "jenkins"
[master (root-commit) 9b9967e] jenkins
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 index.html
~~~ # push到master分支
[root@jenkins easy-springmvc-maven]# git push origin master //提交到主分支(預設分支)
[email protected]'s password:1qaz2wsx
Counting objects: 3, done.
Writing objects: 100% (3/3), 208 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/home/git/easy-springmvc-maven
* [new branch] master -> master
四、Git.ssh祕鑰配置
### --- Git.ssh祕鑰配置
~~~ 生成ssh祕鑰
[root@jenkins ~]# ssh-keygen
[root@jenkins ~]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqyWhdWhod3fz9YNygWhnQjXpZ4lko7SivNATIy1vVgyouEXkFeW2VujpxRU3VCvMXxO7C67iefahnLFm5UX4ZJTDzl9gXblzD3/GhJ0QL2BIjXidY0+eqtNYSx0bxvnYl9sCPXae9S0GyVmIfDyTh6gqWkusTvI3lIu4tfYfn4Y6W2ovBq+Cf/2oe1cFe6jtJnIscA2PeliOT90Gw3Y9wDRm/T1BE+V9Vr1kZ0kvTja+0zKd37sXL2oJwNnECK/kAgV7Paan3WdD9WQ4MhzWPMeuiPbf8MWBKssu8ZRnpQ5ZD4GcYQXqYLR5E3Kslpo9lsbXwpXBSOv4e/lg4Y6B7 root@jenkins
### --- 10.10.10.14 git 伺服器進行配置
~~~ Git伺服器端配置
[root@git ~]# su - git
[git@git ~]$ mkdir -p .ssh/
[git@git ~]$ chmod 700 .ssh/ // 給予目錄700許可權
[git@git ~]$ vim .ssh/authorized_keys // 寫入10.10.10.12伺服器的公鑰
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqyWhdWhod3fz9YNygWhnQjXpZ4lko7SivNATIy1vVgyouEXkFeW2VujpxRU3VCvMXxO7C67iefahnLFm5UX4ZJTDzl9gXblzD3/GhJ0QL2BIjXidY0+eqtNYSx0bxvnYl9sCPXae9S0GyVmIfDyTh6gqWkusTvI3lIu4tfYfn4Y6W2ovBq+Cf/2oe1cFe6jtJnIscA2PeliOT90Gw3Y9wDRm/T1BE+V9Vr1kZ0kvTja+0zKd37sXL2oJwNnECK/kAgV7Paan3WdD9WQ4MhzWPMeuiPbf8MWBKssu8ZRnpQ5ZD4GcYQXqYLR5E3Kslpo9lsbXwpXBSOv4e/lg4Y6B7 root@jenkins
[git@git ~]$ chmod 600 .ssh/authorized_keys // 給予檔案600許可權
### --- 免密clone測試
[root@jenkins ~]# git clone [email protected]:/home/git/easy-springmvc-maven.git
### --- 無法建立連線解決方案
~~~ 更改jenkins使用者為root使用者;
~~~ 更改jenkins使用者為正常的普通使用者/bin/bash,將其的公鑰加入到git伺服器的git使用者中。
~~~ 此處暫時先用第一種解決辦法,更改 jenkins 的執行使用者為 root 使用者,通過如下方式進行更改:
~~~ # 將/etc/sysconfig/jenkins檔案由
[root@jenkins ~]# vim /etc/sysconfig/jenkins
JENKINS_USER="jenkins"
~~~ # 改為
JENKINS_USER="root"
~~~ # 然後再重啟即可。
[root@jenkins ~]# systemctl restart jenkins.service
### --- 報錯現象:
~~~ 無法連線倉庫:Invalid remote URL: git clone [email protected]:/home/git/repos/app.git
### --- 解決方案:
~~~ 配置祕鑰
附錄一:Git commit報錯處理
### --- 報錯現象
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
### --- 解決方案
[root@jenkins easy-springmvc-maven]# git config --global user.email "[email protected]"
[root@jenkins easy-springmvc-maven]# git config --global user.name "yanqi"
附錄二:CI/CD.Maven報錯處理### --- 報錯現象:Maven報錯處理
~~~ # 報錯現象:Maven報錯
~~~ ——>Dashboard——>maven-docker專案
~~~ ——>Build
~~~ ——>Maven Version
~~~ ——>Jenkins needs to know where your Maven is installed.
~~~ ——>Please do so from the tool configuration.
### --- 解決方案
~~~ ——>Dashboard——>全域性工具配置——>Maven安裝——>name:maven3.0.5
~~~ ——>MAVEN_HOME:/usr/share/maven
### --- 檢視maven安裝路徑
~~~ 檢視maven的安裝地址
[root@jenkins ~]# which mvn
/usr/bin/mvn
===============================END===============================
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart ——W.S.Landor
來自為知筆記(Wiz)