下面给你一份**在 CentOS 上安装和配置 GitLab(CE 社区版)**的完整流程,适用于 CentOS 7 / CentOS 8 Stream,并包含常见配置项。
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
yum install -y curl policycoreutils openssh-server openssh-clients
systemctl enable sshd
systemctl start sshd
dnf install -y curl policycoreutils openssh-server
systemctl enable sshd
systemctl start sshd
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce
✅ 说明:
EXTERNAL_URL 是访问地址EXTERNAL_URL="http://192.168.1.100"
gitlab-ctl reconfigure
⏳ 首次执行时间较长,耐心等待。
浏览器访问:
http://服务器IP
首次登录:
rootcat /etc/gitlab/initial_root_password
⚠️ 密码只在 24 小时内有效,建议登录后立即修改。
编辑配置文件:
vim /etc/gitlab/gitlab.rb
修改:
external_url 'http://gitlab.example.com'
生效:
gitlab-ctl reconfigure
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "123456@qq.com"
gitlab_rails['smtp_password'] = "邮箱授权码"
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
生效:
gitlab-ctl reconfigure
测试邮件:
gitlab-rails console
Notify.test_email('test@example.com', 'Test', 'Hello').deliver_now
git_data_dirs({
"default" => {
"path" => "/data/gitlab/git-data"
}
})
gitlab-ctl status # 查看状态
gitlab-ctl stop # 停止
gitlab-ctl start # 启动
gitlab-ctl restart # 重启
gitlab-ctl tail # 查看日志
GitLab 自带中文:
右上角头像 → Preferences → Localization → 简体中文
存在兼容风险,不建议生产环境使用。
gitlab-ctl reconfigure 未完成gitlab-rails console
user = User.find_by(username: 'root')
user.password = 'NewPassword123'
user.password_confirmation = 'NewPassword123'
user.save!
✅ 使用 HTTPS
✅ 定期备份
✅ 至少 8GB 内存
✅ 使用独立服务器,不要和数据库混用
如果你愿意,我可以帮你:
直接告诉我你的 CentOS 版本 + 是否生产环境即可。