ubuntu

ubuntu上gitlab网络配置

小樊
50
2025-10-21 03:43:10
栏目: 智能运维

Ubuntu上GitLab网络配置指南

1. 准备工作

确保Ubuntu服务器满足GitLab的最低要求:2核CPU、4GB以上内存、20GB以上存储空间,且已联网(能访问外网)。安装前建议更新系统软件包:

sudo apt update && sudo apt upgrade -y

2. 安装依赖包

GitLab依赖curl(下载工具)、openssh-server(SSH访问)、ca-certificates(SSL证书)、tzdata(时区设置)等组件,通过以下命令安装:

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

3. 添加GitLab官方软件源

通过官方脚本添加GitLab的APT源,确保后续能获取最新版本的GitLab Community Edition(CE):

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

4. 安装GitLab CE

使用apt安装GitLab,安装时可通过EXTERNAL_URL参数直接设置外部访问地址(如IP或域名):

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

若未在安装时设置,可后续修改配置文件(详见步骤6)。

5. 配置GitLab网络参数

GitLab的核心网络配置文件为/etc/gitlab/gitlab.rb,需修改以下关键参数:

6. 重新配置并重启GitLab

修改配置文件后,需执行reconfigure命令使配置生效,随后重启GitLab服务:

sudo gitlab-ctl reconfigure  # 重新编译配置
sudo gitlab-ctl restart      # 重启GitLab服务

7. 配置防火墙(可选但推荐)

若服务器启用了ufw防火墙,需开放GitLab使用的端口(HTTP默认80,HTTPS默认443,SSH默认22):

sudo ufw allow 80/tcp        # 允许HTTP访问
sudo ufw allow 443/tcp       # 允许HTTPS访问(若配置HTTPS)
sudo ufw allow 22/tcp        # 允许SSH访问
sudo ufw enable              # 启用防火墙

8. 配置HTTPS(可选但强烈推荐)

为提升安全性,建议使用Let’s Encrypt免费SSL证书配置HTTPS。安装Certbot工具并获取证书:

sudo apt install -y certbot python3-certbot-nginx  # 若使用Nginx反向代理
sudo certbot --nginx -d gitlab.example.com         # 替换为你的域名

获取证书后,在/etc/gitlab/gitlab.rb中配置SSL路径:

external_url 'https://gitlab.example.com'
nginx['ssl_certificate'] = "/etc/letsencrypt/live/gitlab.example.com/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/gitlab.example.com/privkey.pem"
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

9. 验证网络访问

在浏览器中输入http://your_server_ip(或配置的域名),若能看到GitLab登录页面,说明网络配置成功。首次登录需修改root用户的默认密码(密码可在/etc/gitlab/initial_root_password中查看,文件有效期为24小时)。

常见问题排查

0
看了该问题的人还看了