我使用以下 terraform 代碼創建了一個虛擬機:
這是虛擬機代碼:
# demo instance
resource "azurerm_virtual_machine" "demo-instance" {
name = "${var.prefix}-vm"
location = var.resource_group_location
resource_group_name = var.resource_group_name
network_interface_ids = [
azurerm_network_interface.demo-instance.id]
vm_size = "Standard_A1_v2"
# this is a demo instance, so we can delete all data on termination
delete_os_disk_on_termination = true
delete_data_disks_on_termination = true
storage_image_reference {
publisher = "RedHat"
offer = "RHEL"
sku = "7-RAW"
version = "7.5.2018042521"
}
storage_os_disk {
name = "RED-HAT-osdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "MyOS"
admin_username = "MyUsername"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
}
resource "azurerm_network_interface" "demo-instance" {
name = "${var.prefix}-instance1"
location = var.resource_group_location
resource_group_name = var.resource_group_name
ip_configuration {
name = "instance1"
subnet_id = azurerm_subnet.demo-internal-1.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.demo-instance.id
}
}
resource "azurerm_network_interface_security_group_association" "allow-ssh" {
network_interface_id = azurerm_network_interface.demo-instance.id
network_security_group_id = azurerm_network_security_group.allow-ssh.id
}
resource "azurerm_public_ip" "demo-instance" {
name = "instance1-public-ip"
location = var.resource_group_location
resource_group_name = var.resource_group_name
allocation_method = "Dynamic"
}
這是網路配置:
resource "azurerm_virtual_network" "demo" {
name = "${var.prefix}-network"
location = var.resource_group_location
resource_group_name = var.resource_group_name
address_space = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "demo-internal-1" {
name = "${var.prefix}-internal-1"
resource_group_name = var.resource_group_name
virtual_network_name = azurerm_virtual_network.demo.name
address_prefixes = ["10.0.0.0/24"]
}
resource "azurerm_network_security_group" "allow-ssh" {
name = "${var.prefix}-allow-ssh"
location = var.resource_group_location
resource_group_name = var.resource_group_name
security_rule {
name = "SSH"
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = var.ssh-source-address
destination_address_prefix = "*"
}
}
結果,我能夠使用 SSH 連接到虛擬機。但是,當我嘗試使用 RDP 連接時,我遇到以下錯誤:

我試過的:
我閱讀
但是,我仍然無法與 RDP 建立聯系。所以,到目前為止,我知道我的虛擬機在網路中,因為它有密碼,而且我知道它正在運行,因為我可以使用 SSH 連接。但是,我仍然不知道為什么 RDP 不起作用。
uj5u.com熱心網友回復:
我從螢屏截圖中看到,您現在正在創建的 VM 中允許 RDP 流量。但是您創建的虛擬機是 RHEL 服務器,您將無法將 RDP 帶入其中,您只能使用 SSH。只有 windows vm 可以使用 RDP 登錄。
如果您想從特定的 Windows 跳轉框登錄 RHEL 服務器,這是可能的,部署一個帶有開放 RDP 埠的 windows VM 并為 RHEL 服務器添加一條規則,其中源 IP 將是 windows VM。然后,您可以作為堡壘登錄到 Windows 虛擬機并從該堡壘使用 ssh 到 RHEL。讓我知道您的查詢是否已清除。
uj5u.com熱心網友回復:
由于這是一個 Linux 虛擬機,因此您只能通過 SSH 協議進行連接,即使您在 NSG 中同時允許了 3389 和 22。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/511812.html
標籤:天蓝色地形虚拟机rdp
