我们可以使用Powershell在azure VM上远程安装Java吗?

问题描述 投票:0回答:2

我正在尝试在VSTS管道中使用PowerShell在azure VM上运行Apache jMeter。问题是azure VM是新创建的,默认情况下没有安装JDK。由于jMeter需要'java',所以它抛出以下错误。

C:\apache-jmeter-5.2.1\bin>jmeter -n -t C:\User-search.jmx -l C:\
Not able to find Java executable or version. Please check your Java installation.
errorlevel=2

我需要在运行jMeter之前安装Java。有什么方法可以使用Powershell远程安装Java吗?

或者如果预安装的java有可用的Windows Azure虚拟机映像?

java powershell jmeter command-line-interface azure-virtual-machine
2个回答
0
投票

您可以使用Powershell Remoting在任何计算机上执行任意命令,最简单的安装Java Runtime的方法是使用Chocolatey package manager,它应该像这样简单:

choco install javaruntime -y

参考:


0
投票

首先与虚拟机建立会话,然后运行以下脚本。

#Download and silent install JDK

#Working directory path
Write-Host "Creating temp working directory..."
$workd = "c:\temp"

#Check if work directory exists if not create it
If (!(Test-Path -Path $workd -PathType Container))
{ 
    New-Item -Path $workd  -ItemType directory 
}

#Create config file for silent install
Write-Host "Creating config file for silent install..."
$text = '
INSTALL_SILENT=Enable
AUTO_UPDATE=Enable
SPONSORS=Disable
REMOVEOUTOFDATEJRES=1
'
$text | Set-Content "$workd\jdkinstall.cfg"

#Download executable file
Write-Host "Download JDK file to temp directory..."
$source = "https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173c853231432d94f001e99d882ca7/jdk-13.0.2_windows-x64_bin.exe"
$destination = "$workd\jdk-13.0.2_windows-x64_bin.exe"
$client = New-Object System.Net.WebClient
$cookie = "oraclelicense=accept-securebackup-cookie"
$client.Headers.Add([System.Net.HttpRequestHeader]::Cookie, $cookie)
$client.DownloadFile($source, $destination)
Write-Host "Download JDK file completed !"

#Install silently
Write-Host "Trying to install JDK silently..."
Start-Process -FilePath "$workd\jdk-13.0.2_windows-x64_bin.exe" -ArgumentList INSTALLCFG="$workd\jdkinstall.cfg" -Wait
Write-Host "JDK installation completed successfully !"

#Remove the installer
Write-Host "Trying to remove JDK file from temp directory..."
rm -Force $workd\jdk*
Write-Host "JDK file deleted successfully !"
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.