侧边栏壁纸
博主头像
faneok博主等级

重剑无锋,大巧不工

  • 累计撰写 33 篇文章
  • 累计创建 17 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Ubuntu & gitlab

faneok
2025-05-25 / 0 评论 / 0 点赞 / 52 阅读 / 3644 字

在 Ubuntu 上安装 GitLab 可以分为以下几个步骤:


​1. 安装依赖​

首先更新系统并安装必要的依赖包:

sudo apt update
sudo apt upgrade -y
sudo apt install -y curl openssh-server ca-certificates postfix
  • ​Postfix​​ 用于邮件通知(可选)。安装时可能会弹出配置界面,选择 ​​Internet Site​​ 并按需填写域名。


​2. 添加 GitLab 仓库​

使用官方脚本添加仓库并安装:

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

​3. 安装 GitLab CE​

替换 YOUR_DOMAIN 为你的实际域名或服务器 IP,然后执行:

sudo EXTERNAL_URL="http://YOUR_DOMAIN" apt install -y gitlab-ce
  • 如果仅本地访问,可以用 http://localhost

  • 安装过程可能需要几分钟(依赖服务器性能)。


​4. 配置防火墙(如有)​

允许 HTTP/HTTPS 和 SSH:

sudo ufw allow http
sudo ufw allow https
sudo ufw allow ssh
sudo ufw enable

​5. 初始化 GitLab​

安装完成后会自动启动服务。首次访问需设置 root 密码:

  1. 打开浏览器访问 http://YOUR_DOMAIN

  2. 输入 root 密码并登录。


​6. 常用命令​

  • ​启动/停止/重启 GitLab​​:

    sudo gitlab-ctl start
    sudo gitlab-ctl stop
    sudo gitlab-ctl restart
  • ​查看状态​​:

    sudo gitlab-ctl status
  • ​重新配置​​(修改 /etc/gitlab/gitlab.rb 后需运行):

    sudo gitlab-ctl reconfigure

​7. 配置 HTTPS(可选)​

  1. 修改 /etc/gitlab/gitlab.rb

    external_url 'https://YOUR_DOMAIN'
    letsencrypt['enable'] = true
    letsencrypt['contact'] = 'your_email@example.com'
  2. 重新配置并重启:

    sudo gitlab-ctl reconfigure
    sudo gitlab-ctl restart

​问题排查​

  • ​502 错误​​:通常因内存不足。建议服务器至少 4GB RAM,或增加 Swap:

    sudo dd if=/dev/zero of=/swapfile bs=1G count=4
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
  • ​端口冲突​​:检查 /etc/gitlab/gitlab.rb 中的 nginx['listen_port']

0

评论区