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

李博帥發表於2022-11-24

環境準備

  • 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

    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
    gitlab部署安裝成功!

相關文章