温馨提示×

CentOS GitLab怎么设置

小樊
38
2026-07-20 04:19:05
栏目: 智能运维

下面以 CentOS 7 / 8 为例,给你一套从零到可用的 GitLab 设置流程(社区版 GitLab CE)。如果你用的是 CentOS Stream / Rocky / Alma,步骤基本一致。


一、安装前准备

1️⃣ 系统要求

  • 内存:≥ 4GB(推荐 8GB)
  • CPU:2 核以上
  • 磁盘:至少 20GB(代码多要更大)
  • CentOS 已更新
sudo yum update -y

二、安装依赖

sudo yum install -y curl policycoreutils openssh-server \
    openssh-clients postfix wget

启动 SSH 和 Postfix

sudo systemctl enable sshd
sudo systemctl start sshd

sudo systemctl enable postfix
sudo systemctl start postfix

三、添加 GitLab 仓库并安装

1️⃣ 添加 GitLab 官方仓库

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

2️⃣ 安装 GitLab CE

sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce

注意

  • EXTERNAL_URL 填你的服务器 IP 或域名
    例如:
    EXTERNAL_URL="http://192.168.1.100"
    

四、配置 GitLab

1️⃣ 初始化配置

sudo gitlab-ctl reconfigure

⏳ 这一步会比较慢,耐心等待


五、访问 GitLab

浏览器访问:

http://服务器IP

首次登录会要求你设置 root 密码


六、常用配置修改

1️⃣ 修改访问地址(IP / 域名)

sudo vi /etc/gitlab/gitlab.rb

修改:

external_url 'http://your-domain.com'

然后:

sudo gitlab-ctl reconfigure

七、防火墙设置(非常重要)

1️⃣ 开放 80 / 443 端口

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

八、GitLab 常用命令

gitlab-ctl status        # 查看状态
gitlab-ctl start         # 启动
gitlab-ctl stop          # 停止
gitlab-ctl restart       # 重启
gitlab-ctl reconfigure   # 重新应用配置

九、设置中文界面

  1. 登录 GitLab
  2. 右上角头像 → Preferences
  3. Localization
  4. Language 选择:简体中文
  5. 保存并刷新

十、常见问题

❌ 页面打不开

  • 检查防火墙
  • 检查 SELinux
sudo setenforce 0

(生产环境建议配置规则,而不是关闭)


❌ 内存不足

编辑:

sudo vi /etc/gitlab/gitlab.rb

减少 sidekiq / unicorn 进程:

puma['worker_processes'] = 2
sidekiq['max_concurrency'] = 10

十一、生产建议(进阶)

✅ 配置 HTTPS(Let’s Encrypt)
✅ 使用独立数据库(PostgreSQL)
✅ 定期备份
✅ 使用域名 + Nginx 反向代理


如果你愿意,可以告诉我:

  • ✅ CentOS 版本
  • ✅ 是 内网用 还是 公网
  • ✅ 是否要 HTTPS
  • ✅ 是否需要 GitLab Runner(CI/CD)

我可以帮你定制一套完整生产方案

0