如何在Linux上安装Elasticsearch和Kibana
获取我们关于安装两者的简化说明。
如果你渴望学习基于开源 Lucene 库的著名开源搜索引擎 Elasticsearch,那么没有比在本地安装它更好的方法了。这个过程在 Elasticsearch 网站中有详细介绍,但如果你是初学者,官方说明就比必要的信息多得多。本文采用一种简化的方法。
添加 Elasticsearch 仓库
首先,将 Elasticsearch 仓库添加到你的系统,以便你可以根据需要安装它并接收更新。如何做取决于你的发行版。在基于 RPM 的系统上,例如 Fedora、CentOS、Red Hat Enterprise Linux(RHEL) 或 openSUSE,(本文任何地方引用 Fedora 或 RHEL 的也适用于 CentOS 和 openSUSE)在 /etc/yum.repos.d/
中创建一个名为 elasticsearch.repo
的仓库描述文件:
<span class="pln">$ </span><span class="kwd">cat</span><span class="pln"> </span><span class="pun"><<</span><span class="pln"> EOF </span><span class="pun">|</span><span class="pln"> </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">tee</span><span class="pln"> </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="kwd">yum</span><span class="pun">.</span><span class="pln">repos</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">elasticsearch</span><span class="pun">.</span><span class="pln">repo</span>
<span class="pun">[</span><span class="pln">elasticsearch</span><span class="pun">-</span><span class="lit">7.x</span><span class="pun">]</span>
<span class="pln">name</span><span class="pun">=</span><span class="typ">Elasticsearch</span><span class="pln"> repository </span><span class="kwd">for</span><span class="pln"> </span><span class="lit">7.x</span><span class="pln"> packages</span>
<span class="pln">baseurl</span><span class="pun">=</span><span class="pln">https</span><span class="pun">:</span><span class="com">//artifacts.elastic.co/packages/oss-7.x/yum</span>
<span class="pln">gpgcheck</span><span class="pun">=</span><span class="lit">1</span>
<span class="pln">gpgkey</span><span class="pun">=</span><span class="pln">https</span><span class="pun">:</span><span class="com">//artifacts.elastic.co/GPG-KEY-elasticsearch</span>
<span class="pln">enabled</span><span class="pun">=</span><span class="lit">1</span>
<span class="pln">autorefresh</span><span class="pun">=</span><span class="lit">1</span>
<span class="pln">type</span><span class="pun">=</span><span class="pln">rpm</span><span class="pun">-</span><span class="pln">md</span>
<span class="pln">EOF</span>
在 Ubuntu 或 Debian 上,不要使用 add-apt-repository
工具。由于它自身默认的和 Elasticsearch 仓库提供的不匹配而导致错误。相反,设置这个:
<span class="pln">$ </span><span class="kwd">echo</span><span class="pln"> </span><span class="str">"deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main"</span><span class="pln"> </span><span class="pun">|</span><span class="pln"> </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">tee</span><span class="pln"> </span><span class="pun">-</span><span class="pln">a </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apt</span><span class="pun">/</span><span class="pln">sources</span><span class="pun">.</span><span class="kwd">list</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">elastic</span><span class="pun">-</span><span class="lit">7.x</span><span class="pun">.</span><span class="kwd">list</span>
在你从该仓库安装之前,导入 GPG 公钥,然后更新:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> apt</span><span class="pun">-</span><span class="pln">key adv </span><span class="pun">--</span><span class="pln">keyserver \</span>
<span class="pln">hkp</span><span class="pun">:</span><span class="com">//keyserver.ubuntu.com:80 \</span>
<span class="pun">--</span><span class="pln">recv D27D666CD88E42B4</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> apt update</span>
此存储库仅包含 Elasticsearch 的开源功能,在 Apache 许可证下发布,没有提供订阅版本的额外功能。如果你需要仅限订阅的功能(这些功能是并不开源),那么 baseurl
必须设置为:
<span class="pln">baseurl</span><span class="pun">=</span><span class="pln">https</span><span class="pun">:</span><span class="com">//artifacts.elastic.co/packages/7.x/yum</span>
安装 Elasticsearch
你需要安装的软件包的名称取决于你使用的是开源版本还是订阅版本。本文使用开源版本,包名最后有 -oss
后缀。如果包名后没有 -oss
,那么表示你请求的是仅限订阅版本。
如果你创建了订阅版本的仓库却尝试安装开源版本,那么就会收到“非指定”的错误。如果你创建了一个开源版本仓库却没有将 -oss
添加到包名后,那么你也会收到错误。
使用包管理器安装 Elasticsearch。例如,在 Fedora、CentOS 或 RHEL 上运行以下命令:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> dnf install elasticsearch</span><span class="pun">-</span><span class="pln">oss</span>
在 Ubuntu 或 Debian 上,运行:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> apt install elasticsearch</span><span class="pun">-</span><span class="pln">oss</span>
如果你在安装 Elasticsearch 时遇到错误,那么你可能安装的是错误的软件包。如果你想如本文这样使用开源包,那么请确保使用正确的 apt 仓库或在 Yum 配置正确的 baseurl
。
启动并启用 Elasticsearch
安装 Elasticsearch 后,你必须启动并启用它:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">systemctl</span><span class="pln"> daemon</span><span class="pun">-</span><span class="pln">reload</span>
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> </span><span class="kwd">systemctl</span><span class="pln"> enable </span><span class="pun">--</span><span class="pln">now elasticsearch</span><span class="pun">.</span><span class="pln">service</span>
要确认 Elasticsearch 在其默认端口 9200 上运行,请在 Web 浏览器中打开 localhost:9200
。你可以使用 GUI 浏览器,也可以在终端中执行此操作:
<span class="pln">$ curl localhost</span><span class="pun">:</span><span class="lit">9200</span>
<span class="pun">{</span>
<span class="pln"> </span><span class="str">"name"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"fedora30"</span><span class="pun">,</span>
<span class="pln"> </span><span class="str">"cluster_name"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"elasticsearch"</span><span class="pun">,</span>
<span class="pln"> </span><span class="str">"cluster_uuid"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"OqSbb16NQB2M0ysynnX1hA"</span><span class="pun">,</span>
<span class="pln"> </span><span class="str">"version"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span>
<span class="pln"> </span><span class="str">"number"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"7.2.0"</span><span class="pun">,</span>
<span class="pln"> </span><span class="str">"build_flavor"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"oss"</span><span class="pun">,</span>
<span class="pln"> </span><span class="str">"build_type"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"rpm"</span><span class="pun">,</span>
<span class="pln"> </span><span class="str">"build_hash"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"508c38a"</span><span class="pun">,</span>
<span class="pln"> </span><span class="str">"build_date"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"2019-06-20T15:54:18.811730Z"</span><span class="pun">,</span>
<span class="pln"> </span><span class="str">"build_snapshot"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">,</span>
<span class="pln"> </span><span class="str">"lucene_version"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"8.0.0"</span><span class="pun">,</span>
<span class="pln"> </span><span class="str">"minimum_wire_compatibility_version"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"6.8.0"</span><span class="pun">,</span>
<span class="pln"> </span><span class="str">"minimum_index_compatibility_version"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"6.0.0-beta1"</span>
<span class="pln"> </span><span class="pun">},</span>
<span class="pln"> </span><span class="str">"tagline"</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="str">"You Know, for Search"</span>
<span class="pun">}</span>
安装 Kibana
Kibana 是 Elasticsearch 数据可视化的图形界面。它包含在 Elasticsearch 仓库,因此你可以使用包管理器进行安装。与 Elasticsearch 本身一样,如果你使用的是 Elasticsearch 的开源版本,那么必须将 -oss
放到包名最后,订阅版本则不用(两者安装需要匹配):
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> dnf install kibana</span><span class="pun">-</span><span class="pln">oss</span>
在 Ubuntu 或 Debian 上:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> apt install kibana</span><span class="pun">-</span><span class="pln">oss</span>
Kibana 在端口 5601 上运行,因此打开图形化 Web 浏览器并进入 localhost:5601
来开始使用 Kibana,如下所示:
Kibana running in Firefox.
故障排除
如果在安装 Elasticsearch 时出现错误,请尝试手动安装 Java 环境。在 Fedora、CentOS 和 RHEL 上:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> dnf install java</span><span class="pun">-</span><span class="pln">openjdk</span><span class="pun">-</span><span class="pln">devel java</span><span class="pun">-</span><span class="pln">openjdk</span>
在 Ubuntu 上:
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> apt install </span><span class="kwd">default</span><span class="pun">-</span><span class="pln">jdk</span>
如果所有其他方法都失败,请尝试直接从 Elasticsearch 服务器安装 Elasticsearch RPM:
<span class="pln">$ </span><span class="kwd">wget</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//artifacts.elastic.co/downloads/elasticsearch/elasticsearch-oss-7.2.0-x86_64.rpm{,.sha512}</span>
<span class="pln">$ shasum </span><span class="pun">-</span><span class="pln">a </span><span class="lit">512</span><span class="pln"> </span><span class="pun">-</span><span class="pln">c elasticsearch</span><span class="pun">-</span><span class="pln">oss</span><span class="pun">-</span><span class="lit">7.2</span><span class="pun">.</span><span class="lit">0</span><span class="pun">-</span><span class="pln">x86_64</span><span class="pun">.</span><span class="pln">rpm</span><span class="pun">.</span><span class="pln">sha512 </span><span class="pun">&&</span><span class="pln"> </span><span class="kwd">sudo</span><span class="pln"> rpm </span><span class="pun">--</span><span class="pln">install elasticsearch</span><span class="pun">-</span><span class="pln">oss</span><span class="pun">-</span><span class="lit">7.2</span><span class="pun">.</span><span class="lit">0</span><span class="pun">-</span><span class="pln">x86_64</span><span class="pun">.</span><span class="pln">rpm</span>
在 Ubuntu 或 Debian 上,请使用 DEB 包。
如果你无法使用 Web 浏览器访问 Elasticsearch 或 Kibana,那么可能是你的防火墙阻止了这些端口。你可以通过调整防火墙设置来允许这些端口上的流量。例如,如果你运行的是 firewalld
(Fedora 和 RHEL 上的默认防火墙,并且可以在 Debian 和 Ubuntu 上安装),那么你可以使用 firewall-cmd
:
相关推荐
另外一部分,则需要先做聚类、分类处理,将聚合出的分类结果存入ES集群的聚类索引中。数据处理层的聚合结果存入ES中的指定索引,同时将每个聚合主题相关的数据存入每个document下面的某个field下。