温馨提示×

centos gitlab怎么部署

小樊
45
2026-09-15 00:02:49
栏目: 智能运维

下面给你一份在 CentOS 上部署 GitLab(CE 社区版)的常用、稳妥方案,适合服务器直接安装(Omnibus 包),也是官方推荐方式。


一、环境准备

1. 系统要求

  • CentOS 7 / 8(推荐 7,最稳定)
  • 至少 4GB 内存(2GB 会很卡)
  • 关闭或配置好防火墙
  • 建议使用干净系统

2. 基础设置

# 关闭 SELinux(或设为 permissive)
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

# 防火墙
systemctl stop firewalld
systemctl disable firewalld

二、安装 GitLab(Omnibus)

1. 安装依赖

yum install -y curl policycoreutils openssh-server postfix
systemctl enable sshd
systemctl start sshd
systemctl enable postfix
systemctl start postfix

2. 添加 GitLab 仓库

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

3. 安装 GitLab

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

如果是内网 IP

EXTERNAL_URL="http://192.168.1.100" yum install -y gitlab-ce

三、配置 GitLab

1. 修改配置文件

vi /etc/gitlab/gitlab.rb

常见修改:

external_url 'http://192.168.1.100'

2. 使配置生效

gitlab-ctl reconfigure

四、启动与访问

1. 常用命令

gitlab-ctl start
gitlab-ctl stop
gitlab-ctl restart
gitlab-ctl status

2. 浏览器访问

http://服务器IP

首次登录:

  • 用户名:root
  • 密码在:
cat /etc/gitlab/initial_root_password

五、常见问题

1. 端口冲突(如 80 被占用)

修改:

external_url 'http://192.168.1.100:8080'
nginx['listen_port'] = 8080

然后:

gitlab-ctl reconfigure

2. 修改 root 密码

gitlab-rake "gitlab:password:reset[root]"

3. 数据备份

gitlab-rake gitlab:backup:create

六、可选:Docker 方式(简要)

如果你更想用 Docker:

docker run -d \
  --hostname gitlab.example.com \
  -p 8080:80 \
  -v /srv/gitlab:/etc/gitlab \
  gitlab/gitlab-ce

七、生产建议

  • 使用 HTTPS(Let’s Encrypt)
  • 单独数据库(PostgreSQL)
  • 定期备份 /var/opt/gitlab

如果你告诉我:

  • CentOS 版本
  • 是否公网 / 内网
  • 是否要用 HTTPS / 域名

我可以给你定制版部署方案

0