ELk elasticsearch 部署(3rd)
<p>根据《ELK 产品支持的平台和软件》选定你所要安装的版本。这里将安装elasticsearch最新版本2.0.0。</p><h3>1. jdk</h3>
<p>elasticsearch只支持Oracle java 和 OpenJDK。</p>
<p>在这里不再重复了,参见《ELK 部署指南》详细的不能再详细了。搞不定跟帖说明吧。</p>
<h3>2. 安装</h3>
<p>elasticsearch 2.0.0版本不能以root用户启动。</p><pre class="brush:bash;toolbar:false"># wget -c https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.0.0/elasticsearch-2.0.0.tar.gz
# tar zxvf elasticsearch-2.0.0.tar.gz -C /usr/local
# useradd --system --shell /sbin/nologin elasticsearch
# chown -R elasticsearch.elasticsearch /usr/local/elasticsearch-2.0.0
# chown -R elasticsearch.elasticsearch /data/ttlsa.com/elasticsearch
# cd /usr/local/elasticsearch-2.0.0
# vi config/elasticsearch.yml
cluster.name: ttlsa-es
node.name: ${HOSTNAME}
path.data: /ttlsa/db/elasticsearch
bootstrap.mlockall: true
bootstrap.max_open_files: true
network.host: 10.6.7.12
# su - elasticsearch -c "/usr/local/elasticsearch-2.0.0/bin/elasticsearch -d"</pre><p>如果有报错,请查看下elasticsearch日志,养成查看日志的好习惯。</p>
<p>目录结构说明如下:</p>
<div class="chapter">
<div class="informaltable">
<table border="1" cellpadding="4px">
<thead><tr>
<th align="left" valign="top">Type</th>
<th align="left" valign="top">Description</th>
<th align="left" valign="top">Location</th>
</tr></thead>
<tbody>
<tr>
<td align="left" valign="top"><span class="strong"><strong>home</strong></span></td>
<td align="left" valign="top">elasticsearch安装的目录</td>
<td align="left" valign="top"><code class="literal">{extract.path}</code></td>
</tr>
<tr>
<td align="left" valign="top"><span class="strong"><strong>bin</strong></span></td>
<td align="left" valign="top">elasticsearch二进制脚本目录</td>
<td align="left" valign="top"><code class="literal">{extract.path}/bin</code></td>
</tr>
<tr>
<td align="left" valign="top"><span class="strong"><strong>conf</strong></span></td>
<td align="left" valign="top">配置文件目录</td>
<td align="left" valign="top"><code class="literal">{extract.path}/config</code></td>
</tr>
<tr>
<td align="left" valign="top"><span class="strong"><strong>data</strong></span></td>
<td align="left" valign="top">数据目录</td>
<td align="left" valign="top"><code class="literal">{extract.path}/data</code></td>
</tr>
<tr>
<td align="left" valign="top"><span class="strong"><strong>logs</strong></span></td>
<td align="left" valign="top"> 日志目录</td>
<td align="left" valign="top"><code class="literal">{extract.path}/logs</code></td>
</tr>
<tr>
<td align="left" valign="top"><span class="strong"><strong>plugins</strong></span></td>
<td align="left" valign="top">插件目录</td>
<td align="left" valign="top"><code class="literal">{extract.path}/plugins</code></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="navfooter"></div>
<p>{extract.path}是elasticsearch zip或者tar.gz包解压的目录。elasticsearch包解压出来就可以使用。</p>
<h3>3. 配置</h3>
<h4>环境变量</h4>
<p>在elasticsearch启动脚本中,通过JAVA_OPTS传递给JVM启动,其中最重要的是通过-Xmx来控制进程使用的最大的内存,通过-Xms来控制进程分配的最小内存。这两个对性能至关重要的,通常这两者设置为一样大小。</p>
<p>多数情况下,不要去改变JAVA_OPTS的设置,要更改JVM设置或参数可通过ES_JAVA_OPTS环境变量来进行。</p>
<p>ES_HEAP_SIZE 环境变量设置elasticsearch java进程分配的内存,将最大值和最小值设置为一样,默认情况下ES_MIN_MEM=256m,ES_MAX_MEM=1g。</p>
<p>建议将ES_MIN_MEM和ES_MAX_MEM设置为相同的值,并启用mlockall。</p>
<h4>系统配置</h4>
<p>文件描述符</p>
<p>这个一般会继承系统的设置。为了查看进程可以打开了多少文件数,可以将 -Des.max-open-files设置为true。可以通过node API进行查看:</p>
<p><img title="ELk elasticsearch 部署(3rd)" class="alignnone size-full wp-image-10599" src="https://zhuji.jb51.net/uploads/img/20230519/e060da423c30ffa10dde43fc480dbd86.jpg" width="473" height="321"></p>
<p><img title="ELk elasticsearch 部署(3rd)" class="alignnone size-full wp-image-10600" src="https://zhuji.jb51.net/uploads/img/20230519/113a5a87c95a16f8f2edfb433cfce689.jpg" width="430" height="332"></p>
<p>虚拟内存</p>
<p>elasticsearch默认使用hybrid mmapfs / niofs目录存储索引。系统默认的mmap数可能太低,会导致内存溢出。在Linux上,需要在/etc/sysctl.conf文件中设置<span class="pln">vm</span><span class="pun">.</span><span class="pln">max_map_count</span><span class="pun">=</span><span class="lit">262144。</span></p>
<p>内存设置</p>
<p>禁用swap。云主机默认都是禁用的。</p>
<p>配置swappiness。将vm.swappiness设置为0。</p>
<p>mlockall 尽可能的将进程锁定在内存中,防止elasticsearch内存被swap出。在elasticsearch.yml文件中设置bootstrap.mlockall: true。</p>
<p>如果设置了bootstrap.mlockall: true,而通过node API查看是fail的值,原因可能是:</p>
<ol>
<li>没有权限<br>
在/etc/security/limits.conf文件中设置<br>
elasticsearch soft memlock unlimited<br>
elasticsearch hard memlock unlimited</li>
<li>临时目录通常是/tmp以noexec选项挂载的,可以另指一个临时目录解决,./bin/elasticsearch -Djna.tmpdir=/path/to/new/dir。</li>
</ol>
<h3>elasticsearch 设置</h3>
<p>elasticsearch配置文件位于ES_HOME/config目录中。该目录中有两个文件elasticsearch.yml配置elasticsearch不同模块,logging.yml配置elasticsearch日志。配置格式是YAML。如果使用json格式,需要将elasticsearch.yml重命名为elasticsearch.json,同时,需要将文件中的配置参数转换成json格式。</p>
<p>elasticsearch.yml配置内容如下:</p><pre class="brush:bash;toolbar:false">cluster.name: ttlsa-es
node.name: ${HOSTNAME}
path.data: /ttlsa/db/elasticsearch
bootstrap.mlockall: true
bootstrap.max_open_files: true
network.host: 10.6.7.12</pre><p>数据目录可以设置为多个如:path.data: ["/ttlsa/db/elasticsearch","/ttlsa/db/elasticsearch2"] 或者 path.data: /ttlsa/db/elasticsearch, /ttlsa/db/elasticsearch2。</p>
<p>如果想以主机名命令节点名称,同时,该服务器上只运行单个elasticsearch实例,可以设置为${HOSTNAME}变量,将从环境变量中获取主机名。也可以设置成${prompt.text},在启动时,需要键入名称。</p>
<p>也可以通过使用ES_JAVA_OPTS或者向elasticsearch命令传递参数,如:</p><pre class="brush:bash;toolbar:false"># bin/elasticsearch -Des.network.host=127.0.0.1</pre><p>上面配置完,并成功启动后,可以通过http://your-ip-address:9200访问了。</p>
<p>前面内容留了一个坑,后续再说了。</p>
頁:
[1]