在CentOS上配置GitLab涉及多個步驟,包括安裝必要的依賴包、添加GitLab倉庫、安裝GitLab、配置GitLab以及啟動和訪問GitLab服務。以下是詳細的步驟:
首先,確保你的CentOS系統是最新的,并安裝必要的依賴包:
sudo yum update -y
sudo yum install -y curl policycoreutils-python openssh-server openssh-clients postfix perl git nodejs rsync cronie
打開必要的端口以允許HTTP和SSH訪問,并添加HTTP服務到防火墻:
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
添加GitLab的官方倉庫:
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
使用以下命令安裝GitLab社區版(CE):
sudo EXTERNAL_URL="http://your_domain_or_ip" yum install -y gitlab-ce
將 your_domain_or_ip 替換為你的GitLab服務器的域名或IP地址。
編輯GitLab的配置文件:
sudo vi /etc/gitlab/gitlab.rb
修改 external_url 為你設置的域名或IP地址。如果需要,添加以下配置以允許HTTP和HTTPS流量:
gitlab_rails['gitlab_shell_ssh_port'] = 22
nginx['listen_port'] = 80
nginx['listen_https'] = 443
保存并關閉文件,然后重新配置并啟動GitLab服務:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
在瀏覽器中輸入你在配置文件中設置的域名或IP地址,你應該能看到GitLab的登錄頁面。首次登錄時,需要設置管理員賬戶的密碼。
以上步驟提供了在CentOS上安裝和配置GitLab的基本指南。根據你的具體需求,可能還需要進行額外的配置,例如設置HTTPS、配置SSL證書等。在生產環境中,建議詳細配置GitLab的安全設置。