Shell 安装 Elasticsearch 的脚本在使用 'yes' 安装 X-Pack 时抛出错误

Shell script to install Elasticsearch throws error when install X-Pack with 'yes'

我正在开发一个 shell 脚本,它会自动安装最新的 Elasticsearch 5.0.0 GA 版本和 X-Pack 插件。

这是我拥有的:

#!/bin/bash

# ========= ES INSTALL =========
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo apt-get install apt-transport-https
echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list
apt-get update && apt-get install -y elasticsearch

# ===== ES PLUGINS INSTALL =====
yes | ./usr/share/elasticsearch/bin/elasticsearch-plugin install x-pack

在安装 X-Pack 时出现以下错误:

Exception in thread "main" java.nio.file.FileAlreadyExistsException: /usr/share/elasticsearch/bin/x-pack
        at sun.nio.fs.UnixException.translateToIOException(UnixException.java:88)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
        at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384)
        at java.nio.file.Files.createDirectory(Files.java:674)
        at org.elasticsearch.plugins.InstallPluginCommand.installBin(InstallPluginCommand.java:519)
        at org.elasticsearch.plugins.InstallPluginCommand.install(InstallPluginCommand.java:482)
        at org.elasticsearch.plugins.InstallPluginCommand.execute(InstallPluginCommand.java:207)
        at org.elasticsearch.plugins.InstallPluginCommand.execute(InstallPluginCommand.java:190)
        at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:96)
        at org.elasticsearch.cli.MultiCommand.execute(MultiCommand.java:69)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:96)
        at org.elasticsearch.cli.Command.main(Command.java:62)
        at org.elasticsearch.plugins.PluginCli.main(PluginCli.java:42)

如果我在没有 yes | 的情况下调用 X-Pack 安装命令,那么一切正常。 yes | 有什么问题?

看来您需要 'echo' 您的 'yes'

echo "y" | sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install x-pack