1. 程式人生 > 其它 >Linux 系統下搭建 Gitlab 伺服器

Linux 系統下搭建 Gitlab 伺服器

1、安裝依賴工具

// 安裝技術依賴
yum install -y curl policycoreutils-python openssh-server
 
// 啟動ssh服務/設定為開機啟動
sudo systemctl enable sshd
sudo systemctl start sshd

2、安裝 Postfix 郵件伺服器

// 安裝 postfix
sudo yum install -y postfix
 
// 啟動 postfix 並設定為開機啟動
sudo systemctl enable postfix
sudo systemctl start postfix

3、安裝防火牆

yum install firewalld systemd -y
// 開放 ssh、http 服務
sudo firewall-cmd --add-service=ssh --permanent
sudo firewall-cmd --add-service=http --permanent
 
//  設定防火牆規則
sudo firewall-cmd --reload

4、新增 gitlab 映象源並安裝 gitlab 伺服器

  • 映象地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.1.2-ce.0.el7.x86_64.rpm
  • 映象有點大,下載比較慢,根據網速快慢,需要等幾分鐘或者十幾分鍾
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.1.2-ce.0.el7.x86_64.rpm

5、安裝 gitlab

  • 安裝過程需要些時間,安心等待,如果出現下圖,則說明安裝成功
rpm -ivh gitlab-ce-13.1.2-ce.0.el7.x86_64.rpm

6、安裝後修改 gitlab 配置檔案,指定訪問伺服器 ip 和自定義埠

// 輸入編輯命令
vim /etc/gitlab/gitlab.rb

// 通過 vim 編輯命名找到 32 行
// 修改訪問 URL
// 格式:external_url '
http://ip:埠' external_url 'http://119.29.xx.xxx:8081'
  • 注意這裡設定的埠不能被佔用,預設是 8080 埠,如果 8080 已經使用,請自定義其它埠,像我這裡就用了 8081 ,需要在防火牆設定開放相對應得埠
  • 配置完以後還需要修改一處,去掉 puma['port'] = 8080 前面的註釋 #,並修改下埠號,注意和上面埠區分開,我這裡用了 8082
// 開放 8081、8082 埠
firewall-cmd --permanent --zone=public --add-port=8081/tcp
firewall-cmd --permanent --zone=public --add-port=8082/tcp

// 重新載入防火牆配置
firewall-cmd --reload 

7、重置 Gitlab(讓修改後的配置生效)

  • 重置過程中如果出現在 action run 時卡住了情況,可以通過執行如下命令解決
    • 卡住問題解決後,需要重新重置下 gitlab
  • 重置過程可能需要幾分鐘,耐心等待就好!
  • 出現 gitlab Reconfigured!,說明 OK 了。
// 重置 gitlab
gitlab-ctl reconfigure

// 解決重置過程中卡住問題
systemctl restart gitlab-runsvdir

8、啟動 gitlab 並通過 ip + 埠訪問

gitlab-ctl start      // 啟動所有 gitlab 元件;
gitlab-ctl stop       // 停止所有 gitlab 元件;
gitlab-ctl restart    // 重啟所有 gitlab 元件;
gitlab-ctl status     // 檢視服務狀態;
gitlab-ctl reconfigure        // 重新整理配置檔案;
vim /etc/gitlab/gitlab.rb     // 修改預設的配置檔案;
gitlab-rake gitlab:check SANITIZE=true --trace    // 檢查gitlab;
gitlab-ctl tail        // 檢視日誌;

9、登入 gitlab

  • 賬號:root
  • 密碼在檔案 /etc/gitlab/initial_root_password 中檢視
cat /etc/gitlab/initial_root_password