GitLab实战十一——Gitlab 8.11.3 升级至 9.3.11

Gitlab 9新特性

服务台,自动部署,进度跟踪,组件优化,采用 Vue 和 webpack 让 GitLab 尽可能速度更快、效率更高。

升级步骤

# MySQL installations (note: the line below states '--without postgres')
sudo -u git -H bundle install --without postgres development test --deployment

# Optional: clean up old gems
sudo -u git -H bundle clean

# Run database migrations
sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production

# Compile GetText PO files
sudo -u git -H bundle exec rake gettext:compile RAILS_ENV=production

# Update node dependencies and recompile assets
sudo -u git -H bundle exec rake yarn:install gitlab:assets:clean gitlab:assets:compile RAILS_ENV=production NODE_ENV=production

# Clean up cache
sudo -u git -H bundle exec rake cache:clear RAILS_ENV=production

数据库表结构变更

# db执行授权
GRANT ALL PRIVILEGES ON *.* TO gitlab_w@'%';

# 删除events日志记录,个人仓库首页contributions统计会清空,不影响升级的进度的话可以不删除
delete from events where created_at<'2017-01-01' limit 100000;

# 连接数据库
mysql -h gitlab.mysql01.chegva.com -P 1234 -u git_wn  gitlabhq_production -p

# db连接信息
production:
 adapter: mysql2
 encoding: utf8mb4
 collation: utf8mb4_general_ci
 reconnect: false
 database: gitlabhq_production
 pool: 10
 username: git_wn
 password: 2cSkJTt1***********
 host: gitlab.mysql01.chegva.com
 port: 3214


# 报错
ActiveRecord::StatementInvalid: Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX `index_pages_domains_on_domain`  ON `pages_domains` (`domain`)

# 执行sql
use gitlabhq_production
alter table pages_domains modify column domain varchar(190);

# 如果报错提示已存在,先注释再执行
vim /home/git/git/db/migrate/20160210105555_create_pages_domain.rb

# def change
#  create_table :pages_domains do |t|
#    t.integer :project_id
#    t.text    :certificate
#    t.text    :encrypted_key
#    t.string  :encrypted_key_iv
#    t.string  :encrypted_key_salt
#    t.string  :domain
#  end

Mysql2::Error:
Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '=':

UPDATE `merge_requests` SET `head_pipeline_id` = ((SELECT max(`ci_pipelines`.`id`) FROM `ci_pipelines` WHERE `ci_pipelines`.`ref` = `merge_requests`.`source_branch` AND `ci_pipelines`.`project_id` = `merge_requests`.`source_project_id`)) WHERE `merge_requests`.`id` >= 1 AND `merge_requests`.`id` < 6692

/home/git/git/vendor/bundle/ruby/2.3.0/gems/peek-mysql2-1.1.0/lib/peek/views/mysql2.rb:14:in `query'

# 查看表结构
show create table merge_requests \G;
merge_requests DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
show create table ci_pipelines\G;
ci_pipelines DEFAULT CHARSET=utf8

解决:
alter table ci_pipelines modify `ref` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL;
alter table ci_pipelines COLLATE=utf8_unicode_ci;

Mysql2::Error: Statement violates GTID consistency: CREATE TABLE ... SELECT.:         CREATE TABLE issue_assignees AS
         SELECT assignee_id AS user_id, id AS issue_id FROM issues WHERE assignee_id IS NOT NULL

CREATE TABLE issue_assignees
AS
SELECT assignee_id AS user_id, id AS issue_id
FROM issues
WHERE assignee_id IS NOT NULL

现象:
使用MySQL的Create table new_bak as select * from new语法复制表,出现如下报错:
Statement violates GTID consistency: CREATE TABLE ... SELECT.

原因:
主库启用了参数enforce_gtid_consistency=1,MySQL官方解释说当启用 enforce_gtid_consistency 功能的时候,MySQL只允许能够保障事务安全,并且能够被日志记录的SQL语句被执行,像create table … select 和 create temporarytable语句,以及同时更新事务表和非事务表的SQL语句或事务都不允许执行。

解决:

在my.cnf 中将
gtid_mode = ON
enforce_gtid_consistency = ON

改为

gtid_mode = OFF
enforce_gtid_consistency = OFF
然后重启数据库,数据库还有别的业务实例,不可行

解决:
手动创建表,然后把数据导进去
CREATE TABLE issue_assignees (
 `user_id` int(11) NOT NULL,
 `issue_id` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into issue_assignees
SELECT assignee_id AS user_id, id AS issue_id
FROM issues
WHERE assignee_id IS NOT NULL;

vim db/migrate/20170516153305_migrate_assignee_to_separate_table.rb
注释掉下边的建表语句,然后执行数据库升级命令即可:
# CREATE TABLE issue_assignees AS
   #   SELECT assignee_id AS user_id, id AS issue_id FROM issues WHERE assignee_id IS NOT NULL

# 查看表信息
show create table merge_requests \G;
merge_requests DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
show create table ci_pipelines\G;
ci_pipelines DEFAULT CHARSET=utf8

# 报错信息
 Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX `index_chat_names_on_service_id_and_team_id_and_chat_id`  ON `chat_names` (`service_id`, `team_id`, `chat_id`)

 alter table chat_names modify column service_id  varchar(190);

 alter table chat_names modify column team_id varchar(190);

 alter table chat_names modify column chat_id varchar(190);

 vim /home/git/git/db/migrate/20161113184239_create_user_chat_names_table.rb

 show index from chat_names;
 Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX `index_routes_on_path`  ON `routes` (`path`)

 alter table routes modify column path  varchar(190);
 alter table routes modify column source_type  varchar(190);

# 报索引已存在,删掉再升级
 ALTER TABLE routes DROP INDEX index_routes_on_path;

 Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX `index_container_repositories_on_project_id_and_name`  ON `container_repositories` (`project_id`, `name`)

   alter table container_repositories modify column name varchar(190);
注释掉语句可以不用执行下边语句删除
   ALTER TABLE container_repositories  DROP INDEX index_container_repositories_on_project_id;

# 报索引已存在的问题,注释掉后再升级
   vim /home/git/git/db/migrate/20170322013926_create_container_repository.rb
    # add_index :container_repositories, [:project_id, :name], unique: true


Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX `index_redirect_routes_on_path`  ON `redirect_routes` (`path`)

alter table redirect_routes  modify column source_type varchar(190);
alter table redirect_routes  modify column path varchar(190);

Mysql2::Error: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '=': UPDATE `merge_requests` SET `head_pipeline_id` = ((SELECT max(`ci_pipelines`.`id`) FROM `ci_pipelines` WHERE `ci_pipelines`.`ref` = `merge_requests`.`source_branch` AND `ci_pipelines`.`project_id` = `merge_requests`.`source_project_id`)) WHERE `merge_requests`.`id` >= 1 AND `merge_requests`.`id` < 6936

alter table ci_pipelines modify `ref` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL;


Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX `index_features_on_key`  ON `features` (`key`)

alter table features modify column `key` varchar(190);

Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX `index_feature_gates_on_feature_key_and_key_and_value`  ON `feature_gates` (`feature_key`, `key`, `value`)

alter table feature_gates modify column feature_key varchar(190);

alter table feature_gates modify column `key` varchar(190);

alter table feature_gates modify column value varchar(190);

vim /home/git/git/db/migrate/20170525174156_create_feature_tables.rb

Gitlab 9.3.11 前端模块版本

{
 "private": true,
 "scripts": {
   "dev-server": "nodemon --watch config/webpack.config.js -- ./node_modules/.bin/webpack-dev-server --config config/webpack.config.js",
   "eslint": "eslint --max-warnings 0 --ext .js,.vue .",
   "eslint-fix": "eslint --max-warnings 0 --ext .js,.vue --fix .",
   "eslint-report": "eslint --max-warnings 0 --ext .js,.vue --format html --output-file ./eslint-report.html .",
   "karma": "karma start config/karma.config.js --single-run",
   "karma-coverage": "BABEL_ENV=coverage karma start config/karma.config.js --single-run",
   "karma-start": "karma start config/karma.config.js",
   "webpack": "webpack --config config/webpack.config.js",
   "webpack-prod": "NODE_ENV=production webpack --config config/webpack.config.js"
 },
 "dependencies": {
   "babel-core": "^6.22.1",
   "babel-loader": "^6.2.10",
   "babel-plugin-transform-define": "^1.2.0",
   "babel-preset-latest": "^6.24.0",
   "babel-preset-stage-2": "^6.22.0",
   "bootstrap-sass": "^3.3.6",
   "compression-webpack-plugin": "^0.3.2",
   "core-js": "^2.4.1",
   "css-loader": "^0.28.0",
   "d3": "^3.5.11",
   "deckar01-task_list": "^2.0.0",
   "document-register-element": "^1.3.0",
   "dropzone": "^4.2.0",
   "emoji-unicode-version": "^0.2.1",
   "eslint-plugin-html": "^2.0.1",
   "exports-loader": "^0.6.4",
   "file-loader": "^0.11.1",
   "jed": "^1.1.1",
   "jquery": "^2.2.1",
   "jquery-ujs": "^1.2.1",
   "js-cookie": "^2.1.3",
   "jszip": "^3.1.3",
   "jszip-utils": "^0.0.2",
   "marked": "^0.3.6",
   "mousetrap": "^1.4.6",
   "name-all-modules-plugin": "^1.0.1",
   "pdfjs-dist": "^1.8.252",
   "pikaday": "^1.5.1",
   "prismjs": "^1.6.0",
   "raphael": "^2.2.7",
   "raven-js": "^3.14.0",
   "raw-loader": "^0.5.1",
   "react-dev-utils": "^0.5.2",
   "select2": "3.5.2-browserify",
   "sql.js": "^0.4.0",
   "stats-webpack-plugin": "^0.4.3",
   "three": "^0.84.0",
   "three-orbit-controls": "^82.1.0",
   "three-stl-loader": "^1.0.4",
   "timeago.js": "^2.0.5",
   "underscore": "^1.8.3",
   "url-loader": "^0.5.8",
   "visibilityjs": "^1.2.4",
   "vue": "^2.2.6",
   "vue-loader": "^11.3.4",
   "vue-resource": "^0.9.3",
   "vue-template-compiler": "^2.2.6",
   "webpack": "^2.6.1",
   "webpack-bundle-analyzer": "^2.8.2"
 },
 "devDependencies": {
   "babel-plugin-istanbul": "^4.0.0",
   "eslint": "^3.10.1",
   "eslint-config-airbnb-base": "^10.0.1",
   "eslint-import-resolver-webpack": "^0.8.1",
   "eslint-plugin-filenames": "^1.1.0",
   "eslint-plugin-import": "^2.2.0",
   "eslint-plugin-jasmine": "^2.1.0",
   "eslint-plugin-promise": "^3.5.0",
   "istanbul": "^0.4.5",
   "jasmine-core": "^2.5.2",
   "jasmine-jquery": "^2.1.1",
   "karma": "^1.4.1",
   "karma-coverage-istanbul-reporter": "^0.2.0",
   "karma-jasmine": "^1.1.0",
   "karma-mocha-reporter": "^2.2.2",
   "karma-phantomjs-launcher": "^1.0.2",
   "karma-sourcemap-loader": "^0.3.7",
   "karma-webpack": "^2.0.2",
   "nodemon": "^1.11.0",
   "webpack-dev-server": "^2.4.2"
 }
}

升级后验证

升级完成后启动gitlab,执行检测命令,打开web端,检测各组件功能是否正常:

GitLab实战十一——Gitlab 8.11.3 升级至 9.3.11


anzhihe 安志合个人博客,版权所有 丨 如未注明,均为原创 丨 转载请注明转自:https://chegva.com/3587.html | ☆★★每天进步一点点,加油!★★☆ | 

您可能还感兴趣的文章!

发表评论

电子邮件地址不会被公开。 必填项已用*标注