gpt4 book ai didi

azure - 无法使用 RDP(远程桌面)连接到虚拟机

转载 作者:行者123 更新时间:2023-12-03 06:47:17 24 4
gpt4 key购买 nike

我使用以下 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 连接时,我遇到以下错误:

enter image description here

<小时/>

我尝试过:

我读到this document并向我的网络添加了入站角色

enter image description here

但是,我仍然无法与 RDP 建立连接。到目前为止,我知道我的虚拟机位于网络中,因为它有密码,并且我知道它正在运行,因为我可以使用 SSH 连接。但是,我仍然不知道为什么 RDP 不起作用。

最佳答案

由于这是 Linux 虚拟机,因此即使您在 NSG 中同时允许 3389 和 22,也只能通过 SSH 协议(protocol)进行连接。

关于azure - 无法使用 RDP(远程桌面)连接到虚拟机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74000802/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com