Gitlab管理项目保存通用设置时报500修复记录

Gitlab管理项目保存通用设置时报500修复记录

1. 遇到问题查日志

这里gitlab是用docker部署的,经历过备份迁移之后,修改项目的通用设置时报了500,页面只有提示了500,没有任何头绪,所以要从日志下手

# 1. 进入gitlab容器
docker exec -it gitlab bash
# 2. 找到日志目录
cd /var/log/gitlab/gitlab-rails
# 3. 查看日志, 一般都是查看productions日志,页面再发起一次保存修改的请求,查看日志
tail -f productions.log
# 4. 报错信息如下
OpenSSL::Cipher::CipherError ():
  
lib/gitlab/crypto_helper.rb:27:in `aes256_gcm_decrypt'

2. 不敢下手找备份

上网搜索发现,这个竟然是因为数据迁移备份的时候,备份数据自带的库里的token值是旧token,访问时用的新token,当然冲突,报500了,但是因为当时不确定,也不是特别熟悉gitlab一些不熟悉的操作,所以决定还是谨慎点,先去找个备用机,去复现这个问题,再备用机上解决之后,再到正式环境下去解决,千万千万不要直接拿起来就操作,万一出了问题,懂的都懂!!!

# 1. 创建备份,备份文件一般都放在容器中的/var/opt/gitlab/backups目录下类似这种形式的文件 1654526291_2022_06_06_14.0.11_gitlab_backup.tar;
docker exec gitlab /bin/bash -c '/opt/gitlab/bin/gitlab-rake gitlab:backup:create '
# 2. 在备胎服务器上启动gitlab容器,所使用的镜像版本要一致,启动命令参考如下,mac地址和ip地址一定要配置成备胎机当前所使用网卡的mac和ip;
docker run --name=gitlab --hostname=GitlabServer --mac-address=a3:77:e6:b8:a2:0c --env='GITLAB_OMNIBUS_CONFIG=external_url '"'"'http://192.168.3.25'"'"'
gitlab_rails['"'"'time_zone'"'"'] = '"'"'Asia/Shanghai'"'"'
gitlab_rails['"'"'smtp_enable'"'"'] = true
gitlab_rails['"'"'smtp_address'"'"'] = "smtp.163.com"
gitlab_rails['"'"'smtp_port'"'"'] = 465
gitlab_rails['"'"'smtp_user_name'"'"'] = "[email protected]"
gitlab_rails['"'"'smtp_password'"'"'] = "123456"
gitlab_rails['"'"'smtp_authentication'"'"'] = "login"
gitlab_rails['"'"'smtp_domain'"'"'] = "163.com"
gitlab_rails['"'"'smtp_enable_starttls_auto'"'"'] = true
gitlab_rails['"'"'smtp_tls'"'"'] = true
gitlab_rails['"'"'gitlab_email_enabled'"'"'] = true
gitlab_rails['"'"'gitlab_email_display_name'"'"'] = "[email protected]"
gitlab_rails['"'"'gitlab_shell_ssh_port'"'"'] = 2022
user['"'"'git_user_email'"'"'] = "[email protected]"
gitlab_rails['"'"'gitlab_email_from'"'"'] = '"'"'[email protected]'"'"'
' --env=PATH=/opt/gitlab/embedded/bin:/opt/gitlab/bin:/assets:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env=TERM=xterm --env=LANG=C.UTF-8 --env=EDITOR=/bin/vi --volume=/home/data/gitlab/config:/etc/gitlab:rw --volume=/home/data/gitlab/logs:/var/log/gitlab:rw --volume=/home/data/gitlab/data:/var/opt/gitlab:rw --volume=/etc/gitlab --volume=/var/log/gitlab --volume=/var/opt/gitlab -p 2022:22 -p 2443:443 -p 2080:80 --restart=unless-stopped --runtime=runc --detach=true gitlab/gitlab-ce:14.0.11-ce.0 /assets/wrapper
# 3. 准备工作,将gitlab.rb和gitlab-secrect.json和备份压缩包传到备胎机上,并将对应文件放到对应的容器挂载目录下
cd /home/data/gitlab/config
cp gitlab.rb gitlab.rb.old
cp gitlab-secret.json gitlab-secret.json.old

cp /home/sg/backup/gitlab.rb ./
cp /home/sg/backup/gitlab-secret.json ./

cd /home/data/gitlab/data/backups/
mv /home/txkj/backup/1654526291_2022_06_06_14.0.11_gitlab_backup.tar
chmod 777 1654526291_2022_06_06_14.0.11_gitlab_backup.tar
# 4. 恢复备份
docker exec -it gitlab bash

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

gitlab-rake gitlab:backup:restore BACKUP=1654526291_2022_06_06_14.0.11
	# 恢复完之后重新启动gitlab即可
gitlab-ctl restart
# 5. 登录验证http://192.168.3.25:2080
# 6. 复现之前的问题,保存通用设置报500

3. 备份解决修正主

解决步骤如下,进入容器后,进入dbconsole,找到有问题的gitlab项目名,这里的gitlab项目名是ManageSystem,进入到数据库的projects表中找到其token值,将token值清空即可恢复。

root@txGitlabServer:/var/log/gitlab/gitlab-rails# 
root@txGitlabServer:/var/log/gitlab/gitlab-rails# gitlab-rails dbconsole
psql (12.7)
Type "help" for help.
gitlabhq_production=>
gitlabhq_production=>
gitlabhq_production=> select name, runners_token_encrypted from projects where name = 'ManageSystem';
     name     |             runners_token_encrypted              
--------------+--------------------------------------------------
 ManageSystem | OFWoIneZAjUNLCtVAm26dc2VZLyfPgMMEX/GuKHnvOkvcdKR
(1 row)

gitlabhq_production=> update projects set runners_token_encrypted = null where name = 'ManageSystem';
UPDATE 1
gitlabhq_production=> select name, runners_token_encrypted from projects where name = 'ManageSystem';
     name     | runners_token_encrypted 
--------------+-------------------------
 ManageSystem | 
(1 row)
gitlabhq_production=>
gitlabhq_production=>

在备份页面上再次发起保存请求,发现不报错了,问题解决,准备修复正主即可

你可能感兴趣的:(docker,运维,git)