插件窝 干货文章 怎么在linux服务器上搭建gitlab服务器

怎么在linux服务器上搭建gitlab服务器

GitLab sudo 配置 bash 449    来源:    2025-04-24

在Linux服务器上搭建GitLab服务器指南

准备工作

  1. 系统要求

    • 推荐至少4GB内存(2GB可以运行但性能较差)
    • 至少2个CPU核心
    • 至少4GB可用存储空间(实际需要根据项目大小调整)
  2. 支持的Linux发行版

    • Ubuntu/Debian
    • CentOS/RHEL
    • openSUSE
    • 其他基于上述发行版的系统

安装步骤(以Ubuntu为例)

1. 安装依赖项

sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates postfix

在Postfix安装过程中,选择"Internet Site"并设置您的服务器域名。

2. 添加GitLab仓库并安装

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

3. 安装GitLab

sudo EXTERNAL_URL="https://gitlab.example.com" apt-get install gitlab-ee

gitlab.example.com替换为您实际的域名或服务器IP地址。

4. 配置防火墙(如有)

sudo ufw allow http
sudo ufw allow https
sudo ufw allow OpenSSH
sudo ufw enable

5. 初始配置

运行以下命令重新配置GitLab:

sudo gitlab-ctl reconfigure

6. 访问GitLab

安装完成后,在浏览器中访问您设置的EXTERNAL_URL(如https://gitlab.example.com)。

首次访问时,系统会提示您设置root用户的密码。

其他Linux发行版安装

CentOS/RHEL

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 systemctl reload firewalld

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="https://gitlab.example.com" yum install -y gitlab-ee

常见配置调整

修改配置文件

主配置文件位于/etc/gitlab/gitlab.rb,修改后需要运行:

sudo gitlab-ctl reconfigure

常用命令

  • 启动所有GitLab组件:sudo gitlab-ctl start
  • 停止所有GitLab组件:sudo gitlab-ctl stop
  • 重启所有GitLab组件:sudo gitlab-ctl restart
  • 检查GitLab状态:sudo gitlab-ctl status

备份与恢复

创建备份

sudo gitlab-rake gitlab:backup:create

恢复备份

sudo gitlab-rake gitlab:backup:restore BACKUP=备份文件名

注意事项

  1. 对于生产环境,建议使用HTTPS并配置SSL证书
  2. 定期备份您的GitLab数据
  3. 监控服务器资源使用情况,GitLab可能占用较多内存
  4. 考虑设置自动更新策略以获取安全更新

如需更详细的配置或遇到问题,可以参考GitLab官方文档