首页 文章

不能使用带有dockerized Gitlab的ssh

提问于
浏览
2

我在centos 7上使用docker安装了最新的gitlab

docker run -d --hostname git.xxxx.com \
-p 8082:80 -p 22:22 \
--name gitlab \
--restart always \
-v /srv/gitlab/config:/etc/gitlab:Z \
-v /srv/gitlab/logs:/var/log/gitlab:Z \
-v /srv/gitlab/data:/var/opt/gitlab:Z \
gitlab/gitlab-ce:latest

我还将主机ssh端口更改为10022并让gitlab使用端口22.Gitlab运行成功 . 克隆使用http工作,但在使用ssh时失败 .

git clone git@git.xxxx.com:yphc/dt-dd-miniprogram.git

Cloning into 'dt-dd-miniprogram'...
ssh: connect to host git.xxxx.com port 22: Bad file number
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

检查Gitlab状态的输出:

root@git:/# gitlab-ctl status
run: gitaly: (pid 472) 241405s; run: log: (pid 467) 241405s
run: gitlab-monitor: (pid 474) 241405s; run: log: (pid 465) 241405s
run: gitlab-workhorse: (pid 471) 241405s; run: log: (pid 464) 241405s
run: logrotate: (pid 15611) 203s; run: log: (pid 456) 241405s
run: nginx: (pid 475) 241405s; run: log: (pid 469) 241405s
run: node-exporter: (pid 460) 241406s; run: log: (pid 459) 241406s
run: postgres-exporter: (pid 453) 241406s; run: log: (pid 452) 241406s
run: postgresql: (pid 470) 241406s; run: log: (pid 463) 241406s
run: prometheus: (pid 482) 241406s; run: log: (pid 476) 241406s
run: redis: (pid 396) 241408s; run: log: (pid 395) 241408s
run: redis-exporter: (pid 455) 241406s; run: log: (pid 454) 241406s
run: sidekiq: (pid 473) 241406s; run: log: (pid 468) 241406s
warning: sshd: unable to open supervise/ok: access denied
run: unicorn: (pid 466) 241406s; run: log: (pid 458) 241406s

warning: sshd: unable to open supervise/ok: access denied

我在gitlab容器中尝试了ssh命令 . 我还在防火墙上添加了端口22 .

[root@localhost zones]# firewall-cmd --list-all 
    public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp2s0
  sources: 
  services: ssh dhcpv6-client
  ports: 2022/tcp 10022/tcp 22/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules:

当我关闭防火墙时,它说

Cloning into 'dt-dd-miniprogram'...
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我在互联网上环顾了很长时间但找不到任何东西 . 如果有任何帮助或想法如何解决这个问题,我将不胜感激 .

2 回答

  • 0

    从kvm迁移后,我在官方gitlab-ce docker镜像中遇到了同样的情况 .

    root@gitlab:/opt/gitlab# /opt/gitlab/embedded/bin/sv start sshd
    warning: sshd: unable to open supervise/ok: access denied
    

    我发现这个sv会产生错误:

    root@gitlab:/opt/gitlab# /opt/gitlab/embedded/bin/sv start sshd
    warning: sshd: unable to open supervise/ok: access denied
    

    因为root无法访问/ opt / gitlab / sv / sshd / supervise / ok管道:

    root@gitlab:/opt/gitlab/sv/sshd/supervise# cat ok
    cat: ok: Permission denied
    

    就像测试我用777权限更新它,但仍然没有运气

    root@gitlab:/opt/gitlab/# /opt/gitlab/embedded/bin/sv start sshd
    fail: sshd: runsv not running
    

    我使用的解决方法是在我的Dockerfile中,它基于gitlab-ce:latest:

    RUN sed -i '/gitlab-ctl reconfigure/a service ssh start' /assets/wrapper
    

    这将启动ssh,现在我可以通过ssh连接git用户来推送和拉动:)

    不要忘记你需要为你想要使用的端口设置适当的env https://docs.gitlab.com/omnibus/docker/

    environment:
        GITLAB_OMNIBUS_CONFIG: |
          external_url 'http://gitlab.m31.com:3080'
          gitlab_rails['gitlab_shell_ssh_port'] = 3022
    

    所以事情现在正在发挥作用,但请记住,这是一个奇怪/丑陋的解决方法,我确信有更好的方法来使这项工作 .

  • 0

    我在另一个centos 7上做了同样的事情,一切都很好,所以我猜操作系统有一些错误,gitlab docker没关系,但是到目前为止我找不到了thx

相关问题