CentOS 上 GitLab 的更新与维护流程
一 升级前准备
sudo gitlab-rake gitlab:env:info。同时确认操作系统与依赖(如 curl、openssh-server、postfix)处于可用状态。sudo gitlab-rake gitlab:backup:create。默认备份目录为 /var/opt/gitlab/backups,可在 /etc/gitlab/gitlab.rb 中通过 gitlab_rails['backup_path'] = "/your/path" 自定义,修改后执行 sudo gitlab-ctl reconfigure 使配置生效。/etc/gitlab/gitlab.rb、/etc/gitlab/gitlab-secrets.json 以及(如用到)/var/opt/gitlab/nginx/conf、/etc/postfix/main.cf。注意:常规备份不会包含上述敏感文件。sudo yum update gitlab-ce。sudo rpm -Uvh gitlab-ce-<version>.rpm。二 标准升级步骤
sudo gitlab-ctl stop unicorn、sudo gitlab-ctl stop sidekiq,必要时 sudo gitlab-ctl stop nginx。sudo gitlab-rake gitlab:backup:create,确保有最新可回滚点。sudo yum update gitlab-ce;sudo rpm -Uvh gitlab-ce-<version>.rpm。sudo gitlab-ctl reconfigure,随后 sudo gitlab-ctl restart。sudo gitlab-rake db:migrate 完成数据结构变更;如需检查迁移状态可执行 sudo gitlab-rake db:migrate:status。sudo gitlab-rake gitlab:check 做健康检查。三 升级后的验证与回滚
sudo gitlab-rake gitlab:env:info 或查看 /opt/gitlab/version-manifest.txt 的头部版本行,确认已到目标版本。sudo gitlab-ctl tail,重点查看 /var/log/gitlab/gitlab-rails/production.log。sudo gitlab-ctl stop unicorn、sudo gitlab-ctl stop sidekiq;sudo gitlab-rake gitlab:backup:restore BACKUP=<timestamp>;sudo gitlab-ctl start。四 日常维护与常见问题处理
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create;定期清理过期备份,避免磁盘占满。sudo gitlab-ctl reconfigure 使配置生效;迁移或恢复时务必确保 gitlab-secrets.json 与 gitlab.rb 一致,否则可能出现权限或签名错误。sudo gitlab-rake db:migrate:status 查看状态,必要时 sudo gitlab-rake db:migrate。reconfigure 报 Chef client 占用:ps aux | grep gitlab 查找进程 PID,必要时 kill -9 <PID> 后重试。sudo chmod 2770 /var/opt/gitlab/git-data/repositories。external_url 与端口,然后 sudo gitlab-ctl reconfigure 使配置生效。