我最近一直在努力学习厨师,因为我计划用它来部署服务器配置和服务器应用软件。我在理解如何使用其他人的烹饪书时遇到了问题。例如,我想部署JDK8u31。我无法弄清楚如何实施这本食谱。 https://supermarket.chef.io/cookbooks/java
我阅读说明书,并看到以下内容
只需在任何您希望安装Java的地方添加java配方,例如运行列表(recipe [java])或cookbook(include_recipe' java')
我试过
include_recipe 'java'
在我的食谱中名为common_java_server
然后
directory '/usr/lib/jvm/' do
owner 'root'
group 'root'
mode '0644'
end
java_ark "jdk" do
url 'http://download.oracle.com/otn-pub/java/jdk/8u31/jdk-8u31-linux-x64.bin'
checksum 'a8603fa62045ce2164b26f7c04859cd548ffe0e33bfc979d9fa73df42e3b3365'
app_home '/usr/lib/jvm/'
bin_cmds ["java", "javac"]
action :install
end
# set alternatives for java and javac commands
java_alternatives "set java alternatives" do
java_location '/usr/local/java'
bin_cmds ["java", "javac"]
action :set
end
这是我得到的错误
Recipe Compile Error in /etc/chef/src/cookbooks/common/recipes/java_dev_server.rb
====
答案 0 :(得分:8)
java cookbook旨在支持不同Java变体的安装。它的行为由节点属性控制。默认值位于cookbook,并将安装OpenJDK。
因此,要安装oracle JDK,您需要指定替代覆盖,这些将在README
中讨论你是怎么做到的?在厨师中,您至少有两种选择:
有关包装食谱的示例,我建议您回答其他问题。
对于示例角色,请尝试以下方法:
{
"name": "java",
"description": "Oracle java role",
"override_attributes": {
"java": {
"jdk_version": 8,
"install_flavor": "oracle",
"oracle": {
"accept_oracle_download_terms": true
}
}
},
"run_list": [
"recipe[apt]",
"recipe[java]"
]
}
将此角色添加到节点的运行列表中,并安装OracleJDK。
以下是测试厨房示例,将针对ubuntu和centos安装和测试“java”角色
├── Berksfile
├── .kitchen.yml
├── roles
│ └── java.json
└── test
└── integration
└── default
└── serverspec
└── java_spec.rb
安装chefDK,vagrant并运行以下命令
kitchen test
注意:
source "https://supermarket.chef.io"
cookbook "apt"
cookbook "java"
---
driver:
name: vagrant
provisioner:
name: chef_zero
require_chef_omnibus: 12.0.3
client_rb:
"Ohai::Config[:disabled_plugins] = [:GCE] #":
platforms:
- name: ubuntu-12.04
- name: centos-6.4
suites:
- name: default
run_list:
- role[java]
注意:
见上文
require 'serverspec'
# Required by serverspec
set :backend, :exec
describe file('/usr/lib/jvm/java-8-oracle-amd64/release'), :if => os[:family] == "ubuntu" do
it { should contain 'JAVA_VERSION="1.8.0_31"' }
end
describe file('/usr/lib/jvm/java/release'), :if => os[:family] == "redhat" do
it { should contain 'JAVA_VERSION="1.8.0_31"' }
end