簡體   English   中英

Windows:為 Jenkins 代理自動檢測、條帶化、配置、安裝 AWS EC2 臨時磁盤

[英]Windows: Automatically Detect, Stripe, Provision, Mount AWS EC2 Ephemeral Disks for Jenkins Agents

我有在 EC2 中運行的 Jenkins 的 Windows 構建代理,我想利用來自“d”類型實例(例如 C5ad.4xl 提供 2 x 300GB NVMe)的臨時磁盤來利用可用的高 IO在這些磁盤上。

由於它們是構建代理,因此驅動器的短暫性質很好。 我需要一些可以檢測、配置和安裝這些磁盤作為 Windows 中的驅動器的東西,基本上不管大小和數量。 我可以很容易地做到這一點(LVM或軟件RAID等),在Linux,但雖然有2014年的指南在這里為實現這一點,似乎並沒有工作在Windows Server 2019和最新的情況下不上。

同一篇文章引用了從 Server 2012 R2 添加的新命令行開關,但那些不支持將磁盤轉換為動態磁盤(這是在原始帖子的代碼中通過 diskpart 對它們進行條帶化所需的關鍵步驟),因此它們不能直接用於做需要做的事。

是否還有其他選項可以使這項工作動態進行,理想情況下使用 powershell(或類似的)可以在啟動時作為其配置的一部分傳遞給 Jenkins 代理?

Windows 現在有存儲池,這些可以用來做這里需要的事情。 此代碼成功檢測到多個磁盤,將它們添加到條帶池中,使用可用的最大大小並將新卷安裝在驅動器號“E”上:

# get a list of the disks that can be pooled
$PhysicalDisks = (Get-PhysicalDisk -CanPool $true)
# only take action if there actually are disks
if ($PhysicalDisks) {
    # create storage pool using the discovered disks, called ephemeral in the standard subsystem
    New-StoragePool –FriendlyName ephemeral -StorageSubSystemFriendlyName "Windows Storage*" –PhysicalDisks $PhysicalDisks
    # Create a virtual disk, striped (simple resiliency in its terms), use all space
    New-VirtualDisk -StoragePoolFriendlyName "ephemeral" -FriendlyName "stripedephemeral" -ResiliencySettingName Simple -UseMaximumSize
    # initialise the disk
    Get-VirtualDisk -FriendlyName 'stripedephemeral'|Initialize-Disk -PartitionStyle GPT -PassThru
    # create a partition, use all available size (this will pop up if you do it interactively to format the drive, not a problem when running as userdata via Jenkins config)
    New-Partition -DiskNumber 3 -DriveLetter 'E' -UseMaximumSize
    # format as NTFS to make it useable
    Format-Volume -DriveLetter E -FileSystem NTFS -Confirm:$false
    # this creates a folder on the drive to use as the workspace by the agent
    New-Item -ItemType Directory -Force -Path E:\jenkins\workspace
}

這里有一些關於磁盤數量的假設,這將根據實例類型而有所不同,但通常它會使用它找到的任何臨時磁盤,如果有多個,它將​​跨它們條帶化,然后使用整個磁盤創建/格式化卷后可用的大小。 這可以全部包裝在<powershell></powershell>並添加到 Jenkins 代理配置的用戶數據部分,以便它在啟動時運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM