gitlab更改ssh端口
由于我的gitlab是在docker中启动的,在宿主机上的22端口是被宿主机占用的,所以需要更改gitlab的默认端口,让容器内端口和容器外部端口保持一致,更加美观。
贴一下我的docker compose文件
compose文件参考地址: https://docs.gitlab.com/install/docker/installation/
networks:
**:
external: true
services:
gitlab:
networks:
- **
image: gitlab/gitlab-ee:18.1.0-ee.0
container_name: gitlab
restart: always
hostname: '*'
environment:
GITLAB_OMNIBUS_CONFIG: |
# Add any other gitlab.rb configuration here, each on its own line
external_url '*'
ports:
- '2222:22'
volumes:
- '/data/gitlab/config:/etc/gitlab'
- '/data/gitlab/logs:/var/log/gitlab'
- '/data/gitlab/data:/var/opt/gitlab'
shm_size: '256m'
由于我是22映射到了2222,我想把容器内的ssh端口更改成2222,这样保持容器内外一致。
更改容器内的ssh端口,因为容器内的ssh配置文件没有映射到容器外边,所有要先把配置文件拷贝到容器外
docker cp gitlab:/etc/ssh/sshd_config /data/gitlab/ssh
然后在volumes标签下添加
- '/data/gitlab/ssh/sshd_config:/etc/ssh/sshd_config'
然后从容器内部更改sshd_config文件,把端口改成2222,这样更改端口就能重启后也生效了。
下边更改gitlab的配置文件
修改了/etc/gitlab/gitlab.rb
中的gitlab_rails['gitlab_shell_ssh_port']= 2222
执行下边命令让配置生效
gitlab-ctl reconfigure # 重新应用配置
gitlab-ctl restart # 重启