ES安装教程详解

<div id="article_content" class="article_content clearfix">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-163de54645.css">
                <div id="content_views" class="markdown_views prism-atom-one-light">
                    <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
                        <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
                    </svg>
                    <p></p>
<div class="toc">
 <h3><a name="t0"></a>文章目录</h3>
 <ul><li><ul><li><ul><li><ul><li><ul><li><a href="#0__1" target="_self">0. 安装前准备</a></li><li><a href="#2_ES_7" target="_self">2. 在官方网站下载ES</a></li><li><a href="#3_JDKJDK18_10" target="_self">3. 安装JDK(必须JDK1.8+)</a></li><li><a href="#4__14" target="_self">4. 配置环境变量</a></li><li><a href="#5__20" target="_self">5. 重载系统配置</a></li><li><a href="#6_elasticsearche_23" target="_self">6. 安装elasticsearche</a></li><li><a href="#7_elasticsearche_26" target="_self">7. elasticsearche的目录结构</a></li><li><a href="#8_es_33" target="_self">8. 运行es服务</a></li><li><a href="#9_root_39" target="_self">9. 不能以root用户身份启动</a></li><li><a href="#10_esES_56" target="_self">10. 登录es用户启动ES</a></li><li><a href="#11_ES_59" target="_self">11. 测试ES是否启动成功</a></li><li><a href="#12_ES_77" target="_self">12. 开启ES远程访问</a></li><li><a href="#13__81" target="_self">13. 启动时错误解决方案</a></li><li><a href="#14__114" target="_self">14. 关闭网络防火墙</a></li><li><a href="#15__118" target="_self">15. 外部浏览器访问即可</a></li></ul>
    </li></ul>
   </li></ul>
  </li></ul>
 </li></ul>
</div>
<p></p> 
<h5><a id="0__1"></a>0. 安装前准备</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">    centos7 +
    java 8  +
    elastic 6.2.4+
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre> 
<h5><a id="2_ES_7"></a>2. 在官方网站下载ES</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">wget http://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.tar.gz
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<h5><a id="3_JDKJDK18_10"></a>3. 安装JDK(必须JDK1.8+)</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">rpm -ivh jdk-8u181-linux-x64.rpm
    /*注意:默认安装位置 /usr/java/jdk1.8.0_171-amd64*/
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
<h5><a id="4__14"></a>4. 配置<a href="https://so.csdn.net/so/search?q=%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F&amp;spm=1001.2101.3001.7020" target="_blank" class="hl hl-1" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.7020&quot;,&quot;dest&quot;:&quot;https://so.csdn.net/so/search?q=%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F&amp;spm=1001.2101.3001.7020&quot;}" data-tit="环境变量" data-pretit="环境变量">环境变量</a></h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">vim /etc/profile
在文件末尾加入:
    export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64
    export PATH=$PATH:$JAVA_HOME/bin
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li></ul></pre> 
<h5><a id="5__20"></a>5. 重载系统配置</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">    source /etc/profile
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<h5><a id="6_elasticsearche_23"></a>6. 安装elasticsearche</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">    tar -zxvf elasticsearch-6.4.1.tar.gz
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<h5><a id="7_elasticsearche_26"></a>7. elasticsearche的目录结构</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">    bin                         可执行的二进制文件的目录
    config                        配置文件的目录
    lib                         运行时依赖的库
    logs  modules               运行时日志文件
    plugins                       es中提供的插件
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre> 
<h5><a id="8_es_33"></a>8. 运行es服务</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">    在bin目录中执行   ./elasticsearch
    
    注意:root用户启动[2018-09-19T14:50:04,029][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre> 
<h5><a id="9_root_39"></a>9. 不能以root用户身份启动</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">a.在linux系统中创建新的组
    groupadd es

b.创建新的用户es并将es用户放入es组中
     

c.修改es用户密码
    passwd es

d.将root用户解压的文件移动到es用户目录中
    mv /root/elasticsearch-6.2.4  /home/es/

f.改变文件的所有者
    chown -R es:es 当前es的安装目录(这里是:/home/es/elasticsearch)
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li></ul></pre> 
<h5><a id="10_esES_56"></a>10. 登录es用户启动ES</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">    ./elasticsearch   启动ES
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<h5><a id="11_ES_59"></a>11. 测试ES是否启动成功</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">在命令终端中执行: curl http://localhost:9200 出现以下信息:
    {
      "name" : "xQK1cwT",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "t7IYk7LKQ0mXcyyrdFWpLg",
      "version" : {
        "number" : "6.2.4",
        "build_hash" : "ccec39f",
        "build_date" : "2018-04-12T20:37:28.497551Z",
        "build_snapshot" : false,
        "lucene_version" : "7.2.1",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
      },
      "tagline" : "You Know, for Search"
    }
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li></ul></pre> 
<h5><a id="12_ES_77"></a>12. 开启ES远程访问</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">    vim elasticsearch.yml 将原来network修改为以下配置:
    network.host: 0.0.0.0
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
<h5><a id="13__81"></a>13. 启动时错误解决方案</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">a.重新启动es出现如下错误
  **ERROR: bootstrap checks failed[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]**
  解决方案:
   # 切换到root用户修改
    vim /etc/security/limits.conf
   # 在最后面追加下面内容
    *               soft    nofile          65536
    *               hard    nofile          65536
    *               soft    nproc           4096
    *               hard    nproc           4096
   # 退出重新登录检测配置是否生效:
    ulimit -Hn
    ulimit -Sn
    ulimit -Hu
    ulimit -Su

b.重新启动出现如下错误
  **ERROR: max number of threads [3802] for user [chenyn] is too low,increase to at least [4096]**
   解决方案:
   #进入limits.d目录下修改配置文件。
    vim /etc/security/limits.d/20-nproc.conf 
   # 修改为 启动ES用户名 soft nproc 4096
   
c.重新启动出现如下错误
  **ERROR: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]**
   解决方案:
    vim /etc/sysctl.conf
    vm.max_map_count=655360
   #执行以下命令生效:
    sysctl -p
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li></ul></pre> 
<h5><a id="14__114"></a>14. 关闭网络防火墙</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">    systemctl stop firewalld
    systemctl disable firewalld
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
<h5><a id="15__118"></a>15. 外部浏览器访问即可</h5> 
<pre class="prettyprint"><code class="has-numbering" οnclick="mdcp.copyCode(event)" style="position: unset;">http://es的主机名:9200 出现如下信息说明安装成功:
{
    "name" : "xQK1cwT",
    "cluster_name" : "elasticsearch",
    "cluster_uuid" : "t7IYk7LKQ0mXcyyrdFWpLg",
    "version" : {
    "number" : "6.2.4",
    "build_hash" : "ccec39f",
    "build_date" : "2018-04-12T20:37:28.497551Z",
    "build_snapshot" : false,
    "lucene_version" : "7.2.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
    },
    "tagline" : "You Know, for Search"
}
<div class="hljs-button {2}" data-title="复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4259&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li></ul></pre>
                </div><div><div></div></div>
                <link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/markdown_views-3fd7f7a902.css" rel="stylesheet">
                <link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/style-49037e4d27.css" rel="stylesheet">
        </div>