【问题标题】:Chef::Exceptions::nginx didn't start when installing nginx-1.16.1 from source从源代码安装 nginx-1.16.1 时 Chef::Exceptions::nginx 没有启动
【发布时间】:2021-06-16 05:36:05
【问题描述】:

我正在尝试从源代码安装 nginx,我的要求是安装特定版本的 nginx,即 1.16.1,因为我从源代码下载。 运行 installNginx.rb 后,我看到 nginx.conf 文件已更新为默认 nginx 配置,但 nginx -v 说找不到命令。

下面是我的配置-

installNginx.rb

include_recipe 'nginx::source'

begin
  t = resources(:template => 'nginx.conf')
  t.source 'nginx.conf'
  t.cookbook 'my_nginx'
rescue Chef::Exceptions::ResourceNotFound
  Chef::Log.warn "Could not find template nginx.conf to modify"
end

service 'nginx' do
  action :restart
end

attributes/Source.rb

node.default['nginx']['source']['version'] = '1.16.1'
node.default['nginx']['source']['url'] = 'http://nginx.org/download/nginx-1.16.1.tar.gz'
node.default['nginx']['source']['checksum'] = 'f11c2a6dd1d3515736f0324857957db2de98be862461b5a542a3ac6188dbe32b'

metadata.rb

depends 'nginx'

在分析了我在食谱日志上观察到的内容后:我给出的源版本是 1.16.1 但由于某种原因,nginx::source 配方正在拉入 1.12.1 并且 nginx 没有启动

"nginx": {
"version": "1.12.1",
"package_name": "nginx",
"port": "80",
"dir": "/etc/nginx",
"script_dir": "/usr/sbin",
"log_dir": "/var/log/nginx",
"log_dir_perm": "0750",
"binary": "/opt/nginx-1.12.1/sbin/nginx",
"default_root": "/var/www/nginx-default",
"ulimit": "1024",
"cleanup_runit": true,
"repo_source": "nginx",
"install_method": "package",
"user": "webadmin",
"upstart": {
"runlevels": "2345",
"respawn_limit": null,
"foreground": true
}


"init_style": "init",
"source": {
"version": "1.16.1",
"prefix": "/opt/nginx-1.12.1",
"conf_path": "/etc/nginx/nginx.conf",
"sbin_path": "/opt/nginx-1.12.1/sbin/nginx",
"default_configure_flags": [
"--prefix=/opt/nginx-1.12.1",
"--conf-path=/etc/nginx/nginx.conf",
"--sbin-path=/opt/nginx-1.12.1/sbin/nginx",
"--with-cc-opt=-Wno-error"
],
"url": "http://nginx.org/download/nginx-1.16.1.tar.gz",
"checksum": "f11c2a6dd1d3515736f0324857957db2de98be862461b5a542a3ac6188dbe32b",
"modules": [
"nginx::http_ssl_module",
"nginx::http_gzip_static_module"
],


INFO: remote_file[nginx source] created file /var/chef/runs/58bffee4-b5aa-4632-97cd-0eeacc4ebd4c/local-mode-cache/cache/nginx-1.16.1.tar.gz
INFO: remote_file[nginx source] updated file contents /var/chef/runs/58bffee4-b5aa-4632-97cd-0eeacc4ebd4c/local-mode-cache/cache/nginx-1.16.1.tar.gz

我无法弄清楚问题出在哪里,感谢任何帮助。

【问题讨论】:

    标签: ruby ubuntu nginx chef-infra cookbook


    【解决方案1】:

    nginx 食谱中的属性文件在多个地方引用了默认版本。例如,它使用默认版本来定义安装 nginx 的目录以及 nginx 源的下载 URL 为

    default['nginx']['source']['prefix'] = "/opt/nginx-#{node['nginx']['source']['version']}"
    default['nginx']['source']['url'] = "http://nginx.org/download/nginx-#{node['nginx']['source']['version']}.tar.gz"
    

    因此,如果您稍后在自己的食谱中更新 version 属性,下载 URL 将不会自动更新为新版本,因为它不再引用它。

    要解决此问题,您有两种选择

    1. 您可以在食谱中手动设置所有相关属性。如您所见,这很可能容易出错并可能导致不一致。

    2. 您可以在设置被覆盖的属性后重新加载默认的 nginx 属性文件。这在您的属性文件中可能如下所示:

      override['nginx']['version'] = '1.16.1'
      override['nginx']['source']['checksum'] = 'f11c2a6dd1d3515736f0324857957db2de98be862461b5a542a3ac6188dbe32b'
      
      # Reload nginx::source attributes with our updated version
      node.from_file(run_context.resolve_attribute('nginx', 'source'))
      

    请注意,nginx 食谱维护了两个 nginx 版本:node['nginx']['version']node['nginx']['source']['version'],后者的值默认设置为前者。

    在您的 ohai 输出中,您只看到了 node['nginx']['version'] 属性(您尚未覆盖该属性)。

    通过覆盖此属性并重新加载attributes/source.rb 文件,如图所示,事情应该再次保持一致。

    【讨论】:

      猜你喜欢
      • 2015-02-06
      • 1970-01-01
      • 2021-11-13
      • 1970-01-01
      • 2014-04-17
      • 1970-01-01
      • 1970-01-01
      • 2014-08-06
      • 2012-01-21
      相关资源
      最近更新 更多