GitLab CE容器在LDAP配置中启动并进入引导循环

122次阅读
没有评论

问题描述

在使用Ansible部署GitLab容器时遇到了问题。在某个时间点,整个部署突然出现了一个非常不明确的错误信息。之后,容器每隔一分钟就会重新启动一次。用户使用docker logs <container>命令查看日志,得到了以下输出:

Thank you for using GitLab Docker Image!
Current version: gitlab-ce=12.7.2-ce.0
Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
And restart this container to reload settings.
To do it use docker exec:  docker exec -it gitlab vim /etc/gitlab/gitlab.rb  docker restart gitlab
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
If this container fails to start due to permission problems try to fix it by executing:  docker exec -it gitlab update-permissions  docker restart gitlab
Cleaning stale PIDs & sockets
Preparing services...
Starting services...
Configuring GitLab...
/opt/gitlab/embedded/bin/runsvdir-start: line 37: /proc/sys/fs/file-max: Read-only file system
Starting Chef Client, version 14.14.29
resolving cookbooks for run list: ["gitlab"]
Synchronizing Cookbooks:
  - postgresql (0.1.0)
  - registry (0.1.0)
  - mattermost (0.1.0)
  - consul (0.1.0)
  - gitaly (0.1.0)
  - gitlab (0.0.1)
  - letsencrypt (0.1.0)
  - runit (4.3.0)
  - crond (0.1.0)
  - redis (0.1.0)
  - nginx (0.1.0)
  - acme (4.0.0)
  - package (0.1.0)
  - monitoring (0.1.0)
  - praefect (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
================================================================================
Recipe Compile Error in /opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/recipes/default.rb
================================================================================

Psych::SyntaxError
------------------
(<unknown>): did not find expected key while parsing a block mapping at line 2 column 5

Cookbook Trace:
---------------
  /opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/helpers/settings_helper.rb:105:in `block in from_file'
  /opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/config_mash.rb:29:in `auto_vivify'
  /opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/helpers/settings_helper.rb:105:in `from_file'
  /opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/helpers/settings_helper.rb:105:in `block in from_file'
  /opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/config_mash.rb:29:in `auto_vivify'
  /opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/helpers/settings_helper.rb:105:in `from_file'
  /opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/recipes/config.rb:22:in `from_file'
  /opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/recipes/default.rb:26:in `from_file'

Relevant File Content:
----------------------
/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/helpers/settings_helper.rb:
 98:
 99:    def from_file(_file_path)
100:      # Throw errors for unrecognized top level calls (usually spelling mistakes)
101:      config_strict_mode true
102:      # Turn on node deprecation messages
103:      Gitlab::Deprecations::NodeAttribute.log_deprecations = true
104:      # Allow auto mash creation during from_file call
105>>     Gitlab::ConfigMash.auto_vivify { super }
106:    ensure
107:      config_strict_mode false
108:      Gitlab::Deprecations::NodeAttribute.log_deprecations = false
109:    end
110:
111:    # Enhance set so strict mode errors aren't thrown as long as the setting is witin our defined config
112:    def internal_set(symbol, value)
113:      if configuration.key?(symbol)
114:        configuration[symbol] = value

System Info:
------------
chef_version=14.14.29
platform=ubuntu
platform_version=16.04
ruby=ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
program_name=/opt/gitlab/embedded/bin/chef-client
executable=/opt/gitlab/embedded/bin/chef-client
Running handlers:
There was an error running gitlab-ctl reconfigure:
(<unknown>): did not find expected key while parsing a block mapping at line 2 column 5
Running handlers complete
Chef Client failed. 0 resources updated in 01 seconds

解决方案

请注意以下操作注意版本差异及修改前做好备份。

方案1

根据日志信息,错误发生在/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/recipes/default.rb文件的第2行第5列,错误类型为Psych::SyntaxError,错误信息为did not find expected key while parsing a block mapping at line 2 column 5
根据用户提供的问题描述,问题出现在LDAP服务器的内联YAML中引入了Jinja2条件语句的地方。具体来说,用户在gitlab_rails['ldap_servers']的值中使用了Jinja2条件语句,但是在条件语句成立时,由于额外的缩进导致YAML解析器出错。
为了解决这个问题,用户需要注意以下两点:
1. 在内联YAML中使用Jinja2条件语句时,确保正确关闭条件语句块。
2. 在条件语句成立时,确保没有额外的缩进。
以下是修复问题的步骤:
1. 打开/etc/gitlab/gitlab.rb文件。
2. 定位到gitlab_rails['ldap_servers']的值,并检查是否存在Jinja2条件语句。
3. 如果存在条件语句,确保条件语句块正确关闭,并且没有额外的缩进。
4. 保存文件并重新启动GitLab容器。

方案2

如果用户不确定如何修复问题,或者修复问题后仍然遇到困难,可以尝试以下方法:
1. 进入GitLab容器的命令行界面。
2. 执行以下命令以编辑/etc/gitlab/gitlab.rb文件:
docker exec -it gitlab vim /etc/gitlab/gitlab.rb
3. 在编辑器中查找并修复与LDAP配置相关的问题。
4. 保存文件并退出编辑器。
5. 重新启动GitLab容器。
请注意,这种方法需要一定的Linux命令行和编辑器的使用经验。如果不熟悉这些工具,请谨慎操作或寻求专业人士的帮助。

正文完