ruby - 自定义厨师资源在 ubuntu 中启动 newrelic-infra
问题描述
最初,我开始查看使用 Chef 配置 New Relic 基础设施,以便使用 chef solo 为我的项目设置 newrelic infra chef食谱,经过一些研究后,我发现不再支持说明书中的依赖项。
所以我决定在食谱中编写一个自定义资源,这样我就可以利用厨师幂等性。
我在我的 ubuntu 框中尝试了Install for Ubuntu下的以下步骤,并验证了新的 relic-infra 安装:
现在我正在尝试编写这样的厨师资源:
Step1:创建一个配置文件,并添加您的许可证密钥:
echo "license_key: YOUR_LICENSE_KEY" | sudo tee -a /etc/newrelic-infra.yml
在我的第 1 步配方中添加了此资源块:
file '/etc/newrelic-infra.yml' do
content 'license_key: added_key_here'
mode '0755'
owner 'root'
group 'root'
end
Step2:启用New Relic的GPG密钥:
curl https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg | sudo apt-key add -
在我的第 2 步配方中添加了此资源块:
apt_repository 'newrelic_key' do
uri 'https://download.newrelic.com/infrastructure_agent/gpg'
trusted true
key 'https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg'
end
我通过使用以下命令列出密钥在本地框中验证了此步骤:
sudo apt-key list
第 3 步:使用适用于您的分发版本的命令创建代理的 apt 存储库:
printf "deb [arch=amd64] https://download.newrelic.com/infrastructure_agent/linux/apt bionic main" | sudo tee -a /etc/apt/sources.list.d/newrelic-infra.list
在我的第 3 步配方中添加了此资源块:
file '/etc/apt/sources.list.d/newrelic-infra.list' do
content 'deb [arch=amd64] https://download.newrelic.com/infrastructure_agent/linux/apt bionic main'
mode '0755'
owner 'root'
group 'root'
end
第 4 步:更新您的 apt 缓存并运行安装脚本:
sudo apt-get update
sudo apt-get install newrelic-infra -y
在我的第 4 步配方中添加了此资源块:
apt_update
apt_package 'newrelic-infra'
错误:
但是安装失败并出现以下错误:
===============================================================================
default: Error executing action `update` on resource 'apt_update[newrelic-infra]'
default: ================================================================================
default:
default: Mixlib::ShellOut::ShellCommandFailed
default: ------------------------------------
default: execute[apt-get -q update] (/opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/provider/apt_update.rb line 70) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '100'
default: ---- Begin output of ["apt-get", "-q", "update"] ----
default: STDOUT:
default:
default: STDERR: E: Malformed entry 1 in list file /etc/apt/sources.list.d/newrelic-infra.list (Component)
default:
default:
default: * apt_package[newrelic-infra] action install
default: * No candidate version available for newrelic-infra
default:
default:
default: ================================================================================
default:
default: Error executing action `install` on resource 'apt_package[newrelic-infra]'
default:
default: ================================================================================
default:
default:
default:
default:
default: Chef::Exceptions::Package
default: -------------------------
default: No candidate version available for newrelic-infra
default:
default: Resource Declaration:
default: ---------------------
default: # In /etc/chef/local-mode-cache/cache/cookbooks/repo/recipes/default.rb
default:
default: 38: apt_package 'newrelic-infra'
default: 39:
default:
default: Compiled Resource:
default: ------------------
default: # Declared in /etc/chef/local-mode-cache/cache/cookbooks/repo/recipes/default.rb:38:in `from_file'
default:
default: apt_package("newrelic-infra") do
default: package_name "newrelic-infra"
default: action [:install]
default: default_guard_interpreter :default
default:
default: declared_type :apt_package
default:
default:
default: cookbook_name "repo"
default: recipe_name "default"
default: end
default:
default: System Info:
default: ------------
default: chef_version=14.4.56
default: platform=ubuntu
default: platform_version=18.04
default: ruby=ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
default: program_name=/usr/bin/chef-solo
default: executable=/opt/chefdk/bin/chef-solo
default:
default:
default: Running handlers:
default: [2019-08-30T18:19:30+00:00] ERROR: Running exception handlers
default: Running handlers complete
default: [2019-08-30T18:19:30+00:00] ERROR: Exception handlers complete
default: Chef Client failed. 6 resources updated in 48 seconds
default: [2019-08-30T18:19:30+00:00] FATAL: Stacktrace dumped to /etc/chef/local-mode-cache/cache/chef-stacktrace.out
default: [2019-08-30T18:19:30+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
default: [2019-08-30T18:19:30+00:00] FATAL: Chef::Exceptions::Package: apt_package[newrelic-infra] (repo-deploy::default line 38) had an error: Chef::Exceptions::Package: No candidate version available for newrelic-infra
我运行了我的流浪文件,它成功地适用于每一步,但在最后的安装步骤中失败了......我做错了什么?任何故障排除提示都会有所帮助。谢谢!
解决方案
首先,您可以使用 and 将步骤 2 和 3apt_repository
组合arch
在一起distribution
。
如果您阅读apt_repository
文档,您可以看到您甚至可以删除apt update
第 4 步中的
添加新存储库将立即更新 APT 包缓存。
其次,回到你的问题...
通过查看您的日志,特别是
default: execute[apt-get -q update] (/opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.4.56/lib/chef/provider/apt_update.rb line 70) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '100'
看来您没有在节点上运行 chef-client,而是使用 chef-dk。确保您在您想要聚合的节点内运行chef-client (或现在的 chef infra client)。
您可以在更高的日志级别运行chef-client ,通过指定log_level
要存储在日志文件中的日志记录级别。
debug
可能的级别:自动info
(默认)、、、、、、warn
或。默认值:(当终端可用时)或(当终端不可用时)。error
fatal
warn
info
我希望它能帮助你解决你的问题
推荐阅读
- php - 如何在php函数之外分配变量
- magento - 将缺货更改为符号
- c# - 如何在 DataTable 上使用 RowFilter 来查找列不为空且大于/小于值的行?
- python - 如何知道一个函数在 python 中正在做什么
- npm - 节点 - 电子包装器
- antlr - 使用 ANTLR 插件在 IntelliJ 中的启动规则上运行“测试 ANTLR 规则”的问题
- laravel - Laravel 中的 ACF 专业地图(刀片)
- python - Scrapy无限滚动 - 没有分页指示
- python - if 语句的默认情况(如果未指定)
- vue.js - 将付款详细信息添加到 Stripe API 收费调用