在 CentOS 上使用 GitLab,通常有两种常见方式:
git 命令连接 GitLab 仓库下面我分别说明。
如果你只是想 拉代码、推代码,不需要安装 GitLab,只需安装 Git。
sudo yum install -y git
git config --global user.name "你的名字"
git config --global user.email "你的邮箱"
git clone https://gitlab.com/用户名/项目名.git
或 SSH 方式(推荐):
git clone git@gitlab.com:用户名/项目名.git
ssh-keygen -t rsa -b 4096 -C "你的邮箱"
cat ~/.ssh/id_rsa.pub
把公钥添加到 GitLab → Settings → SSH Keys
⚠️ 建议:
sudo yum install -y curl policycoreutils openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install -y postfix
sudo systemctl enable postfix
sudo systemctl start postfix
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="http://你的服务器IP" yum install -y gitlab-ee
浏览器打开:
http://服务器IP
首次登录设置 root 密码
# 查看状态
sudo gitlab-ctl status
# 重启
sudo gitlab-ctl restart
# 查看日志
sudo gitlab-ctl tail
修改:
sudo vi /etc/gitlab/gitlab.rb
external_url 'http://IP:端口'
然后:
sudo gitlab-ctl reconfigure
可关闭部分服务(如 Prometheus)
如果你告诉我:
我可以给你更精确的命令。