4.9. 配置共享块存储
要让多个集群节点访问同一数据,请将 Azure Shared Disks 配置为共享块存储。这样可确保所有节点的一致性、同步数据访问,以实现高可用性(HA)集群和应用程序,如数据库或文件系统。
先决条件
- 还没有创建集群。
- 您有三个带有 1TB 共享磁盘的 Azure 虚拟机(一个三节点集群)。
- 在主机 系统中有 Azure CLI,并创建了 SSH 密钥。
您必须在 Azure 中创建了集群环境。为此,请按照此列表中的资源操作:
- 资源组
- 虚拟网络
- 网络安全组
- 网络安全组规则
- 子网
- 负载均衡器(可选)
- 存储帐户
- 代理放置组
- 可用性集
流程
创建 共享块卷 :
$ az disk create -g <resource_group> \ -n <shared_block_volume_name> \ --size-gb <disk_size> \ --max-shares <number_vms> \ -l <location>例如,以下命令在 Azure Availability Zone
westcentralus的资源组sharedblock中创建名为shared-block-volume.vhd的共享块卷。$ az disk create -g sharedblock-rg \ -n shared-block-volume.vhd \ --size-gb 1024 \ --max-shares 3 \ -l westcentralus{ "creationData": { "createOption": "Empty", "galleryImageReference": null, "imageReference": null, "sourceResourceId": null, "sourceUniqueId": null, "sourceUri": null, "storageAccountId": null, "uploadSizeBytes": null }, "diskAccessId": null, "diskIopsReadOnly": null, "diskIopsReadWrite": 5000, "diskMbpsReadOnly": null, "diskMbpsReadWrite": 200, "diskSizeBytes": 1099511627776, "diskSizeGb": 1024, "diskState": "Unattached", "encryption": { "diskEncryptionSetId": null, "type": "EncryptionAtRestWithPlatformKey" }, "encryptionSettingsCollection": null, "hyperVgeneration": "V1", "id": "/subscriptions/12345678910-12345678910/resourceGroups/sharedblock-rg/providers/Microsoft.Compute/disks/shared-block-volume.vhd", "location": "westcentralus", "managedBy": null, "managedByExtended": null, "maxShares": 3, "name": "shared-block-volume.vhd", "networkAccessPolicy": "AllowAll", "osType": null, "provisioningState": "Succeeded", "resourceGroup": "sharedblock-rg", "shareInfo": null, "sku": { "name": "Premium_LRS", "tier": "Premium" }, "tags": {}, "timeCreated": "2020-08-27T15:36:56.263382+00:00", "type": "Microsoft.Compute/disks", "uniqueId": "cd8b0a25-6fbe-4779-9312-8d9cbb89b6f2", "zones": null }验证 共享块卷 :
$ az disk show -g <resource_group> -n <shared_block_volume_name>例如,以下命令显示资源组
sharedblock-rg中共享块卷shared-block-volume.vhd的详细信息。$ az disk show -g sharedblock-rg -n shared-block-volume.vhd{ "creationData": { "createOption": "Empty", "galleryImageReference": null, "imageReference": null, "sourceResourceId": null, "sourceUniqueId": null, "sourceUri": null, "storageAccountId": null, "uploadSizeBytes": null }, "diskAccessId": null, "diskIopsReadOnly": null, "diskIopsReadWrite": 5000, "diskMbpsReadOnly": null, "diskMbpsReadWrite": 200, "diskSizeBytes": 1099511627776, "diskSizeGb": 1024, "diskState": "Unattached", "encryption": { "diskEncryptionSetId": null, "type": "EncryptionAtRestWithPlatformKey" }, "encryptionSettingsCollection": null, "hyperVgeneration": "V1", "id": "/subscriptions/12345678910-12345678910/resourceGroups/sharedblock-rg/providers/Microsoft.Compute/disks/shared-block-volume.vhd", "location": "westcentralus", "managedBy": null, "managedByExtended": null, "maxShares": 3, "name": "shared-block-volume.vhd", "networkAccessPolicy": "AllowAll", "osType": null, "provisioningState": "Succeeded", "resourceGroup": "sharedblock-rg", "shareInfo": null, "sku": { "name": "Premium_LRS", "tier": "Premium" }, "tags": {}, "timeCreated": "2020-08-27T15:36:56.263382+00:00", "type": "Microsoft.Compute/disks", "uniqueId": "cd8b0a25-6fbe-4779-9312-8d9cbb89b6f2", "zones": null }创建 三个网络接口。对每个节点使用不同的
<nic_name>运行以下命令三次:$ az network nic create \ -g <resource_group> \ -n <nic_name> \ --subnet <subnet_name> \ --vnet-name <virtual_network> \ --location <location> \ --network-security-group <network_security_group> \ --private-ip-address-version IPv4例如,以下命令创建一个名为
shareblock-nodea-vm-nic-protected的网络接口:$ az network nic create \ -g sharedblock-rg \ -n sharedblock-nodea-vm-nic-protected \ --subnet sharedblock-subnet-protected \ --vnet-name sharedblock-vn \ --location westcentralus \ --network-security-group sharedblock-nsg \ --private-ip-address-version IPv4创建三个虚拟机,并附加共享块卷。每个虚拟机的选项值都一样,除了每个虚拟机都有自己的
<vm_name>,<new_vm_disk_name>和<nic_name>:$ az vm create \ -n <vm_name> \ -g <resource_group> \ --attach-data-disks <shared_block_volume_name> \ --data-disk-caching None \ --os-disk-caching ReadWrite \ --os-disk-name <new_vm_disk_name> \ --os-disk-size-gb <disk_size> \ --location <location> \ --size <virtual_machine_size> \ --image <image_name> \ --admin-username <vm_username> \ --authentication-type ssh \ --ssh-key-values <ssh_key> \ --nics <nic_name> \ --availability-set <availability_set> \ --ppg <proximity_placement_group>例如,以下命令创建一个名为
sharedblock-nodea-vm的虚拟机:$ az vm create \ -n sharedblock-nodea-vm \ -g sharedblock-rg \ --attach-data-disks shared-block-volume.vhd \ --data-disk-caching None \ --os-disk-caching ReadWrite \ --os-disk-name sharedblock-nodea-vm.vhd \ --os-disk-size-gb 64 \ --location westcentralus \ --size Standard_D2s_v3 \ --image /subscriptions/12345678910-12345678910/resourceGroups/sample-azureimagesgroupwestcentralus/providers/Microsoft.Compute/images/sample-azure-rhel-10.3.0-20200713.n.0.x86_64 \ --admin-username sharedblock-user \ --authentication-type ssh \ --ssh-key-values @sharedblock-key.pub \ --nics sharedblock-nodea-vm-nic-protected \ --availability-set sharedblock-as \ --ppg sharedblock-ppg{ "fqdns": "", "id": "/subscriptions/12345678910-12345678910/resourceGroups/sharedblock-rg/providers/Microsoft.Compute/virtualMachines/sharedblock-nodea-vm", "location": "westcentralus", "macAddress": "00-22-48-5D-EE-FB", "powerState": "VM running", "privateIpAddress": "198.51.100.3", "publicIpAddress": "", "resourceGroup": "sharedblock-rg", "zones": "" }
验证
对于集群中的每个虚拟机,验证块设备是否可用。为此,使用
ssh命令和虚拟机的 IP 地址连接到 vm:# ssh <ip_address> "hostname ; lsblk -d | grep ' 1T '"例如,以下命令列出了包括虚拟机 IP
198.51.100.3的主机名和块设备的详细信息:# ssh 198.51.100.3 "hostname ; lsblk -d | grep ' 1T '"nodea sdb 8:16 0 1T 0 disk使用
ssh工具验证集群中的每个虚拟机是否都使用同一个共享磁盘:# ssh <ip_address> "hostname ; lsblk -d | grep ' 1T ' | awk '{print \$1}' | xargs -i udevadm info --query=all --name=/dev/{} | grep '^E: ID_SERIAL='"例如,以下命令列出了包括实例 IP 地址
198.51.100.3的主机名和共享磁盘卷 ID 的详细信息:# ssh 198.51.100.3 "hostname ; lsblk -d | grep ' 1T ' | awk '{print \$1}' | xargs -i udevadm info --query=all --name=/dev/{} | grep '^E: ID_SERIAL='"nodea E: ID_SERIAL=3600224808dd8eb102f6ffc5822c41d89验证每个虚拟机是否连接到共享磁盘后,您可以为集群配置弹性存储。