在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集群。根据具体需求,你可能需要进行更多的配置和优化。