shell 使用“vagrant up”安装java 8(jdk 1.8)在debian上不起作用

s4n0splo  于 2023-03-09  发布在  Shell
关注(0)|答案(4)|浏览(195)

当我用shell运行我的Vagrantfile时,我在安装Java 8时遇到了同样的错误:
StackOverflow - jdk-8-is-not-installed-error-404-not-found
为了修复这个错误,我添加了以下代码行:

sudo sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u162|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="68ec82d47fd9c2b8eb84225b6db398a72008285fafc98631b1ff8d2229680257"|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_162|' /var/lib/dpkg/info/oracle-java8-installer.*

我在我的Shell中有这个java代码块:

# /*======================
# =            JAVA      =
# ======================*/
# https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-debian-8
sudo apt-get install -y software-properties-common
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list.d/webupd8team-java.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
sudo apt-get update

# Silent !! Sshh !
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections

# see https://stackoverflow.com/questions/46815897/jdk-8-is-not-installed-error-404-not-found
# Still not work
sudo sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u162|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="68ec82d47fd9c2b8eb84225b6db398a72008285fafc98631b1ff8d2229680257"|' /var/lib/dpkg/info/oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_162|' /var/lib/dpkg/info/oracle-java8-installer.*

sudo apt-get install -y oracle-java8-installer
sudo apt-get install -y oracle-java8-set-default

奇怪的是这些行通过SSH一个接一个地获取,当盒子启动时,你可以安装Java,它工作,但是当我第一次提供我的流浪盒子时,它不工作。
问题是来自sed还是其他命令?我猜是sed的命令,但不知道如何修复它,因为如果我通过SSH粘贴它们,它就可以工作。
我想在没有任何人工干预的情况下完成这项工作。
你可以使用这个github repo(V2)来测试我的虚拟机:VagrantFile + shells
我怎么能用流浪汉来做这件事呢?
编辑:

  • 我在流浪汉2.0和虚拟机5.6上测试过
  • 还使用vagrant 1.7和virtualBox 5.1进行了测试
iqxoj9l9

iqxoj9l91#

我把这个放在这里是为了以防有人对Debian的基本版本很满意,但却错过了它。我认为它应该已经安装在除了最基本的系统之外的任何系统上。
要让openJDK工作,这是Debian标准repos中提供的版本,您只需要使用

apt-get install -y openjdk-8-jdk

还有其他的debug和docs包。
Debian还在contrib repos中提供了一个名为java-package的包,它可以转换来自Oracle站点的源代码(你必须自己获得它以确定条款和条件),并从中创建一个deb。不幸的是,似乎没有一种方法可以直接假定所问问题的答案是肯定的,所以它需要一个expect脚本或其他东西。

config.vm.provision "shell", inline: <<-SHELL
    # add contrib repos into source files.
    mv /etc/apt/sources.list /etc/apt/sources.bk
    sed -r ‘s/stretch([^ ]*) main$/& contrib/‘ /etc/apt/sources.bk | sudo tee /etc/apt/sources.list
    # vi -c ':%s/stretch\([^ ]*\) main$/& contrib/g' /etc/apt/sources.list -c 'wq'
    apt-get update
    apt-get install -y java-package java-common expect
    # some `expect` needed magic here
    sudo -u vagrant fakeroot make-jpkg /vagrant/jdk-8*
    dpkg -i oracle-java8*
SHELL

就我使用make-jpkg获得的交互而言,这个脚本可以工作(从命令行)

expect -c '
set timeout -1
spawn fakeroot make-jpkg /vagrant/jdk-8u162-linux-x64.tar.gz

expect "Is this correct \\\[Y/n\\\]: $" { send "Y\r" }
expect "Press \\\[Return\\\] to continue: "  { send "\r" }
expect "*Press \\\[Return\\\] to continue or Ctrl-C to abort."      { send "\r" }
expect eof { exit 0 }
'

但是也可以用其它方式来实现。
差不多是个答案了,但可能会让你更接近。

yh2wf1be

yh2wf1be2#

很抱歉我的回答太晚了。另一个选择是挂接一个驱动器并静默安装oracle rpm包。
1.创建一个目录并把你的流浪汉文件放在那里。这是你的项目的根目录。

流浪者

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|

  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.
  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "bento/centos-7.4"
  config.vm.boot_timeout = 240

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # View the documentation for the provider you are using for more
  # information on available options.
  config.vm.provider "virtualbox" do |vb|

    # Enable the Host I/O cache for more performance
    vb.customize [
                 "storagectl", :id,
                 "--name", "SATA Controller",
                 "--hostiocache", "on"
                 ]
    vb.auto_nat_dns_proxy = false
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
    vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
    vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
    vb.customize ["modifyvm", :id, "--nictype2", "virtio"

    vb.customize ["modifyvm", :id, "--memory", 4096]
    vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
    vb.cpus = 4
  end

  # Synced folders are configured within your Vagrantfile using the config.vm.synced_folder method.
  # Vagrant shares by default the root directory of (./) with guest on /vagrant
  config.vm.synced_folder ".", "/vagrant", disabled: true

  # Synced folder is set as read-only for guest machine. You can configure the files on the host machine.
  # For more mount options check: http://manpages.ubuntu.com/manpages/precise/man8/mount.vboxsf.8.html
  config.vm.synced_folder "./installfiles", "/installfiles",
                           owner: "vagrant", group: "vagrant", mount_options: ["ro"]

  # Bootstrap shell scripts.
  config.vm.provision "shell", path: "./bootstrap/setup.sh"

  config.vm.post_up_message = "Finsihed provisioning!\n" \
                              "Type \"vagrant ssh\" to get started"
end

1.从项目的根目录创建另一个名为bootstrap的目录。创建一个名为www.example.com的空文件setup.sh,将以下内容放入setup.sh文件中。文件路径为./bootstrap/setup.sh

设置.sh

#!/usr/bin/env bash
echo "installing Java 8 64 bit"
sudo rpm -i /installfiles/java8/jdk-8u144-linux-x64.rpm
unzip /installfiles/java8/jce_policy-8.zip -d /tmp
sudo cp -f /tmp/UnlimitedJCEPolicyJDK8/* $JAVA_HOME/lib/security/

1.转到Oracle网站下载正确的32或64位rpm linux软件包。Oracle网站上提供的版本可能会更改。在本例中,我下载了jdk-8u144-linux-x64.rpm软件包。我还从Oracle网站下载了无限加密强度策略,文件名为:jce_策略-8.zip。
1.从项目的根目录创建两个名为installfiles/java8的目录,将下载的文件放在其中,文件路径为:./installfiles/java8/jdk-8u144-linux-x64.rpm和./installfiles/java8/jce_policy-8.zip格式的文件
1.运行命令 vagrant up。在您的主机上,目录./installfiles将与您的virtualbox客户机在路径/installfiles上同步。在vagrant的供应状态下,java-8将自动安装。请记住,rpm包管理器随Red Hat发行版一起提供。但也可以在debian发行版上安装rpm包。

31moq8wy

31moq8wy3#

以下代码段修复了从webupd8team repo for Debian发行版静默安装java的问题

sudo apt-get -y install software-properties-common
sudo add-apt-repository -y ppa:webupd8team/java
sudo bash -c "echo deb http://http.debian.net/debian jessie-backports main >> /etc/apt/sources.list"
sudo bash -c "echo deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main >> /etc/apt/sources.list.d/webupd8team-java.list"
sudo bash -c "echo deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main >> /etc/apt/sources.list.d/webupd8team-java.list"
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
sudo apt-get update
sudo apt-get -y upgrade

echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selectionssudo 

sudo apt-get -y install oracle-java8-installer oracle-java8-set-default

到目前为止,它安装了以下内容

vagrant@debian-8:~$ java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
sgtfey8w

sgtfey8w4#

Debian 9“Stretch”有java 8(jdk 1.8)作为默认的jre。如果你不关心debian版本,下面的方法可能对你有用。我把dabian/stretch64配置为box。对我来说,-y标志对所有问题都有效。我有下面的流浪者文件:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "debian/stretch64"
  config.vm.synced_folder ".", "/vagrant", disabled: true

  config.vm.provision "shell" do |s|
    s.inline = <<-SHELL
      sudo apt update
      sudo apt install default-jre -y
    SHELL
  end

相关问题