下面以 GitLab CE(社区版)在 CentOS 7 / CentOS 8 上的常见部署方式 为例,给你一个清晰、可操作的完整流程。如果你用的是 Rocky / Alma / RHEL,步骤基本一致。
最低配置(建议)
⚠️ GitLab 比较吃内存,2GB 内存基本不可用。
# 关闭 SELinux(不推荐生产环境)
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
防火墙放行 HTTP/HTTPS:
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="http://192.168.1.100" yum install -y gitlab-ce
安装过程会较慢,耐心等待。
gitlab-ctl reconfigure
✅ 这一步会:
gitlab-ctl status
浏览器访问:
http://服务器IP
首次登录:
rootcat /etc/gitlab/initial_root_password
⚠️ 该文件 24 小时后自动删除
编辑配置文件:
vim /etc/gitlab/gitlab.rb
external_url 'http://gitlab.example.com'
gitlab-ctl reconfigure
gitlab-ctl start # 启动
gitlab-ctl stop # 停止
gitlab-ctl restart # 重启
gitlab-ctl status # 状态
gitlab-ctl tail # 查看日志
external_url 'https://gitlab.example.com'
letsencrypt['enable'] = true
letsencrypt['auto_renew'] = true
然后:
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 未完成prometheus_monitoring['enable'] = false
我可以继续帮你:
你可以直接告诉我:
我的是 CentOS 几?内存多少?是否生产环境?