【问题标题】:installing postgres in azure ubuntu virtual machine using powershell使用 powershell 在 azure ubuntu 虚拟机中安装 postgres
【发布时间】:2017-11-29 14:29:35
【问题描述】:

我能够在 azure 中使用 powershell 脚本创建 ubuntu 虚拟机。 但是我想知道如何将postgresql数据库安装到新创建的azure ubuntu虚拟机中,如果需要,还可以安装其他软件。

我需要在 powershell 中这样做的帮助。任何关于它的指南或建议。

【问题讨论】:

  • 您是要登录虚拟机,还是要从外部登录?
  • 为此使用自定义脚本扩展
  • 我想从外部做,我的意思是一旦创建虚拟机。它应该仅与 powershell 脚本一起使用。计划像自动化脚本。

标签: postgresql powershell azure ubuntu azure-virtual-machine


【解决方案1】:

不,您无法使用 PowerShell 在 VM 外部安装 postgresql。你需要编写一个 bash 脚本来安装 postgresql,像这样example:install_postgresql.sh

您可以使用Azure Custom Extension 来执行此脚本。

您可以通过运行来部署 CustomScript 扩展:

$RGName = '<resource-group-name>'
$VmName = '<vm-name>'
$Location = '<location>'

$ExtensionName = 'CustomScriptForLinux'
$Publisher = 'Microsoft.OSTCExtensions'
$Version = '<version>'

$PublicConf = '{
    "fileUris": ["<url>"],
    "commandToExecute": "<command>"
}'
$PrivateConf = '{
    "storageAccountName": "<storage-account-name>",
    "storageAccountKey": "<storage-account-key>"
}'

Set-AzureRmVMExtension -ResourceGroupName $RGName -VMName $VmName -Location $Location `
  -Name $ExtensionName -Publisher $Publisher `
  -ExtensionType $ExtensionName -TypeHandlerVersion $Version `
  -Settingstring $PublicConf -ProtectedSettingString $PrivateConf

您也可以使用此template 来实现此目的。

New-AzureRmResourceGroupDeployment -Name shuitest -ResourceGroupName shui -TemplateFile "D:\azuredeploy.json"

【讨论】:

  • @ManVin 创建虚拟机时部署postgresql很容易。
  • 在按照您的代码指南执行上述自定义脚本使用时遇到错误。我稍微修改了代码并收到错误状态代码:127
  • 现在终于按照您的建议工作了。非常感谢。节省了很多时间。
【解决方案2】:

@Walter - MSFT

我尝试不执行 Set-AzureVMExtension ,一段时间后抛出错误如下:

Set-AzureRmVMExtension:长时间运行的操作失败,状态为“失败”。 错误代码:VMExtensionProvisioningError 错误消息:VM 在处理扩展“customscript”时报告失败。错误消息:“启用失败:执行命令失败:命令以退出状态=127 终止”。 开始时间:6/29/2017 10:09:39 PM 结束时间:2017 年 6 月 29 日晚上 10:10:03 操作ID:9d615221-e656-4367-a5e8-57441a323a93 状态:失败 在 E:\Projects_EDrive\Azure\PowerShellScripts\CentOSVM.ps1:95 char:1 + 设置-AzureRmVMExtension -ResourceGroupName $ResourceGroupName -VMName $VMName -Lo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Set-AzureRmVMExtension], ComputeCloudException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.SetAzureVMExtensionCommand


我手动连接到 VM 并尝试使用以下命令安装名为 apt、apt-get、erlang(rabbitMQ 消息代理依赖项)的基本软件包:

sudo yum install apt sudo yum install apt-get sudo yum install erlang

它说没有找到包,在创建的虚拟机上似乎没有可用的包。

【讨论】:

    猜你喜欢
    • 2015-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 2014-06-29
    • 1970-01-01
    相关资源
    最近更新 更多