头图

环境准备

  • Centos 7
  • Docker 20.10.17(其他版本也是OK的)
  • Gitlab gitlab-ce:14.0.5-ce.0

写在前面

文章参考:https://soulteary.com/2021/07...

我自己用的云服务器只有4g内存,在部署了gitlab后,发现机器卡主不动了,一看内存直接来到了3.4左右。浏览器访问Gitlab页面,也是缓慢卡顿异常。遂发觉Gitlab本身带有的各种服务是很消耗内存的,于是在网上找寻如何有效解决gitlab消耗内存过大的问题。发现了,上面参考链接中的文章。下面是我的最佳实践:

准备Docker环境

推荐教程:https://segmentfault.com/a/11...

部署Gitlab(基于Docker)

  1. 任意目录下创建一个docker-compose.yml文件,内容如下:

    # yml的格式缩进可能被打乱了,需要自己进行一下格式化(必要!)
    version: "3"
    
    
    services:
      gitlab:
        restart: always
        # 设置镜像源
        image: gitlab/gitlab-ce:14.0.5-ce.0
        container_name: gitlab
        hostname: gitlab.soulteary.com
        ports:  
          # 映射gitlab https访问端口到主机9443
          - "8444:443"
          # 映射gitlab http访问端口到主机9080
          - "8980:80"
          # 映射gitlab ssh访问端口到主机9022
          - "8922:22"
        volumes:
          # 挂载gitlab配置文件目录到主机/usr/local/gitlab/config
          - /usr/local/gitlab/config:/etc/gitlab
          # 挂载gitlab日志文件目录到主机/usr/local/gitlab/logs
          - /usr/local/gitlab/logs:/var/log/gitlab
          # 挂载gitlab数据目录到主机/usr/local/gitlab/data
          - /usr/local/gitlab/data:/var/opt/gitlab
          # 如果启动报错, 可以删除这个
          - /usr/local/gitlab/config/gitlab.yml:/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
        environment:
          # 设置时区
          TZ: Asia/Shanghai
          GITLAB_OMNIBUS_CONFIG: |
            external_url 'http://gitlab.soulteary.com'
            gitlab_rails['time_zone'] = 'Asia/Shanghai'
    
            # 关闭电子邮件相关功能
            gitlab_rails['smtp_enable'] = false
            gitlab_rails['gitlab_email_enabled'] = false
            gitlab_rails['incoming_email_enabled'] = false
    
            # Terraform
            gitlab_rails['terraform_state_enabled'] = false
    
            # Usage Statistics
            gitlab_rails['usage_ping_enabled'] = false
            gitlab_rails['sentry_enabled'] = false
            grafana['reporting_enabled'] = false
    
            # 关闭容器仓库功能
            gitlab_rails['gitlab_default_projects_features_container_registry'] = false
            gitlab_rails['registry_enabled'] = false
            registry['enable'] = false
            registry_nginx['enable'] = false
    
            # 包仓库
            gitlab_rails['packages_enabled'] = false
            gitlab_rails['dependency_proxy_enabled'] = false
    
            # GitLab KAS
            gitlab_kas['enable'] = false
            gitlab_rails['gitlab_kas_enabled'] = false
    
            # Mattermost
            mattermost['enable'] = false
            mattermost_nginx['enable'] = false
    
            # Kerberos
            gitlab_rails['kerberos_enabled'] = false
            sentinel['enable'] = false
    
            # GitLab Pages
            gitlab_pages['enable'] = false
            pages_nginx['enable'] = false
    
            # 禁用 PUMA 集群模式
            puma['worker_processes'] = 0
            puma['min_threads'] = 1
            puma['max_threads'] = 2
    
            # 降低后台守护进程并发数
            sidekiq['max_concurrency'] = 5
    
            gitlab_ci['gitlab_ci_all_broken_builds'] = false
            gitlab_ci['gitlab_ci_add_pusher'] = false
    
            # 关闭监控
            prometheus_monitoring['enable'] = false
            alertmanager['enable'] = false
            node_exporter['enable'] = false
            redis_exporter['enable'] = false
            postgres_exporter['enable'] = false
            pgbouncer_exporter['enable'] = false
            gitlab_exporter['enable'] = false
            grafana['enable'] = false
            sidekiq['metrics_enabled'] = false        
  2. docker-compose.yml文件同目录下面,执行下面命令,启动gitlab

    docker-compose up -d

    image.png

    如果遇到docker-compose不可用的提示,请参考下面文章,进行docker-compose的安装。https://segmentfault.com/a/11...
  3. 执行命令查看,gitlab是否启动

    docker ps

    image.png

  4. 浏览器访问http://主机ip:9080
    image.png

    默认账号为root,初始密码在/etc/gitlab/initial_root_password中查看
    image.png
  5. 遇到clone地址不对的情况
    http://ftxtool.org/2021/11/20...

李博帅
23 声望5 粉丝