一、 安装

  • docker安装

    • 拉取镜像 docker pull gitlab/gitlab-ce:rc

    • 使用docker-file创建容器

      ##docker file
      version: "3"
      services:
        gitlab:
          image: 'gitlab/gitlab-ce:rc'
          restart: always
          hostname: 'git.abc.com'
          environment:
            GITLAB_OMNIBUS_CONFIG: |
              external_url 'http://git.abc.com'
              gitlab_rails['gitlab_shell_ssh_port'] = 2228
          ports:
            - '127.0.0.1:8000:80'
            - '2228:22'
          volumes:
            - '/data/gitlab/config:/etc/gitlab'
            - '/data/gitlab/logs:/var/log/gitlab'
            - '/data/gitlab/data:/var/opt/gitlab'
            - '/etc/localtime:/etc/localtime:ro'
             
      ##项目启动命令##
      # docker-compose -f docker-gitlab-compose.yml  -p gitlab up  -d
             
      ##项目停止命令##
      # docker-compose -f docker-gitlab-compose.yml  -p gitlab down
      
  • 主机安装

    ####安装镜像源
    vim /etc/yum.repos.d/gitlab-ce.repo
    #添加内容如下,使用清华源,速度快
    [gitlab-ce]
    name=Gitlab CE Repository
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
    gpgcheck=0
    enabled=1
         
    #生成yum缓存
    yum makecache
         
    ####安装gitlab-ce
    yum install gitlab-ce
    

二、配置

  • gitlab配置修改

    vim /etc/gitlab/gitlab.rb
    
    #配置完成重启gitlab 重置配置
    gitlab-ctl reconfigure
         
    # 启动Gitlab所有组件
    gitlab-ctl start
         
    # 停止Gitlab所有组件
    gitlab-ctl stop
         
    # 重启Gitlab所有组件
    gitlab-ctl restart
         
    
  • nginx配置

    server
    {
       listen 80;
       server_name  git.abc.com;
       return       301 https://git.abc.com$request_uri;
       access_log off;
    }
         
    server
    {
            listen 443 backlog=5120;
         
            server_name git.abc.com;
            ssl on;
            ssl_certificate /usr/local/nginx/conf/cert/11.pem;
            ssl_certificate_key /usr/local/nginx/conf/cert/11.key;
            ssl_session_timeout 5m;
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_prefer_server_ciphers on;
         		
           set $node_port 8000;
         		
            location / {
                # 这个大小的设置非常重要,如果 git 版本库里面有大文件,设置的太小,文件push 会失败,根据情况调整
                client_max_body_size 50m; 
                proxy_redirect off;
                     
               #以下确保 gitlab中项目的 url 是域名而不是 http://git,不可缺少
                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 Upgrade $http_upgrade;
               proxy_set_header Connection "upgrade";
               proxy_pass http://127.0.0.1:$node_port$request_uri;
           }
    
           access_log logs/git_access.log;
           error_log  logs/git_error.log;
    }
    

三、docker安装更新

可以参考gitlab官方更新文档

#1.拉取新的gitlab镜像
docker pull gitlab/gitlab-ce:latest

#2.修改docker-gitlab-compose.yml 中的gitlab image为最新镜像

#3.停止并删除gitlab的docker
docker-compose -f docker-gitlab-compose.yml  -p gitlab down

# 4.使用新镜像创建
docker-compose -f docker-gitlab-compose.yml  -p gitlab up  -d