本文介紹如何在debian系統上部署并配置gitLab和gitlab Runner,實現高效的持續集成/持續交付(CI/CD)流程。
一、GitLab安裝
- 系統更新: 確保系統軟件包是最新的:
sudo apt update sudo apt upgrade
- 安裝依賴: 安裝必要的依賴項:
sudo apt install curl openssh-server ca-certificates postfix
- 添加GitLab倉庫: 添加GitLab軟件包倉庫:
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
- 安裝GitLab CE: 安裝GitLab社區版:
sudo apt install gitlab-ce
-
GitLab配置:
- 編輯 /etc/gitlab/gitlab.rb 文件,將 external_url 設置為你的GitLab服務器地址(域名或IP地址)。
- 運行以下命令重新配置GitLab:
sudo gitlab-ctl reconfigure
- 啟動GitLab服務: 啟動并設置GitLab服務開機自啟動:
sudo systemctl start gitlab sudo systemctl enable gitlab
- 訪問GitLab: 通過瀏覽器訪問你的GitLab服務器地址,完成管理員賬號和密碼的設置。
二、GitLab Runner安裝與配置
-
安裝GitLab Runner:
對于Debian/ubuntu系統:
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash sudo apt get install gitlab-ci-multi-runner
-
注冊GitLab Runner:
- 在你的GitLab項目中,進入CI/CD設置頁面,找到Runners部分,獲取注冊命令。
- 執行該命令,輸入你的GitLab服務器URL和注冊令牌。
-
配置GitLab Runner服務:
- 檢查 /etc/systemd/system/gitlab-runner.service 文件配置是否正確。
- 運行以下命令啟動并設置GitLab Runner服務開機自啟動:
sudo systemctl daemon-reload sudo systemctl start gitlab-runner.service sudo systemctl enable gitlab-runner.service
- 配置CI/CD流水線: 在你的GitLab項目根目錄下創建 .gitlab-ci.yml 文件,定義你的CI/CD流水線任務(構建、測試、部署等)。
完成以上步驟后,你便可以在Debian系統上成功運行GitLab和GitLab Runner,并利用其強大的CI/CD功能進行項目構建和部署。 根據實際需求,你可能還需要進行其他配置,例如設置Harbor鏡像倉庫、配置ssl證書等。
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END