我公司的gitlab是部署在Ubuntu: 乌班图(也有友帮拓、优般图等译名)

1、通过 WindTerm 连接 Ubuntu

在这里插入图片描述

2、检查 GitLab 服务状态

首先,检查 GitLab 的各个服务是否正常运行:

sudo gitlab-ctl status
root@ubuntu20:~# sudo gitlab-ctl status
run: alertmanager: (pid 1422) 2245853s; run: log: (pid 1416) 2245853s
run: gitaly: (pid 1421) 2245853s; run: log: (pid 1414) 2245853s
run: gitlab-monitor: (pid 1440) 2245853s; run: log: (pid 1431) 2245853s
run: gitlab-workhorse: (pid 1436) 2245853s; run: log: (pid 1426) 2245853s
run: grafana: (pid 1437) 2245853s; run: log: (pid 1429) 2245853s
run: logrotate: (pid 8999) 2934s; run: log: (pid 1439) 2245853s
run: nginx: (pid 1434) 2245853s; run: log: (pid 1428) 2245853s
run: node-exporter: (pid 1438) 2245853s; run: log: (pid 1430) 2245853s
run: postgres-exporter: (pid 1425) 2245853s; run: log: (pid 1418) 2245853s
run: postgresql: (pid 1415) 2245853s; run: log: (pid 1412) 2245853s
run: prometheus: (pid 1432) 2245853s; run: log: (pid 1420) 2245853s
run: redis: (pid 1419) 2245853s; run: log: (pid 1413) 2245853s
run: redis-exporter: (pid 1424) 2245853s; run: log: (pid 1417) 2245853s
run: sidekiq: (pid 1435) 2245853s; run: log: (pid 1423) 2245853s
run: unicorn: (pid 426) 1s; run: log: (pid 1427) 2245853s

根据 gitlab-ctl status 输出的内容,GitLab 的大部分服务都在运行,但是 unicorn 进程的 PID 是 426,运行了仅 1 秒钟。unicorn 是 GitLab 的应用服务器,它处理主要的 HTTP 请求。如果 unicorn 反复重启或无法正常运行,这很可能是导致 502 Bad Gateway 错误的原因。

3、查看 Unicorn 日志

首先,检查 Unicorn 的日志,看看是什么原因导致它无法正常启动。日志文件位于 /var/log/gitlab/unicorn/。
运行以下命令查看 Unicorn 日志:

sudo cat /var/log/gitlab/unicorn/current
root@ubuntu20:~# sudo cat /var/log/gitlab/unicorn/current
2024-10-10_07:09:33.63838 failed to start a new unicorn master
2024-10-10_07:09:33.64968 starting new unicorn master
2024-10-10_07:09:33.87437 master failed to start, check stderr log for details
2024-10-10_07:09:34.88615 failed to start a new unicorn master
2024-10-10_07:09:34.89920 starting new unicorn master
2024-10-10_07:09:35.13327 master failed to start, check stderr log for details
2024-10-10_07:09:36.14580 failed to start a new unicorn master
2024-10-10_07:09:36.15991 starting new unicorn master
2024-10-10_07:09:36.40057 master failed to start, check stderr log for details
2024-10-10_07:09:37.41466 failed to start a new unicorn master
2024-10-10_07:09:37.42728 starting new unicorn master
2024-10-10_07:09:37.66208 master failed to start, check stderr log for details
2024-10-10_07:09:38.67082 failed to start a new unicorn master
2024-10-10_07:09:38.68441 starting new unicorn master
2024-10-10_07:09:38.91950 master failed to start, check stderr log for details

查看日志中是否有任何错误信息,比如内存不足、数据库连接问题等。
从日志中可以看出,Unicorn 服务的 master 进程无法启动,日志提到 master failed to start, check stderr log for details,这意味着你需要查看 stderr 日志文件中的更多详细信息,以了解具体的启动失败原因。

4、检查 Unicorn 的 stderr 日志

Unicorn 的 stderr 日志通常可以在以下路径中找到:

sudo cat /var/log/gitlab/unicorn/unicorn_stderr.log
root@ubuntu20:~# sudo cat /var/log/gitlab/unicorn/unicorn_stderr.log
ArgumentError: Already running on PID:1487 (or pid=/opt/gitlab/var/unicorn/unicorn.pid is stale)
  /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:205:in `pid='
  /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:137:in `start'
  /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn:126:in `<top (required)>'
  /opt/gitlab/embedded/bin/unicorn:23:in `load'
  /opt/gitlab/embedded/bin/unicorn:23:in `<top (required)>'
ArgumentError: Already running on PID:1487 (or pid=/opt/gitlab/var/unicorn/unicorn.pid is stale)
  /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:205:in `pid='
  /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:137:in `start'
  /opt/gitlab/embedded/lib/ruby/gems/2.6.0/gems/unicorn-5.4.1/bin/unicorn:126:in `<top (required)>'
  /opt/gitlab/embedded/bin/unicorn:23:in `load'
  /opt/gitlab/embedded/bin/unicorn:23:in `<top (required)>'

从错误日志中可以看出,Unicorn 尝试启动时遇到了 ArgumentError: Already running on PID:1487 错误。这意味着 Unicorn 认为自己已经在运行,或者 unicorn.pid 文件是陈旧的,并且没有正确清理。
这是一个常见问题,通常发生在 Unicorn 崩溃或意外停止后,未正确删除 .pid 文件,从而阻止新的 Unicorn 实例启动

5、检查 PID

首先,确认 Unicorn 是否真的在运行:

ps -ef | grep unicorn

如果 Unicorn 实例已经运行,会显示它的进程信息。如果没有运行但仍然有 .pid 文件,则是因为这个 .pid 文件已经陈旧。

root@ubuntu20:~# ps -ef | grep unicorn
root      1410  1394  0 Sep15 ?        00:09:06 runsv unicorn
root      1427  1410  0 Sep15 ?        00:01:54 svlogd -tt /var/log/gitlab/unicorn
git       4369  1410  0 15:03 ?        00:00:00 /bin/bash /opt/gitlab/embedded/bin/gitlab-unicorn-wrapper
git       4384  4369  0 15:03 ?        00:00:00 /opt/gitlab/embedded/bin/unicorn -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru
root      4386 10412  0 15:03 pts/0    00:00:00 grep --color=auto unicorn

从输出结果中可以看出,Unicorn 的相关进程已经在运行:

  • gitlab-unicorn-wrapper (PID 4369)
  • unicorn 主进程 (PID 4384)

但是,你之前遇到的错误显示 Unicorn 已经在运行,可能是由于在尝试启动新实例时,旧的 Unicorn 进程仍在运行。这种情况通常发生在重启不干净或崩溃时。
解决步骤:停止当前运行的 Unicorn 服务

6、停止当前运行的 Unicorn 服务

为了清理当前的进程,可以停止 GitLab 的 Unicorn 服务:

sudo gitlab-ctl stop unicorn

这将停止所有 Unicorn 相关的进程。

root@ubuntu20:~# sudo gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up

7、确认 Unicorn 已停止

再次运行以下命令,确保所有 Unicorn 进程都已停止:

ps -ef | grep unicorn
root@ubuntu20:~# ps -ef | grep unicorn
root      1410  1394  0 Sep15 ?        00:09:06 runsv unicorn
root      1427  1410  0 Sep15 ?        00:01:54 svlogd -tt /var/log/gitlab/unicorn
root      6447 10412  0 15:05 pts/0    00:00:00 grep --color=auto unicorn

从当前的输出结果来看,Unicorn 的主要进程(如 gitlab-unicorn-wrapper 和 unicorn)已经不在运行,只有日志相关的进程 (runsv unicorn 和 svlogd) 在运行,这表示 Unicorn 已成功停止。
接下来,可以按照以下步骤继续操作:

8、删除陈旧的 .pid 文件

确保删除陈旧的 Unicorn PID 文件,以避免启动时冲突:

sudo rm /opt/gitlab/var/unicorn/unicorn.pid
root@ubuntu20:~# sudo rm /opt/gitlab/var/unicorn/unicorn.pid

9、重新启动 GitLab 服务

在清理 .pid 文件后,重新启动 GitLab 服务,确保 Unicorn 重新正常启动:

sudo gitlab-ctl restart
root@ubuntu20:~# sudo gitlab-ctl restart
ok: run: alertmanager: (pid 6491) 0s
ok: run: gitaly: (pid 6500) 0s
ok: run: gitlab-monitor: (pid 6523) 1s
ok: run: gitlab-workhorse: (pid 6525) 0s
ok: run: grafana: (pid 6535) 1s
ok: run: logrotate: (pid 6545) 0s
ok: run: nginx: (pid 6627) 0s
ok: run: node-exporter: (pid 6632) 1s
ok: run: postgres-exporter: (pid 6640) 0s
ok: run: postgresql: (pid 6650) 1s
ok: run: prometheus: (pid 6659) 0s
ok: run: redis: (pid 6667) 1s
ok: run: redis-exporter: (pid 6671) 0s
ok: run: sidekiq: (pid 6678) 1s
ok: run: unicorn: (pid 6684) 0s

10、检查状态

重新启动后,检查所有 GitLab 服务的状态,确保 Unicorn 进程已经成功启动:

sudo gitlab-ctl status
root@ubuntu20:~# sudo gitlab-ctl status
run: alertmanager: (pid 6491) 15s; run: log: (pid 1416) 2246223s
run: gitaly: (pid 6500) 14s; run: log: (pid 1414) 2246223s
run: gitlab-monitor: (pid 6523) 14s; run: log: (pid 1431) 2246223s
run: gitlab-workhorse: (pid 6525) 13s; run: log: (pid 1426) 2246223s
run: grafana: (pid 6535) 13s; run: log: (pid 1429) 2246223s
run: logrotate: (pid 6545) 12s; run: log: (pid 1439) 2246223s
run: nginx: (pid 6627) 12s; run: log: (pid 1428) 2246223s
run: node-exporter: (pid 6632) 12s; run: log: (pid 1430) 2246223s
run: postgres-exporter: (pid 6640) 11s; run: log: (pid 1418) 2246223s
run: postgresql: (pid 6650) 11s; run: log: (pid 1412) 2246223s
run: prometheus: (pid 6659) 10s; run: log: (pid 1420) 2246223s
run: redis: (pid 6667) 10s; run: log: (pid 1413) 2246223s
run: redis-exporter: (pid 6671) 9s; run: log: (pid 1417) 2246223s
run: sidekiq: (pid 6678) 9s; run: log: (pid 1423) 2246223s
run: unicorn: (pid 6684) 8s; run: log: (pid 1427) 2246223s

11、查看 Unicorn 日志

最后,查看 Unicorn 的日志文件,确保没有新的错误:

sudo cat /var/log/gitlab/unicorn/current
root@ubuntu20:~# sudo cat /var/log/gitlab/unicorn/current
2024-10-11_07:05:24.03624 Received TERM from runit, sending to process group (-PID)
2024-10-11_07:06:27.33565 starting new unicorn master
2024-10-11_07:06:47.00138 adopted new unicorn master 6699

从日志中可以看出,Unicorn 服务在 2024-10-11_07:06:27 启动了一个新的主进程 (unicorn master),并且在 2024-10-11_07:06:47 成功接管了新的 Unicorn 主进程 (PID 6699),日志中没有显示任何错误。这意味着 Unicorn 服务现在已经成功启动,并且运行正常。

在这里插入图片描述

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部