Linux 上容器化部署 GitLab 的可落地方案
一 方案总览与选型
二 单机 Docker 快速部署
docker run -d \
--hostname gitlab.example.com \
-p 8443:443 -p 8080:80 -p 2222:22 \
--name gitlab \
--restart always \
-v /srv/gitlab/config:/etc/gitlab \
-v /srv/gitlab/logs:/var/log/gitlab \
-v /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
三 Docker Compose 编排部署
version: '3.6'
services:
gitlab:
image: gitlab/gitlab-ce:latest
container_name: gitlab
restart: always
hostname: 'gitlab.example.com'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://gitlab.example.com'
gitlab_rails['gitlab_shell_ssh_port'] = 22
nginx['redirect_http_to_https'] = true
ports:
- '80:80'
- '443:443'
- '22:22'
volumes:
- /data/gitlab/config:/etc/gitlab
- /data/gitlab/logs:/var/log/gitlab
- /data/gitlab/data:/var/opt/gitlab
- /etc/localtime:/etc/localtime:ro
shm_size: '256m'
四 Kubernetes 生产级部署
helm repo add gitlab https://charts.gitlab.io
helm repo update
kubectl create namespace gitlab
五 关键配置与运维要点
nginx['enable'] = true
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/server_cert.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/private.key"
修改后执行:gitlab-ctl reconfigure 与 gitlab-ctl restart。