天天看點

debian9安裝指定版本gitlab,并實作備份還原

介紹
由于項目分割 需要搭建雙倉庫位址,但是之前的gitlab是舊版本的10.1.1版本的。
現在實作備份還原,則需要同樣版本的gitlab           

檢查gitlab版本

root@test:~#  cat /opt/gitlab/embedded/service/gitlab-rails/VERSION           

版本不一緻備份恢複報錯

debian9安裝指定版本gitlab,并實作備份還原

gitlab擷取安裝

[官方下載下傳安裝位址](https://packages.gitlab.com/gitlab/gitlab-ce/packages/debian/jessie/gitlab-ce_10.1.1-ce.0_amd64.deb)           

部署安裝gitlab

root@test:~# curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
root@test:~#  sudo apt-get install gitlab-ce=10.1.1-ce.0           

修改gitlab配置檔案

vim /etc/gitlab/gitlab.rb
 external_url 'http://gitlab.hanye.com'   #gitlab展示和clone位址
 gitlab_rails['object_store']['enabled'] = false
 gitlab_rails['object_store']['connection'] = {}
 gitlab_rails['object_store']['storage_options'] = {}
 gitlab_rails['object_store']['proxy_download'] = false
 gitlab_rails['object_store']['objects']['artifacts']['bucket'] = nil
 gitlab_rails['object_store']['objects']['external_diffs']['bucket'] = nil
 gitlab_rails['object_store']['objects']['lfs']['bucket'] = nil
 gitlab_rails['object_store']['objects']['uploads']['bucket'] = nil
 gitlab_rails['object_store']['objects']['packages']['bucket'] = nil
 gitlab_rails['object_store']['objects']['dependency_proxy']['bucket'] = nil
 gitlab_rails['object_store']['objects']['terraform_state']['bucket'] = nil
 gitlab_rails['gitlab_shell_ssh_port'] = 7080   #修改gitlab使用SSH的端口
 gitlab_rails['gitlab_shell_git_timeout'] = 800  #修改gitlab使用SSH連結逾時時間
 gitlab_rails['rack_attack_git_basic_auth'] = {    #開放白名單
    'enabled' => true,
    'ip_whitelist' => ["127.0.0.1","123.160.235.102","123.160.172.34","123.160.234.96"],
    'maxretry' => 100,
    'findtime' => 60,
    'bantime' => 3600
  }
 gitlab_rails['redis_host'] = "127.0.0.1"   #連結redis服務配置
 gitlab_rails['redis_port'] = 6379
 gitlab_rails['redis_password'] = "passwd"
 gitlab_rails['redis_database'] = 0
 unicorn['listen'] = '192.168.31.10'   #unicorn監聽位址(内網或者外網,看自己需要) 
 unicorn['port'] = 8091   #unicorn監聽端口(netstat -ntpl檢視伺服器已經占用的端口,不要沖突,不然起不來unicorn服務)
 nginx['enable'] = false   #nginx不開啟 預設使用socket監聽
 nginx['listen_addresses'] = ['*', '[::]']           

external_url #是通路和gitlab克隆對外展示的位址

debian9安裝指定版本gitlab,并實作備份還原

gitlab_rails['gitlab_shell_ssh_port'] #是你的伺服器ssh監聽的位址,預設22。

gitlab_rails['redis_host'] #redis伺服器監聽位址,預設localhost

檢查配置和啟動gitlab

root@test:~#  gitlab-ctl reconfigure  #檢查配置檔案
root@test:~#  gitlab-ctl restart            

nginx 代理到 gitlab

cat /usr/local/nginx/conf/vhost/gitlab.hanye.com.conf
    proxy_cache_path proxy_cache keys_zone=gitlab:10m max_size=1g levels=1:2;
 proxy_cache gitlab;

 map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
 }

        upstream gitlab-workhorse {
          server unix:/var/opt/gitlab/gitlab-workhorse/socket;
        }

        server {
          listen *:80;
          server_name  gitlab.hanye.com;
          server_tokens off; ## Don't show the nginx version number, a security best practice
          include deny_host.conf;
          client_max_body_size 0;
          add_header Strict-Transport-Security "max-age=31536000";
          error_log /data/wwwlogs/gitlab_error_nginx.log;
          access_log /data/wwwlogs/access_nginx.log combined;

          if ($http_host = "") {
            set $http_host_with_default "gitlab.hanye.com";
          }

          if ($http_host != "") {
            set $http_host_with_default $http_host;
          }
          proxy_read_timeout      3600;
          proxy_connect_timeout   300;
          proxy_redirect          off;
          proxy_http_version 1.1;

          proxy_set_header Host $http_host_with_default;
          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 $connection_upgrade;
          proxy_set_header X-Forwarded-Proto http;

          location ~ (\.git/gitlab-lfs/objects|\.git/info/lfs/objects/batch$) {
            proxy_cache off;
            proxy_pass http://gitlab-workhorse;
            proxy_request_buffering off;
          }

          location / {
            proxy_cache off;
            proxy_pass  http://gitlab-workhorse;
          }

          location /assets {
            proxy_cache gitlab;
            proxy_pass  http://gitlab-workhorse;
          }

          error_page 404 /404.html;
          error_page 422 /422.html;
          error_page 500 /500.html;
          error_page 502 /502.html;
          location ~ ^/(404|422|500|502)(-custom)?\.html$ {
            root /opt/gitlab/embedded/service/gitlab-rails/public;
            internal;
          }

        }           

啟動報錯 502 處理方式

處理方式:  
      ps -ef|grep nginx #檢視ngxin啟動使用者
      sudo usermod -aG gitlab-www www  #授權nginx使用者附加組 為gitlab-www
      /etc/init.d/nginx restart   # 重新開機nginx           
gitlab-rake gitlab:check 檢查報錯           
unicorn['port'] = 8091   #unicorn監聽端口(netstat -ntpl檢視伺服器已經占用的端口,不要沖突,不然起不來unicorn服務)           

gitlab備份還原

gitlab備份:
         /usr/bin/gitlab-rake gitlab:backup:create > /dev/null
             預設備份位址: gitlab_rails['backup_path'] = "/var/opt/gitlab/backups" 指定
             會在/var/opt/gitlab/backups生成一個序号+日期的備份檔案
    gitlab還原
        gitlab-rake gitlab:backup:restore BACKUP=1606073532_2020_11_23_10.1.1 #指定序号恢複
        會覆寫使用者配置 需要手動 yes 确認
  會覆寫 SSH-key檔案 需要Yes 确認