elasticsearch安装部署

elasticsearch安装部署

六月 06, 2021

安装

官网找到所需版本的elasticsearchkibana下载对应系统的包或者使用docker的方式

elasticsearch和kibana的版本必须对应一致

ElasticSearch

分布式搜索引擎

集群方式部署elasticsearch(win版)

version 7.13.0

下载的压缩包解压出三份对应三个节点的部署

更改config目录下的elasticsearch.yml如下所示

node-1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# ======================== Elasticsearch Configuration =========================
多节点部署指定唯一的集群名称
cluster.name: elasticsearch-app
# ------------------------------------ Node ------------------------------------
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
# ---------------------------------- Network -----------------------------------
network.host: 127.0.0.1
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9200
# 为了集群各节点之间的指令通信
transport.tcp.port: 9300
# 允许前端跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"
# 发现集群之间各个节点,对应transport.tcp.port
discovery.seed_hosts: ["127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:

#初始化主节点,三个节点都可以竞选主
cluster.initial_master_nodes: ["127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302"]

node-2:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# ======================== Elasticsearch Configuration =========================
多节点部署指定唯一的集群名称
cluster.name: elasticsearch-app
# ------------------------------------ Node ------------------------------------
# Use a descriptive name for the node:
#
node.name: node-2
#
# Add custom attributes to the node:
# ---------------------------------- Network -----------------------------------
network.host: 127.0.0.1
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9201
# 为了集群各节点之间的指令通信
transport.tcp.port: 9301
# 允许前端跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"
# 发现集群之间各个节点,对应transport.tcp.port
discovery.seed_hosts: ["127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:

#初始化主节点,三个节点都可以竞选主
cluster.initial_master_nodes: ["127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302"]

node-3:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# ======================== Elasticsearch Configuration =========================
多节点部署指定唯一的集群名称
cluster.name: elasticsearch-app
# ------------------------------------ Node ------------------------------------
# Use a descriptive name for the node:
#
node.name: node-3
#
# Add custom attributes to the node:
# ---------------------------------- Network -----------------------------------
network.host: 127.0.0.1
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9202
# 为了集群各节点之间的指令通信
transport.tcp.port: 9302
# 允许前端跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"
# 发现集群之间各个节点,对应transport.tcp.port
discovery.seed_hosts: ["127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:

#初始化主节点,三个节点都可以竞选主
cluster.initial_master_nodes: ["127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302"]

启动:双击/bin目录下的elasticsearch.bat即可,linux则为:

1
/bin/elasticsearch

启动窗口如有中文乱码可添加对应config下的jvm.options中的

1
-Dfile.encoding=GBK

访问http://locathost:端口/_cat查看对应节点的辅助命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
/_cat/ml/anomaly_detectors
/_cat/ml/anomaly_detectors/{job_id}
/_cat/ml/trained_models
/_cat/ml/trained_models/{model_id}
/_cat/ml/datafeeds
/_cat/ml/datafeeds/{datafeed_id}
/_cat/ml/data_frame/analytics
/_cat/ml/data_frame/analytics/{id}
/_cat/transforms
/_cat/transforms/{transform_id}

../_cat/health 查看各个节点的健康状态:

  • yellow,代表分布式场景下一些分片的缺失;

  • green是健康的状态,对外可以提供读写服务;

  • red具有部分功能,需要尽快修复

_cat/nodes 查看节点数

kibana

对应elasticsearch的可视化操作控制台

version 7.13.0

  1. 解压缩
  2. 启动同上:对应目录下对应的应用名称

此版本直接启动通过http://localhost:5601访问时会出现500错误码,对应日志文件输出:

1
2
TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["kbn-name"]
at ServerResponse.setHeader (_http_outgoing.js:561:3)

需要指定kibana的服务名称,即更改对应/config下的kibana.yaml文件:

1
2
3
4
5
# The Kibana server's name.  This is used for display purposes.
server.name: "kibana"
# The URLs of the Elasticsearch instances to use for all your queries.
# 这是默认的elasticsearch端口
# elasticsearch.hosts: ["http://localhost:9200"]

kibana控制台

  • Manage模块下Data下Index Management可查看对应节点中索引的数据清空
  • Dev Tools - Console可操作elasticsearch中的数据