教你部署自己的"Github"-Gitlab

2年前 (2022) 程序员胖胖胖虎阿
242 0 0

环境准备

  • 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
          - "9443:443"
          # 映射gitlab http访问端口到主机9080
          - "9080:80"
          # 映射gitlab ssh访问端口到主机9022
          - "9022: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
        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

    教你部署自己的

    如果遇到docker-compose不可用的提示,请参考下面文章,进行docker-compose的安装。https://segmentfault.com/a/11...

  3. 执行命令查看,gitlab是否启动

    docker ps

    教你部署自己的

  4. 浏览器访问http://主机ip:9080
    教你部署自己的

    默认账号为root,初始密码在/etc/gitlab/initial_root_password中查看
    教你部署自己的
    gitlab部署安装成功!

版权声明:程序员胖胖胖虎阿 发表于 2022年11月11日 下午1:48。
转载请注明:教你部署自己的"Github"-Gitlab | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...