下面给你一份在 Linux 上搭建 GitLab(社区版 CE)的实用指南,按最常见、最稳妥的方式来讲(以 Ubuntu / CentOS 为主)。
# Ubuntu
sudo apt update
sudo apt install -y curl openssh-server ca-certificates postfix
# CentOS
sudo yum install -y curl policycoreutils openssh-server postfix
sudo systemctl enable sshd postfix
postfix 用于邮件通知,可选(以后也能配)
curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo EXTERNAL_URL="http://你的IP或域名" apt install gitlab-ce
curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="http://你的IP或域名" yum install gitlab-ce
安装完成后会看到:
Thank you for installing GitLab!
sudo gitlab-ctl reconfigure
这一步会:
浏览器访问:
http://服务器IP
首次登录:
rootsudo cat /etc/gitlab/initial_root_password
⚠️ 该文件 24 小时后会被删除,记得改密码
sudo gitlab-ctl start # 启动
sudo gitlab-ctl stop # 停止
sudo gitlab-ctl restart # 重启
sudo gitlab-ctl status # 状态
sudo gitlab-ctl tail # 查看日志
编辑配置文件:
sudo vim /etc/gitlab/gitlab.rb
external_url 'https://gitlab.example.com'
启用 Let’s Encrypt:
letsencrypt['enable'] = true
letsencrypt['auto_renew'] = true
然后:
sudo gitlab-ctl reconfigure
# Ubuntu
sudo ufw allow 80
sudo ufw allow 443
# CentOS
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
unicorn['worker_processes'] = 2
postgresql['shared_buffers'] = "256MB"
然后:
sudo gitlab-ctl reconfigure
sudo gitlab-rake "gitlab:password:reset[root]"
如果你更想用 Docker:
docker run -d \
--hostname gitlab.example.com \
-p 443:443 -p 80:80 -p 22:22 \
--name gitlab \
gitlab/gitlab-ce
✅ 最推荐:
GitLab CE 官方包 + Ubuntu + Nginx + HTTPS
如果你愿意,可以告诉我:
我可以直接给你定制部署方案。