Gitlab升级14.0.12-->14.3.6遇到的gitlab-ctl reconfigure错误

问题描述

在按照官方文档升级路线11.0.2=>17.2.2的过程中,升级14.0.12–》14.3.6时遇到一个错误:

Running handlers:
There was an error running gitlab-ctl reconfigure:

rails_migration[gitlab-rails] (gitlab::database_migrations line 51) had an error: Mixlib::ShellOut::ShellCommandFailed: bash[migrate gitlab-rails database] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/resources/rails_migration.rb line 16) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of "bash"  "/tmp/chef-script20240917-12026-tupa61" ----
。。。中间略过。。。。
-- execute("ALTER TABLE \"vulnerability_finding_evidence_sources\"\nADD CONSTRAINT \"check_86b537ba1a\" CHECK (char_length(\"name\") <= 2048),\nADD CONSTRAINT \"check_0fe01298d6\" CHECK (char_length(\"url\") <= 2048)\n")rake aborted!
StandardError: An error has occurred, all later migrations canceled:

Expected batched background migration for the given configuration to be marked as 'finished', but it is 'paused':      {:job_class_name=>"CopyColumnUsingBackgroundMigrationJob", :table_name=>"ci_builds_metadata", :column_name=>"id", :job_arguments=>[["id"], ["id_convert_to_bigint"]]}

Finalize it manualy by running

	sudo gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,ci_builds_metadata,id,'[["id"]\, ["id_convert_to_bigint"]]']

原因调查

查询chatgpt,这个错误与数据库迁移失败有关,根据错误日志显示,问题出在某个后台迁移任务未完成。GitLab 在进行某些大表的数据迁移时,会将任务分批次处理,而你的迁移任务被暂停了,导致后续的迁移被中止。

具体原因是 GitLab 的 CopyColumnUsingBackgroundMigrationJob 后台任务没有标记为“已完成”,而是处于“暂停”状态,任务没有被完全执行,因此阻止了后续迁移。这个问题通常发生在你升级 GitLab 版本时,GitLab 使用后台迁移任务处理大表(如 ci_builds_metadata 表)的数据,以避免在迁移过程中占用大量资源。

解决方案

1、检查数据库连接

sudo gitlab-rake db:migrate:status

结果显示,无法连接数据库。
2、重启数据库

sudo gitlab-ctl status postgresql
sudo gitlab-ctl start postgresql

3、执行

sudo gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,ci_builds_metadata,id,'[["id"], ["id_convert_to_bigint"]]']

sudo gitlab-ctl reconfigure

又遇到了Redis无法连接错误:

Caused by:Redis::CannotConnectError: Error connecting to Redis on /var/opt/gitlab/redis/redis.socket (Errno::ENOENT) 

但是检查Redis服务,却是正常运行的。咨询chatgpt,有时候 Redis 启动过程中出现问题,可能导致 GitLab 其他组件无法正常启动。可以尝试重启所有 GitLab 组件。
4、执行如下步骤:

sudo gitlab-ctl restart
sudo gitlab-ctl reconfigure

又遇到错误,根据日志信息,执行:

sudo gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,taggings,id,'[["id"\, "taggable_id"]\, ["id_convert_to_bigint"\, "taggable_id_convert_to_bigint"]]']

然后再执行

sudo gitlab-ctl reconfigure

没有报错, 再执行:

sudo gitlab-rake db:migrate

没有错误,然后检查日志和服务,均已正常。
问题解决,记之。

### 如何配置 `/etc/gitlab/gitlab.rb` 中的 `gitlab-shell` URL 在 GitLab 配置文件 `/etc/gitlab/gitlab.rb` 中,可以通过设置参数来定义 `gitlab-shell` 的行为以及其关联的 URL。具体到 `gitlab-shell` 的 URL 设置,主要涉及的是 SSH 主机名和端口号的相关配置。 以下是详细的说明: #### 1. 修改 SSH 主机名 为了指定 `gitlab-shell` 使用的 URL 或者主机名,可以调整以下参数: ```bash gitlab_rails[&#39;gitlab_ssh_host&#39;] = &#39;your-domain-or-ip&#39; ``` 这里的 `&#39;your-domain-or-ip&#39;` 应替换为实际的域名或者 IP 地址[^1]。此参数决定了通过 SSH 连接时使用的主机名称。 #### 2. 调整 SSH 端口 如果需要自定义 SSH 端口(默认情况下是 22),则需修改如下参数: ```bash gitlab_rails[&#39;gitlab_shell_ssh_port&#39;] = your_custom_port_number ``` 例如,将端口更改为 9922,则应写成: ```bash gitlab_rails[&#39;gitlab_shell_ssh_port&#39;] = 9922 ``` #### 3. 更新外部访问 URL 确保外部访问地址也正确无误,这会影响整个系统的可用性和用户体验: ```bash external_url &#39;http://your-gitlab-url&#39; ``` 此处的 `&#39;http://your-gitlab-url&#39;` 是指 GitLab 实例对外暴露的服务地址[^1]。它不仅影响 Web 访问路径,还间接决定克隆仓库时所用的 URL 形式。 #### 4. 完成更改后的操作 完成以上编辑之后,保存并关闭文件。接着执行命令使新配置生效: ```bash gitlab-ctl reconfigure ``` 该指令会基于当前 `/etc/gitlab/gitlab.rb` 文件的内容重新生成必要的配置文件,并应用新的设定。 最后一步是重启服务以加载最新的改动: ```bash gitlab-ctl restart ``` #### 注意事项 尽管上述过程涵盖了大部分场景下的需求,但在某些复杂环境中可能还需要额外考虑防火墙规则、DNS 解析等问题。另外,若使用 HTTPS 协议代替 HTTP 提供服务,则还需进一步处理证书等相关事宜[^3]。 --- ### 示例代码片段 假设要将 GitLab Shell 的 SSH 主机设为 `example.com` 并启用非标准端口 9922,同时保持外网可访问的状态,那么完整的配置部分看起来像这样: ```ruby # /etc/gitlab/gitlab.rb external_url &#39;https://example.com&#39; # gitlab-shell settings gitlab_rails[&#39;gitlab_ssh_host&#39;] = &#39;example.com&#39; gitlab_rails[&#39;gitlab_shell_ssh_port&#39;] = 9922 ``` 随后按照前述方法依次运行 `reconfigure` 和 `restart` 命令即可。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值