此文档是基于ElasticSearch5.4.2版本的部署文档,旨在说明ElasticSearch的安装部署步骤,做为后续ElasticSearch的安装部署参考。java
ElasticSearch是业界最流行的开源搜索引擎,基于apache-luncene的开源实现,同类比和apache-solr有不少类似处,但在部署、可扩展性和功能方面有差别。node
ElasticSearch和solr在使用场景也有不同的针对性,ElasticSearch基于json格式的数据配置,而solr基于schema格式的配置,在使用场景上,ElasticSearch更偏向于查询、过滤和分组分析统计方面,他支持range、关联的查询;而solr更加偏向于文本的全文检索;对于高级检索的支持并无那么强。sql
ElasticSearch安装,包括插件的支持须要如下的依赖:apache
ntpd service status
tar -zvxf elasticsearch-5.4.2.tar.gz
cluster.name: elasticsearch #集群名称(集群名称需配置成一致)
node.name: es-node-01 #节点名称
node.master: true #是不是master节点(集群环境下配置)
node.data: true #是不是数据节点
path.data: /usr/local/es-5.4/data #数据文件存储路径
path.logs: /usr/local/es-5.4/logs #日志文件存储路径
network.host: 192.168.1.23 #对外暴露的IP地址
http.port: 9200 #es的http访问端口
http.cors.enabled: true #http跨域访问设置
http.cors.allow-orign: "" #请求访问限制,为不限制
discovery.zen.ping.unicast.hosts: ["192.168.11.11", "192.168.11.12"] #集群节点列表配置
discovery.zen.ping_timeout: 120s #集群节点ping值超时时间配置json
ElasticSearch在使用上须要对系统参数进行调优处理,以知足es的平常应用vim
vim /etc/sysctl.conf
设置 vm.max_map_count = 262144
设置完成后执行如下命令生效
sysctl -papi
配置进程最大打开文件描述符跨域
vim /etc/security/limits.conf
在文件最后添加:cors
ElasticSearch支持不少插件安装,包括kibana监控、ElasticSearch-sql支持、ElasticSearch-head插件,此处,仅介绍ElasticSearch-head插件安装;head插件是一个基于node.js的ElasticSearch的UI管理界面,基于此插件,咱们能够在head界面中:dom
maven依赖
<!-- https://mvnrepository.com/art... -->
<dependency>
<groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> <version>6.6.0</version>
</dependency>
<!-- https://mvnrepository.com/art... -->
<dependency>
<groupId>org.apache.lucene</groupId> <artifactId>lucene-highlighter</artifactId> <version>6.6.0</version>
</dependency>
<!-- https://mvnrepository.com/art... -->
<dependency>
<groupId>org.apache.lucene</groupId> <artifactId>lucene-queries</artifactId> <version>6.6.0</version>
</dependency>
java代码
Settings settings = Settings.builder().put("client.transport.sniff", true). put("client.transport.ignore_cluster_name", false).put("cluster.name","es-cluster").build(); TransportClient client = new PreBuiltTransportClient(settings). addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.11.11"),9300)) .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.11.12"),9300)); Map<String, Object> map = new HashMap<String, Object>(); Random ran = new Random(); map.put("nickname", "测试" + ran.nextInt(100)); map.put("sex", ran.nextInt(100)); map.put("age", ran.nextInt(100)); map.put("mobile", "15014243232"); IndexResponse response = client.prepareIndex("users", "user").setSource(map).get(); System.out.println(response);