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

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

gitlab 安装包下载路径:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
https://www.ilanni.com/?p=13917

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.kzlicai.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.kzlicai.com

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

update  application_settings set signin_enabled = '1';

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

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

浏览器访问登录 http://git.kzlicai.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.chinam888.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.chinam888.com' identified by 'kongzhong123';
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.kzlicai.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.17.8-ce.0.el7.x86_64.rpm,
执行一下也没有问题。会提示你已经安装    package gitlab-ce-8.17.8-ce.0.el7.x86_64 is already installed
sudo sed -i "s#mysql#postgresql#g"  /opt/gitlab/embedded/service/gitlab-rails/.bundle/config
我擦,这样修改尽然不可以了
仔细看一下报错内容:尽然和上面的报错不一样,大意了
  ================================================================================
    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-10569-fpnl6g" ----
    STDOUT: bundler: failed to load command: rake (/opt/gitlab/embedded/bin/rake)
    Bundler::GemNotFound: Your bundle is locked to rake (10.5.0),
    but that version could not be found in any of the sources listed in your Gemfile.
    If you haven't changed sources, that means the author of rake (10.5.0) has removed it.
    You'll need to update your bundle to a different version of rake (10.5.0) that hasn't been removed in order to install.

这里我们查看gem源是官方国外源,修改一下
cd /opt/gitlab/embedded/service/gitlab-rails/
/opt/gitlab/embedded/bin/gem source
*** CURRENT SOURCES ***
 
https://rubygems.org/

/opt/gitlab/embedded/bin/gem sources --add https://gems.ruby-china.org/ --remove https://ruby
sudo vim  /opt/gitlab/embedded/service/gitlab-rails/Gemfile


sudo /opt/gitlab/embedded/bin/bundle install
又报错:
An error occurred while installing charlock_holmes (0.7.3), and Bundler cannot continue.
Make sure that `gem install charlock_holmes -v '0.7.3'` succeeds before bundling.

sudo /opt/gitlab/embedded/bin/gem install bundler

sudo /opt/gitlab/embedded/bin/gem install charlock_holmes -v '0.7.3'
再次报错:
make: g++: Command not found
make: *** [transliterator.o] Error 127

make failed, exit code 2

报错再解决:
yum -y install gcc automake autoconf libtool make  gcc-c++

再执行:sudo /opt/gitlab/embedded/bin/gem install charlock_holmes -v '0.7.3'
好了,通过

gitlab-ctl reconfigure
再次报错:
    ================================================================================
    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-32605-15064zs" ----
    STDOUT: `/var/opt/gitlab` is not writable.
    Bundler will use `/tmp/bundler/home/wwwad' as your home directory temporarily.
    bundler: failed to load command: rake (/opt/gitlab/embedded/service/gem/ruby/2.3.0/bin/rake)
    Bundler::GemNotFound: Could not find activesupport-4.2.7.1 in any of the sources

处理思路:
 sudo /opt/gitlab/embedded/bin/bundle install
一个报错没解决,又来一个:
Downloading omniauth-google-oauth2-0.4.1 revealed dependencies not in the API or the lockfile (omniauth-oauth2 (>= 1.3.1), jwt (~> 1.5.2)).
Either installing with `--full-index` or running `bundle update omniauth-google-oauth2` should fix the problem.

In Gemfile:
  omniauth-google-oauth2

sudo /opt/gitlab/embedded/bin/bundle install --full-index
报相同的错误,那么执行
sudo /opt/gitlab/embedded/bin/bundle update omniauth-google-oauth2
又来一个报错:屋漏偏逢连夜雨......
An error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.4' --source 'https://gems.ruby-china.org/'` succeeds before bundling.

In Gemfile:
  pg


解决方案:
sudo yum  install  freetype-devel  ghostscript-devel   jasper-devel   lcms-devel   libpng-devel    libtiff-devel   zlib-devel libxml2-devel
sudo yum install ImageMagick-devel
sudo yum install postgresql-devel
sudo /opt/gitlab/embedded/bin/gem install pg -v '0.18.4'

再次执行:
sudo /opt/gitlab/embedded/bin/bundle update omniauth-google-oauth2

又报错:
An error occurred while installing rugged (0.24.0), and Bundler cannot continue.
Make sure that `gem install rugged -v '0.24.0' --source 'https://gems.ruby-china.org/'` succeeds before bundling.

In Gemfile:
  gemnasium-gitlab-service was resolved to 0.2.6, which depends on
    rugged

执行:
sudo /opt/gitlab/embedded/bin/gem install rugged -v '0.24.0'
再报错:
        Building native extensions.  This could take a while...
        ERROR:  Error installing rugged:
            ERROR: Failed to build gem native extension.

            current directory: /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/rugged-0.24.0/ext/rugged
        /opt/gitlab/embedded/bin/ruby -r ./siteconf20180704-9867-61nf8j.rb extconf.rb
        checking for gmake... yes
        checking for cmake... no
        ERROR: CMake is required to build Rugged.
        *** extconf.rb failed ***
        Could not create Makefile due to some reason, probably lack of necessary
        libraries and/or headers.  Check the mkmf.log file for more details.  You may
        need configuration options.

        Provided configuration options:
            --with-opt-dir
            --with-opt-include
            --without-opt-include=${opt-dir}/include
            --with-opt-lib
            --without-opt-lib=${opt-dir}/lib
            --with-make-prog
            --without-make-prog
            --srcdir=.
            --curdir
            --ruby=/opt/gitlab/embedded/bin/$(RUBY_BASE_NAME)
            --use-system-libraries

        To see why this extension failed to compile, please check the mkmf.log which can be found here:

          /opt/gitlab/embedded/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0/rugged-0.24.0/mkmf.log

        extconf failed, exit code 1

        Gem files will remain installed in /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/rugged-0.24.0 for inspection.
        Results logged to /opt/gitlab/embedded/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0/rugged-0.24.0/gem_make.out

sudo yum -y install cmake
sudo /opt/gitlab/embedded/bin/gem install rugged -v '0.24.0'
sudo /opt/gitlab/embedded/bin/bundle install

gitlab-ctl reconfigure
感谢上帝,终于成功了,重启访问看看。。。。。=
gitlab-ctl restart

伤心透了,访问500,直接页面都没了
看日志吧:
    Started GET "/" for 180.163.108.210 at 2018-07-04 12:52:06 +0800
    Processing by RootController#index as HTML
    Completed 500 Internal Server Error in 77ms (ActiveRecord: 4.8ms)

    ActiveRecord::StatementInvalid (Mysql2::Error: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '=': SELECT project_id, MAX(access_level) AS access_level FROM (SELECT 1 AS user_id, projects.id AS project_id, 40 AS access_level FROM `projects` INNER JOIN `namespaces` ON `projects`.`namespace_id` = `namespaces`.`id` WHERE `projects`.`pending_delete` = 0 AND `namespaces`.`deleted_at` IS NULL AND `namespaces`.`owner_id` = 1 AND `namespaces`.`type` IS NULL
    UNION
    SELECT members.user_id, projects.id AS project_id, members.access_level FROM `projects` INNER JOIN `namespaces` ON `projects`.`namespace_id` = `namespaces`.`id` INNER JOIN `members` ON `namespaces`.`id` = `members`.`source_id` WHERE `projects`.`pending_delete` = 0 AND `namespaces`.`deleted_at` IS NULL AND `namespaces`.`type` IN ('Group') AND `members`.`source_type` = 'Namespace' AND `members`.`user_id` = 1 AND `members`.`type` IN ('GroupMember') AND `members`.`requested_at` IS NULL
    UNION
    SELECT members.user_id, projects.id AS project_id, members.access_level FROM `projects` INNER JOIN `members` ON `projects`.`id` = `members`.`source_id` WHERE `projects`.`pending_delete` = 0 AND `members`.`source_type` = 'Project' AND `members`.`user_id` = 1 AND `members`.`type` IN ('ProjectMember') AND `members`.`requested_at` IS NULL
    UNION
    SELECT members.user_id, projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level FROM `namespaces` INNER JOIN `project_group_links` ON `project_group_links`.`group_id` = `namespaces`.`id` INNER JOIN `projects` ON `projects`.`id` = `project_group_links`.`project_id` AND `projects`.`pending_delete` = 0 INNER JOIN `members` ON `namespaces`.`id` = `members`.`source_id` INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id WHERE `namespaces`.`deleted_at` IS NULL AND `members`.`source_type` = 'Namespace' AND `namespaces`.`type` IN ('Group') AND `members`.`user_id` = 1 AND `members`.`type` IN ('GroupMember') AND `members`.`requested_at` IS NULL AND (project_namespace.share_with_group_lock = 0)
    UNION
    SELECT members.user_id, projects.id AS project_id, members.access_level FROM `projects` INNER JOIN `namespaces` ON `namespaces`.`id` = `projects`.`namespace_id` AND `namespaces`.`deleted_at` IS NULL INNER JOIN `routes` ON `routes`.`source_id` = `projects`.`id` AND `routes`.`source_type` = 'Project' INNER JOIN routes r2 ON routes.path LIKE CONCAT(REPLACE(r2.path, '_', '\_'), '/%')
                   INNER JOIN members ON members.source_id = r2.source_id
                   AND members.source_type = r2.source_type WHERE `projects`.`pending_delete` = 0 AND (namespaces.parent_id IS NOT NULL) AND (members.user_id = 1)) project_authorizations GROUP BY `project_id`):
      config/initializers/connection_fix.rb:20:in `execute'
      app/services/users/refresh_authorized_projects_service.rb:90:in `fresh_access_levels_per_project'
      app/services/users/refresh_authorized_projects_service.rb:50:in `execute_without_lease'
      app/services/users/refresh_authorized_projects_service.rb:41:in `execute'
      app/models/user.rb:467:in `refresh_authorized_projects'
      app/models/user.rb:481:in `authorized_projects'
      app/controllers/dashboard/projects_controller.rb:5:in `index'
      app/controllers/root_controller.rb:16:in `index'
      lib/gitlab/middleware/multipart.rb:93:in `call'
      lib/gitlab/request_profiler/middleware.rb:14:in `call'
      lib/gitlab/middleware/go.rb:16:in `call'

这里问了一下DBA这个是字符编码的问题,找DBA帮忙处理了一下


待继续补充.......

猜你喜欢

转载自www.cnblogs.com/smail-bao/p/9263073.html
今日推荐