下面给你一份**在 CentOS 上安装 GitLab(CE 社区版)**的完整、常用做法,适用于 CentOS 7 / CentOS 8 Stream。如果你用的是其他版本,可以再告诉我。
sudo yum update -y
sudo yum install -y curl policycoreutils openssh-server \
openssh-clients postfix wget
sudo systemctl enable sshd
sudo systemctl start sshd
sudo systemctl enable postfix
sudo systemctl start postfix
curl -fsSL https://packages.gitlab.com/setup.sh | sudo bash
国内服务器如果慢,可先配置代理或使用清华镜像(下面会讲)
sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce
✅ 注意:
EXTERNAL_URL 填你的 服务器 IP 或域名sudo EXTERNAL_URL="http://192.168.1.100" yum install -y gitlab-ce
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.7.0-ce.0.el7.x86_64.rpm
sudo rpm -ivh gitlab-ce-*.rpm
sudo gitlab-ctl reconfigure
⏳ 第一次会耗时 2–5 分钟
浏览器访问:
http://服务器IP
首次登录:
rootsudo cat /etc/gitlab/initial_root_password
⚠️ 密码 24 小时后会被自动删除
gitlab-ctl status # 查看状态
gitlab-ctl restart # 重启
gitlab-ctl stop # 停止
gitlab-ctl tail # 查看日志
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
编辑配置文件:
sudo vi /etc/gitlab/gitlab.rb
常用配置:
external_url 'http://gitlab.example.com'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
修改后执行:
sudo gitlab-ctl reconfigure
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/ | cat
或在 /etc/gitlab/gitlab.rb 中:
gitlab_rails['registry_mirror'] = "https://mirrors.tuna.tsinghua.edu.cn"
gitlab-ctl restart
登录后 → Preferences → Localization → 简体中文
如果你告诉我:
我可以给你定制版安装方案(比如 Docker / HTTPS / 企业级优化)