docker-compose搭建gitlab|内存优化

1 环境

  • docker
  • docker-compose
  • 良心云2核4G

2 搭建

  • mkdir /home/gitlab
    cd /home/gitlab
    vim docker-compose.yml
    
    version: '3'
    
    services:
      gitlab:
        image: 'gitlab/gitlab-ce:latest'
        restart: always
        container_name: gitlab-ce
        privileged: true
        environment:
          - GITLAB_OMNIBUS_CONFIG=external_url 'http://123.456.789.10'
          - TZ=Asia/Shanghai
        ports:
          - '1080:80'
        volumes:
          - '/home/gitlab/config:/etc/gitlab'
          - '/home/gitlab/logs:/var/log/gitlab'
          - '/home/gitlab/data:/var/opt/gitlab'
    

    注:

    1. 不使用https证书,无需映射443,22端口也无需映射

3 内存优化

  • vim /home/gitlab/config/gitlab.rb
    # 添加如下配置
    
    # 关闭业务监控
    prometheus_monitoring['enable'] = false
    puma['enable'] = true
    puma['worker_timeout'] = 60
    # 进程数(最低2,默认cpu核数+1)
    puma['worker_processes'] = 2
    puma['per_worker_max_memory_mb'] = 300
    # sidekiq并发数
    sidekiq['concurrency'] = 16
    # 数据库缓存大小
    postgresql['shared_buffers'] = "256MB"
    # 数据库并发数
    postgresql['max_worker_processes'] = 8
    
  • # gitlab-ce重新加载配置,容器id更改为自己的id
    docker exec -it 3nh32nhoeu gitlab-ctl reconfigure
    

启用swap分区也可以优化内存。


错误:
  • Gitlab 更新后gitlab-ctl reconfigure 提示 can only have one web server puma unicorn 错误

    在更新从老版本更新到14.0版本后,自动更新失败,手动执行gitlab-ctl reconfigure后,程序提示can only have on web server puma unicorn的错误。此错误是由于新版本的gitlab默认使用puma代替unicorn。如果你的配置文件里面以前启动了uncorn的设置,那么就会出现puma和unicorn冲突的问题。解决方法就是把gitlab.rb中的unicorn的配置改为puma相关配置即可。具体参数可以对照此表

    更改完成后再次执行gitlab-ctl reconfigure就可以成功了

    Unicorn Puma
    unicorn['enable'] puma['enable']
    unicorn['worker_timeout'] puma['worker_timeout']
    unicorn['worker_processes'] puma['worker_processes']
    n/a puma['ha']
    n/a puma['min_threads']
    n/a puma['max_threads']
    unicorn['listen'] puma['listen']
    unicorn['port'] puma['port']
    unicorn['socket'] puma['socket']
    unicorn['pidfile'] puma['pidfile']
    unicorn['tcp_nopush'] n/a
    unicorn['backlog_socket'] n/a
    unicorn['somaxconn'] puma['somaxconn']
    n/a puma['state_path']
    unicorn['log_directory'] puma['log_directory']
    unicorn['worker_memory_limit_min'] n/a
    unicorn['worker_memory_limit_max'] puma['per_worker_max_memory_mb']
    unicorn['exporter_enabled'] puma['exporter_enabled']
    unicorn['exporter_address'] puma['exporter_address']
    unicorn['exporter_port'] puma['exporter_port']

你可能感兴趣的:(docker-compose搭建gitlab|内存优化)