debian9安裝指定版本gitlab,並實現備份還原

腫諏遜汲發表於2020-12-01

  介紹

  由於專案分割需要搭建雙倉庫地址,但是之前的gitlab是舊版本的10.1.1版本的。

  現在實現備份還原,則需要同樣版本的gitlab

  檢查gitlab版本

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

  版本不一致備份恢復報錯

  debian9安裝指定版本gitlab,並實現備份還原

  gitlab獲取安裝

  [官方下載安裝地址]()

  部署安裝gitlab

  root test:~#curl-s |sudo bash

  root test:~#sudo apt-get install gitlab-ce=10.1.1-ce.0

  修改gitlab配置檔案

  vim/etc/gitlab/gitlab.rb

  external_url'展示和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

  proxy_request_buffering off;

  }

  location/{

  proxy_cache off;

  proxy_pass

  }

  location/assets{

  proxy_cache gitlab;

  proxy_pass

  }

  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,並實現備份還原

  處理方式:

  ps-ef|grep nginx#檢視ngxin啟動使用者

  sudo usermod-aG gitlab-www www#授權nginx使用者附加組為gitlab-www

  /etc/init.d/nginx restart#重啟nginx

  2其他報錯使用

  gitlab-rake gitlab:check檢查報錯

  3 unicorn埠占用檢查8080埠是否被佔用被佔用修改埠

  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確認


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69920892/viewspace-2738549/,如需轉載,請註明出處,否則將追究法律責任。

相關文章