温馨提示×

gitlab在centos咋部署

小樊
50
2026-09-11 18:57:05
栏目: 智能运维

下面给你一份**在 CentOS 上部署 GitLab(社区版 CE)**的常用、稳妥方案,适合大多数内网/公司环境。


一、环境准备

1. 系统要求

  • CentOS 7 或 CentOS 8(推荐 7,资料最多)
  • 最少 4GB 内存(2GB 很容易卡死)
  • root 权限

2. 关闭防火墙(或放行端口)

systemctl stop firewalld
systemctl disable firewalld

或放行 80 / 443 / 22:

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

3. 安装依赖

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

二、安装 GitLab(推荐官方 RPM 包)

方式一:使用官方脚本(最简单)

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

方式二:手动下载 RPM(适合离线)

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.0.0-ce.0.el7.x86_64.rpm
rpm -ivh gitlab-ce-*.rpm

三、配置 GitLab

1. 修改配置文件

vi /etc/gitlab/gitlab.rb

常见配置:

external_url 'http://gitlab.example.com'
# 或
external_url 'http://192.168.1.100'

如需改端口:

external_url 'http://192.168.1.100:8080'

四、初始化并启动

gitlab-ctl reconfigure
gitlab-ctl start

查看状态:

gitlab-ctl status

五、访问 GitLab

浏览器访问:

http://服务器IP

第一次登录:

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

六、常用运维命令

gitlab-ctl restart
gitlab-ctl stop
gitlab-ctl tail

日志查看:

gitlab-ctl tail nginx

七、常见问题

1. 内存不足

修改:

unicorn['worker_processes'] = 2
postgresql['shared_buffers'] = "256MB"

然后:

gitlab-ctl reconfigure

2. 端口被占用

改 external_url 端口即可。

3. 忘记 root 密码

gitlab-rails console
user = User.where(id:1).first
user.password = '新密码'
user.save!

八、可选增强

  • 配置 HTTPS(Let’s Encrypt)
  • 配置 SMTP 邮件
  • 使用 Docker 版 GitLab
  • 配置备份:
gitlab-rake gitlab:backup:create

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

  • CentOS 版本
  • 是否内网
  • 是否用 Docker
  • 是否需要 HTTPS / 邮件

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

0 踩