无法在 Azure WebApp 中启动 ElasticSearch
Could not start ElasticSearch in Azure WebApp
我下载了 ElasticSearch、运行 bin/elasticsearch.bat
,它在我的本地机器上运行。然后我将 elasticsearch 文件夹添加到我的存储库并更新了部署脚本 (deploy.cmd),添加了这些行:
echo starting ElasticSearch...
elasticsearch-1.7.2\bin\elasticsearch.bat
echo ElasticSearch started!
将我的存储库推送到我的 Azure 网站后,日志中出现此错误:
starting ElasticSearch...
Error occurred during initialization of VM
Error: Could not create the Java Virtual Machine.
Could not reserve enough space for object heap
Error: A fatal exception has occurred. Program will exit.
Java 在我的 WebApp 配置中打开。所以有什么问题?为什么无法创建 Java 虚拟机?
编辑:Could not reserve enough space for object heap
看起来我的 RAM 较少,但我已经用 3.5GB 的 RAM 试过了,错误也出现了——ElasticSearch 在我的本地机器上只使用 155 MB 的 RAM)
编辑2:
经过一些尝试后,我得到了一个新的错误日志:
starting ElasticSearch...
[2015-10-15 12:59:18,879][INFO ][node ] [Marsha Rosenberg] version[1.7.2], pid[3728], build[e43676b/2015-09-14T09:49:53Z]
[2015-10-15 12:59:18,879][INFO ][node ] [Marsha Rosenberg] initializing ...
[2015-10-15 12:59:19,273][INFO ][plugins ] [Marsha Rosenberg] loaded [], sites []
[2015-10-15 12:59:20,692][INFO ][env ] [Marsha Rosenberg] using [1] data paths, mounts [[Windows (D:)]], net usable_space [13.5gb], net total_space [32gb], types [NTFS]
[2015-10-15 12:59:28,869][INFO ][node ] [Marsha Rosenberg] initialized
[2015-10-15 12:59:28,869][INFO ][node ] [Marsha Rosenberg] starting ...
{1.7.2}: Startup Failed ...
- ChannelException[Failed to create a selector.]
IOException[Unable to establish loopback connection]
SocketException[Address family not supported by protocol family: bind]
我怀疑这是由于尝试发出本地请求而失败的。请参阅 this document 了解有关 Azure Web App 沙盒限制的更多信息。
将 -Djava.net.preferIPv4Stack=true
参数传递给 elasticsearch.bat
。
还要确保 JAVA_HOME
设置为 Java 8 而不是 Java 7。Azure Web Apps 上的路径是 D:\Program Files\Java\jdk1.8.0_25
另请记住,如果您 运行 同一虚拟机上的多个弹性搜索服务器(在同一应用服务计划中),它们将不会全部侦听 9200
。默认情况下,我认为 elasticsearch 会尝试来自 9200 - 9300
的端口,因此请查看标准输出。
您可能想在 elasticsearch.yml
中禁用集群和自动发现,因为无论如何您都无法通过设置
来形成集群
node.local: true
discovery.zen.ping.multicast: false
index.number_of_shards: 1
index.number_of_replicas: 0
这对于 testing/dev 场景可能没问题,但对于生产环境,您真的应该考虑 运行 在它自己的 VM 或 VM 集群上使用 elasticsearch,它们 运行ning 在他们自己的 VNET 并通过 VPN 将站点加入 VNET。然后您将拥有一个受 VPN 保护的完整 elasticsearch 集群,网络应用程序将通过其私有 IP 与其通信。
最后,请记住elasticsearch.bat
正在阻塞。如果您在 deploy.cmd 中这样做,它将永远阻止您的部署。 (不是真的永远,有一个超时,它会在最后杀死 elasticsearch)。你想从 Kudu Console 尝试 运行 它。基本上去 https://<yourSitenName>.scm.azurewebsites.net/DebugConsole
你会得到 cmd
window 到 运行 的东西。你可以点击Use old console
。新旧控制台之间的区别在于,新控制台是交互式的(您会在服务器上看到标准输出)但超时为 30 分钟,而旧控制台不是交互式的(输出只会显示一旦命令完成 运行ning),但没有超时。
当 elasticsearch 服务器 运行ning 时,打开 Kudu 控制台的另一个实例和 运行 curl localhost:9200
以验证它 运行ning。
根据我的经验,使用部署脚本在 Azure WebApp 上启动 ElasticSearch 不是正确的方法。
在文档 https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox 中,"Network endpoint listening" 部分说 "The only way an application can be accessed via the internet is through the already-exposed HTTP (80) and HTTPS (443) TCP ports; applications may not listen on other ports for packets arriving from the internet." 所以我认为你的问题 "JavaVM could not be created" 是由 ElasticSearch 无法将端口 9200 绑定为 HTTP 侦听器引起的.
如果您想使用 ElasticSearch,您应该使用 Azure VM 或从 Azure Marketplace 安装 Facetflow ElasticSearch。请参考 https://azure.microsoft.com/en-us/documentation/templates/elasticsearch/ for Elastic on Azure VM, and refer to https://azure.microsoft.com/en-us/marketplace/partners/facetflow/facetflow/ 了解 Azure 上的 Facetflow ElasticSearch。
即使您只想将搜索功能添加到您的 webapp 中,Azure 搜索也可能是一个不错的选择。关于Azure Search,请参考https://azure.microsoft.com/en-us/documentation/services/search/.
我下载了 ElasticSearch、运行 bin/elasticsearch.bat
,它在我的本地机器上运行。然后我将 elasticsearch 文件夹添加到我的存储库并更新了部署脚本 (deploy.cmd),添加了这些行:
echo starting ElasticSearch...
elasticsearch-1.7.2\bin\elasticsearch.bat
echo ElasticSearch started!
将我的存储库推送到我的 Azure 网站后,日志中出现此错误:
starting ElasticSearch...
Error occurred during initialization of VM
Error: Could not create the Java Virtual Machine.
Could not reserve enough space for object heap
Error: A fatal exception has occurred. Program will exit.
Java 在我的 WebApp 配置中打开。所以有什么问题?为什么无法创建 Java 虚拟机?
编辑:Could not reserve enough space for object heap
看起来我的 RAM 较少,但我已经用 3.5GB 的 RAM 试过了,错误也出现了——ElasticSearch 在我的本地机器上只使用 155 MB 的 RAM)
编辑2: 经过一些尝试后,我得到了一个新的错误日志:
starting ElasticSearch...
[2015-10-15 12:59:18,879][INFO ][node ] [Marsha Rosenberg] version[1.7.2], pid[3728], build[e43676b/2015-09-14T09:49:53Z]
[2015-10-15 12:59:18,879][INFO ][node ] [Marsha Rosenberg] initializing ...
[2015-10-15 12:59:19,273][INFO ][plugins ] [Marsha Rosenberg] loaded [], sites []
[2015-10-15 12:59:20,692][INFO ][env ] [Marsha Rosenberg] using [1] data paths, mounts [[Windows (D:)]], net usable_space [13.5gb], net total_space [32gb], types [NTFS]
[2015-10-15 12:59:28,869][INFO ][node ] [Marsha Rosenberg] initialized
[2015-10-15 12:59:28,869][INFO ][node ] [Marsha Rosenberg] starting ...
{1.7.2}: Startup Failed ...
- ChannelException[Failed to create a selector.]
IOException[Unable to establish loopback connection]
SocketException[Address family not supported by protocol family: bind]
我怀疑这是由于尝试发出本地请求而失败的。请参阅 this document 了解有关 Azure Web App 沙盒限制的更多信息。
将 -Djava.net.preferIPv4Stack=true
参数传递给 elasticsearch.bat
。
还要确保 JAVA_HOME
设置为 Java 8 而不是 Java 7。Azure Web Apps 上的路径是 D:\Program Files\Java\jdk1.8.0_25
另请记住,如果您 运行 同一虚拟机上的多个弹性搜索服务器(在同一应用服务计划中),它们将不会全部侦听 9200
。默认情况下,我认为 elasticsearch 会尝试来自 9200 - 9300
的端口,因此请查看标准输出。
您可能想在 elasticsearch.yml
中禁用集群和自动发现,因为无论如何您都无法通过设置
node.local: true
discovery.zen.ping.multicast: false
index.number_of_shards: 1
index.number_of_replicas: 0
这对于 testing/dev 场景可能没问题,但对于生产环境,您真的应该考虑 运行 在它自己的 VM 或 VM 集群上使用 elasticsearch,它们 运行ning 在他们自己的 VNET 并通过 VPN 将站点加入 VNET。然后您将拥有一个受 VPN 保护的完整 elasticsearch 集群,网络应用程序将通过其私有 IP 与其通信。
最后,请记住elasticsearch.bat
正在阻塞。如果您在 deploy.cmd 中这样做,它将永远阻止您的部署。 (不是真的永远,有一个超时,它会在最后杀死 elasticsearch)。你想从 Kudu Console 尝试 运行 它。基本上去 https://<yourSitenName>.scm.azurewebsites.net/DebugConsole
你会得到 cmd
window 到 运行 的东西。你可以点击Use old console
。新旧控制台之间的区别在于,新控制台是交互式的(您会在服务器上看到标准输出)但超时为 30 分钟,而旧控制台不是交互式的(输出只会显示一旦命令完成 运行ning),但没有超时。
当 elasticsearch 服务器 运行ning 时,打开 Kudu 控制台的另一个实例和 运行 curl localhost:9200
以验证它 运行ning。
根据我的经验,使用部署脚本在 Azure WebApp 上启动 ElasticSearch 不是正确的方法。
在文档 https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox 中,"Network endpoint listening" 部分说 "The only way an application can be accessed via the internet is through the already-exposed HTTP (80) and HTTPS (443) TCP ports; applications may not listen on other ports for packets arriving from the internet." 所以我认为你的问题 "JavaVM could not be created" 是由 ElasticSearch 无法将端口 9200 绑定为 HTTP 侦听器引起的.
如果您想使用 ElasticSearch,您应该使用 Azure VM 或从 Azure Marketplace 安装 Facetflow ElasticSearch。请参考 https://azure.microsoft.com/en-us/documentation/templates/elasticsearch/ for Elastic on Azure VM, and refer to https://azure.microsoft.com/en-us/marketplace/partners/facetflow/facetflow/ 了解 Azure 上的 Facetflow ElasticSearch。
即使您只想将搜索功能添加到您的 webapp 中,Azure 搜索也可能是一个不错的选择。关于Azure Search,请参考https://azure.microsoft.com/en-us/documentation/services/search/.