ElasticSearch 安装

Posted zk1023

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ElasticSearch 安装相关的知识,希望对你有一定的参考价值。

测试单实例安装ElasticSearch 5.6.10 版本

参考 http://blog.51cto.com/zero01/2130696

首先准备好Java环境:

[[email protected] ~]# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

复制地址进行下载
[[email protected] ~]# cd /usr/local/src/

[[email protected] src]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.10.tar.gz

[[email protected] src]# ls
elasticsearch-5.6.10.tar.gz

一直不知道解压命令如何指定文件夹,今天学到了一个 -C 参数
[[email protected] src]# tar -zxvf elasticsearch-5.6.10.tar.gz -C /usr/local/

[[email protected] src]# ls /usr/local/elasticsearch-5.6.10/
bin config lib LICENSE.txt modules NOTICE.txt plugins README.textile

因为ElasticSearch不允许在root用户下运行,所以我们需要创建独立的用户来运行es,so我们来创建elsearch用户组elasticSerach 及elsearch用户 elasticUser 

[[email protected] ~]# groupadd elsearch
[[email protected] ~]# useradd elsearch -g elsearch -p elasticsearch

可以更改密码
[[email protected] ~]# passwd elsearch

 

更改elasticsearch安装目录及其内部文件的所属用户及组为elsearch:elsearch

[[email protected] local]# chown -R elsearch:elsearch elasticsearch-5.6.10/
[[email protected] local]# ll | grep elasticsearch-5.6.10
drwxr-xr-x. 7 elsearch elsearch 131 Jun 6 2018 elasticsearch-5.6.10
[[email protected] local]#

在CentOS7下,elasticsearch 5.x 设置了ip后,启动会有些问题导致启动报错,我们需要设置如下系统参数来解决这个问题

 

[[email protected] local]# vim /etc/security/limits.conf

* hard nofile 65536 * soft nofile 131072

* soft nproc 2048 * hard nproc 4096

[[email protected] elasticsearch-5.6.10]# cd /etc/security/limits.d/
[[email protected] limits.d]# ls
20-nproc.conf
[[email protected] local]# vim 20-nproc.conf

* soft nproc 2048

[[email protected] local]# vim /etc/sysctl.conf vm.max_map_count=655360

[[email protected] local]# sysctl -p vm.max_map_count = 655360

root用户切换到elsearch用户

 

[[email protected] local]# su elsearch
[[email protected] local]$

 

 

 

在启动es前先设置一下绑定的ip,设置为可被外部访问的ip,以及设置bootstrap相关的参数

[[email protected] local]$ cd /usr/local/elasticsearch-5.6.10/
[[email protected] elasticsearch-5.6.10]$ ls
bin config lib LICENSE.txt modules NOTICE.txt plugins README.textile
[[email protected] elasticsearch-5.6.10]$ cd config/
[[email protected] config]$ ls
elasticsearch.yml jvm.options log4j2.properties
[[email protected] config]$ vim elasticsearch.yml

bootstrap.memory_lock: false

bootstrap.system_call_filter: false

network.host: 0.0.0.0 # 找到该项,设置为可被外部访问的ip

 

启动ElasticSearch服务的命令

[[email protected] elasticsearch-5.6.10]$ cd bin/
[[email protected] bin]$ sh elasticsearch

一般我们都采用后台启动的方式 加上-d参数表示后台启动

 

[[email protected] bin]$ sh elasticsearch -d

   进程

[[email protected] bin] ps aux |grep elasticsearch

ElasticSearch服务所监听的端口

netstat -lntp |grep java

设置防火墙规则,开放ElasticSearch服务所监听的端口
[[email protected] elasticsearch-5.6.10]# sudo firewall-cmd --zone=public --add-port=9200/tcp --permanent
[[email protected] elasticsearch-5.6.10]# sudo firewall-cmd --zone=public --add-port=9300/tcp --permanent
[[email protected] elasticsearch-5.6.10]# sudo firewall-cmd --reload
开放了相应的端口后,从浏览器中访问,看看能否访问成功 http://192.168.217.150:9200/

elasticsearch没有直接的关闭或重启命令,关闭elasticsearch服务只能通过kill命令来杀掉服务的进程
[[email protected] elasticsearch-5.6.10]# ps aux | grep elasticsearch
[[email protected] elasticsearch-5.6.10]#kill -9 4829



 

































以上是关于ElasticSearch 安装的主要内容,如果未能解决你的问题,请参考以下文章

Elasticsearch笔记九之优化

使用标准库Ruby将数据标记到Elasticsearch批量中

Elasticsearch:如何在 Elasticsearch 中正确使用同义词功能

Elasticsearch:如何在 Elasticsearch 中正确使用同义词功能

Elasticsearch-PHP 索引操作

在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途