在CentOS上实现GitLab的高可用部署可以通过多种方式来完成,以下是一个基本的步骤指南,使用Keepalived和HAProxy来实现高可用性。
在所有服务器上安装必要的依赖包:
sudo yum install -y policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
在所有服务器上安装GitLab。你可以使用官方的安装脚本或者手动安装。这里使用官方脚本:
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="http://yourdomain.com" yum install gitlab-ce
编辑GitLab配置文件 /etc/gitlab/gitlab.rb
,设置外部URL和其他必要的配置:
external_url 'http://yourdomain.com'
gitlab_rails['lfs_enabled'] = true
gitlab_rails['gitlab_shell_ssh_port'] = 2222
然后重新配置并重启GitLab:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
在两台服务器上安装Keepalived:
sudo yum install -y keepalived
编辑Keepalived配置文件 /etc/keepalived/keepalived.conf
:
主服务器(假设IP为192.168.1.101):
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
virtual_ipaddress {
192.168.1.100
}
}
备用服务器(假设IP为192.168.1.102):
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
virtual_ipaddress {
192.168.1.100
}
}
启动Keepalived服务:
sudo systemctl enable keepalived
sudo systemctl start keepalived
在两台服务器上安装HAProxy:
sudo yum install -y haproxy
编辑HAProxy配置文件 /etc/haproxy/haproxy.cfg
:
global
log /dev/log local0
log /dev/log local1 notice
daemon
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http_front
bind *:80
stats uri /haproxy?stats
default_backend http_back
backend http_back
balance roundrobin
server gitlab1 192.168.1.101:80 check
server gitlab2 192.168.1.102:80 check
启动HAProxy服务:
sudo systemctl enable haproxy
sudo systemctl start haproxy
http://yourdomain.com
,你应该能够看到GitLab的登录页面。通过以上步骤,你可以在CentOS上实现GitLab的高可用部署。根据实际需求,你可能还需要配置SSL证书、监控和日志记录等。