在azure VM上访问DSC中的新连接的磁盘时遇到问题 [英] Trouble Accessing Newly attached disk in DSC on an azure VM

查看:59
本文介绍了在azure VM上访问DSC中的新连接的磁盘时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Azure VM上安装和运行mongo服务时遇到了DSC配置问题.

I have an issue with a DSC config i'm trying to use to install and run a mongo service on an Azure VM.

当DSC在VM的初始部署上运行时,辅助磁盘'F'已附加并成功格式化,但是...在尝试在新磁盘上创建目录时收到错误消息:

When the DSC runs on the initial deployment of the VM, the secondary disk 'F' is attached and formatted successfully, however... i receive an error when trying to create directories on the new disk:

Error message: \"DSC Configuration 'Main' completed with error(s).
Cannot find drive. A drive with the name 'F' does not exist. 
The PowerShell DSC resource '[Script]SetUpDataDisk' with SourceInfo 'C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\MongoDSC.0\\MongoDSC.ps1::51::2::Script' threw one or more non-terminating errors while running the Set-TargetResource functionality. 

这是我的DSC脚本:

Configuration Main
{

Param ( [string] $nodeName )

Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName xStorage

Node $nodeName
{
    xWaitforDisk Disk2
    {
        DiskId = 2
        RetryIntervalSec = 60
        RetryCount = 60
    }
    xDisk FVolume
    {
        DiskId = 2
        DriveLetter = 'F'
        FSLabel = 'MongoData'
        DependsOn = "[xWaitforDisk]Disk2"
    }
    Script SetUpDataDisk{
        TestScript ={
            return Test-Path "f:\mongoData\"
        }
        SetScript ={
            #set up the directories for mongo

            $retries = 0
            Do{
                $mountedDrive = Get-Volume | Where DriveLetter -eq 'F'
                if($mountedDrive -eq $null)
                {
                    Start-Sleep -Seconds 60
                    $retries = $retries + 1
                }
            }While(($mountedDrive -eq $null) -and ($retries -lt 60))

            $dirName = "mongoData"
            $dbDirName = "db"
            $logDirName = "logs"

            ##! ERROR THROWN FROM THESE LINES
            New-Item -Path "F:\$dirName" -ItemType Directory
            New-Item -Path "F:\$dirName\$dbDirName" -ItemType Directory
            New-Item -Path "F:\$dirName\$logDirName" -ItemType Directory
        }
        GetScript = {@{Result = "SetUpDataDisk"}}
        DependsOn = "[xDisk]FVolume"
    }
  }
}

令人讨厌的事情是,如果我再次运行部署,一切都会正常进行,那么我就会陷入循环,尝试等待磁盘准备就绪,但这仍然会引发错误.我是DSC的新手,所以任何指针都将对您有所帮助.

The annoying thing is that if i run the deployment again everything works with no errors, i have put a loop in to try and wait for the disk to be ready but this still throws the error. I'm very new to DSC so any pointers would be helpful.

推荐答案

似乎可以使用 xDiskAccessPath :

<#
    .EXAMPLE
        This configuration will wait for disk 2 to become available, and then make the disk available as
        two new formatted volumes mounted to folders c:\SQLData and c:\SQLLog, with c:\SQLLog using all
        available space after c:\SQLData has been created.
#>
Configuration Example
{

    Import-DSCResource -ModuleName xStorage

    Node localhost
    {
        xWaitforDisk Disk2
        {
             DiskId = 2
             RetryIntervalSec = 60
             RetryCount = 60
        }

        xDiskAccessPath DataVolume
        {
             DiskId = 2
             AccessPath = 'c:\SQLData'
             Size = 10GB
             FSLabel = 'SQLData1'
             DependsOn = '[xWaitForDisk]Disk2'
        }

        xDiskAccessPath LogVolume
        {
             DiskId = 2
             AccessPath = 'c:\SQLLog'
             FSLabel = 'SQLLog1'
             DependsOn = '[xDiskAccessPath]DataVolume'
        }
    }
}

https://github.com/PowerShell/xStorage/blob/dev/Modules/xStorage/Examples/Resources/xDiskAccessPath/1-xDiskAccessPath_InitializeDataDiskWithAccessPath.ps1

这篇关于在azure VM上访问DSC中的新连接的磁盘时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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