Ubuntu安装elasticsearch

Posted by baicai on August 11, 2016

首先安装jdk是前提。</p>

然后有几种方法:

直接官网下载zip/tar包</h2>

然后./xxxx运行

apt-get

<p style="font-size: 16px; color: rgb(68, 68, 68); font-family: "Open Sans", "arial, helvetica, sans-serif"; line-height: 26px; white-space: normal; background-color: rgb(255, 255, 255);">Download and install the Public Signing Key:</p><div class="pre_wrapper" style="overflow-x: auto; position: relative; width: 750px; margin-bottom: 15px; border-left: 3px solid rgb(0, 169, 229); display: inline-flex; color: rgb(68, 68, 68); font-family: "Open Sans", "arial, helvetica, sans-serif"; font-size: 16px; line-height: 26px; white-space: normal; background-color: rgb(240, 240, 240);"><pre class="programlisting prettyprint lang-sh prettyprinted" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 16px; display: inline-block; padding: 8px 0px 8px 18px; margin-bottom: 0px; line-height: 1.5em; word-break: break-word; border: none; border-top-right-radius: 5px; border-bottom-right-radius: 5px; width: auto; max-width: 10000px; background-color: rgb(240, 240, 240);">wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
</div><p style="font-size: 16px; color: rgb(68, 68, 68); font-family: "Open Sans", "arial, helvetica, sans-serif"; line-height: 26px; white-space: normal; background-color: rgb(255, 255, 255);">Save the repository definition to <code class="literal" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 0.9em; padding-right: 3px; padding-left: 3px; color: rgb(85, 85, 85); border-radius: 4px; display: inline; white-space: normal; word-wrap: break-word; width: auto; overflow-x: auto; vertical-align: middle; background: rgb(248, 248, 248);">/etc/apt/sources.list.d/elasticsearch-2.x.list</code>:</p><div class="pre_wrapper" style="overflow-x: auto; position: relative; width: 750px; margin-bottom: 15px; border-left: 3px solid rgb(0, 169, 229); display: inline-flex; color: rgb(68, 68, 68); font-family: "Open Sans", "arial, helvetica, sans-serif"; font-size: 16px; line-height: 26px; white-space: normal; background-color: rgb(240, 240, 240);"><pre class="programlisting prettyprint lang-sh prettyprinted" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 16px; display: inline-block; padding: 8px 0px 8px 18px; margin-bottom: 0px; line-height: 1.5em; word-break: break-word; border: none; border-top-right-radius: 5px; border-bottom-right-radius: 5px; width: auto; max-width: 10000px; background-color: rgb(240, 240, 240);">echo "deb https://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list</pre></div><div class="warning admon" style="padding: 10px; min-height: 80px; margin-top: 15px; margin-bottom: 15px; border-radius: 5px; position: relative; color: rgb(68, 68, 68); font-family: "Open Sans", "arial, helvetica, sans-serif"; font-size: 16px; line-height: 26px; white-space: normal; background: rgb(251, 251, 251);">
Warning

Use the <code class="literal" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 0.9em; padding-right: 3px; padding-left: 3px; color: rgb(85, 85, 85); border-radius: 4px; display: inline; white-space: normal; word-wrap: break-word; width: auto; overflow-x: auto; vertical-align: middle; background: rgb(248, 248, 248);">echo</code> method described above to add the Elasticsearch repository. Do not use<code class="literal" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 0.9em; padding-right: 3px; padding-left: 3px; color: rgb(85, 85, 85); border-radius: 4px; display: inline; white-space: normal; word-wrap: break-word; width: auto; overflow-x: auto; vertical-align: middle; background: rgb(248, 248, 248);">add-apt-repository</code> as it will add a <code class="literal" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 0.9em; padding-right: 3px; padding-left: 3px; color: rgb(85, 85, 85); border-radius: 4px; display: inline; white-space: normal; word-wrap: break-word; width: auto; overflow-x: auto; vertical-align: middle; background: rgb(248, 248, 248);">deb-src</code> entry as well, but we do not provide a source package. If you have added the <code class="literal" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 0.9em; padding-right: 3px; padding-left: 3px; color: rgb(85, 85, 85); border-radius: 4px; display: inline; white-space: normal; word-wrap: break-word; width: auto; overflow-x: auto; vertical-align: middle; background: rgb(248, 248, 248);">deb-src</code> entry, you will see an error like the following:

<pre class="literallayout" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; display: inline-block; line-height: 1.42857; white-space: pre-wrap; width: 650px;">Unable to find expected entry 'main/source/Sources' in Release file (Wrong sources.list entry or malformed file)</pre>

Just delete the <code class="literal" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 0.9em; padding-right: 3px; padding-left: 3px; color: rgb(85, 85, 85); border-radius: 4px; display: inline; white-space: normal; word-wrap: break-word; width: auto; overflow-x: auto; vertical-align: middle; background: rgb(248, 248, 248);">deb-src</code> entry from the <code class="literal" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 0.9em; padding-right: 3px; padding-left: 3px; color: rgb(85, 85, 85); border-radius: 4px; display: inline; white-space: normal; word-wrap: break-word; width: auto; overflow-x: auto; vertical-align: middle; background: rgb(248, 248, 248);">/etc/apt/sources.list</code> file and the installation should work as expected.

</div><p style="font-size: 16px; color: rgb(68, 68, 68); font-family: "Open Sans", "arial, helvetica, sans-serif"; line-height: 26px; white-space: normal; background-color: rgb(255, 255, 255);">Run apt-get update and the repository is ready for use. You can install it with:</p><div class="pre_wrapper" style="overflow-x: auto; position: relative; width: 750px; margin-bottom: 15px; border-left: 3px solid rgb(0, 169, 229); display: inline-flex; color: rgb(68, 68, 68); font-family: "Open Sans", "arial, helvetica, sans-serif"; font-size: 16px; line-height: 26px; white-space: normal; background-color: rgb(240, 240, 240);"><pre class="programlisting prettyprint lang-sh prettyprinted" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 16px; display: inline-block; padding: 8px 0px 8px 18px; margin-bottom: 0px; line-height: 1.5em; word-break: break-word; border: none; border-top-right-radius: 5px; border-bottom-right-radius: 5px; width: auto; max-width: 10000px; background-color: rgb(240, 240, 240);">sudo apt-get update && sudo apt-get install elasticsearch</pre></div><div class="warning admon" style="padding: 10px; min-height: 80px; margin-top: 15px; margin-bottom: 15px; border-radius: 5px; position: relative; color: rgb(68, 68, 68); font-family: "Open Sans", "arial, helvetica, sans-serif"; font-size: 16px; line-height: 26px; white-space: normal; background: rgb(251, 251, 251);">
Warning

If two entries exist for the same Elasticsearch repository, you will see an error like this during <code class="literal" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 0.9em; padding-right: 3px; padding-left: 3px; color: rgb(85, 85, 85); border-radius: 4px; display: inline; white-space: normal; word-wrap: break-word; width: auto; overflow-x: auto; vertical-align: middle; background: rgb(248, 248, 248);">apt-get update</code>:

<pre class="literallayout" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; display: inline-block; line-height: 1.42857; white-space: pre-wrap; width: 650px;">Duplicate sources.list entry https://packages.elastic.co/elasticsearch/2.x/debian/ ...`</pre>

Examine <code class="literal" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 0.9em; padding-right: 3px; padding-left: 3px; color: rgb(85, 85, 85); border-radius: 4px; display: inline; white-space: normal; word-wrap: break-word; width: auto; overflow-x: auto; vertical-align: middle; background: rgb(248, 248, 248);">/etc/apt/sources.list.d/elasticsearch-2.x.list</code> for the duplicate entry or locate the duplicate entry amongst the files in <code class="literal" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 0.9em; padding-right: 3px; padding-left: 3px; color: rgb(85, 85, 85); border-radius: 4px; display: inline; white-space: normal; word-wrap: break-word; width: auto; overflow-x: auto; vertical-align: middle; background: rgb(248, 248, 248);">/etc/apt/sources.list.d/</code> and the<code class="literal" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 0.9em; padding-right: 3px; padding-left: 3px; color: rgb(85, 85, 85); border-radius: 4px; display: inline; white-space: normal; word-wrap: break-word; width: auto; overflow-x: auto; vertical-align: middle; background: rgb(248, 248, 248);">/etc/apt/sources.list</code> file.

</div><p style="font-size: 16px; color: rgb(68, 68, 68); font-family: "Open Sans", "arial, helvetica, sans-serif"; line-height: 26px; white-space: normal; background-color: rgb(255, 255, 255);">Configure Elasticsearch to automatically start during bootup. If your distribution is using SysV init, then you will need to run:</p><div class="pre_wrapper" style="overflow-x: auto; position: relative; width: 750px; margin-bottom: 15px; border-left: 3px solid rgb(0, 169, 229); display: inline-flex; color: rgb(68, 68, 68); font-family: "Open Sans", "arial, helvetica, sans-serif"; font-size: 16px; line-height: 26px; white-space: normal; background-color: rgb(240, 240, 240);"><pre class="programlisting prettyprint lang-sh prettyprinted" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 16px; display: inline-block; padding: 8px 0px 8px 18px; margin-bottom: 0px; line-height: 1.5em; word-break: break-word; border: none; border-top-right-radius: 5px; border-bottom-right-radius: 5px; width: auto; max-width: 10000px; background-color: rgb(240, 240, 240);">sudo update-rc.d elasticsearch defaults 95 10</pre></div><p style="font-size: 16px; color: rgb(68, 68, 68); font-family: "Open Sans", "arial, helvetica, sans-serif"; line-height: 26px; white-space: normal; background-color: rgb(255, 255, 255);">Otherwise if your distribution is using systemd:</p><div class="pre_wrapper" style="overflow-x: auto; position: relative; width: 750px; margin-bottom: 15px; border-left: 3px solid rgb(0, 169, 229); display: inline-flex; color: rgb(68, 68, 68); font-family: "Open Sans", "arial, helvetica, sans-serif"; font-size: 16px; line-height: 26px; white-space: normal; background-color: rgb(240, 240, 240);"><pre class="programlisting prettyprint lang-sh prettyprinted" style="font-family: Consolas, Menlo, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Lucida Console"; font-size: 16px; display: inline-block; padding: 8px 0px 8px 18px; margin-bottom: 0px; line-height: 1.5em; word-break: break-word; border: none; border-top-right-radius: 5px; border-bottom-right-radius: 5px; width: auto; max-width: 10000px; background-color: rgb(240, 240, 240);">sudo /bin/systemctl daemon-reload sudo /bin/systemctl enable elasticsearch.service</pre></div></pre>发现访问很慢啊<p></p>

deb包</h2>

官网直接下载deb包</p>

https://www.elastic.co/downloads/elasticsearch

https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.5/elasticsearch-2.3.5.deb

sudo dpkg -i xxx.deb

sudo /etc/init.d/elasticsearch start

添加到默认启动:

sudo update-rc.d elasticsearch defaults 95 10