从 gitlab 推送到远程 git 服务器时出现“连接被拒绝 - connect(2) (Errno::ECONNREFUSED)”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19341965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:11:47  来源:igfitidea点击:

"Connection refused - connect(2) (Errno::ECONNREFUSED)" when pushing to the remote git server from gitlab

gitpushgitlab

提问by static

I started gitlab with:

我开始使用 gitlab:

rvmsudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

When I create a new project, I get the remote repo url:

当我创建一个新项目时,我得到了远程 repo url:

git remote add origin ssh://[email protected]:12035/root/my_project.git

(so not the default 22 ssh port, but 12035)

So when I try to push it to the gitlab:

因此,当我尝试将其推送到 gitlab 时:

git push --verbose -u origin master

Then I get:

然后我得到:

Pushing to ssh://[email protected]:12035/root/my_project.git
/home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:878:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
        from /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:878:in `open'
        from /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
        from /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
        from /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:877:in `connect'
        from /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
        from /home/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/http.rb:851:in `start'
        from /home/git/gitlab-shell/lib/gitlab_net.rb:62:in `get'
        from /home/git/gitlab-shell/lib/gitlab_net.rb:17:in `allowed?'
        from /home/git/gitlab-shell/lib/gitlab_shell.rb:60:in `validate_access'
        from /home/git/gitlab-shell/lib/gitlab_shell.rb:23:in `exec'
        from /home/git/gitlab-shell/bin/gitlab-shell:16:in `<main>'
fatal: Could not read from remote repository.

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

So I have two users: a normal one: kaiand the gitfor gitlab. But the gitlabuser has no .sshdirectory. But I already added the ssh-key from the remote machine from where I am trying to push to the gitlab. The key is added to the ~/.ssh/configas:

所以我有两个用户:一个普通用户:kaigitfor gitlab。但是gitlab用户没有.ssh目录。但是我已经从我试图推送到 gitlab 的远程机器上添加了 ssh 密钥。键被添加到~/.ssh/config作为:

Host gitlab.mydomain.com
        User [email protected]
        # User Administrator
        IdentityFile ~/.ssh/gitlab_rsa

P.S.

聚苯乙烯

already looked into all similar questions here related to the error. but either didn't not get the answers or they didn't help

已经在这里查看了与错误相关的所有类似问题。但要么没有得到答案,要么他们没有帮助

Update:

更新:

the lines in the /var/log/auth.logfor the last git pushattempt:

在该行/var/log/auth.log最后git push的尝试:

Oct 13 06:53:04 80-69-77-159 sudo:  kai : TTY=pts/2 ; PWD=/home/git/gitlab ; USER=root ; COMMAND=/usr/bin/less /var/log/auth.log
Oct 13 06:53:04 80-69-77-159 sudo: pam_unix(sudo:session): session opened for user root by kai(uid=0)

So all the possible users appear there. What does it mean?

所以所有可能的用户都出现在那里。这是什么意思?

Update 2:

更新 2:

I checked the gitlab-shell with:

我检查了 gitlab-shell:

sudo -u git -H /home/git/gitlab-shell/bin/check

and got the same:

并得到相同的:

http.rb:878:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)

I changed then the gitlab_urlto httpsin config.yml:

然后我将其更改gitlab_urlhttpsin config.yml

sudo -u git -H nano /home/git/gitlab-shell/config.yml

gitlab_url: "http://gitlab.udesk.org/" -> gitlab_url: "https://gitlab.udesk.org/"

Now I get from the sudo -u git -H /home/git/gitlab-shell/bin/check:

现在我从sudo -u git -H /home/git/gitlab-shell/bin/check

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)

What could be now the problem?

现在可能是什么问题?

Update 3:

更新 3:

Then I changed the self_signed_cert: falseto self_signed_cert: truein /home/git/gitlab-shell/config.yml.

然后我将其更改self_signed_cert: falseself_signed_cert: truein /home/git/gitlab-shell/config.yml

Now I get from the sudo -u git -H /home/git/gitlab-shell/bin/check:

现在我从sudo -u git -H /home/git/gitlab-shell/bin/check

Check GitLab API access: OK
Check directories and files: 
    /home/git/repositories: OK
    /home/git/.ssh/authorized_keys: OK

But still cannot push:

但是还是不能推送:

Pushing to ssh://[email protected]:12035/root/my_project.git
Access denied.
fatal: Could not read from remote repository.

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

Update 4:

更新 4:

Now I noticed that the test ssh line now works:

现在我注意到测试 ssh 行现在可以工作了:

> ssh -vT -p 12035 [email protected]

debug1: Authentication succeeded (publickey).
Authenticated to gitlab.mydomain.com ([x.x.x.x]:12035).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Remote: Forced command.
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
Welcome to GitLab, Administrator!
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3264, received 3248 bytes, in 0.7 seconds
Bytes per second: sent 4782.6, received 4759.2
debug1: Exit status 0

Update 5:

更新 5:

in the /home/git/gitlab-shell/gitlab-shell.logthe corresponding line to the git push --verbose -u origin masteris:

/home/git/gitlab-shell/gitlab-shell.log对应的行中git push --verbose -u origin master是:

W, [2013-10-13T15:18:05.276231 #24654]  WARN -- : gitlab-shell: Access denied for git command <git-receive-pack '/root/myproject.git'> by user with key key-1.

What could be still the problem?

什么可能仍然是问题?

回答by Carl

By default unicorn is configured to listening on 127.0.0.1:8080(/home/git/gitlab/config/unicorn.rb), so gitlab_urlneeds to set as http://yourURL:8080/

默认 unicorn 配置为监听127.0.0.1:8080(/home/git/gitlab/config/unicorn.rb),所以gitlab_url需要设置为http://yourURL:8080/

回答by DagW

I realize this is an old post, but for the general internet knowledge base.. Got this error in the latest version of gitlab setup, with a proxy virtual host in apache2, but also applies for nginx.

我意识到这是一个旧帖子,但对于一般的互联网知识库.. 在最新版本的 gitlab 设置中遇到此错误,在 apache2 中使用代理虚拟主机,但也适用于 nginx。

Ok, got the same issue - and here is how I solved it;

好的,遇到了同样的问题 - 这是我解决它的方法;

in /home/git/gitlab/config/unicorn.rb

在 /home/git/gitlab/config/unicorn.rb

find the lines

找到线条

# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 64
listen "127.0.0.1:8080", :tcp_nopush => true

Change the last line to

将最后一行更改为

listen "0.0.0.0:8080", :tcp_nopush => true

so it accepts connections not just from the local machine.

所以它不仅接受来自本地机器的连接。

回答by jpappe

Again, in the hope that this might be useful to someone, somewhere; I had this same problem and none of the suggested solutions worked for me. Specifically, I do not care about HTTPS and my GitLab is not proxied behind Apache.

再次,希望这可能对某人有用;我遇到了同样的问题,没有一个建议的解决方案对我有用。具体来说,我不关心 HTTPS 并且我的 GitLab 不在 Apache 后面代理。

My gitlab-shell's config had gitlab_url: http://hostname:9999/. My gitlab/config/unicorn.rb had listen "10.80.40.169:9999". So, I just changed the gitlab_urlto match unicorn.rb (gitlab_url: http://10.80.40.169:9999/) and everything works.

我的 gitlab-shell 配置有gitlab_url: http://hostname:9999/. 我的 gitlab/config/unicorn.rb 有listen "10.80.40.169:9999". 所以,我只是改变了gitlab_url匹配 unicorn.rb ( gitlab_url: http://10.80.40.169:9999/) 并且一切正常。

回答by static

After I executed (on the server with gitlab):

在我执行之后(在带有 gitlab 的服务器上):

> pwd # just to get context
    /home/git/gitlab

> sudo -u git -H /home/git/gitlab-shell/bin/gitlab-keys clear
> sudo -u git -H bundle exec rake gitlab:shell:setup RAILS_ENV=production

then removed git remote and added it back again (on the local server with git repo to push to gitlab):

然后删除 git remote 并再次添加它(在本地服务器上使用 git repo 推送到 gitlab):

> git remote remove origin
> git remote add origin ssh://[email protected]:12035/root/myproject.git

Then tried to push:

然后尝试推:

> git push --verbose -u origin master

Pushing to ssh://[email protected]:12035/root/myproject.git
Counting objects: 401, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (289/289), done.
Writing objects: 100% (401/401), 1.05 MiB | 98.00 KiB/s, done.
Total 401 (delta 127), reused 0 (delta 0)
To ssh://[email protected]:12035/root/myproject.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
updating local tracking ref 'refs/remotes/origin/master'  

Now:

现在:

> cat /home/git/gitlab-shell/gitlab-shell.log

I, [2013-10-13T15:38:49.332477 #24935]  INFO -- : gitlab-shell: executing git command <git-receive-pack /home/git/repositories/'/root/myproject.git'> for user with key key-1.
I, [2013-10-13T15:40:00.037092 #24958]  INFO -- : Update head in project root/myproject.git to <master>.

I don't know what the real problem was here, but trying to investigate it step by step helped (first fixing the gitlab_url problem, then getting ssh working with the repo, and finally getting the git working properly). I hope these steps could help to solve some similar problems (e.g. named in the updates)

我不知道这里真正的问题是什么,但是尝试逐步调查它是有帮助的(首先修复 gitlab_url 问题,然后让 ssh 与 repo 一起工作,最后让 git 正常工作)。我希望这些步骤可以帮助解决一些类似的问题(例如在更新中命名)