温馨提示×

CentOS怎么重置GitLab

小樊
45
2026-08-18 17:22:51
栏目: 智能运维

CentOS 上“重置 GitLab”要看你具体指的是哪一层(密码、配置、数据、完全重装)。下面把最常见的几种场景都列出来,你可以按需选择。


一、重置 GitLab root 密码(最常见)

只忘记管理员账号密码,不影响仓库和数据

# 进入 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 用户


二、重置 GitLab 配置文件

把配置恢复到初始状态,但保留数据

# 备份当前配置
cp /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb.bak

# 恢复默认配置
gitlab-ctl revert-config

或手动清空后重新生成:

> /etc/gitlab/gitlab.rb
gitlab-ctl reconfigure

⚠️ 会丢失自定义端口、邮箱、HTTPS 等配置,需重新配置。


三、重置 GitLab 所有数据(清空仓库 / 用户)

⚠️ 不可逆,慎用!

方法 1:使用 GitLab 自带命令(推荐)

gitlab-ctl cleanse
gitlab-ctl reconfigure
gitlab-ctl restart

会删除:

  • 仓库
  • 数据库
  • CI/CD 数据
  • 用户

方法 2:手动删除数据目录

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

最彻底的“重置”

1️⃣ 卸载 GitLab

gitlab-ctl stop
yum remove -y gitlab-ee gitlab-ce

2️⃣ 清理残留

rm -rf /var/opt/gitlab
rm -rf /etc/gitlab
rm -rf /var/log/gitlab

3️⃣ 重新安装

# 以 GitLab CE 为例
curl -fsSL https://packages.gitlab.com/setup.sh | bash
yum install -y gitlab-ce
gitlab-ctl reconfigure

五、重置 GitLab Runner(如果你指的是 Runner)

gitlab-runner stop
gitlab-runner verify
gitlab-runner restart

或重新注册:

gitlab-runner register

六、我该选哪种?

需求 推荐方式
忘记 root 密码 ✅ 方案一
改坏配置 ✅ 方案二
想清空所有数据 ✅ 方案三
GitLab 严重损坏 ✅ 方案四

如果你愿意,可以告诉我:

  • ✅ GitLab 版本(gitlab-ctl --version
  • ✅ CentOS 版本(7 / 8 / Stream)
  • ✅ 是 密码 / 配置 / 仓库 / 完全重装

我可以给你精确到命令级别的方案。

0