无法连接到 SonarQube 私有 IP,端口号为 9000。

huangapple go评论56阅读模式
英文:

Unable to connect to SonarQube private IP with port 9000

问题

I am having some trouble and was needing some assistance.

我遇到了一些问题,需要一些帮助。

I have set up a SonarQube instance on a machine in Azure, and I am trying to connect to it through its private IP address and port 9000. However, I am unable to connect and get a "connection timed out" error.

我在Azure上的一台机器上设置了一个SonarQube实例,我正在尝试通过它的私有IP地址和端口9000连接到它。然而,我无法连接并收到了“连接超时”的错误。

Here are the steps I have taken so far:

以下是我迄今为止所采取的步骤:

Checked the firewall rules: The firewall on the machine is not blocking incoming traffic on port 9000.

检查防火墙规则:机器上的防火墙未阻止端口9000上的传入流量。

Checked the IP address: The private IP address of the machine is correct.

检查IP地址:机器的私有IP地址是正确的。

Checked the port: Port 9000 is the correct port for my SonarQube instance.

检查端口:端口9000是我的SonarQube实例的正确端口。

Checked the logs: There are no error messages related to the connection issue in the logs.

检查日志:日志中没有与连接问题相关的错误消息。

Restarted the SonarQube instance: Restarting the instance did not resolve the issue.

重新启动SonarQube实例:重新启动实例未解决问题。

What else can I do to resolve this issue and connect to my SonarQube instance?

我还能做什么来解决这个问题并连接到我的SonarQube实例?

Note: I am using a Linux machine and bash commands.

注意:我正在使用Linux机器和bash命令。

Here is terraform code in case I did something incorrectly.

以下是Terraform代码,以防我做错了什么。

provider "azurerm" {
features {}
}

locals {
sonarqube_image_name = "sonarqube:9.9-community"
sonarqube_container_name = "sonarqube-container"
postgres_container_name = "postgres-container"
}

resource "azurerm_resource_group" "examplegroup" {
name = "example-rg"
location = "South Central US"
}

resource "azurerm_network_security_group" "nsg-example-sonargroup" {
name = "nsg-example-sonargroup"
location = azurerm_resource_group.sonargroup.location
resource_group_name = azurerm_resource_group.sonargroup.name
}

resource "azurerm_virtual_network" "example-sonar-vnet" {
name = "example-sonar-vnet"
location = azurerm_resource_group.sonargroup.location
resource_group_name = azurerm_resource_group.sonargroup.name
address_space = ["10.0.0.0/16"]
}

resource "azurerm_subnet" "example-sonar-subnet" {
name = "sonar-subnet"
resource_group_name = azurerm_resource_group.sonargroup.name
virtual_network_name = azurerm_virtual_network.example-sonar-vnet.name
address_prefixes = ["10.0.0.0/16"]

delegation {
name = "delegation"

service_delegation {
  name    = "Microsoft.ContainerInstance/containerGroups"
  actions = ["Microsoft.Network/virtualNetworks/subnets/join/action", "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action"]
}

}
}

resource "azurerm_container_group" "sonarqube" {
name = "sonarqube-group"
location = azurerm_resource_group.sonargroup.location
resource_group_name = azurerm_resource_group.sonargroup.name
ip_address_type = "Private"
os_type = "Linux"
subnet_ids = [azurerm_subnet.example-sonar-subnet.id]

container {
name = local.sonarqube_container_name
image = local.sonarqube_image_name
cpu = 1
memory = 1.5

ports {
  port = 9000
}
environment_variables = {
  SONARQUBE_JDBC_URL = "jdbc:postgresql://postgres-container:5432/sonarqube_db"
  SONARQUBE_JDBC_USERNAME = "example_user"
  SONARQUBE_JDBC_PASSWORD = "example_password"
}

}

container {
name = local.postgres_container_name
image = "postgres:11"
cpu = 1
memory = 2
ports {
port = 5432
}
environment_variables = {
POSTGRES_DB = "example_db"
POSTGRES_USER = "example_user"
POSTGRES_PASSWORD = "example_password"
}
}
}

output "private_ip_address" {
value = azurerm_container_group.sonarqube.ip_address
}

英文:

I am having some trouble and was needing some assistance.

I have set up a SonarQube instance on a machine in Azure, and I am trying to connect to it through its private IP address and port 9000. However, I am unable to connect and get a "connection timed out" error.

Here are the steps I have taken so far:

Checked the firewall rules: The firewall on the machine is not blocking incoming traffic on port 9000.

Checked the IP address: The private IP address of the machine is correct.

Checked the port: Port 9000 is the correct port for my SonarQube instance.

Checked the logs: There are no error messages related to the connection issue in the logs.

Restarted the SonarQube instance: Restarting the instance did not resolve the issue.

What else can I do to resolve this issue and connect to my SonarQube instance?

Note: I am using a Linux machine and bash commands.

Here is terraform code in case I did something incorrectly.

provider "azurerm" {
   features {}
}


locals {
  sonarqube_image_name = "sonarqube:9.9-community"
  sonarqube_container_name = "sonarqube-container"
  postgres_container_name = "postgres-container"
}

resource "azurerm_resource_group" "examplegroup" {
  name     = "example-rg"
  location = "South Central US"
}

resource "azurerm_network_security_group" "nsg-example-sonargroup" {
  name                = "nsg-example-sonargroup"
  location            = azurerm_resource_group.sonargroup.location
  resource_group_name = azurerm_resource_group.sonargroup.name
}

resource "azurerm_virtual_network" "example-sonar-vnet" {
  name                = "example-sonar-vnet"
  location            = azurerm_resource_group.sonargroup.location
  resource_group_name = azurerm_resource_group.sonargroup.name
  address_space       = ["10.0.0.0/16"]
}

resource "azurerm_subnet" "example-sonar-subnet" {
  name                 = "sonar-subnet"
  resource_group_name  = azurerm_resource_group.sonargroup.name
  virtual_network_name = azurerm_virtual_network.example-sonar-vnet.name
  address_prefixes     = ["10.0.0.0/16"] 

  delegation {
    name = "delegation"

    service_delegation {
      name    = "Microsoft.ContainerInstance/containerGroups"
      actions = ["Microsoft.Network/virtualNetworks/subnets/join/action", "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action"]
    }
  }
}

resource "azurerm_container_group" "sonarqube" {
  name                = "sonarqube-group"
  location            = azurerm_resource_group.sonargroup.location
  resource_group_name = azurerm_resource_group.sonargroup.name
  ip_address_type     = "Private"
  os_type             = "Linux"
  subnet_ids          = [azurerm_subnet.example-sonar-subnet.id]

  container {
    name   = local.sonarqube_container_name
    image  = local.sonarqube_image_name
    cpu    = 1
    memory = 1.5

    ports {
      port = 9000
    }
    environment_variables = {
      SONARQUBE_JDBC_URL = "jdbc:postgresql://postgres-container:5432/sonarqube_db"
      SONARQUBE_JDBC_USERNAME = "example_user"
      SONARQUBE_JDBC_PASSWORD = "example_password"
    }
  }

  container {
    name   = local.postgres_container_name
    image  = "postgres:11"
    cpu    = 1
    memory = 2
    ports {
      port = 5432
    }
    environment_variables = {
      POSTGRES_DB = "example_db"
      POSTGRES_USER = "example_user"
      POSTGRES_PASSWORD = "example_password"
    }
  }
}

output "private_ip_address" {
  value = azurerm_container_group.sonarqube.ip_address
}

答案1

得分: 1

以下是您要翻译的代码部分:

provider "azurerm" {
   features {}
}


locals {
  sonarqube_image_name = "sonarqube:9.9-community"
  sonarqube_container_name = "sonarqube-container"
  postgres_container_name = "postgres-container"
}

resource "azurerm_resource_group" "examplegroup" {
  name     = "example1-rg"
  location = "EAST US"
}

resource "azurerm_network_security_group" "nsg-example-sonargroup" {
  name                = "nsg-example-sonargroup"
  location            = azurerm_resource_group.examplegroup.location
  resource_group_name = azurerm_resource_group.examplegroup.name
}

resource "azurerm_virtual_network" "example-sonar-vnet" {
  name                = "vt1231"
  location            = azurerm_resource_group.examplegroup.location
  resource_group_name = azurerm_resource_group.examplegroup.name
  address_space       = ["10.0.0.0/16"]
}

resource "azurerm_subnet" "example-sonar-subnet" {
  name                 = "default"
  resource_group_name = azurerm_resource_group.examplegroup.name
  virtual_network_name = azurerm_virtual_network.example-sonar-vnet.name
  address_prefixes     = ["10.0.1.0/24"] 

  delegation {
    name = "delegation"

    service_delegation {
      name    = "Microsoft.ContainerInstance/containerGroups"
      actions = ["Microsoft.Network/virtualNetworks/subnets/join/action", "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action"]
    }
  }
}

resource "azurerm_container_group" "sonarqube" {
  name                = "sonarqube-group"
  location            = azurerm_resource_group.examplegroup.location
  resource_group_name = azurerm_resource_group.examplegroup.name
  ip_address_type     = "Private"
  os_type             = "Linux"
  subnet_ids          = [azurerm_subnet.example-sonar-subnet.id]

  container {
    name   = local.sonarqube_container_name
    image  = local.sonarqube_image_name
    cpu    = 1
    memory = 1.5

    ports {
      port = 9000
    }
    environment_variables = {
      SONARQUBE_JDBC_URL = "jdbc:postgresql://postgres-container:5432/sonarqube_db"
      SONARQUBE_JDBC_USERNAME = "example_user"
      SONARQUBE_JDBC_PASSWORD = "example_password"
    }
  }

  container {
    name   = local.postgres_container_name
    image  = "postgres:11"
    cpu    = 1
    memory = 2
    ports {
      port = 5432
    }
    environment_variables = {
      POSTGRES_DB = "example_db"
      POSTGRES_USER = "example_user"
      POSTGRES_PASSWORD = "example_password"
    }
  }
}

output "private_ip_address" {
  value = azurerm_container_group.sonarqube.ip_address
}

希望这能满足您的需求。

英文:

I tried in my environment and got below results:

Initially, I used the same code to create the container instance with virtual network.

test.tf

provider "azurerm" {
features {}
}
locals {
sonarqube_image_name = "sonarqube:9.9-community"
sonarqube_container_name = "sonarqube-container"
postgres_container_name = "postgres-container"
}
resource "azurerm_resource_group" "examplegroup" {
name     = "example1-rg"
location = "EAST US"
}
resource "azurerm_network_security_group" "nsg-example-sonargroup" {
name                = "nsg-example-sonargroup"
location            = azurerm_resource_group.examplegroup.location
resource_group_name = azurerm_resource_group.examplegroup.name
}
resource "azurerm_virtual_network" "example-sonar-vnet" {
name                = "vt1231"
location            = azurerm_resource_group.examplegroup.location
resource_group_name = azurerm_resource_group.examplegroup.name
address_space       = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "example-sonar-subnet" {
name                 = "default"
resource_group_name = azurerm_resource_group.examplegroup.name
virtual_network_name = azurerm_virtual_network.example-sonar-vnet.name
address_prefixes     = ["10.0.1.0/24"] 
delegation {
name = "delegation"
service_delegation {
name    = "Microsoft.ContainerInstance/containerGroups"
actions = ["Microsoft.Network/virtualNetworks/subnets/join/action", "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action"]
}
}
}
resource "azurerm_container_group" "sonarqube" {
name                = "sonarqube-group"
location            = azurerm_resource_group.examplegroup.location
resource_group_name = azurerm_resource_group.examplegroup.name
ip_address_type     = "Private"
os_type             = "Linux"
subnet_ids          = [azurerm_subnet.example-sonar-subnet.id]
container {
name   = local.sonarqube_container_name
image  = local.sonarqube_image_name
cpu    = 1
memory = 1.5
ports {
port = 9000
}
environment_variables = {
SONARQUBE_JDBC_URL = "jdbc:postgresql://postgres-container:5432/sonarqube_db"
SONARQUBE_JDBC_USERNAME = "example_user"
SONARQUBE_JDBC_PASSWORD = "example_password"
}
}
container {
name   = local.postgres_container_name
image  = "postgres:11"
cpu    = 1
memory = 2
ports {
port = 5432
}
environment_variables = {
POSTGRES_DB = "example_db"
POSTGRES_USER = "example_user"
POSTGRES_PASSWORD = "example_password"
}
}
}
output "private_ip_address" {
value = azurerm_container_group.sonarqube.ip_address
}

Console:
无法连接到 SonarQube 私有 IP,端口号为 9000。

无法连接到 SonarQube 私有 IP,端口号为 9000。
Whenever we create an instance with private IP, we should be in the same network to access that instance as it is not publicly accessible.

I created virtual machine with virtual network same as created by SonarQube instance to connect SonarQube instance to accessing the private Ip with port 9000.

无法连接到 SonarQube 私有 IP,端口号为 9000。

After creation, I connected the virtual machine through RDP and able to access the SonarQube instance through Private IP with port 9000.

无法连接到 SonarQube 私有 IP,端口号为 9000。

Reference:

Deploy container group to Azure virtual network - Azure Container Instances | Microsoft Learn

huangapple
  • 本文由 发表于 2023年2月8日 22:47:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75387460.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定