0
点赞
收藏
分享

微信扫一扫

ElasticSearch解析五:集群安装

一、为什么要集群

单台Elasticsearch服务器提供服务,往往都有最大的负载能力,超过这个阈值,服务器性能就会大大降低甚至不可用,所以生产环境中,一般都是运行在指定服务器集群中。 除了负载能力,单点服务器也存在其他问题:

  • 单台机器存储容量有限
  • 单服务器容易出现单点故障,无法实现高可用
  • 单服务的并发处理能力有限

配置服务器集群时,集群中节点数量没有限制,大于等于2个节点就可以看做是集群了。一般出于高性能及高可用方面来考虑集群中节点数量都是3个以上。

一个集群就是由一个或多个服务器节点组织在一起,共同持有整个的数据,并一起提供索引和搜索功能。一个Elasticsearch集群有一个唯一的名字标识,这个名字默认就是”elasticsearch”。这个名字是重要的,因为一个节点只能通过指定某个集群的名字,来加入这个集群。

二、Windows下安装集群

正常来我们是在Linux服务器上运行我们的程序,集群安装应该安装在Linux上比较好,这里介绍Windows的安装主要是因为动手试一下,方便看一下集群,不用开多余的虚拟机,Windows上的安装出来的集群推荐还是学习为主。真正的开发,公司的也是会有自己的Linux服务器不用安装在自己的电脑上。

1、把ElasticSearch解压,复制三份:

ElasticSearch解析五:集群安装_elasticsearch

2、配置文件:config/elasticsearch.yml

es-1的配置信息

#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: es-1
node.master: true
node.data: true
#ip地址
network.host: localhost
#http端口
http.port: 1001
#tcp监听端口
transport.tcp.port: 9301
#discovery.seed_hosts: ["localhost:9301", "localhost:9302","localhost:9303"]
#discovery.zen.fd.ping_timeout: 1m
#discovery.zen.fd.ping_retries: 5
#集群内的可以被选为主节点的节点列表
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
#跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

es-2的配置信息

#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: es-2
node.master: true
node.data: true
#ip地址
network.host: localhost
#http端口
http.port: 1002
#tcp监听端口
transport.tcp.port: 9302
discovery.seed_hosts: ["localhost:9301"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
#集群内的可以被选为主节点的节点列表
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
#跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

es-2的配置信息

#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: es-2
#ip地址
network.host: localhost
#http端口
http.port: 1003
#tcp监听端口
transport.tcp.port: 9303
#候选主节点的地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["localhost:9301", "localhost:9302"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
#集群内的可以被选为主节点的节点列表
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
#跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

3、启动集群:分别运行bin下的elasticsearch.bat。最后用GET请求查看集群状态:

  • ​http://127.0.0.1:10001/_cluster/health​
  • ​http://127.0.0.1:10002/_cluster/health​
  • ​http://127.0.0.1:10003/_cluster/health​

status字段表示当前集群是否正常工作。green所有主分片和副本都正常运行;yellow所有主分片都运行正常,但是不是所有的副本分片都运行正常;red所有主分片没能正擦汗给你运行。

三、Linux(Centos7)上安装ElasticSearch集群

1、首先准备三台Linux服务器,并安装好ElasticSearch。关于Linux上的安装注意事项,可参考:​​ElasticSearch解析一:安装和索引​​

2、配置配置文件 说明:这里的elk-01、elk-02、elk-03是我在hosts文件中配置的主机IP的映射,比IP地址更加的方便记忆和配置。 节点1

cluster.name: ELK-cluster
#集群内同时启动的数据任务个数,默认是2个
cluster.routing.allocation.cluster_concurrent_rebalance: 16
##添加或删除节点及负载均衡时并发恢复的线程个数,默认4个
cluster.routing.allocation.node_concurrent_recoveries: 16
#初始化数据恢复时,并发恢复线程的个数,默认4个
cluster.routing.allocation.node_initial_primaries_recoveries: 16

node.name: node-1
node.master: true
node.data: true

network.host: elk-01
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true

#
# Set a custom port for HTTP:
#
http.port: 9200

discovery.seed_hosts: ["elk-01:9300", "elk-02:9300","elk-03:9300"]

cluster.initial_master_nodes: ["node-1"]

gateway.recover_after_nodes: 2

# head插件
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb

节点2

cluster.name: ELK-cluster
#集群内同时启动的数据任务个数,默认是2个
cluster.routing.allocation.cluster_concurrent_rebalance: 16
##添加或删除节点及负载均衡时并发恢复的线程个数,默认4个
cluster.routing.allocation.node_concurrent_recoveries: 16
#初始化数据恢复时,并发恢复线程的个数,默认4个
cluster.routing.allocation.node_initial_primaries_recoveries: 16

node.name: node-2
node.master: true
node.data: true

network.host: elk-02
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true

http.port: 9200

discovery.seed_hosts: ["elk-01:9300", "elk-02:9300","elk-03:9300"]

cluster.initial_master_nodes: ["node-1"]

gateway.recover_after_nodes: 2

# head插件跨域配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200m

节点3

cluster.name: ELK-cluster
#集群内同时启动的数据任务个数,默认是2个
cluster.routing.allocation.cluster_concurrent_rebalance: 16
##添加或删除节点及负载均衡时并发恢复的线程个数,默认4个
cluster.routing.allocation.node_concurrent_recoveries: 16
#初始化数据恢复时,并发恢复线程的个数,默认4个
cluster.routing.allocation.node_initial_primaries_recoveries: 16

node.name: node-3
node.master: true
node.data: true


network.host: elk-03
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true

#
# Set a custom port for HTTP:
#
http.port: 9200

discovery.seed_hosts: ["elk-01:9300", "elk-02:9300","elk-03:9300"]

cluster.initial_master_nodes: ["node-1"]

gateway.recover_after_nodes: 2

# head插件跨域配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb

3、运行集群 分别运行bin目录下的elasticsearch可执行文件。 浏览器访问:​​http://elk1:9200/_cat/nodes​

ElasticSearch解析五:集群安装_elasticsearch_02


举报

相关推荐

0 条评论