在 Azure VM 上访问 DSC 中新连接的磁盘时出现问题
Trouble Accessing Newly attached disk in DSC on an azure VM
我尝试使用 DSC 配置在 Azure VM 上安装和 运行 mongo 服务时遇到问题。
当 DSC 运行 初始部署 VM 时,辅助磁盘 'F' 已成功附加并格式化,但是...我在尝试创建目录时收到错误新磁盘:
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 的新手,所以任何指示都会有所帮助。
似乎 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'
}
}
}
我尝试使用 DSC 配置在 Azure VM 上安装和 运行 mongo 服务时遇到问题。
当 DSC 运行 初始部署 VM 时,辅助磁盘 'F' 已成功附加并格式化,但是...我在尝试创建目录时收到错误新磁盘:
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 的新手,所以任何指示都会有所帮助。
似乎 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'
}
}
}