在CentOS上搭建GitLab環境是一個相對復雜的過程,需要安裝多個依賴項并進行配置。以下是一個基本的步驟指南,幫助你在CentOS 7上安裝和配置GitLab。
更新系統:
sudo yum update -y
安裝必要的依賴包:
sudo yum install -y curl policycoreutils-python openssh-server openssh-clients postfix wget
配置SSH服務:
sudo systemctl enable sshd
sudo systemctl start sshd
配置防火墻:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld
安裝Postfix(用于郵件通知,可選):
sudo yum install postfix -y
sudo systemctl enable postfix
sudo systemctl start postfix
添加GitLab的YUM源:
創建 /etc/yum.repos.d/gitlab-ce.repo
文件,內容如下:
[gitlab-ce]
name=GitLab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
gpgcheck=0
enabled=1
安裝GitLab CE:
sudo yum install -y gitlab-ce
修改GitLab配置文件:
使用 vim
編輯 /etc/gitlab/gitlab.rb
文件,修改外部URL:
sudo vim /etc/gitlab/gitlab.rb
將 external_url 'http://your_server_ip'
修改為你的服務器IP地址或域名。
重新配置GitLab:
sudo gitlab-ctl reconfigure
啟動GitLab服務:
sudo gitlab-ctl start
設置首頁語言(可選):
用戶登錄后,進入 Preferences
-> Localization
,選擇簡體中文并保存。
打開瀏覽器,訪問 http://your_server_ip
,按照提示設置root用戶的密碼。
修改監聽端口:
編輯 /etc/gitlab/gitlab.rb
文件,修改 external_url
和 gitlab_rails['smtp_port']
,然后執行 sudo gitlab-ctl reconfigure
。
修改數據存儲路徑:
編輯 /etc/gitlab/gitlab.rb
文件,修改 git_data_dirs
和 backup_path
,然后執行 sudo gitlab-ctl reconfigure
。
以上步驟應該可以幫助你在CentOS 7上成功搭建GitLab環境。如果在安裝過程中遇到問題,建議參考GitLab的官方文檔或尋求在線幫助。