Debian9 installs the specified version of gitlab and implements backup and restore

Introduction
由于项目分割 需要搭建双仓库地址,但是之前的gitlab是旧版本的10.1.1版本的。
现在实现备份还原,则需要同样版本的gitlab

Check gitlab version

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

Version inconsistent backup and restore error

Debian9 installs the specified version of gitlab and implements backup and restore

gitlab get installation

[官方下载安装地址](https://packages.gitlab.com/gitlab/gitlab-ce/packages/debian/jessie/gitlab-ce_10.1.1-ce.0_amd64.deb)

Deploy and install 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

Modify the gitlab configuration file

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 # is the address for access and gitlab clone external display

Debian9 installs the specified version of gitlab and implements backup and restore

gitlab_rails['gitlab_shell_ssh_port'] # is the address of your server ssh monitoring, the default is 22.
gitlab_rails['redis_host'] #redis server listening address, default localhost

Check configuration and start gitlab

root@test:~#  gitlab-ctl reconfigure  #检查配置文件
root@test:~#  gitlab-ctl restart 

nginx proxy to 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;
          }

        }

Start error 502 processing method

1 nginx access permission denied
Debian9 installs the specified version of gitlab and implements backup and restore

 处理方式:  
      ps -ef|grep nginx #查看ngxin启动用户
      sudo usermod -aG gitlab-www www  #授权nginx用户附加组 为gitlab-www
      /etc/init.d/nginx restart   # 重启nginx

2 Other error usage

   gitlab-rake gitlab:check 检查报错

3 Unicorn Port Occupation Check whether port 8080 is occupied or not. Modify the port

   unicorn['port'] = 8091   #unicorn监听端口(netstat -ntpl查看服务器已经占用的端口,不要冲突,不然起不来unicorn服务)

gitlab backup and restore

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 确认    

Guess you like

Origin blog.51cto.com/9025736/2553853