下面给你一份**在 Linux 上搭建 GitLab(社区版 CE)**的实用指南,以 Ubuntu / Debian 和 CentOS / RHEL 为例,适合自建服务器或云主机。
sudo apt update
sudo apt install -y curl openssh-server ca-certificates postfix
postfix 可选(用于邮件),也可用 SMTP
curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo EXTERNAL_URL="http://git.example.com" apt install gitlab-ce
如果是 IP 访问:
sudo EXTERNAL_URL="http://192.168.1.100" apt install gitlab-ce
sudo gitlab-ctl reconfigure
浏览器访问:
http://git.example.com
首次登录账号:
rootsudo cat /etc/gitlab/initial_root_password
sudo yum install -y curl policycoreutils openssh-server postfix
sudo systemctl enable --now sshd postfix
curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="http://git.example.com" yum install gitlab-ce
sudo gitlab-ctl reconfigure
sudo gitlab-ctl status # 查看状态
sudo gitlab-ctl stop # 停止
sudo gitlab-ctl start # 启动
sudo gitlab-ctl restart # 重启
sudo gitlab-ctl tail # 查看日志
sudo vim /etc/gitlab/gitlab.rb
常见配置:
external_url 'http://git.example.com'
gitlab_rails['gitlab_email_from'] = 'gitlab@example.com'
修改后执行:
sudo gitlab-ctl reconfigure
使用 Let’s Encrypt:
letsencrypt['enable'] = true
letsencrypt['auto_renew'] = true
gitlab-ctl reconfigure修改:
nginx['listen_port'] = 8080
sudo gitlab-rake "gitlab:password:reset[root]"
如果你只是想要 Git 服务:
如果你告诉我:
我可以给你一份定制化搭建方案。