温馨提示×

debian下gitlab怎样设置

小樊
46
2026-09-08 12:07:25
栏目: 智能运维

Debian 下部署和设置 GitLab,通常有两种主流方式:

  1. Omnibus 包安装(官方推荐,最简单)
  2. Docker 安装(隔离性好,适合已有 Docker 环境)

下面以 Debian 11 / 12 + GitLab CE(社区版) 为例说明。


一、使用 Omnibus 包安装(推荐)

1. 更新系统

sudo apt update
sudo apt upgrade -y

2. 安装依赖

sudo apt install -y curl openssh-server ca-certificates tzdata perl

3. 添加 GitLab 仓库

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

4. 安装 GitLab CE

替换为你自己的域名或 IP:

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

如果是本地服务器:

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

二、基础配置

1. 修改配置文件

sudo vim /etc/gitlab/gitlab.rb

常见配置项:

external_url 'http://gitlab.example.com'
# 修改端口(可选)
# nginx['listen_port'] = 8080

2. 重新加载配置

sudo gitlab-ctl reconfigure

3. 启动服务

sudo gitlab-ctl start

查看状态:

sudo gitlab-ctl status

三、初始登录设置

1. 获取 root 密码

sudo cat /etc/gitlab/initial_root_password

⚠️ 该文件仅在首次安装后 24 小时内有效

2. 浏览器访问

http://你的IP或域名

使用:

  • 用户名:root
  • 密码:上一步获取的密码

四、常用管理命令

# 启动
sudo gitlab-ctl start

# 停止
sudo gitlab-ctl stop

# 重启
sudo gitlab-ctl restart

# 查看日志
sudo gitlab-ctl tail

五、HTTPS(可选,推荐)

使用 Let’s Encrypt

external_url 'https://gitlab.example.com'
letsencrypt['enable'] = true
letsencrypt['auto_renew'] = true

然后:

sudo gitlab-ctl reconfigure

六、Docker 方式(简要)

docker run --detach \
  --hostname gitlab.example.com \
  --publish 443:443 --publish 80:80 \
  --name gitlab \
  --restart always \
  gitlab/gitlab-ce:latest

七、常见问题

1. 访问慢

  • 内存建议 ≥ 4GB
  • 可关闭部分服务(如 Mattermost)

2. 端口冲突

修改 gitlab.rb 中的 nginx['listen_port']

3. 忘记 root 密码

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

如果你需要:

  • 配置邮件(SMTP)
  • GitLab CI/CD
  • 备份与恢复
  • LDAP / 统一登录

可以告诉我你的具体需求,我可以给你对应配置示例。

0