Docker Compose方式安装GitLab

文章目录

  • 用Docker Compose方式安装GitLab
    • 前提条件
    • 一键自动化以Docker Compose方式安装GitLab
    • GitLab Docker Compose文件
    • 安装和运行GitLab
    • 打开防火墙端口
    • 访问GitLab
    • 配置Gitlab
    • Troubleshooting
    • 其它参考文档

用Docker Compose方式安装GitLab

前提条件

要求至少2vCPU4G配置,否则会因为CPU太忙或内存不足导致GitLab不断重启和502错误。

参见:

  • https://gitlab.com/help/install/requirements.md

建议安装htop里监控CPU、内存和Swap的资源使用情况:

yum install htop -y

一键自动化以Docker Compose方式安装GitLab

  • https://github.com/cookcodeblog/OneDayDevOps/blob/master/components/gitlab-docker/install_gitlab.sh

GitLab Docker Compose文件

GitLab官方给的GitLab Docker镜像启动后无法访问,且定位不到问题,所以使用GitHub著名博主sameersbn封装的镜像。

Gitlab的docker-compose.yml参见:https://github.com/sameersbn/docker-gitlab

  1. Replace values of below keys using pwgen -Bsv1 64
  • GITLAB_SECRETS_DB_KEY_BASE
  • GITLAB_SECRETS_SECRET_KEY_BASE
  • GITLAB_SECRETS_OTP_KEY_BASE

Run yum install pwgen -y to install pwgen if it is not installed.

  1. Set value of GITLAB_HOST

  2. Set value of password

  3. Set timezone TZ as Asia/Shanghai and GITLAB_TIMEZONE=Beijing

GITLAB_TIMEZONE的值为RubyOnRails的timezone语法,参见:

https://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html

一个GitLab的docker-compose.yml例子:

https://github.com/cookcodeblog/OneDayDevOps/blob/master/components/gitlab-docker/docker-compose.yml

这里使用10080和10022分别作为HTTP和SSH端口,并设置时区为中国时间。

安装和运行GitLab

mkdir -p /opt/gitlab
cp docker-compose.yml /opt/gitlab
cd /opt/gitlab

docker-compose up -d

查看日志:

docker-compose logs -f

Debug:

docker-compose exec gitlab /bin/bash

打开防火墙端口

在防火墙上打开HTTP和SSH端口:

firewall-cmd --list-all

# http port
firewall-cmd --zone=public --add-port=10080/tcp
firewall-cmd --zone=public --add-port=10080/tcp --permanent

# ssh port
firewall-cmd --zone=public --add-port=10022/tcp
firewall-cmd --zone=public --add-port=10022/tcp --permanent

firewall-cmd --reload
firewall-cmd --list-all

访问GitLab

在浏览器中打开http://:10080

配置Gitlab

参见:

  • 配置GitLab

Troubleshooting

Q: GitLb不断重启,CPU负载很高,且报错:unicorn (exit status 1; not expected)

A:

  1. 先运行htop检查服务器的CPU和内存资源使用情况,最少需要2vCPU4G

  2. 运行ulimit -a查看ulimit,并可运行以下命令增加ulimit

    ulimit -u unlimited
    ulimit -n 65535
    

    参见:https://blog.csdn.net/duanbiren123/article/details/80190750

  3. 运行docker-compose logs -f查看日志

  4. 运行以下命令:

    docker-compose exec gitlab tail -f /var/log/gitlab/gitlab/unicorn.stderr.log
    

    查看unicorn日志,如果日志中报错如下:

    /home/git/gitlab/vendor/bundle/ruby/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:205:in `pid=': Already running on PID:581 (or pid=/home/git/gitlab/tmp/pids/unicorn.pid is stale) (ArgumentError)
    

    则需要执行以下命令删除unicorn.pid,再重启GitLab:

    docker-compose exec gitlab rm -f /home/git/gitlab/tmp/pids/unicorn.pid && docker-compose down && docker-compose up -d
    
  5. 或者更彻底地先删除持久卷,再重启GitLab:

    docker-compose exec gitlab rm -f /home/git/gitlab/tmp/pids/unicorn.pid && docker-compose down && rm -rf /srv/docker/gitlab && docker-compose up -d
    
  6. 重启浏览器,再次访问GitLab

参考文档:

  • https://blog.stead.id.au/2017/03/synology-gitlab-error-502.html
  • https://github.com/sameersbn/docker-gitlab/issues/1861

Q: Docker Compose启动GitLab不成功,报错:Bind for 0.0.0.0:10080 failed: port is already allocated’

A:

  1. 先运行docker stop gitlab停止GitLab相关容器
  2. 再运行docker-compose up -d启动GitLab

其它参考文档

  • https://docs.gitlab.com/omnibus/docker/#install-gitlab-using-docker-compose
  • https://docs.gitlab.com/omnibus/docker/#pre-configure-docker-container
  • https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/files/gitlab-config-template/gitlab.rb.template
  • https://hub.docker.com/r/gitlab/gitlab-ce
  • https://developer.ibm.com/code/2017/07/13/step-step-guide-running-gitlab-ce-docker/

你可能感兴趣的:(Docker,GitLab)