温馨提示×

centos如何集成gitlab

小樊
46
2026-10-08 18:56:49
栏目: 智能运维

在 CentOS 上“集成 GitLab”通常指安装并部署 GitLab(CE/EE),或者将 GitLab 与其他系统(如 Jenkins、LDAP、Nginx)集成。下面我分两种常见场景说明。


一、在 CentOS 上安装并部署 GitLab(最常见)

1. 系统要求

  • CentOS 7 / 8(推荐 7,8 已 EOL,需注意源)
  • 至少 4 GB 内存(2 GB 勉强可用)
  • 开放端口:80 / 443 / 22

2. 安装依赖

sudo yum install -y curl policycoreutils openssh-server openssh-clients
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-ce/script.rpm.sh | sudo bash

4. 安装 GitLab

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

如果是本机测试,可写 IP:

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

5. 初始化并启动

sudo gitlab-ctl reconfigure
sudo gitlab-ctl status

6. 登录

  • 浏览器访问:http://服务器IP
  • 初始密码:
cat /etc/gitlab/initial_root_password

二、GitLab 与其他系统集成(企业常见)

1. GitLab + Jenkins(CI/CD)

  • GitLab 管理代码
  • Jenkins 负责构建/部署
  • 集成方式:
    • GitLab Webhook → Jenkins
    • 或使用 GitLab CI(推荐)

GitLab CI 示例(.gitlab-ci.yml):

stages:
  - build
  - deploy

build:
  stage: build
  script:
    - mvn package

deploy:
  stage: deploy
  script:
    - scp target/app.jar user@server:/opt/app

2. GitLab + LDAP(统一登录)

修改:

/etc/gitlab/gitlab.rb
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-EOS
  main:
    label: 'LDAP'
    host: 'ldap.example.com'
    port: 389
    uid: 'sAMAccountName'
    bind_dn: 'cn=admin,dc=example,dc=com'
    password: 'password'
    base: 'dc=example,dc=com'
EOS
sudo gitlab-ctl reconfigure

3. GitLab + Nginx(反向代理)

GitLab 自带 Nginx,若需外部 Nginx:

nginx['enable'] = false

外部 Nginx 示例:

location / {
    proxy_pass http://127.0.0.1:8080;
}

三、常见问题

1. 内存不足

sudo gitlab-ctl stop

减少 sidekiq / puma 进程数

2. 修改访问地址

sudo vim /etc/gitlab/gitlab.rb
external_url 'http://new-domain.com'
sudo gitlab-ctl reconfigure

3. 数据备份

sudo gitlab-rake gitlab:backup:create

如果你指的是:

  • ✅ GitLab 安装
  • ✅ GitLab + Jenkins
  • ✅ GitLab + Kubernetes
  • ✅ GitLab API 集成

可以告诉我你的具体使用场景,我可以给你更精确的方案。

0 踩