ruby Gitlab 配置问题:: NGINX Unicorn 端口冲突

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25011895/
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-06 06:32:51  来源:igfitidea点击:

Gitlab Configuration Issues:: NGINX Unicorn Port Conflict

rubygitnginxcentosgitlab

提问by rhand

I have managed to partly setup Gitlabon a Linux CentOS server with Apache, Git, PHP, PostGreSQL and MySQL. I am running the Chef Cookbook version. I got the rpm from here. I wanted to use it to manage my Git repo better and more visually and this seemed to be a good choice. But now I run into issues getting it to work.

我已经设法在 Linux CentOS 服务器上使用 Apache、Git、PHP、PostGreSQL 和 MySQL部分设置了Gitlab。我正在运行Chef Cookbook 版本。我从这里得到了 rpm 。我想用它来更好、更直观地管理我的 Git 存储库,这似乎是一个不错的选择。但是现在我遇到了让它工作的问题。

Just to make it really work and update all files I decided to rerun the configuration using gitlab-ctl reconfigure. Second run did work:

只是为了让它真正工作并更新所有文件,我决定使用gitlab-ctl reconfigure. 第二次运行确实有效:

Chef Client finished, 4 resources updated
gitlab Reconfigured!

See full log

查看完整日志

The hoster had already put NGINX on 8080 not get into an argument with Apache running on port 80 where we have a LAMP project running. But now Ruby's Unicorn Web Server seems to be conflicting with NGINX. I have worked with NGINX a little bit, not much and this is my first stab at Gitlab. Anyways this is what I figured out with the help of my hoster.

托管商已经将 NGINX 放在 8080 上,而不是与运行在端口 80 上的 Apache 发生争执,我们正在运行 LAMP 项目。但是现在Ruby的Unicorn Web Server好像和NGINX有冲突。我曾与 NGINX 合作过一些,但并不多,这是我在 Gitlab 上的第一次尝试。无论如何,这是我在房东的帮助下发现的。

When I log into testserver.domain.net and pass the following command:

当我登录 testserver.domain.net 并传递以下命令时:

netstat -ln |grep 8080I see

netstat -ln |grep 8080我懂了

tcp        0      0 127.0.0.1:8080              0.0.0.0:*                   LISTEN      

So something is running on 8080 According to my hoster it should run on 0.0.0.0:8080. And when we check what is running on that port we see

所以有些东西在 8080 上运行 根据我的主机,它应该在 0.0.0.0:8080 上运行。当我们检查该端口上正在运行的内容时,我们会看到

netstat -tupln |grep 8080
tcp        0      0 127.0.0.1:8080              0.0.0.0:*                   LISTEN      21627/unicorn maste 

When we check the process id 21627, we see

当我们检查进程 id 21627 时,我们看到

cat /proc/21627/cmdline 
unicorn master -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru

That is a Ruby process, and not a NGINX process.

那是一个 Ruby 进程,而不是一个 NGINX 进程。

So NGINX seems to be conflicting with Unicorn.

所以NGINX似乎和Unicorn有冲突。

And when we check the logs of nginx we see that nginx cannot get going because of this:

当我们检查 nginx 的日志时,我们发现 nginx 无法运行,因为:

tail -f /var/log/gitlab/nginx/error.log 
2014/07/28 09:43:10 [emerg] 23122#0: bind() to 0.0.0.0:8080 failed (98: Address already in use)
2014/07/28 09:43:10 [emerg] 23122#0: still could not bind()
2014/07/28 09:43:12 [emerg] 23123#0: bind() to 0.0.0.0:8080 failed (98: Address already in use)
2014/07/28 09:43:12 [emerg] 23123#0: bind() to 0.0.0.0:8080 failed (98: Address already in use)
2014/07/28 09:43:12 [emerg] 23123#0: bind() to 0.0.0.0:8080 failed (98: Address already in use)
2014/07/28 09:43:12 [emerg] 23123#0: bind() to 0.0.0.0:8080 failed (98: Address already in use)
2014/07/28 09:43:12 [emerg] 23123#0: bind() to 0.0.0.0:8080 failed (98: Address already in use)
2014/07/28 09:43:12 [emerg] 23123#0: still could not bind()

I googled Unicorn.rb and found this link. I also read that:

我用谷歌搜索 Unicorn.rb 并找到了这个链接。我还读到:

Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels. Slow clients should only be served by placing a reverse proxy capable of fully buffering both the the request and response in between Unicorn and slow clients.

Unicorn 是 Rack 应用程序的 HTTP 服务器,旨在仅在低延迟、高带宽连接上为快速客户端提供服务,并利用 Unix/类 Unix 内核中的功能。只能通过放置一个能够完全缓冲 Unicorn 和慢速客户端之间的请求和响应的反向代理来为慢速客户端提供服务。

When I check the file /var/opt/gitlab/gitlab-rails/etc/unicorn.rbI do see it uses 8080. Issue is that it seems Unicorn should work together with NGINX so perhaps I should not change the port.

当我检查文件时,/var/opt/gitlab/gitlab-rails/etc/unicorn.rb我确实看到它使用 8080。问题是 Unicorn 似乎应该与 NGINX 一起工作,所以也许我不应该更改端口。

What step should I take to make Gitlab work? Can Gitlab work without Unicorn? I would think not. Should I then pick another port for it or perhaps for NGINX?

我应该采取什么步骤来使 Gitlab 工作?Gitlab 可以在没有 Unicorn 的情况下工作吗?我想不会。我应该为它选择另一个端口还是为 NGINX 选择另一个端口?

采纳答案by axil

You should override the ports in /etc/gitlab/gitlab.rb. Don't mess with /var/opt/gitlab/...because any manual configuration will be lost after a reconfigure. In particular read on Setting the NGINX listen port. In the downloads page there is a sentence: For troubleshooting and configuration options please see the Omnibus GitLab readme. I wonder if this is not seen by people :/ If not we should make it more clear.

您应该覆盖/etc/gitlab/gitlab.rb. 不要乱来,/var/opt/gitlab/...因为任何手动配置在重新配置后都会丢失。特别阅读设置 NGINX 监听端口。在下载页面中有一句话:有关故障排除和配置选项,请参阅 Omnibus GitLab 自述文件。我想知道人们是否没有看到这一点:/如果没有,我们应该说得更清楚。

回答by Akarsh

To add to Axil's comments. I had to change it in /var/opt/gitlab/gitlab-rails/etc/unicorn.rb file as well. A restart after that worked, I did not lose my configs. The unicorn master was not picking my changes from /etc/gitlab/gitlab.rb file even after multiple restarts.

添加到 Axil 的评论中。我也必须在 /var/opt/gitlab/gitlab-rails/etc/unicorn.rb 文件中更改它。工作后重新启动,我没有丢失我的配置。即使在多次重新启动后,独角兽大师也没有从 /etc/gitlab/gitlab.rb 文件中选择我的更改。

回答by zeusAlmighty

You should update the /etc/gitlab/gitlab.rb file.

您应该更新 /etc/gitlab/gitlab.rb 文件。

Make sure when you modify the file that you are uncommenting the line that you are changing. It's using chef, so if the gitlab.rb file is configured properly when you run sudo gitlab-ctl reconfigure;it will update the corresponding file properly. Then sudo gitlab-ctl restartto restart the services.

确保在修改文件时取消注释要更改的行。它使用的是chef,所以如果运行时gitlab.rb 文件配置正确,sudo gitlab-ctl reconfigure;它将正确更新相应的文件。然后sudo gitlab-ctl restart重新启动服务。

sudo lsof -Pni |grep <port number>is your friend when determining port conflicts

sudo lsof -Pni |grep <port number>在确定端口冲突时是您的朋友

回答by Ian

The documentationsuggests setting 'nginx['listen_port'] = 8080' but when I did this unicorn failed to bind port 8080. I set the nginx port to 8888 instead and it worked. This suggests that in order to set the nginx port to 8080, it is necessary to change unicorn from default port of 8080 to something else, but I didn't explore that possibility. It would be nice if the example for setting the nginx port was a setting that would work in the default configuration, which mine is, as well as I know - I only installed it this morning.

文档建议设置 'nginx['listen_port'] = 8080' 但是当我这样做时,这个独角兽未能绑定端口 8080。我将 nginx 端口设置为 8888 并且它起作用了。这表明为了将 nginx 端口设置为 8080,需要将 unicorn 从默认端口 8080 更改为其他端口,但我没有探索这种可能性。如果设置 nginx 端口的示例是一个可以在默认配置下工作的设置,那就太好了,我就是这样,据我所知 - 我今天早上才安装了它。