厨师::例外::nginx从源代码安装nginx-1.16.1时没有启动



我正在尝试从源代码安装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

我不知道问题出在哪里,请提供任何帮助。

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文件(如所示(,事情应该再次保持一致。

最新更新