HTTP 502: Whoops, GitLab is taking too much time to respond.

HTTP 502: Whoops, GitLab is taking too much time to respond.

小周啊 2018-11-02 09:51:57 瀏覽4364nginx

 

此次排錯過程主要是思路,視野打開後會以爲豁然開朗,原來這實際上是個小問題[尷尬]。git

 

一、沒注重應用啓動的各服務及其用途,只會簡單查看 status;sql

 

二、看到錯誤第一時間想到的是 Baidu(沒其餘意思),找找 logpath 先看日誌很差嗎?ruby

 

三、未認識到服務之間的關聯關係(好比 postgresql 與 unicorn 之間),前面一直知道 unicorn 啓動後沒正常監聽到端口,可是日誌並沒啥特別信息(嗯,多是由於看錯了文件)[苦笑]服務器

 


 1、錯誤信息

 

12a0d151eb203205d9453bed097a6d03f64.jpg

 

 

2、排錯過程

一、啓動 unicorn 未監聽端口

日誌路徑 :   /var/log/gitlab/unicorn/unicorn_stderr.log運維

PG::ConnectionBad: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/opt/gitlab/postgresql/.s.PGSQL.5432"?

  /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
  /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
  /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
  /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
  /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
  /opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.10/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'

··· ···
··· ···

 

信息顯示是由於連不上PG,因此啓動 postgresql 後重啓便可正常(嗯,是醬)。。dom

二、postgresql down

down: postgresql: 0s, normally up, want up; run: log: (pid 623) 15816094s

經過 PG 的日誌路徑 : /var/log/gitlab/postgresql/current 能夠查看到以下信息socket

2018-11-01_08:18:09.49669 FATAL:  could not map anonymous shared memory: Cannot allocate memory
2018-11-01_08:18:09.49671 HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory, swap space, or huge pages. To reduce the request size (currently 4292984832 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
2018-11-01_08:18:09.49671 LOG:  database system is shut down

也能夠經過命令 `gitlab-ctl tail postgresql`,獲得同樣的信息,因而能夠肯定問題。。oop

This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory, swap space, or huge pages. To reduce the request size (currently 4292984832 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
2018-11-01_07:52:06.63024 LOG:  database system is shut down

因而在配置文件中對 postgresql 的 shared_buffers 和 max_connections 兩項進行了限制gitlab

[root@V2 ~]# cat /etc/gitlab/gitlab.rb |grep -v ^$ |grep -v ^#
external_url 'http://xxx.xxx.xxx.xxx.xxx:8090'
unicorn['worker_timeout'] = 60
unicorn['worker_processes'] = 3
unicorn['listen'] = 'xxx.xxx.xxx.xxx.xxx'
unicorn['port'] = 8870
postgresql['enable'] = true
postgresql['data_dir'] = "/var/opt/gitlab/postgresql/data"
postgresql['shared_buffers'] = "256MB"   # ! **recommend value is 1/4 of total RAM, up to 14GB.**      
postgresql['max_connections'] = 200
nginx['listen_addresses'] = ['*']
nginx['listen_port'] = 8090

配置完成保存,以後更新配置,重啓應用便可。

gitlab-ctl reconfigure       # 更新配置
gitlab-ctl restart           # 重啓應用
gitlab-ctl status            # 查看服務狀態


 

參考資料

1. 502-Whoops, GitLab is taking to

相關文章
相關標籤/搜索