Powershell远程在Azure A7虚拟机运行Java JVM失败

       最近,使用Powershell脚本在A7 (8核,56G内存)配置的 Azure VM(Virtual Machine,虚拟机)上远程运行Java JVM时 (java.exe -version),总是失败并返回如下的错误信息。同样的Powershell脚本,在其它低于A7配置的VM上远程执行一切正常;此外,如果使用远程桌面登录到VM上,再进行同样的操作,一切执行正常。


Error occurred during initialization of VM
Unable to allocate 458752KB bitmaps for parallel garbage collection for the requested 14680064KB heap.

Error occurred during initialization of VM
Could not reserve enough space for object heap

   

       以上的实验排除了是JVM(1.7)本身的问题, 看来问题很有可能是出在Powershell的远程执行方式上。Powershell Remoting依赖于WinRM (Windows Remote Management)在远程机器上执行操作。默认情况下,WinRM为每个Powershell远程连接分配了最大(MaxMemoryPerShellMB=1024)1G的内存空间(早期的版本只有150M),用于执行远程操作。但远程操作所需的执行内存空间 > 1G时,就会出现了内存不足的问题,不同的操作可能表现会有所不同,如:有的会抛出OutOfMemoryException等。针对这个问题,解决的办法就是增加MaxMemoryPerShellMB,然后重启WinRM服务:


$maxMemoryPerShellVM = 3072
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB $maxMemoryPerShellVM
Set-Item WSMan:\localhost\Plugin\Microsoft.PowerShell\Quotas\MaxMemoryPerShellMB $maxMemoryPerShellVM

Write-Output "List MaxMemoryPerShellMB configuration"
Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 
Get-Item WSMan:\localhost\Plugin\Microsoft.PowerShell\Quotas\MaxMemoryPerShellMB 

# Restart WinRM service to make the change take effect
Restart-Service winrm


具体要增加到多大的内存,需要自己去实验一下。


参考资源

http://blog.patricknielsen.net/2012/01/powershell-remote-system-call-using.html

http://stackoverflow.com/questions/4741676/powershell-problem-running-java-remotely





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值