温馨提示×

centos怎样配置gitlab

小樊
38
2026-09-11 18:56:07
栏目: 智能运维

在 CentOS 上配置 GitLab,通常有两种常见方式:

  1. 使用官方 Omnibus 包(推荐,最简单)
  2. 使用 Docker 部署(更灵活)

下面我分别说明,最推荐第一种。


一、CentOS 使用官方包安装 GitLab(推荐)

1. 系统要求

  • CentOS 7 / 8(CentOS 8 已 EOL,建议用 Rocky/Alma 或 CentOS 7)
  • 至少 4GB 内存(2GB 会很卡)
  • 已配置好 hostname

2. 安装依赖

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

防火墙(如开启):

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

3. 添加 GitLab 源

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

如果是社区版(免费):

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

4. 安装 GitLab

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

⚠️ 把 gitlab.example.com 改成你的域名或服务器 IP


5. 配置并启动

sudo gitlab-ctl reconfigure

访问:

http://服务器IP

首次登录账号:

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

二、修改 GitLab 配置(常用)

配置文件:

/etc/gitlab/gitlab.rb

修改访问地址

external_url 'http://192.168.1.100'

修改后执行:

sudo gitlab-ctl reconfigure

三、使用 Docker 安装 GitLab(可选)

docker run --detach \
  --hostname gitlab.example.com \
  --publish 443:443 --publish 80:80 --publish 22:22 \
  --name gitlab \
  --restart always \
  --volume /srv/gitlab/config:/etc/gitlab \
  --volume /srv/gitlab/logs:/var/log/gitlab \
  --volume /srv/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce:latest

访问:

http://服务器IP

四、常见问题

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

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

2. 修改 root 密码

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

3. 查看状态

sudo gitlab-ctl status

如果你告诉我:

  • CentOS 版本
  • 是否用域名
  • 是否内网/云服务器

我可以给你一份完全可执行的配置方案。

0 踩