可以使用java cookbook来安装oracle java的本地副本吗? [英] Can the java cookbook be used to install a local copy of oracle java?

查看:164
本文介绍了可以使用java cookbook来安装oracle java的本地副本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在努力学习厨师,因为我计划用它来部署服务器配置和服务器应用软件。我在理解如何使用其他人的食谱时遇到了问题。例如,我想部署JDK8u31。我无法弄清楚如何实现这本食谱。 https://supermarket.chef.io/cookbooks/java

I have been trying to learn chef recently because I was planning on using it for deploying server config and server application software. I am having issues understanding how to use other people's cookbooks. For example, I want to deploy JDK8u31. I can't figure it out how to implement this cookbook. https://supermarket.chef.io/cookbooks/java

我阅读了说明书,并且看到以下内容

I read the instructions and I see the following

只需在任何您想要安装Java的地方添加java食谱,例如运行列表(食谱) [java])或食谱(include_recipe'java')

Simply include the java recipe wherever you would like Java installed, such as a run list (recipe[java]) or a cookbook (include_recipe 'java')

我试过

include_recipe 'java' 

我的食谱中名为common_java_server

inside my cookbook called 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
====


推荐答案

java cookbook 旨在支持不同Java变体的安装。它的行为由节点属性控制。默认值位于食谱中,并将安装OpenJDK。

The java cookbook is designed to support the installation of different Java variants. It's behaviour is controlled by node attributes. The defaults are in the cookbook and will install the OpenJDK.

因此,要安装oracle JDK,您需要指定替代覆盖,这些将在自述文件

So, to install the oracle JDK you need to specify alternative overrides and these are discussed in the README

你是怎么做到的?在厨师中你至少有两个选择:

How do you do this? In chef you have at least two options:


  1. 包装食谱

  2. 角色

有关包装食谱的示例,我建议您使用我的其他答案。

For an example of a wrapper cookbook I refer you to my other answer.

  • How to use chef to update-alternatives for java using execute?

对于示例角色,请尝试:

For an example role try this:

{
  "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将b已安装。

Add this role to the run-list of your node and the OracleJDK will be installed.

以下是测试厨房示例,它将安装并测试针对ubuntu和centos的java角色

The following is a test kitchen example that will install and test a "java" role against both ubuntu and centos

├── Berksfile
├── .kitchen.yml
├── roles
│   └── java.json
└── test
    └── integration
        └── default
            └── serverspec
                └── java_spec.rb

安装chefDK,vagrant并运行以下命令

Install chefDK, vagrant and run the following command

kitchen test

注意:

  • The simplest way to get test kitchen running is to install both vagrant and chefdk
source "https://supermarket.chef.io"

cookbook "apt"
cookbook "java"



.kitchen.yml



.kitchen.yml

---
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]

注意:


  • 特殊角色java是添加到节点运行列表。

  • 此示例禁用gce插件。请参阅 issue 624

  • The special role "java" is added to the node run-list.
  • This example disables the "gce" plugin. See issue 624.

见上文

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

这篇关于可以使用java cookbook来安装oracle java的本地副本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆