温馨提示×

centos如何重置gitlab

小樊
43
2026-10-14 16:11:16
栏目: 智能运维

在 CentOS 上“重置 GitLab”通常有以下几种含义,我分别说明,请先确认你想要的是哪一种:


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

如果你只是忘了 GitLab 的登录密码:

# 进入 GitLab Rails 控制台
gitlab-rails console -e production

进入后执行:

user = User.where(id: 1).first
user.password = 'NewPassword123!'
user.password_confirmation = 'NewPassword123!'
user.save!
exit

然后访问 GitLab 页面,用 root / 新密码 登录。


二、重置 GitLab 配置(恢复默认配置)

如果你改坏了 /etc/gitlab/gitlab.rb:

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

# 重新生成默认配置
gitlab-ctl reconfigure

或者彻底重置配置(危险):

rm -f /etc/gitlab/gitlab.rb
gitlab-ctl reconfigure

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

⚠️ 这会删除所有数据,不可恢复

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

# 重新安装或重装 GitLab
gitlab-ctl reconfigure
gitlab-ctl start

四、卸载并重新安装 GitLab

# 停止服务
gitlab-ctl stop

# 卸载
yum remove gitlab-ce -y
rm -rf /opt/gitlab /var/opt/gitlab /etc/gitlab

# 重新安装
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
yum install gitlab-ce -y
gitlab-ctl reconfigure

五、只重置某个 GitLab 服务

gitlab-ctl restart nginx
gitlab-ctl restart sidekiq
gitlab-ctl restart unicorn   # 老版本
gitlab-ctl restart puma      # 新版本

如果你能告诉我:

  • GitLab 版本(gitlab-rake gitlab:env:info)
  • 是 密码忘了 / 配置错了 / 数据要清空

我可以给你更精确的命令。

0 踩