linux

GitLab在Linux中的网络配置怎样设置

小樊
47
2025-10-12 04:45:20
栏目: 智能运维

GitLab在Linux中的网络配置步骤

1. 准备工作

2. 配置静态IP地址(可选但推荐)

若服务器需固定IP(避免DHCP动态分配导致IP变动),需修改网络接口配置文件:

保存后重启网络服务:

# CentOS
sudo systemctl restart network
# Ubuntu
sudo netplan apply

通过ip a命令验证IP是否生效。

3. 安装并配置防火墙

GitLab需开放**HTTP(80)、HTTPS(443)、SSH(22)**等端口,以下以firewalld(CentOS默认)和ufw(Ubuntu默认)为例:

通过sudo firewall-cmd --list-all(CentOS)或sudo ufw status(Ubuntu)验证端口是否开放。

4. 修改GitLab核心网络配置

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

保存文件后,执行以下命令使配置生效:

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

通过grep "external_url" /etc/gitlab/gitlab.rb验证配置是否正确。

5. 配置HTTPS(可选但推荐)

若需通过HTTPS加密访问,需获取SSL证书(如Let’s Encrypt免费证书),并修改/etc/gitlab/gitlab.rb

external_url 'https://your_domain_or_IP'  # 强制使用HTTPS
nginx['ssl_certificate'] = "/etc/letsencrypt/live/your_domain_or_IP/fullchain.pem"  # 证书路径
nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/your_domain_or_IP/privkey.pem"  # 私钥路径

重新配置并重启GitLab:

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

通过浏览器访问https://your_domain_or_IP,验证HTTPS是否生效。

6. 验证网络配置

首次登录需设置管理员密码(默认用户名为root)。

注意事项

0
看了该问题的人还看了