环境介绍:
CentOS 6.8 final
gitlab:8.6.5
需求:gitlab从8.6.5升级到8.11.7
第一、gitlab8.6.5安装
参考《GitLab完整搭建(8.6.5).docx》
第二、gitlab8.6.5升级到8.11.7
0.升级之前Backup备份
# su - git
$ cd /home/git/gitlab
$ bundle exec rake gitlab:backup:create RAILS_ENV=production
备份的文件在/home/git/gitlab/tmp/backups目录下:
1.停止服务
# service gitlab stop
2.获取最新版本分支代码
$ su - git
$ cd /home/git/gitlab
$ git fetch --all
$ git checkout -- Gemfile.lock db/schema.rb
$ git checkout v8.11.7 -b v8.11.7
如果报错,删除修改过的文件
$ vi VERSION
将8.6.5替换为8.11.7
3.升级gitlab-shell版本
$ cd /home/git/gitlab-shell
$ git fetch
$ git checkout v`cat /home/git/gitlab/GITLAB_SHELL_VERSION` -b v`cat /home/git/gitlab/GITLAB_SHELL_VERSION`
4.升级gitlab-workhorse版本
$ cd /home/git/gitlab-workhorse
$ git fetch
$ git checkout v`cat /home/git/gitlab/GITLAB_WORKHORSE_VERSION` -b v`cat /home/git/gitlab/GITLAB_WORKHORSE_VERSION`
$ make
5. 安装库环境
$ cd /home/git/gitlab
修改Gem source
$ gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
# PostgreSQL
$bundle install --without development test mysql --deployment
# MySQL
$bundle install --without development test postgres --deployment
# Optional: clean up old gems
$bundle clean
# Run database migrations
$bundle exec rake db:migrate RAILS_ENV=production
# Clean up assets and cache
$bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production
6.启动gitlab服务
# service gitlab start
# service nginx restart
7.检查程序状态
检查GitLab及其环境是否配置正确:
$ bundle exec rake gitlab:env:info RAILS_ENV=production
确保没有报错,运行一次更彻底的检查:
$bundle exec rake gitlab:check RAILS_ENV=production
如果所有项目是绿色的,那么恭喜你升级完成!
gitlab从8.6.5升级到8.11.7到此结束。
第三、备份数据迁移
1.备份
1).备份mysql数据库
$ mysqldump -uroot -pxxxx gitlabhq_production > /tmp/gitlabhq_production.sql
2).备份keys
$ cp /home/git/.ssh/authorized_keys /tmp/authorized_keys
3).备份repos
$ cd /home/git/gitlab
$ bundle exec rake gitlab:backup:create RAILS_ENV=production
备份的文件在/home/git/gitlab/tmp/backups目录下
2.恢复数据
1). 导入仓库,检查权限
$cd /home/git
$tar zxvf repositories.tar.gz
如果权限有异常,直接重新赋权
$ chown -R git.git /home/git/repositories/
2).导入数据库
$ mysql -uroot -pxxx gitlabhq_production < gitlabhq_production.sql
3).导入keys
$ cat authorized_keys >> /home/git/.ssh/authorized_keys
4).导入repos
$ cd /home/git/gitlab/
$ bundle exec rake gitlab:import:repos RAILS_ENV=production
$ bundle exec rake gitlab:satellites:create RAILS_ENV=production
5).检测
$ bundle exec rake gitlab:check RAILS_ENV=production
如果检测没有异常,可以重启gitlab服务
# /etc/init.d/gitlab restart
第四、验证git pull/push与异常解决
1. git pull
2. git push
如果报错:
git.exe push –progress “origin” master:master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 350 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: GitLab: An unexpected error occurred (redis-cli returned 1).
remote: error: hook declined to update refs/heads/master
To http://192.168.3.124/caoyang/test1121.git
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to ‘http://192.168.4.251/caoyang/test1121.git’
屏蔽 /home/git/gitlab-shell/config.yml 47行redis配置