/etc/hosts中关于localhosts行的内容,导致gitlab 502问题。
-
0、gitlab出现502,内存/磁盘都正常,原因是缺少/etc/hosts中关于localhosts行的内容。
-
1、常规三件套
gitlab-ctl stop
gitlab-ctl reconfigure
gitlab-ctl restart
事后才发现reconfigure 执行时完全没有提示,所以其实这里能就发现配置没启用,肯定某地方设置的有问题。
-
2、当时没发现问题,因此就用
gitlab-ctl status
反复看。
发现在status 多次执行时,monitor的 进程id不停在增加,然后node-exporter只在restatus那一下是up,再status查看时始终是down。
因此,就用gitlab-ctl tail
看,发现日志里有报错,报错的ip 是之前旧ip。 -
3、因此 找/etc/gitlab/gitlab.rb 去搜这个旧ip,发现没有,都已经改成新ip或者是localhost的了。感觉很奇怪。
-
4、上网搜原因,说可以用grep方法来查找,node_export的端口是9100,因此进入/opt/gitlab和/etc/gitlab分别去匹配:9100,执行如下:
grep :9100 * -r
然后会出来匹配内容
Binary file embedded/bin/node_exporter matches
embedded/cookbooks/gitlab/attributes/default.rb:default['gitlab']['node-exporter']['listen_address'] = 'localhost:9100'
embedded/cookbooks/cache/cookbooks/gitlab/attributes/default.rb:default['gitlab']['node-exporter']['listen_address'] = '10.0.1.149:9100'
embedded/cookbooks/cache/backup/var/opt/gitlab/prometheus/prometheus.yml.chef-20190329230954.139634: - localhost:9100
sv/node-exporter/run:exec chpst -P -U gitlab-prometheus -u gitlab-prometheus /opt/gitlab/embedded/bin/node_exporter --web.listen-address=10.0.0.49:9100 --collector.textfile.directory=/var/opt/gitlab/node-exporter/textfile_collector
上面这些匹配内容就有跟tail报错一样的地方,因此逐个修改掉。
-
5、然后再三件套+status+tail看,现在status都正常了,tail里也不报错了。但访问页面还是502,凌乱了。
-
6、再回想了下gitlab.rb,试着ping ip ,ping 127.0.0.1和ping localhost,发现ping localhost不通。然后去/etc/hosts看,发现只有ip那行,没有localhost行。于是增加一行localhost内容。
再三件套,这时,reconfgiure就有一堆提示内容出来了, restart后,果然502问题解决。 -
7、回过头分析,因为服务器3个月前迁移,被集中改过一次IP,可能是那次时通过工具软件把hosts里旧内容去掉了,只增了新ip那一行。但是还是不太清楚,为啥这几个月用着好好的,突然到今天才502,我有看了服务器重启日志,发现也没有重启过。