在 CentOS 上运行 GitLab,官方最推荐、最稳定的方式是使用 GitLab CE(社区版)官方 RPM 包。下面我按从零开始给你一份可操作的完整流程,适用于 CentOS 7 / CentOS 8 Stream。
sudo yum update -y
sudo yum install -y curl policycoreutils-python openssh-server
sudo dnf install -y curl policycoreutils openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce
把
gitlab.example.com换成你的 服务器 IP 或域名
sudo yum install -y gitlab-ce
sudo gitlab-ctl reconfigure
⚠️ 这一步会:
编辑配置文件:
sudo vi /etc/gitlab/gitlab.rb
修改:
external_url 'http://你的IP或域名'
然后重新配置:
sudo gitlab-ctl reconfigure
在浏览器中访问:
http://服务器IP
首次登录:
rootsudo cat /etc/gitlab/initial_root_password
⚠️ 密码只显示一次,建议登录后立即修改
sudo gitlab-ctl status
sudo gitlab-ctl start
sudo gitlab-ctl stop
sudo gitlab-ctl restart
sudo gitlab-ctl tail
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload
sudo vi /etc/gitlab/gitlab.rb
配置 smtp_settings,然后:
sudo gitlab-ctl reconfigure
external_url 'https://gitlab.example.com'
letsencrypt['enable'] = true
✅ 建议:
如果你想用 Docker:
docker run -d \
--hostname gitlab.example.com \
-p 80:80 -p 443:443 -p 22:22 \
--name gitlab \
gitlab/gitlab-ce:latest
CentOS 上运行 GitLab 最稳妥的方式就是:官方 RPM + gitlab-ctl 管理
如果你愿意,可以告诉我:
我可以帮你写一份完全贴合你环境的 GitLab 部署方案。