简体   繁体   English

Selenium 服务器 HUB 设置为特定的 IP 和端口

[英]Selenium server HUB setting up to specific IP and PORT

Can somebody explain me please how to properly set up Selenium server HUB to specific IP and PORT?有人可以向我解释一下如何将 Selenium 服务器 HUB 正确设置为特定的 IP 和端口吗? I found this Bind selenium to a specific IP - Possible?我发现这个Bind selenium to a specific IP - 可能吗? but I am not sure what is the proper IP as it would be safe.但我不确定什么是正确的 IP,因为它是安全的。 Every solution uses different IP 192..... 127.... Is it important which one I choose or it does not matter?每个解决方案使用不同的 IP 192..... 127.... 我选择哪个重要还是无关紧要?

I mean it is necessary if is necessary to restart HUB as the code will refer to the same HUB IP我的意思是如果有必要重新启动 HUB 是必要的,因为代码将引用相同的 HUB IP

It is important in the sense how do you want this hub to be reachable;从某种意义上说,您希望如何访问此集线器很重要; only from the same machine, or from others too.仅来自同一台机器,或也来自其他机器。
The question is not that much selenium, but rather networking one;问题不是硒,而是网络问题; so here are the three most common options:所以这里是三个最常见的选项:

  • use 127.0.0.1 - aka "localhost", the loopback interface - the hub will be reachable only from the same machine, and no other.使用127.0.0.1 - 又名“localhost”,环回接口 - 集线器只能从同一台机器访问,而不能从其他机器访问。 By definition the loopback interface is nonroutable in the networks - all packets are staying within the same host, thus - no one else can send a packet to it (because their packet will not leave their machine).根据定义,环回接口在网络中是不可路由的——所有数据包都位于同一主机内,因此 - 没有其他人可以向它发送数据包(因为他们的数据包不会离开他们的机器)。 In short, the hub and the selenium client must be on the same machine for this scenario.简而言之,对于这种情况,集线器和 selenium 客户端必须在同一台机器上。
  • 192.168.xy , 10.xyz or just an ip address abcd - the selenium hub process will bind to this address, and as long as it is reachable any client will be able to communicate with it (vs just local when using the loopback). 192.168.xy10.xyz或只是一个 ip 地址abcd - selenium 集线器进程将绑定到这个地址,只要它是可访问的,任何客户端都可以与它通信(而在使用环回时只是本地)。 If the server has multiple network interfaces, the hub is going to be accessible only on the one you specified.如果服务器有多个网络接口,则只能在您指定的接口上访问集线器。
  • the 0.0.0.0 - that is not an actual ip address (cannot be assigned, and used only for specific/special cases like DHCP), but used to communicate to the OS the process wants to bind to all available ip addresses on the host. 0.0.0.0 - 这不是实际的 ip 地址(无法分配,仅用于特定/特殊情况,如 DHCP),但用于与操作系统通信,该进程希望绑定到主机上的所有可用 ip 地址。 So if it has 2 network interfaces, one with ip 1.2.3.4 and the other 192.168.100.57 , the hub will be reachable on both of them (plus localhost, 127.0.0.1 this is also an address).因此,如果它有 2 个网络接口,一个具有 ip 1.2.3.4另一个具有192.168.100.57 ,则集线器将可以在它们两个上访问(加上 localhost, 127.0.0.1这也是一个地址)。 This by the way is the default behavior of Selenium Hub (and most server services).顺便说一下,这是 Selenium Hub(和大多数服务器服务)的默认行为。

So pick one depending on your needs - limiting to local connections only, to a specific interface if you have a few, or to all of them.因此,根据您的需要选择一个 - 仅限于本地连接,如果您有几个,则仅限于特定接口,或者仅限于所有接口。

By the way, the question you link to is a little bit different - apparently when it was raised, Selenium had a bug that the binding to a specific address didn't work, it was always using the 0.0.0.0 option.顺便说一句,您链接到的问题有点不同 - 显然,当它被提出时,Selenium 有一个错误,即绑定到特定地址不起作用,它总是使用0.0.0.0选项。

Generally, you would like to set up the Selenium Grid HUB on the localhost and to use a specific PORT you can use the following command:通常,您希望在localhost上设置Selenium Grid HUB并使用特定的端口,您可以使用以下命令:

  • Start the Selenium Grid Server (on port 5786 ):启动 Selenium Grid Server(在端口5786 ):

     java -jar selenium-server-standalone-3.14.0.jar -role hub -port 5786
  • Console logs:控制台日志:

     20:25:31.123 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.14.0', revision: 'aacccce0' 20:25:31.139 INFO [GridLauncherV3$2.launch] - Launching Selenium Grid hub on port 5786 2020-02-10 20:25:31.998:INFO::main: Logging initialized @1573ms to org.seleniumhq.jetty9.util.log.StdErrLog 20:25:32.706 INFO [Hub.start] - Selenium Grid hub is up and running 20:25:32.707 INFO [Hub.start] - Nodes should register to http://192.168.1.125:5786/grid/register/ 20:25:32.708 INFO [Hub.start] - Clients should connect to http://192.168.1.125:5786/wd/hub
  • Now, you can access the Selenium Grid HUB accessing the url http://localhost:5786/grid/console as follows:现在,您可以通过访问 URL http://localhost:5786/grid/console访问Selenium Grid HUB ,如下所示:

GridHub 控制台

我使用以下命令启动集线器(当系统连接到 VPN 时非常有用):

java -jar selenium-server-standalone-3.141.59.jar -role hub -host <IP Address> -port <port number>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM