2

我开始使用 gitlab:

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

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

git remote add origin ssh://git@gitlab.mydomain.com:12035/root/my_project.git

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

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

git push --verbose -u origin master

然后我得到:

Pushing to ssh://git@gitlab.mydomain.com: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.

所以我有两个用户:一个普通用户:kaigitgitlab 用户。但是gitlab用户没有.ssh目录。但是我已经从我试图推送到 gitlab 的远程机器上添加了 ssh-key。将密钥添加到~/.ssh/configas:

Host gitlab.mydomain.com
        User admin@local.host
        # User Administrator
        IdentityFile ~/.ssh/gitlab_rsa

附言

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

更新:

/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)

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

更新 2:

我检查了 gitlab-shell:

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

并得到相同的结果:

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

然后我将其更改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/"

现在我从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)

现在可能是什么问题?

更新 3:

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

现在我从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

但仍然无法推送:

Pushing to ssh://git@gitlab.mydomain.com: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.

更新 4:

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

> ssh -vT -p 12035 git@gitlab.mydomain.com

debug1: Authentication succeeded (publickey).
Authenticated to gitlab.mydomain.com ([x.x.x.x]:12035).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
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 eow@openssh.com 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

更新 5:

/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.

还有什么问题?

4

4 回答 4

2

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

于 2013-11-14T23:44:59.103 回答
1

在我执行之后(在带有 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

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

> git remote remove origin
> git remote add origin ssh://git@gitlab.mydomain.com:12035/root/myproject.git

然后尝试推:

> git push --verbose -u origin master

Pushing to ssh://git@gitlab.mydomain.com: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://git@gitlab.mydomain.com: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'  

现在:

> 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>.

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

于 2013-10-13T13:51:25.860 回答
1

再次,希望这可能对某个地方的某人有用;我遇到了同样的问题,建议的解决方案都不适合我。具体来说,我不关心 HTTPS,我的 GitLab 也没有被 Apache 代理。

我的 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/) 并且一切正常。

于 2014-07-17T13:49:47.223 回答
1

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

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

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

找到线条

# 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

将最后一行更改为

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

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

于 2014-07-14T08:35:05.557 回答