nisbos


安装

<h2>一、安装方式</h2> <p>因为平台使用的Elasticsearch版本为6.6.0,因此本文都以该版本进行安装</p> <h3>1、单机版</h3> <p>单机版主要针对个人学习使用,本文以在window 64位系统安装Elasticsearch为例</p> <blockquote> <p>1.1 下载地址</p> </blockquote> <p><a href="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.0.zip" title="elasticsearch/elasticsearch-6.6.0.zip">elasticsearch/elasticsearch-6.6.0.zip</a></p> <blockquote> <p>1.2 解压后,进入bin/目录,双击执行 elasticsearch.bat启动</p> </blockquote> <p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/f0ffd0e747ab7b179df6a31993019602?showdoc=.jpg" alt="" /></p> <blockquote> <p>1.3 浏览器访问localhost:9200</p> </blockquote> <p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/3d125d8f6f1af93166414f5b294a52c1?showdoc=.jpg" alt="" /></p> <blockquote> <p>1.4 如果想安装其他版本,可以访问以下链接,链接也有提供具体单机版安装教程</p> </blockquote> <p><a href="https://www.elastic.co/cn/downloads/elasticsearch" title="Download Elasticsearch And Installation steps">Download Elasticsearch And Installation steps</a></p> <h3>2、集群版</h3> <p>集群主要针对预发布环境以及生产环境使用,本文以在centos7系统安装Elasticsearch为例为例</p> <blockquote> <p>2.1 安装准备条件</p> </blockquote> <p>准备三台装有centos7系统机器(因为目前只有2台机子,因此就以2台机子演示)</p> <table> <thead> <tr> <th>ip</th> <th>主从</th> </tr> </thead> <tbody> <tr> <td>10.1.4.70</td> <td>master</td> </tr> <tr> <td>10.1.4.71</td> <td>slave</td> </tr> </tbody> </table> <p><strong>ps</strong>:Elasticsearch6版本需要依赖jdk8+,因此安装的时候要确保,安装上的机子上已经装好jdk8+,执行 java -verison <img src="https://www.showdoc.cc/server/api/common/visitfile/sign/b43a60fae899f2b1d9be47ebd93cdb41?showdoc=.jpg" alt="" /> 出现上文说明jdk已经有安装。censto7已经默认装有jdk8。其他环境安装jdk8可参考如下链接进行搭建 <a href="https://www.jianshu.com/p/f000e05f3512" title="Linux安装jdk8及环境变量配置">Linux安装jdk8及环境变量配置</a></p> <blockquote> <p>2.2 下载安装包,点击如下链接进行下载</p> </blockquote> <p><a href="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.0.tar.gz" title="elasticsearch-6.6.0.tar.gz">elasticsearch-6.6.0.tar.gz</a></p> <blockquote> <p>2.3 修改系统配置【所有安装机器都要执行】</p> </blockquote> <ul> <li> <p>2.3.1 修改limits.conf</p> <p>增加连接数,不然ES无法启动</p> <pre><code class="language-shell">vim /etc/security/limits.conf</code></pre> <p>添加如下内容</p> <pre><code class="language-shell">* soft nofile 65536 * hard nofile 131072 * soft nproc 65536 * hard nproc 524288 * soft memlock unlimited * hard memlock unlimited</code></pre> <ul> <li>2.3.2 修改sysctl.conf</li> </ul> <p>增加连接数,不然ES无法启动</p> <pre><code class="language-shell">vim /etc/sysctl.conf 最后一行增加 vm.max_map_count=655360</code></pre> <p>运行命令</p> <pre><code class="language-shell">sysctl -p</code></pre> <p>使之生效</p> </li> </ul> <blockquote> <p>2.4 添加新用户(所有机器上都要操作)</p> </blockquote> <p><strong>ES启动必须使用非Root用户启动,所以我们需要创建一个新用户用于启动</strong></p> <pre><code class="language-shell">groupadd es useradd -m es -g es -p es</code></pre> <p>新添加完成后切换到新创建的用户</p> <pre><code class="language-shell">su es</code></pre> <blockquote> <p>2.5 安装ES【不能以root用户安装,以新建的用户es来安装】</p> </blockquote> <ul> <li>2.5.1 将ES压缩包放到/home/es 目录下并解压ES安装包,(所欲机器上都要操作)</li> </ul> <pre><code class="language-shell">tar -zxvf elasticsearch-6.6.0.tar.gz</code></pre> <ul> <li>2.5.2 创建存储ES的数据目录</li> </ul> <pre><code class="language-shell">mkdir /home/es/elasticsearch-6.6.0/data</code></pre> <ul> <li>2.5.3 修改ES配置文件 (下文只保留所需内容)</li> </ul> <pre><code class="language-shell">vim /home/es/elasticsearch-6.6.0/config/elasticsearch.yml</code></pre> <pre><code class="language-shell"># --------------------------------- Cluster ----------------- cluster.name : my-cluster # ------------------------------------ Node ----------------- node.name : node-1 node.master: true node.data: true # ----------------------------------- Paths --------------- path.data: /home/es/elasticsearch-6.6.0/data path.logs: /home/es/elasticsearch-6.6.0/logs # ----------------------------------- Memory ---------------- bootstrap.memory_lock: true # ---------------------------------- Network ---------------- network.host: 10.1.4.70 http.port: 9200 # --------------------------------- Discovery --------------- discovery.zen.ping.unicast.hosts: ["10.1.4.70", "10.1.4.71"] discovery.zen.minimum_master_nodes: 1 # ---------------------------------- Gateway --------------- gateway.recover_after_nodes: 2</code></pre> <p>配置内容解析:</p> <table> <thead> <tr> <th>属性</th> <th>作用</th> </tr> </thead> <tbody> <tr> <td>cluster.name</td> <td>配置的集群名称,通过集群名称这个属性来区分不同的集群</td> </tr> <tr> <td>node.name</td> <td>当前配置所在机器的节点名,你不设置就默认随机指定一个name列表中名字</td> </tr> <tr> <td>node.master</td> <td>指定该节点是否有资格被选举成为node(注意这里只是设置成有资格, 不代表该node一定就是master),默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master。</td> </tr> <tr> <td>node.data</td> <td>指定该节点是否存储索引数据,默认为true。</td> </tr> <tr> <td>path.data</td> <td>设置索引数据的存储路径</td> </tr> <tr> <td>path.logs</td> <td>设置日志文件的存储路径</td> </tr> <tr> <td>bootstrap.memory_lock</td> <td>锁定物理内存地址,防止es内存被交换出去,也就是避免es使用swap交换分区,频繁的交换,会导致IOPS变高</td> </tr> <tr> <td>network.host</td> <td>这个参数是用来同时设置bind_host和publish_host</td> </tr> <tr> <td>http.port</td> <td>可以为Http传输监听定制端口</td> </tr> <tr> <td>discovery.zen.ping.unicast.hosts</td> <td>设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点</td> </tr> <tr> <td>discovery.zen.minimum_master_nodes</td> <td>设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点</td> </tr> <tr> <td>gateway.recover_after_nodes</td> <td>设置集群中N个节点启动时进行数据恢复</td> </tr> </tbody> </table> <p>其他节点可复制上述内容,并修改其他几个关键信息,其他同上述一致。</p> <pre><code class="language-shell">node.name: node-2 node.master: true node.data: false network.host: 10.1.4.71</code></pre> <ul> <li>2.5.4 启动ES集群</li> </ul> <p>运行与节点顺序无关,但是必须得用普通用户(比如es用户)启动。</p> <pre><code class="language-shell">cd /home/es/elasticsearch-6.6.0/bin ./elasticsearch -d -d 代表以后台形式启动</code></pre> <ul> <li>2.5.5 通过P地址加9200端口进行访问 <img src="https://www.showdoc.cc/server/api/common/visitfile/sign/0823b40ceb308db37a1265bb43523d1c?showdoc=.jpg" alt="" /></li> </ul> <h3>3、安装过程可能踩到的坑</h3> <blockquote> <p>3.1 uncaught exception in thread [main] org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root</p> </blockquote> <pre><code class="language-shell">不能以root用户启动</code></pre> <blockquote> <p>3.2 ERROR: bootstrap checks failed memory locking requested for elasticsearch process but memory is not locked</p> </blockquote> <pre><code class="language-shell">内存锁定失败,切换到root用户,修改limits.conf配置文件,vim /etc/security/limits.conf 添加* soft memlock unlimited / * hard memlock unlimited</code></pre> <blockquote> <p>3.3 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]</p> </blockquote> <pre><code class="language-shell">最大虚拟内存太小,切换到root用户下,修改配置文件sysctl.conf vim /etc/sysctl.conf 添加下面配置: vm.max_map_count=655360 并执行命令: sysctl -p</code></pre> <blockquote> <p>3.4 java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in</p> </blockquote> <pre><code class="language-shell">内核太低的缘故,可以升级linux内核(可忽略)</code></pre> <blockquote> <p>3.5 ERROR: bootstrap checks failed system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk</p> </blockquote> <pre><code class="language-shell">修改elasticsearch-6.6.0/config/elasticsearch.yml ,增加 bootstrap.system_call_filter: false</code></pre>

页面列表

ITEM_HTML