1

我正在尝试在 Hashicorp Nomad 中设置 Selenium Grid,但我不知道如何使网络正常工作。我想要的是拥有一个硒集线器和 8 个铬节点。我发现如果我将节点任务放入自己的组中,我只能对节点任务进行多次分配。

在本地运行它,我会像这样启动网格:

docker network create grid
docker run -d -p 4442-4444:4442-4444 --net grid --name selenium-hub selenium/hub:4
docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 -v /dev/shm:/dev/shm selenium/node-chrome:4
docker run -d --net grid -e SE_EVENT_BUS_HOST=selenium-hub -e SE_EVENT_BUS_PUBLISH_PORT=4442 -e SE_EVENT_BUS_SUBSCRIBE_PORT=4443 -v /dev/shm:/dev/shm selenium/node-chrome:4
...

我需要如何配置网络才能使其正常工作?

我现在的工作是这样的:

job "selenium" {
  datacenters = ["dc1"]
  type = "service"
  group "selenium_hub" {
    network {

    }
    task "selenium_hub" {
      driver = "docker"
      config {
        image = "selenium/hub:4"
      }
    }
  }
  group "selenium_nodes" {
    count = 8
    network {

    }
    task "selenium_node" {
      driver = "docker"
      env {
        SE_EVENT_BUS_HOST = "selenium-hub"
        SE_EVENT_BUS_PUBLISH_PORT = "4442"
        SE_EVENT_BUS_SUBSCRIBE_PORT = "4443"
      }
      config {
        image = "selenium/node-chrome:4"
      }
    }
  }  
}
4

1 回答 1

1

如果有人遇到这个问题,我会这样工作:

job "selenium" { 
  datacenters = ["dc1"]
  type = "service"
  group "selenium_hub" {
    network {
      mode = "host"
    }
    task "selenium_hub" {
      driver = "docker"
      config {
        image = "selenium/hub:3.141.59-20201010"
        network_mode = "host"
      }
    }
  }
  group "selenium_nodes" {
    count = 8
    network {
        mode = "host"
        port "http" {}
    }
    task "selenium_node" {
      driver = "docker"
      env {
        HUB_HOST = "localhost"
        SE_OPTS = "-port ${NOMAD_PORT_http}"
      }
      config {
        network_mode = "host"
        image = "selenium/node-chrome:3.141.59-20201010"
      }
    }
  }  
}

我使用 Selenium 3 而不是 4,因为 4 也存在其他问题。由于我使用了主机网络并且所有节点都使用端口 5555,因此我需要通过 SE_OPTS 环境变量将动态端口 (http) 传递给 Selenium。

于 2020-11-04T14:34:52.093 回答