elasticsearch集群配置

ElasticSearch 是一个分布式、高扩展、高实时的搜索与数据分析引擎。它能很方便的使大量数据具有搜索、分析和探索的能力。充分利用ElasticSearch的水平伸缩性,能使数据在生产环境变得更有价值。ElasticSearch 的实现原理主要分为以下几个步骤,首先用户将数据提交到Elastic Search 数据库中,再通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据,当用户搜索数据时候,再根据权重将结果排名,打分,再将返回结果呈现给用户。

Elasticsearch是与名为Logstash的数据收集和日志解析引擎以及名为Kibana的分析和可视化平台一起开发的。这三个产品被设计成一个集成解决方案,称为“Elastic Stack”(以前称为“ELK stack”)。
Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。”Elasticsearch是分布式的,这意味着索引可以被分成分片,每个分片可以有0个或多个副本。每个节点托管一个或多个分片,并充当协调器将操作委托给正确的分片。再平衡和路由是自动完成的。“相关数据通常存储在同一个索引中,该索引由一个或多个主分片和零个或多个复制分片组成。一旦创建了索引,就不能更改主分片的数量。

Elasticsearch使用Lucene,并试图通过JSON和Java API提供其所有特性。它支持facetting和percolating,如果新文档与注册查询匹配,这对于通知非常有用。另一个特性称为“网关”,处理索引的长期持久性;例如,在服务器崩溃的情况下,可以从网关恢复索引。Elasticsearch支持实时GET请求,适合作为NoSQL数据存储,但缺少分布式事务。

ES 2.x版本
优点:

  1. Java技术栈, spring-boot-starter-data-elasticsearch 支持in-memory方式启动,单元测试开箱即用
  2. 当前线上运行的主流版本, 比较稳定
    缺点:
  3. 版本较老,无法体验新功能,且性能不如5.x
  4. 后期升级数据迁移比较麻烦
  5. 周边工具版本比较混乱;Kinbana等工具的对应版本需要自己查

ES 5.x版本
优点
6. 版本相对较新,性能较好官方宣称索引吞吐量提升在25%到80%之间,新的数据结构用于存储数值和地理位置字段,性能大幅提升;5.x版本搜索进行了重构,搜索聚合能力大幅提高
7. 周边工具比较全,版本号比较友好。 ES官方在5.x时代统一了 ELK体系的版本号
8. 升级到6.x也比较方便
缺点:
9. 官方宣布已不支持In-Memory模式和Node Client已失效, 如果需要使用in-memory方式单测,需要自己手动配置ES版本、spring-data-elasticsearch版本、打开http访问开关等配置,并行使用REST API访问

-------------------------------以下采用es6.x------------------------------------

集群配置

elasticsearch.yml 【更目录下的 config目录下】
核心配置项

#集群名称
cluster.name: my-application
#集群中节点名称 (3个节点以此为:node-1,node-2,node-3 )
node.name: node-1
#服务接口(本实例采用单机部署,每个节点端口都不一样)
http.port: 9201
transport.tcp.port: 9301
#节点信息
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]

参考配置文件:

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
http.port: 9201
transport.tcp.port: 9301
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes: 2
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#allow origin
http.cors.enabled: true
http.cors.allow-origin: "*"
# xpack head
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type


安装head插件

【es5以上版本安装head需要安装node和grunt 】
在https://github.com/mobz/elasticsearch-head中下载head插件 解压到Elasticsearch根目录
进入head目录(建议:如果多节部署每个节点都安装,这样任意一个节点够可以访问,本本文是单机多实例,只在节点1上配置):

npm install -g grunt-cli 
npm install

【修改配置 Gruntfile.js hostname 指定端口】
在这里插入图片描述
elasticsearch.yml 中配置跨域(如果不配置head插件无法正常访问):

#allow origin
http.cors.enabled: true
http.cors.allow-origin: "*"

安装完成后执行grunt server 或者npm run start 运行head插件(windows上启动脚本如下head.bat)

D:
cd D:\ToolsDev\elk\elasticsearch-6.5.4-1\elasticsearch-head-5.0.0
grunt server 

以此启动各节点和head插件(访问 http://localhost:9100/)
在这里插入图片描述
集群健康值:

green
所有的主分片和副本分片都正常运行。
yellow
所有的主分片都正常运行,但不是所有的副本分片都正常运行。
red
有主分片没能正常运行。

在这里插入图片描述
在这里插入图片描述

es授权用户访问 x-pack

一般情况下es只会放在内网使用,xpack意义不是很重要,如果在某些情况下需要放在内网使用时需要使用x-pack了, x-pack是收费产品,不建议使用,尽量吧es放在内网使用(理论上不应该放在外网)

【安装】
	elasticsearch-plugin install x-pack
	kibana-plugin install x-pack
	logstash-plugin install x-pack
【删除】
	----kibana-plugin remove x-pack
【配置】
默认情况下,所有X-Pack功能都被启用。
您可以启用或禁用特定的X-Pack功能elasticsearch.yml,kibana.yml以及logstash.yml 配置文件。
	xpack.graph.enabled                       #设置为false禁用X-Pack图形功能。
	xpack.ml.enabled	               #设置为false禁用X-Pack机器学习功能。
	xpack.monitoring.enabled	#设置为false禁用X-Pack监视功能。
	xpack.reporting.enabled             	#设置为false禁用X-Pack报告功能。
	xpack.security.enabled       	#设置为false禁用X-Pack安全功能。
	xpack.watcher.enabled     	#设置false为禁用观察器。
	{or}
	action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*,.ml*

	# xpack head
	http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
  【访问的时候需要加上: http://127.0.0.1:9100/?auth_user=elastic&auth_password=changeme 】


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值