在CentOS系統上進行GitLab的集群部署,通常涉及多個步驟,包括準備環境、安裝GitLab、配置負載均衡和高可用性等。以下是一個基本的指南,幫助你在CentOS上部署GitLab集群:
首先,確保你的CentOS系統是最新的:
sudo yum update -y
安裝必要的依賴包:
sudo yum install -y curl policycoreutils openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
確保防火墻允許HTTP(80)、HTTPS(443)和SSH(22)端口:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --permanent --zone=public --add-service=ssh
sudo firewall-cmd --reload
添加GitLab官方倉庫:
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
安裝GitLab Community Edition:
sudo yum install -y gitlab-ce
編輯GitLab配置文件 /etc/gitlab/gitlab.rb
,設置外部URL:
external_url 'http://your-gitlab-domain.com'
運行以下命令以應用更改并重啟GitLab:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
安裝Nginx:
sudo yum install -y nginx
編輯Nginx配置文件 /etc/nginx/nginx.conf
,添加以下內容:
upstream gitlab {
server gitlab-node1.example.com;
server gitlab-node2.example.com;
}
server {
listen 80;
server_name your-gitlab-domain.com;
location / {
proxy_pass http://gitlab;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
啟動Nginx并設置開機自啟:
sudo systemctl start nginx
sudo systemctl enable nginx
你可以使用Let’s Encrypt獲取免費的SSL證書:
sudo yum install -y certbot python2-certbot-nginx
sudo certbot --nginx -d your-gitlab-domain.com
按照提示完成證書的獲取和配置。
訪問 http://your-gitlab-domain.com
,你應該能夠看到GitLab的登錄頁面。使用默認的用戶名和密碼(通常是 root
/ 5iveL!fe
)登錄。
為了實現高可用性,你可以考慮以下幾點:
通過以上步驟,你應該能夠在CentOS上成功部署一個GitLab集群。根據具體需求,你可能需要進行更多的配置和優化。