gitlab 迁移、升级打怪之路:8.8.5--> 8.10.8 --> 8.17.8 --> 9.5.9 --> 10.1.4 --> 10.2.5

 gitlab 迁移、升级打怪之路:8.8.5--> 8.10.8 --> 8.17.8 --> 9.5.9 --> 10.1.4 --> 10.2.5

gitlab 数据迁移、升级打怪之路:8.8.5--> 8.10.8 --> 8.17.8 --> 9.5.9 --> 10.1.4 --> 10.2.5
打怪之路背景介绍:
    我们的gitlab服务器原先服务器版本是8.8.5,使用的是源码安装,每个插件单独安装,数据库使用的是mysql5.6.39,
    现在有个需求是升级gitlab的版本。现在最新的gitlab的版本是11.0.2
    https://about.gitlab.com/blog/categories/releases/
    gitlab的版本更新也真是快,所以这里我们决定升级。
    因为我们使用的是源码安装,升级不太方便,同时gitlab不支持跨版本的数据迁移。所以......看下面:
1、新买一台服务器使用rpm(或者yum)的方式安装gitlab-ce-8.8.5(我这里用的是rpm包)
2、在老的gitlab服务器上备份数据,然后导入到新服务器的gitlab上。
3、数据导入完毕后,开始一步一步的版本升级。本次版本升级的历程是这样的:
    8.8.5--> 8.10.8 --> 8.17.8 --> 9.5.9 --> 10.1.4 --> 10.2.5


gitlab 安装包下载路径:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

gitlab 上部署pages:https://www.chenxuefei.com/2017/build-gitlab-pages/

1、初始化服务器
cd /init
sudo sh init.sh live test-gitlab

2、下载gitlab对应版本的安装包。这里我们下载8.8.5
cd /data/tools
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-8.8.5-ce.1.el7.x86_64.rpm

3、这里我们因为要设置把默认的数据库postgrasql 修改为mysql
这里我们之前的mysql 是5.6
所以这里我们使用yum 的形式来安装mysql
centos自带的repo是不会自动更新每个软件的最新版本,所以无法通过yum方式安装MySQL的高级版本。
所以,即使使劲用yum -y install mysql mysql-server mysql-devel,也是没用的。
所以,正确的安装mysql5姿势是要先安装带有可用的mysql5系列社区版资源的rpm包
cd /data/tools
sudo rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

这个时候查看当前可用的mysql安装资源:
[wwwad@test-gitlab tools]$ yum repolist enabled | grep "mysql.*-community*"
mysql-connectors-community/x86_64 MySQL Connectors Community                  51
mysql-tools-community/x86_64      MySQL Tools Community                       63
mysql56-community/x86_64          MySQL 5.6 Community Server                 395

这里我们只安装mysql-server  和  mysql-client
sudo yum -y install mysql-community-server
这里我们可以看到进度条中我们安装的是mysql5.6.40
 开机自启动
 sudo systemctl enable mysqld
 启动
 sudo systemctl start mysqld
 重置密码
 mysql_secure_installation
 
下面就是mysql有关gitlab的一些操作了
mysql> CREATE DATABASE IF NOT EXISTS`gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_general_ci`;
Query OK, 1 row affected (0.00 sec)


> GRANT SELECT, INSERT, UPDATE, DELETE,CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES, REFERENCES ON`gitlabhq_production`.* TO 'git'@'localhost' identified by "123456";
Query OK, 0 rows affected (0.00 sec)

> flush privileges;


4、接下来就是安装gitlab了
cd /data/tools/
sudo rpm -ivh gitlab-ce-8.8.5-ce.1.el7.x86_64.rpm

gitlab 的配置文件是/etc/gitlab/gitlab.rb
sudo vim /etc/gitlab/gitlab.rb
修改gitlab的访问地址
external_url "http://git.bigbao.com"

这里gitlab的默认配置文件使用的数据库是postgresql,这里我们要给他改成mysql的
postgresql['enable'] = false
gitlab_rails['db_adapter'] = 'mysql2'
gitlab_rails['db_encoding'] = 'utf8'
gitlab_rails['db_host'] = '10.19.104.17'
gitlab_rails['db_port'] = '3306'
gitlab_rails['db_username'] = 'git'
gitlab_rails['db_password'] = '123456'


执行:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

bundle禁止使用postgresql:不要舍弃mysql包
    sudo vi  /opt/gitlab/embedded/service/gitlab-rails/.bundle/config
    把mysql替换成postgresql

安装插件ruby插件,要不然执行gitlab:check 会报错,如果没有安装mysql-devel库也会有提示的。
cd /opt/gitlab/embedded/bin/
这里我们更换gem 源

#查看gem源
/opt/gitlab/embedded/bin/gem source
*** CURRENT SOURCES ***
 
https://rubygems.org/
 
#更换开源中国的gem源,否则使用时会出现错误
/opt/gitlab/embedded/bin/gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
 
/opt/gitlab/embedded/bin/gem sources --add https://rubygems.org/ --remove https://gems.ruby-china.org/

#查看更好后的gem源
/opt/gitlab/embedded/bin/gem sources
*** CURRENT SOURCES ***
 
https://gems.ruby-china.org/
 
#更改配置Gemfile文件的gem源
vi /opt/gitlab/embedded/service/gitlab-rails/Gemfile
source 'https://gems.ruby-china.org'

bundle install安装更新
cd /opt/gitlab/embedded/service/gitlab-rails/
执行下面的命令之前必须执行上面这一步,在这个目录下执行才有效
sudo /opt/gitlab/embedded/bin/bundle install    ---》这个命令会尝试更新系统中已经存在的gem包
报错了:
An error occurred while installing mysql2 (0.3.20), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.20'` succeeds before bundling.

执行一下

这里报错了:
libmysqlclient is missing. You may need to 'apt-get install libmysqlclient-dev' or 'yum install mysql-devel', and try again.

yum install mysql-devel
cd /opt/gitlab/embedded/service/gitlab-rails/
sudo /opt/gitlab/embedded/bin/gem install mysql2 -v'0.3.20'  这里安装之后check 的话一直说没有,就用了下面指定-i的方法。gem源我也是一直在切换china  和  官方源来回切
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.20
Parsing documentation for mysql2-0.3.20
Installing ri documentation for mysql2-0.3.20
Done installing documentation for mysql2 after 0 seconds
1 gem installed


这里我们要指定 -i 路径。之前这里被坑了
cd /opt/gitlab/embedded/service/gitlab-rails/
sudo /opt/gitlab/embedded/bin/gem install -i /opt/gitlab/embedded/service/gem/ruby/2.1.0  mysql2 -v'0.3.20'
[root@test-gitlab backups]# sudo /opt/gitlab/embedded/bin/gem install -i /opt/gitlab/embedded/service/gem/ruby/2.1.0  mysql2 -v'0.3.20'
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.20    这里会提示success
1 gem installed


这里我check的时候提示没有表,先不管,我们那老机器的备份文件来恢复
 gitlab-rake gitlab:backup:restore BACKUP:1530554436

还是提示没有相关表
那么执行初始化数据库
gitlab-rake gitlab:setup

 gitlab-rake gitlab:backup:restore BACKUP:1530554436
再次报错
ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'keys CASCADE' at line 1: DROP TABLE IF EXISTS keys CASCADE

》》keys占用了关键字,导入备份drop表的时候报错了,登录到数据库drop tables `keys`;成功删除表后,重新导入备份

mysql> use gitlabhq_production;
mysql> drop tables `keys`;

再来:
 gitlab-rake gitlab:backup:restore BACKUP:1530554436

终于导入成功了。要死人啊

这里我配置的URL是git.bigbao.com

所以这里修改数据库
use gitlabhq_production;

update  application_settings set signin_enabled = '1';

update  application_settings set home_page_url = 'http://git.bigbao.com';

update  application_settings set after_sign_out_path = 'http://git.bigbao.com'

浏览器访问登录 http://git.bigbao.com
访问成功,yes,感谢上帝,点击项目,我擦,500 了
看日志
tail -f production.log

Started GET "/market/market" for 180.163.108.210 at 2018-07-03 18:15:44 +0800
Processing by ProjectsController#show as HTML
  Parameters: {"namespace_id"=>"market", "id"=>"market"}
Completed 500 Internal Server Error in 57ms (ActiveRecord: 3.6ms)

OpenSSL::Cipher::CipherError (bad decrypt):
  app/models/project.rb:383:in `import_url'
  app/models/project.rb:413:in `external_import?'
  app/models/project.rb:405:in `import?'
  app/models/project.rb:421:in `import_in_progress?'
  app/controllers/projects_controller.rb:93:in `show'
  lib/gitlab/middleware/go.rb:16:in `call'

google 搜索 OpenSSL::Cipher::CipherError (bad decrypt):
找到解决方案:
https://gitlab.com/gitlab-org/gitlab-ce/issues/17873
gitlab-ce: 执行下面的这个命令即可恢复:
gitlab-rails runner  "Project.where.not(import_url: nil).each { |p| p.import_data.destroy if p.import_data }"



接下来不如gitlab的正式升级之路
升级目前的流程定位8.8.5--> 8.10.8 --> 8.17.8 --> 9.5.9 --> 10.1.4
我们现在下载8.10.8 安装包
cd /data/tools
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-8.10.8-ce.0.el7.x86_64.rpm

关闭gitlab 的部分服务:
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
sudo gitlab-ctl stop nginx
sudo rpm -Uvh gitlab-ce-8.10.8-ce.0.el7.x86_64.rpm
[wwwad@test-gitlab tools]$ sudo rpm -Uvh gitlab-ce-8.10.8-ce.0.el7.x86_64.rpm
Preparing...                          ################################# [100%]
gitlab preinstall: Automatically backing up only the GitLab SQL database (excluding everything else!)
Dumping database ...
Dumping MySQL database gitlabhq_production ... mysqldump: Got error: 1130: Host 'git.bigbao.com' is not allowed to connect to this MySQL server when trying to connect
[FAILED]
Backup failed
gitlab preinstall:
gitlab preinstall: Backup failed! If you want to skip this backup, run the following command and
gitlab preinstall: try again:

又报错,解决,mysql去给这个host授权一下。目前只受理了select,我擦,select的权限还是权限拒绝,添加权限
mysql> GRANT SELECT, INSERT, UPDATE, DELETE,CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES, REFERENCES ON`gitlabhq_production`.* TO 'git'@'git.bigbao.com' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

再次执行:sudo rpm -Uvh gitlab-ce-8.10.8-ce.0.el7.x86_64.rpm
又报别的错误了:
    Error executing action `run` on resource 'bash[migrate gitlab-rails database]'
    ================================================================================
    
    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '1'
    ---- Begin output of "bash"  "/tmp/chef-script20180704-5663-1ykn369" ----
    STDOUT: rake aborted!
    Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

   这个mysql2 我已经添加到gem里面了,我去

[root@test-gitlab tools]# cat  /opt/gitlab/embedded/service/gitlab-rails/.bundle/config
---
BUNDLE_RETRY: 5
BUNDLE_PATH: "/opt/gitlab/embedded/service/gem"
BUNDLE_JOBS: 9
BUNDLE_WITHOUT: development:test:mysql
BUNDLE_DISABLE_SHARED_GEMS: '1'

我们看到这里变成了mysql
我们修改一下,把这里的mysql变成postgresql

重新配置gitlab和重启
gitlab-ctl reconfigure
gitlab-ctl restart

yes 升级成功,我的小心脏。。。

我们登录到git.bigbao.com 查看一下面板,终于变成了8.10.8


接下来我们升级到8.17.8
cd /data/tools
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-8.17.8-ce.0.el7.x86_64.rpm
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
sudo gitlab-ctl stop nginx
sudo rpm -Uvh gitlab-ce-8.17.8-ce.0.el7.x86_64.rpm
果然又报上面的同一个错误了,这个错误是在检测的时候报的错误。我们不需要再次执行rpm -Uvh gitlab-ce-8.1

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值