gitlab之:502解决

时间:2024-05-20 07:39:34

 

gitlab之:502解决

前文提到过一个奇葩的问题,就是配置好后,出现了问题,不能访问gitlab,重启后才可以访问,当时并不认为有问题。但最近发现配置后,这个问题时常出现。所以这里要解决下。

找到了http://blog.****.net/rodjohnsondoctor/article/details/45605469 ,总体思路与解决方法可以借鉴。

可能性一

文中大致提到是unicorn服务与tomcat端口冲突,配置下unicorn使用端口应该就可以了[这个端口在《GitLab之:简单安装属于自己的一个GitLab服务器》这里特意提到过是8080,不知道你注意到了没]

设置端口(设置自己合适的端口即可)的方法:

unicorn['port'] = 9090

1

unicorn['port'] = 9090

gitlab-ctl reconfigure 重启配置,这样GitLab服务器就可以正常运行了。

可能性二

而这次遇到的明显不是这个问题,已经修改了unicorn使用的端口,restart了多次,但是依然是502。

查看了下gitlab的状态

$gitlab-ctl status gitlab run: gitlab-workhorse: (pid 18179) 99s; <span style="color: #ff0000;"><strong>down</strong></span>: log: 0s, normally up, want up run: logrotate: (pid 41667) 2739s; run: log: (pid 1437) 708348s run: postgresql: (pid 1453) 708348s; run: log: (pid 1436) 708348s run: sidekiq: (pid 1450) 708348s; run: log: (pid 1438) 708348s run: unicorn: (pid 1452) 708348s; run: log: (pid 1435) 708348s

1

2

3

4

5

6

$gitlab-ctl status

gitlab run: gitlab-workhorse: (pid 18179) 99s; <span style="color: #ff0000;"><strong>down</strong></span>: log: 0s, normally up, want up

run: logrotate: (pid 41667) 2739s; run: log: (pid 1437) 708348s

run: postgresql: (pid 1453) 708348s; run: log: (pid 1436) 708348s

run: sidekiq: (pid 1450) 708348s; run: log: (pid 1438) 708348s

run: unicorn: (pid 1452) 708348s; run: log: (pid 1435) 708348s

看到没gitlab-workhorse中处于down状态。

502吗,是nginx返回的错误,那我们在看下nginx的错误日志:

2017/03/22 10:36:23 [error] 19487#0: *358778 connect() to unix:/var/opt/gitlab/gitlab-workhorse/socket failed (111: Connection refused) while connecting to upstream, client: 117.100.247.144, server: demo.nideyuan.com, request: "GET / HTTP/1.1", upstream: "http://unix:/var/opt/gitlab/gitlab-workhorse/socket:/", host: "demo.nideyuan.com" 2017/03/22 10:36:23 [error] 19487#0: *358778 connect() to unix:/var/opt/gitlab/gitlab-workhorse/socket failed (111: Connection refused) while connecting to upstream, client: 117.100.247.144, server: demo.nideyuan.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/var/opt/gitlab/gitlab-workhorse/socket:/favicon.ico", host: "demo.nideyuan.com"

1

2

2017/03/22 10:36:23 [error] 19487#0: *358778 connect() to unix:/var/opt/gitlab/gitlab-workhorse/socket failed (111: Connection refused) while connecting to upstream, client: 117.100.247.144, server: demo.nideyuan.com, request: "GET / HTTP/1.1", upstream: "http://unix:/var/opt/gitlab/gitlab-workhorse/socket:/", host: "demo.nideyuan.com"

2017/03/22 10:36:23 [error] 19487#0: *358778 connect() to unix:/var/opt/gitlab/gitlab-workhorse/socket failed (111: Connection refused) while connecting to upstream, client: 117.100.247.144, server: demo.nideyuan.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/var/opt/gitlab/gitlab-workhorse/socket:/favicon.ico", host: "demo.nideyuan.com"

可以确定gitlab-workhorse出问题了,日志中说是/var/opt/gitlab/gitlab-workhorse/socket无法访问(注意:有遇到Permission denied-的比较多,自行解决吧)。看下是否存在有该文件

$ll /var/opt/gitlab/gitlab-workhorse/socket srwxrwxrwx 1 git git 0 Mar 21 12:17 /var/opt/gitlab/gitlab-workhorse/socket

1

2

$ll /var/opt/gitlab/gitlab-workhorse/socket

srwxrwxrwx 1 git git 0 Mar 21 12:17 /var/opt/gitlab/gitlab-workhorse/socket

存在且权限没有问题。这如何是好?有看了下有关gitlab-workhorse的进程

 

# ps -ef |grep workhorse git 18179 31313 0 09:38 ? 00:00:00 /opt/gitlab/embedded/bin/gitlab-workhorse -listenNetwork unix -listenUmask 0 -listenAddr /var/opt/gitlab/gitlab-workhorse/socket -authBackend <span style="color: #ff0000;">http://localhost:8080</span> -authSocket /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket -documentRoot /opt/gitlab/embedded/service/gitlab-rails/public -pprofListenAddr root 19063 18927 0 09:43 pts/2 00:00:00 grep workhorse root 23287 1 0 Mar21 ? 00:00:00 svlogd -tt /var/log/gitlab/gitlab-workhorse git 27842 1 0 Mar21 ? 00:00:00 /opt/gitlab/embedded/bin/gitlab-workhorse -listenNetwork unix -listenUmask 0 -listenAddr /var/opt/gitlab/gitlab-workhorse/socket -authBackend <span style="color: #ff0000;">http://localhost:8080</span> -authSocket /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket -documentRoot /opt/gitlab/embedded/service/gitlab-rails/public -pprofListenAddr root 31311 1 0 Mar21 ? 00:00:22 runsvdir -P /opt/gitlab/service log: ock directory: /var/log/gitlab/gitlab-workhorse: temporary failure?svlogd: fatal: no functional log directories.?svlogd: <span style="color: #ff0000;">warning:</span> unable to lock directory: /var/log/gitlab/gitlab-workhorse: temporary failure?svlogd: fatal: no functional log directories.?svlogd: warning: unable to lock directory: /var/log/gitlab/gitlab-workhorse: temporary failure?svlogd: fatal: no functional log directories.? root 31313 31311 0 Mar21 ? 00:00:57 runsv gitlab-workhorse

1

2

3

4

5

6

7

# ps -ef  |grep workhorse

git      18179 31313  0 09:38 ?        00:00:00 /opt/gitlab/embedded/bin/gitlab-workhorse -listenNetwork unix -listenUmask 0 -listenAddr /var/opt/gitlab/gitlab-workhorse/socket -authBackend <span style="color: #ff0000;">http://localhost:8080</span> -authSocket /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket -documentRoot /opt/gitlab/embedded/service/gitlab-rails/public -pprofListenAddr

root     19063 18927  0 09:43 pts/2    00:00:00 grep workhorse

root     23287     1  0 Mar21 ?        00:00:00 svlogd -tt /var/log/gitlab/gitlab-workhorse

git      27842     1  0 Mar21 ?        00:00:00 /opt/gitlab/embedded/bin/gitlab-workhorse -listenNetwork unix -listenUmask 0 -listenAddr /var/opt/gitlab/gitlab-workhorse/socket -authBackend <span style="color: #ff0000;">http://localhost:8080</span> -authSocket /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket -documentRoot /opt/gitlab/embedded/service/gitlab-rails/public -pprofListenAddr

root     31311     1  0 Mar21 ?        00:00:22 runsvdir -P /opt/gitlab/service log: ock directory: /var/log/gitlab/gitlab-workhorse: temporary failure?svlogd: fatal: no functional log directories.?svlogd: <span style="color: #ff0000;">warning:</span> unable to lock directory: /var/log/gitlab/gitlab-workhorse: temporary failure?svlogd: fatal: no functional log directories.?svlogd: warning: unable to lock directory: /var/log/gitlab/gitlab-workhorse: temporary failure?svlogd: fatal: no functional log directories.?

root     31313 31311  0 Mar21 ?        00:00:57 runsv gitlab-workhorse

晕倒,怎么又两个一样的gitlab-workhorse的进程,且含有8080端口,不就是我们开始改之前unicorn使用的端口嘛。先停到gitlab服务,kill掉gitlab-workhorse的进程

 

#gitlab-ctl stop # kill -9 27842

1

2

3

#gitlab-ctl stop

 

# kill -9 27842

我们再检查下gitlab的配置文件(/etc/gitlab/gitlab.rb ),看其中是否还有与8080端口有关的配置

果然还有

# gitlab_workhorse['auth_backend'] = "http://localhost:8080" #ä¿®æ¹ä¸º gitlab_workhorse['auth_backend'] = "http://localhost:9090"

1

2

3

4

# gitlab_workhorse['auth_backend'] = "http://localhost:8080"

 

#修改为

gitlab_workhorse['auth_backend'] = "http://localhost:9090"

gitlab-ctl reconfigure 重启配置,这样GitLab服务器就可以正常运行了。

 

整体思路:检查gitlab的状态,查看nginx日志,查看进程状态,在做判断。