在Linux上进行GitLab的容器化部署,可以按照以下步骤进行:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose 创建存储目录:
mkdir -p /opt/docker/gitlab cd /opt/docker/gitlab 创建docker-compose.yml文件:
touch docker-compose.yml 编辑docker-compose.yml文件: 在docker-compose.yml文件中添加以下内容:
version: '3' services: gitlab: image: 'gitlab/gitlab-ce:latest' restart: always container_name: gitlab hostname: '192.168.1.200' environment: GITLAB_OMNIBUS_CONFIG: | gitlab_rails['time_zone'] = 'asia/shanghai' GITLAB_SSH_PORT: 22 GITLAB_HTTP_PORT: 80 GITLAB_外部URL: 'http://192.168.1.200' ports: - '80:80' - '22:22' volumes: - './config:/etc/gitlab' - './logs:/var/log/gitlab' - './data:/var/opt/gitlab' healthcheck: test: ["cmd", "/opt/gitlab/bin/gitlab-healthcheck", "--fail"] interval: 30s timeout: 10s retries: 5 deploy: resources: limits: cpus: '4.00' memory: 4096m reservations: cpus: '2.00' memory: 2048m 请将hostname处的内容修改为你实际的主机IP地址。
启动GitLab容器:
docker-compose up -d 放行端口(如果需要):
firewall-cmd --add-port=80/tcp --permanent firewall-cmd --add-port=22/tcp --permanent firewall-cmd --reload 访问GitLab管理页面: 打开浏览器,访问http://192.168.1.200,初次登录需要设置账号密码。使用用户名root和你设置的密码登录。
如果你想将GitLab配置为HTTPS,可以按照以下步骤进行:
生成SSL证书:
mkdir -p conf/ssl cd conf/ssl openssl genrsa -out server.key 2048 openssl genrsa -out private.key 2048 openssl req -new -key private.key -out cert_req.csr -subj "/C=CN/ST=TEST/L=TEST/O=test/OU=main/CN=*.gitpool.com/emailAddress=root@localhost.com" openssl x509 -req -days 365 -in cert_req.csr -signkey private.key -out server_cert.crt 修改docker-compose.yml文件:
version: '3' services: gitlab: image: 'gitlab/gitlab-ce:latest' restart: always container_name: gitlab hostname: 'gitlab' environment: TZ: 'Asia/Shanghai' GITLAB_OMNIBUS_CONFIG: | gitlab_rails['gitlab_shell_ssh_port'] = 22 gitlab_rails['http_port'] = 80 gitlab_rails['https_port'] = 443 GITLAB_外部URL: 'https://192.168.1.200' ports: - '443:443' - '80:80' volumes: - '/etc/localtime:/etc/localtime:ro' - './data:/var/opt/gitlab' - './logs:/var/log/gitlab' - './conf:/etc/gitlab' - './conf/ssl:/etc/gitlab/ssl' healthcheck: test: ["cmd", "/opt/gitlab/bin/gitlab-healthcheck", "--fail"] interval: 30s timeout: 10s retries: 5 deploy: resources: limits: cpus: '4.00' memory: 4096m reservations: cpus: '2.00' memory: 2048m 修改GitLab配置文件:
vim /opt/docker/gitlab/conf/gitlab.rb 找到以下配置并修改:
nginx['enable'] = true nginx['client_max_body_size'] = '512m' nginx['redirect_http_to_https'] = true nginx['redirect_http_to_https_port'] = 80 nginx['ssl_certificate'] = "/etc/gitlab/ssl/server_cert.crt" nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/private.key" nginx['ssl_session_cache'] = "client_sessions" 重新配置并重启GitLab:
sudo gitlab-ctl reconfigure sudo gitlab-ctl restart 现在,你应该可以通过https://192.168.1.200访问配置为HTTPS的GitLab管理页面。
希望这些步骤能帮助你成功在Linux上进行GitLab的容器化部署。如果有任何问题,请参考GitLab的官方文档或相关社区资源。