gitlab 資料配置遷移
背景
最開始gitlab是部署在公司內網的機器上,現在需要將gitlab遷移至阿里雲上。以下是遷移的詳細步驟。
準備工作
首先需要做的準備有這些。原系統為CentOS 7.4。
安裝相同版本的gitlab
-
檢視gitlab版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
根據系統以及gitlab版本去清華大學映象站_gitlab-ce 下載特定版本的gitlab的RPM或者DEB包。
# CentOS 6 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/yum/el6 # CentOS 7 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/yum/el7 # Debian 9 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/debian/pool/stretch/main/g/gitlab-ce/ https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/debian/pool/stretch/main/g/gitlab-ee/
-
安裝gitlab
安裝gitlab比較簡單
# 下載rpm包 wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.5.1-ce.0.el7.x86_64.rpm # 安裝rpm包(在下載的rpm包目錄下) yum install -y gitlab-ce-10.5.1-ce.0.el7.x86_64.rpm
備份
-
備份資料(使用者資訊、專案資訊、程式碼)
利用gitlab自帶的命令
gitlab-rake
進行資料備份,備份位於/etc/gitlab/gitlab.rb
中gitlab_rails['backup_path']
選項對應的目錄,備份目錄預設位於/var/opt/gitlab/backups
# 備份命令 gitlab-rake gitlab:backup:create # 檢視備份目錄 cat /etc/gitlab/gitlab.rb|grep gitlab_rails|grep backup_path
-
備份原伺服器上的配置資訊
儲存gitlab的域名、郵件傳送資訊、白名單等相關資訊的配置檔案
/etc/gitlab/gitlab.rb
儲存了gitlab的db secret資訊的配置檔案
/etc/gitlab/gitlab-secrets.json
-
打包備份資料和配置檔案
cp /etc/gitlab/gitlab.rb /etc/gitlab/gitlab-secrets.json /var/opt/gitlab/backups cd /var/opt/gitlab/backups tar zcvf gitlab_all_backup.tar.gz ./*
還原gitlab配置和資料
-
將打包的備份檔案上傳至新伺服器
scp gitlab_all_backup.tar.gz root@newHost:/tmp/ # 登入新伺服器 ssh root@newHost cd /tmp tar zxvf gitlab_all_backup.tar.gz
-
還原配置檔案
將配置檔案移到/etc/gitlab下cd /tmp # 反斜線是忽略系統的alias,不會有覆蓋檔案提醒,慎重使用 \mv gitlab.rb gitlab-secrets.json /etc/gitlab/ # 過載gitlab配置 gitlab-ctl reconfigure
-
還原資料
將之前備份的資料檔案移到/var/opt/gitlab/backups下,然後恢復資料cd /tmp # 注意前面一串數字為時間戳,將你備份的檔案移進去 mv 1552743127_2019_03_16_10.5.1_gitlab_backup.tar /var/opt/gitlab/backups # 恢復資料,注意BACKUP=後面只要 _gitlab_backup.tar 前面的版本號,如下 gitlab-rake gitlab:backup:restore BACKUP=1552743127_2019_03_16_10.5.1 # 過載gitlab配置 gitlab-ctl reconfigure
配置檔案/etc/gitlab/gitlab.rb簡介
external_url 'http://gitlab.xxx.com'#gitlab域名 gitlab_rails['gitlab_email_enabled'] = true#gitlab啟用email通知 gitlab_rails['gitlab_email_from'] = 'xxx-gitlab@xxx.com'#gitlab email來源 gitlab_rails['gitlab_email_display_name'] = 'gitlab-servce'#email展示名稱 gitlab_rails['gitlab_email_reply_to'] = 'xxx-gitlab@xxx.com'#gitlab返回郵箱地址 gitlab_rails['gitlab_email_subject_suffix'] = '' gitlab_rails['manage_backup_path'] = true#啟用backup路徑配置 gitlab_rails['backup_path'] = "/NFS"#設定gitlab備份路徑 gitlab_rails['gitlab_shell_ssh_port'] = xxxx#設定gitlab ssh埠 gitlab_rails['git_max_size'] = 20971520 gitlab_rails['git_timeout'] = 10 gitlab_rails['gitlab_shell_git_timeout'] = 800 gitlab_rails['rack_attack_git_basic_auth'] = { 'enabled' => true, 'ip_whitelist' => ["192.168.8.118"],#設定gitlab白名單列表 'maxretry' => 300, 'findtime' => 5, 'bantime' => 60 } gitlab_rails['initial_root_password'] = "xxxxxxx"#gitlab初始化root密碼 gitlab_rails['smtp_enable'] = true#設定gitlab 傳送郵件smtp伺服器資訊 gitlab_rails['smtp_address'] = "smtp.xxx.xxx.com"#設定smtp伺服器地址 gitlab_rails['smtp_port'] = xxx#設定smtp伺服器埠 gitlab_rails['smtp_user_name'] = "xxx-gitlab@xxx.com"#設定smtp使用者名稱 gitlab_rails['smtp_password'] = "xxxxxx"#設定smtp密碼 gitlab_rails['smtp_domain'] = "smtp.xxx.com"#設定smtp域名 gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true gitlab_rails['gitlab_email_from'] = 'xxx-gitlab@xxx.com' git_data_dir "/data/gitlab-data"#設定gitlab資料目錄 gitlab_rails['ldap_enabled'] = true#設定gitlab ldap認證 gitlab_rails['ldap_servers'] = YAML.load <<-'EOS' main: # 'main' is the GitLab 'provider ID' of this LDAP server label: 'LDAP' host: 'xx.xx.xx.xx'#設定ldap伺服器地址 port: xxx#設定ldap伺服器埠 uid: 'cn' method: 'plain' # "tls" or "ssl" or "plain" bind_dn: 'cn=xxx,dc=xxx,dc=com'#ldap bind dn password: 'xxx'#ldap bind dn使用者對應的密碼 active_directory: true allow_username_or_email_login: true#允許使用者名稱和郵箱登入 block_auto_created_users: false base: 'dc=xxx,dc=com'#ldap base dn資訊,即搜尋域 attributes: username: ['cn', 'uid'] email:['mail', 'email']