Gitlab从 7.1.1 升级到 10.6.6

参考

  • https://blog.securityevaluators.com/upgrading-gitlab-ce-from-a-6-9-2-source-installation-to-10-1-0-omnibus-a-novel-cf8c4f78bf99
  • https://fak3r.com/2017/12/11/upgrading-gitlab-from-6x-to-10x/
  • https://www.huangzz.xyz/gitlab-8-upgrading-gitlab-10-considerations.html

安装包下载

  • https://about.gitlab.com/downloads/archives/
  • https://packages.gitlab.com/gitlab/gitlab-ce

安装 7.1.1 版本,迁移数据

rpm -ivh gitlab-7.1.1_omnibus-1.el6.x86_64.rpm
mkdir -p /etc/gitlab
vim /etc/gitlab/gitlab.rb
vim /var/opt/gitlab/gitlab-rails/etc/gitlab.yml

mkdir -p /data/gitlab/git-data/repositories /data/gitlab/backups /data/gitlab/git-data/gitlab-satellites; chown -R git:git /data/gitlab
cat /etc/gitlab/gitlab.rb

# Change the external_url to the address your users will type in their browser
external_url 'http://gitlab.xxx.com'
git_data_dir '/data/gitlab/git-data/'
gitlab_rails['backup_path'] = '/data/gitlab/backups'
gitlab-ctl reconfigure
gitlab-ctl restart
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl status

gitlab-rake gitlab:backup:restore BACKUP={{LATEST,timestamp_only}}
# 空仓库会 FAILED  耗时2小时

gitlab-ctl restart

gitlab-rake gitlab:check SANITIZE=true
# 然后fix error

gitlab-rake gitlab:satellites:create RAILS_ENV=production
# gitlab.yml 中配置的 /var/opt/gitlab/git-data/gitlab-satellites 目录被写满了
# 修改成 /data/gitlab/git-data/gitlab-satellites,把原文件夹下面全删了,再重新运行命令

fix check errors

git config --global user.name  "GitLab"
git config --global user.email "gitlab@xxx.com"
chmod -R ug+rwX,o-rwx /data/gitlab/git-data/repositories
chmod -R ug-s /data/gitlab/git-data/repositories
find /data/gitlab/git-data/repositories -type d -print0 | sudo xargs -0 chmod g+s
chmod u+rwx,g=rx,o-rwx /data/gitlab/git-data/gitlab-satellites

测试可用性:

  • web
  • git clone, push
  • LDAP login

升级到 7.2.3

rpm -Uvh gitlab-7.2.3_omnibus-1.el6.x86_64.rpm
gitlab-ctl reconfigure
gitlab-ctl restart

升级到 7.10.4

rpm -Uvh gitlab-ce-7.10.4_omnibus-1.x86_64.rpm

# If you just upgraded from GitLab 7.9 or earlier, please run 
ln -sf   /opt/gitlab/bin/gitlab-ctl   /opt/gitlab/bin/gitlab-rake   /opt/gitlab/bin/gitlab-rails   /opt/gitlab/bin/gitlab-ci-rake   /opt/gitlab/bin/gitlab-ci-rails  /usr/bin/

gitlab-ctl reconfigure
gitlab-ctl restart

查看仓库大小

cd /data/gitlab/git-data/repositories
find -name "*.git" | xargs -i du -sh \{} |grep 'G' | sort -nrk1

升级到 8.10.0

8.2版本以上有新特性:Git LFS,Managing large files such as audio, video and graphics files has always been one of the shortcomings of Git. https://docs.gitlab.com/ee/workflow/lfs/manage_large_binaries_with_git_lfs.html

rpm -Uvh gitlab-ce-8.10.0-ce.1.el6.x86_64.rpm

# 会dump database , migrate 等。。。。

升级后,gitlab.yml会被修改,LDAP配置丢失,需要重新手动修改加上,不能直接修改 gitlab.yml,因为gitlab.yml会被 gitlab-ctl reconfigure 命令覆盖掉。

vim /etc/gitlab/gitlab.rb

gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_host'] = '172.18.8.xx'
gitlab_rails['ldap_port'] = 389
gitlab_rails['ldap_uid'] = 'xxx'
gitlab_rails['ldap_method'] = 'plain'
gitlab_rails['ldap_bind_dn'] = 'xxx'
gitlab_rails['ldap_password'] = 'xxx'
gitlab_rails['ldap_allow_username_or_email_login'] = true
gitlab_rails['ldap_base'] = 'xxx'

修改配置,开启 LFS 功能

vim /etc/gitlab/gitlab.rb

gitlab_rails['lfs_enabled'] = true
gitlab_rails['lfs_storage_path'] = "/data/gitlab/git-data/lfs-objects"
mkdir /data/gitlab/git-data/lfs-objects
chown -R git:git /data/gitlab/git-data/lfs-objects

gitlab-ctl reconfigure
gitlab-ctl restart

如何使用 git lfs : https://github.com/git-lfs/git-lfs/wiki/Tutorial

# install git lfs from https://packagecloud.io/github/git-lfs/install
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
git lfs install

如果是一个新的仓库:

git lfs track "*.psd"
git add .gitattributes
git commit -m "track *.psd files using Git LFS"
git push origin master

将旧的仓库转换成LFS文件:

git rm --cached *.psd
git add *.psd
git commit -m "Convert last commit to LFS"

git lfs ls-files

push lfs 文件后报错

No such file or directory - git-lfs-authenticate (Errno::ENOENT)

原因是 git-lfs-authenticate 是 gitlab 8.12之后才支持的功能 ,所以升级吧

 升级到 8.11.0

rpm -Uvh gitlab-ce-8.11.0-ce.1.el6.x86_64.rpm
gitlab-rake gitlab:check SANITIZE=true

# fixing....
chown -R git /var/opt/gitlab/gitlab-rails/uploads
find /var/opt/gitlab/gitlab-rails/uploads -type f -exec chmod 0644 {} \;
find /var/opt/gitlab/gitlab-rails/uploads -type d -not -path /var/opt/gitlab/gitlab-rails/uploads -exec chmod 0700 {} \;

gitlab-ctl restart

升级到 8.15.0

rpm -Uvh gitlab-ce-8.15.0-ce.0.el6.x86_64.rpm

升级到 10.1.0

rpm -Uvh gitlab-ce-10.1.0-ce.0.el6.x86_64.rpm 
# 报错,说 PostgreSQL 版本太低

那么只能先升级内部 PostgreSQL,参考 https://docs.gitlab.com/omnibus/settings/database.html#upgrade-packaged-postgresql-server

gitlab-ctl upgrade
gitlab-ctl pg-upgrade

再升级

rpm -Uvh gitlab-ce-10.1.0-ce.0.el6.x86_64.rpm 
gitlab-rake gitlab:check SANITIZE=true 
gitlab-ctl reconfigure
gitlab-ctl restart

确认没问题后,可以删除老版本 PostgreSQL 的文件

rm -rf /var/opt/gitlab/postgresql/data.9.2.18

升级到 10.6.6

rpm -Uvh gitlab-ce-10.6.6-ce.0.el6.x86_64.rpm
gitlab-ctl reconfigure
gitlab-ctl restart

gitlab.rb内容

# Change the external_url to the address your users will type in their browser
external_url 'http://gitlab.xxx.com'
git_data_dir '/data/gitlab/git-data/'
gitlab_rails['backup_path'] = '/data/gitlab/backups'

gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_host'] = 'xxx'
gitlab_rails['ldap_port'] = 389
gitlab_rails['ldap_uid'] = 'xxx'
gitlab_rails['ldap_method'] = 'plain'
gitlab_rails['ldap_bind_dn'] = 'xxx'
gitlab_rails['ldap_password'] = 'xxx'
gitlab_rails['ldap_allow_username_or_email_login'] = true
gitlab_rails['ldap_base'] = 'xxx'

gitlab_rails['lfs_enabled'] = true
gitlab_rails['lfs_storage_path'] = "/data/gitlab/git-data/lfs-objects"

备份数据

新版本有copy方式进行备份,可以避免“data changes while tar is reading it, the error file changed as we read it may occur ” 这个问题。 这种备份方式会多占用一倍额外的硬盘空间。

gitlab-rake gitlab:backup:create STRATEGY=copy

配置ssh访问权限

与org服务器保持一致

vim /etc/hosts.allow

sshd:172.30.15.27
sshd:172.28.6.204