在 CentOS 上“重置 GitLab”要看你具体指的是哪一层(密码、配置、数据、完全重装)。下面把最常见的几种场景都列出来,你可以按需选择。
只忘记管理员账号密码,不影响仓库和数据
# 进入 GitLab 控制台
gitlab-rails console -e production
在控制台中执行:
user = User.where(id: 1).first
user.password = 'NewPassword123!'
user.password_confirmation = 'NewPassword123!'
user.save!
exit
id:1通常是 root 用户
把配置恢复到初始状态,但保留数据
# 备份当前配置
cp /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb.bak
# 恢复默认配置
gitlab-ctl revert-config
或手动清空后重新生成:
> /etc/gitlab/gitlab.rb
gitlab-ctl reconfigure
⚠️ 会丢失自定义端口、邮箱、HTTPS 等配置,需重新配置。
⚠️ 不可逆,慎用!
gitlab-ctl cleanse
gitlab-ctl reconfigure
gitlab-ctl restart
会删除:
systemctl stop gitlab-runsvdir
rm -rf /var/opt/gitlab
rm -rf /etc/gitlab
rm -rf /var/log/gitlab
gitlab-ctl reconfigure
gitlab-ctl start
最彻底的“重置”
gitlab-ctl stop
yum remove -y gitlab-ee gitlab-ce
rm -rf /var/opt/gitlab
rm -rf /etc/gitlab
rm -rf /var/log/gitlab
# 以 GitLab CE 为例
curl -fsSL https://packages.gitlab.com/setup.sh | bash
yum install -y gitlab-ce
gitlab-ctl reconfigure
gitlab-runner stop
gitlab-runner verify
gitlab-runner restart
或重新注册:
gitlab-runner register
| 需求 | 推荐方式 |
|---|---|
| 忘记 root 密码 | ✅ 方案一 |
| 改坏配置 | ✅ 方案二 |
| 想清空所有数据 | ✅ 方案三 |
| GitLab 严重损坏 | ✅ 方案四 |
如果你愿意,可以告诉我:
gitlab-ctl --version)我可以给你精确到命令级别的方案。