在CentOS上安裝和配置GitLab可以分為以下幾個步驟:
首先,確保你的CentOS系統已經安裝了必要的依賴包,包括 curl、policycoreutils、openssh-server、postfix 等。這些是GitLab運行所必須的。
sudo yum update -y
sudo yum install -y curl policycoreutils-python openssh-server postfix
安裝并配置SSH服務,并設置開機自啟動。同時,配置防火墻以允許HTTP和HTTPS流量。
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
添加GitLab的官方倉庫鏡像,以便使用YUM命令安裝GitLab。
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
使用YUM命令安裝GitLab CE(社區版)。
sudo yum install -y gitlab-ce
編輯GitLab的配置文件 /etc/gitlab/gitlab.rb,設置外部URL和其他必要配置。
sudo vi /etc/gitlab/gitlab.rb
在文件中添加或修改以下配置:
external_url 'http://your_domain_or_ip' # 替換為你的服務器地址
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.example.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "your_email@example.com"
gitlab_rails['smtp_password'] = "your_password"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
保存并退出編輯器,然后重新配置并啟動GitLab服務。
sudo gitlab-ctl reconfigure
sudo gitlab-ctl start
打開瀏覽器,訪問你在配置文件中設置的地址,例如 http://your_domain_or_ip。首次訪問時,GitLab會引導你設置管理員賬戶和密碼。
如果你需要使用郵件通知功能,可以配置PostgreSQL數據庫并設置SMTP郵件服務器。
sudo yum install -y postgresql-server postgresql-contrib
sudo postgresql-setup initdb
sudo systemctl enable postgresql
sudo systemctl start postgresql
編輯PostgreSQL的配置文件 /var/lib/pgsql/data/pg_hba.conf,將 peer 改為 md5。
local all all md5
然后重啟PostgreSQL服務。
sudo systemctl restart postgresql
以上步驟應該可以幫助你在CentOS上成功安裝和配置GitLab。如果在安裝過程中遇到任何問題,可以參考GitLab的官方文檔或尋求社區幫助。