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 處理方式

1 nginx訪問 權限拒絕
debian9安裝指定版本gitlab,並實現備份還原html

處理方式:  
      ps -ef|grep nginx #查看ngxin啓動用戶
      sudo usermod -aG gitlab-www www  #受權nginx用戶附加組 爲gitlab-www
      /etc/init.d/nginx restart   # 重啓nginx

2 其餘報錯 使用 nginx

gitlab-rake gitlab:check 檢查報錯

3 unicorn 端口占用 檢查8080端口是否被佔用 被佔用修改端口git

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 確認
相關文章
相關標籤/搜索