温馨提示×

centos gitlab如何换端口

小樊
37
2026-09-11 19:19:04
栏目: 智能运维

在 CentOS 上修改 GitLab 的访问端口,通常分 HTTP / HTTPS 端口SSH 端口 两种情况。下面以 Omnibus 版 GitLab(最常见) 为例说明。


一、修改 GitLab HTTP/HTTPS 端口

1. 编辑配置文件

sudo vi /etc/gitlab/gitlab.rb

2. 修改端口(例如改成 8081)

external_url 'http://your-domain-or-ip:8081'

或如果是 HTTPS:

external_url 'https://your-domain-or-ip:8443'

external_url 里的端口就是 GitLab 对外访问端口

3. 重新配置 GitLab

sudo gitlab-ctl reconfigure

4. 重启服务(通常 reconfigure 已包含)

sudo gitlab-ctl restart

二、修改 GitLab SSH 端口(可选)

默认是 22,如果你不想用 22:

1. 修改 gitlab.rb

gitlab_rails['gitlab_shell_ssh_port'] = 2222

2. 重新配置

sudo gitlab-ctl reconfigure

改完后 clone 地址会变成: ssh -p 2222 git@ip:group/project.git


三、防火墙 / SELinux(很重要)

1. 开放新端口(firewalld)

sudo firewall-cmd --permanent --add-port=8081/tcp
sudo firewall-cmd --reload

2. 如果是云服务器

  • 安全组 中放行新端口

3. SELinux(如开启)

sudo semanage port -a -t http_port_t -p tcp 8081

四、验证

sudo gitlab-ctl status
netstat -tunlp | grep 8081

浏览器访问:

http://服务器IP:8081

五、常见问题

1. 端口被占用

lsof -i:8081

2. Nginx 冲突

若用了外部 Nginx:

nginx['enable'] = false

如果你是用 Docker 版 GitLab源码安装,请告诉我,我可以给你对应方案。

0