ElasticSearch实战-ElasticSearch集群环境搭建
Posted 张志翔ۤ
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ElasticSearch实战-ElasticSearch集群环境搭建相关的知识,希望对你有一定的参考价值。
本篇的ES集群是基于 ElasticSearch实战(一)-ElasticSearch单机环境搭建 的配置来做的,如果你还没有完成第一篇ES单机环境的部署,不建议阅读本文。
一、准备工作
三台服务器配置信息,如下所示:
主机名称 | IP地址 | 硬盘容量 | 内存容量 | CPU核数 |
es-01 | 192.168.181.132 | 50GB | 8GB | 4C |
es-02 | 192.168.181.133 | 50GB | 8GB | 4C |
es-03 | 192.168.181.134 | 50GB | 8GB | 4C |
将第一篇文章配置好的 192.168.181.132 克隆出 192.168.181.133、192.168.181.134 节点(如果已经已经存在这三台节点,并已按照第一篇文章配置好了系统环境,则不用克隆)。
二、ES集群环境搭建
es-01 主机配置 elasticsearch.yml,打开 /opt/elasticsearch/elasticsearch-7.11.1/config/elasticsearch.yml,内容如下:
# ======================== 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:
#
#集群名称,默认可以不修改,此处es-cluster
cluster.name: es-cluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#节点名称,必须修改,默认修改为当前机器名称,若是多示例则需要区分
node.name: es-01-9200
#
# 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: /opt/elasticsearch/9200/data
#
# Path to log files:
#
path.logs: /opt/elasticsearch/9200/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):
#
# IP地址,默认是local,仅限本机访问,外网不可访问,设置0.0.0.0通用做法
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
# 访问端口,默认9200,9300,建议明确指定
http.port: 9200
transport.port: 9300
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# 节点发现
discovery.seed_hosts: ["192.168.181.132:9300","192.168.181.133:9300","192.168.181.134:9300"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#集群初始化节点
cluster.initial_master_nodes: ["192.168.181.132:9300","192.168.181.133:9300","192.168.181.134:9300"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# 部分电脑CPU不支持SSE4.2+,启动会报错,设置禁用机器学习功能
xpack.ml.enabled: false
#
# ---------------------------------- 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
#
# 设置处理器数量,默认无需设置,单机器多实例需要设置
node.processors: 4
#
# 访问允许跨域(head插件访问集群的时候需要)
http.cors.enabled: true
http.cors.allow-origin: "*"
es-02 主机配置 elasticsearch.yml,打开 /opt/elasticsearch/elasticsearch-7.11.1/config/elasticsearch.yml,内容如下:
# ======================== 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:
#
#集群名称,默认可以不修改,此处es-cluster
cluster.name: es-cluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#节点名称,必须修改,默认修改为当前机器名称,若是多示例则需要区分
node.name: es-02-9200
#
# 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: /opt/elasticsearch/9200/data
#
# Path to log files:
#
path.logs: /opt/elasticsearch/9200/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):
#
# IP地址,默认是local,仅限本机访问,外网不可访问,设置0.0.0.0通用做法
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
# 访问端口,默认9200,9300,建议明确指定
http.port: 9200
transport.port: 9300
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# 节点发现
discovery.seed_hosts: ["192.168.181.132:9300","192.168.181.133:9300","192.168.181.134:9300"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#集群初始化节点
cluster.initial_master_nodes: ["192.168.181.132:9300","192.168.181.133:9300","192.168.181.134:9300"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# 部分电脑CPU不支持SSE4.2+,启动会报错,设置禁用机器学习功能
xpack.ml.enabled: false
#
# ---------------------------------- 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
#
# 设置处理器数量,默认无需设置,单机器多实例需要设置
node.processors: 4
#
es-03 主机配置 elasticsearch.yml,打开 /opt/elasticsearch/elasticsearch-7.11.1/config/elasticsearch.yml,内容如下:
# ======================== 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:
#
#集群名称,默认可以不修改,此处es-cluster
cluster.name: es-cluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#节点名称,必须修改,默认修改为当前机器名称,若是多示例则需要区分
node.name: es-03-9200
#
# 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: /opt/elasticsearch/9200/data
#
# Path to log files:
#
path.logs: /opt/elasticsearch/9200/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):
#
# IP地址,默认是local,仅限本机访问,外网不可访问,设置0.0.0.0通用做法
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
# 访问端口,默认9200,9300,建议明确指定
http.port: 9200
transport.port: 9300
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# 节点发现
discovery.seed_hosts: ["192.168.181.132:9300","192.168.181.133:9300","192.168.181.134:9300"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#集群初始化节点
cluster.initial_master_nodes: ["192.168.181.132:9300","192.168.181.133:9300","192.168.181.134:9300"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# 部分电脑CPU不支持SSE4.2+,启动会报错,设置禁用机器学习功能
xpack.ml.enabled: false
#
# ---------------------------------- 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
#
# 设置处理器数量,默认无需设置,单机器多实例需要设置
node.processors: 4
#
es-01 主机配置 kibana.yml,打开 /opt/kibana/kibana-7.11.1-linux-x86_64/config/kibana.yml,内容如下:
# Kibana is served by a back end server. This setting specifies the port to use.
# 访问端口,默认无需修改
server.port: 5601
# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# The default is 'localhost', which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
# 访问地址IP,默认本地
server.host: "192.168.181.132"
# Enables you to specify a path to mount Kibana at if you are running behind a proxy.
# Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
# from requests it receives, and to prevent a deprecation warning at startup.
# This setting cannot end in a slash.
#server.basePath: ""
# Specifies whether Kibana should rewrite requests that are prefixed with
# `server.basePath` or require that they are rewritten by your reverse proxy.
# This setting was effectively always `false` before Kibana 6.3 and will
# default to `true` starting in Kibana 7.0.
#server.rewriteBasePath: false
# Specifies the public URL at which Kibana is available for end users. If
# `server.basePath` is configured this URL should end with the same basePath.
#server.publicBaseUrl: ""
# The maximum payload size in bytes for incoming server requests.
#server.maxPayloadBytes: 1048576
# The Kibana server's name. This is used for display purposes.
#server.name: "your-hostname"
# The URLs of the Elasticsearch instances to use for all your queries.
# ES服务指向,集群下配置多个
elasticsearch.hosts: ["http://192.168.181.132:9200","http://192.168.181.133:9200","http://192.168.181.134:9200"]
# Kibana uses an index in Elasticsearch to store saved searches, visualizations and
# dashboards. Kibana creates a new index if the index doesn't already exist.
# kibana元数据存储索引名称,默认.kibana无需修改
kibana.index: ".kibana-elk-01"
# The default application to load.
#kibana.defaultAppId: "home"
# If your Elasticsearch is protected with basic authentication, these settings provide
# the username and password that the Kibana server uses to perform maintenance on the Kibana
# index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
# is proxied through the Kibana server.
#elasticsearch.username: "kibana_system"
#elasticsearch.password: "pass"
# Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively.
# These settings enable SSL for outgoing requests from the Kibana server to the browser.
#server.ssl.enabled: false
#server.ssl.certificate: /path/to/your/server.crt
#server.ssl.key: /path/to/your/server.key
# Optional settings that provide the paths to the PEM-format SSL certificate and key files.
# These files are used to verify the identity of Kibana to Elasticsearch and are required when
# xpack.security.http.ssl.client_authentication in Elasticsearch is set to required.
#elasticsearch.ssl.certificate: /path/to/your/client.crt
#elasticsearch.ssl.key: /path/to/your/client.key
# Optional setting that enables you to specify a path to the PEM file for the certificate
# authority for your Elasticsearch instance.
#elasticsearch.ssl.certificateAuthorities: [ "/path/to/your/CA.pem" ]
# To disregard the validity of SSL certificates, change this setting's value to 'none'.
#elasticsearch.ssl.verificationMode: full
# Time in milliseconds to wait for Elasticsearch to respond to pings. Defaults to the value of
# the elasticsearch.requestTimeout setting.
#elasticsearch.pingTimeout: 1500
# Time in milliseconds to wait for responses from the back end or Elasticsearch. This value
# must be a positive integer.
#elasticsearch.requestTimeout: 30000
# List of Kibana client-side headers to send to Elasticsearch. To send *no* client-side
# headers, set this value to [] (an empty list).
#elasticsearch.requestHeadersWhitelist: [ authorization ]
# Header names and values that are sent to Elasticsearch. Any custom headers cannot be overwritten
# by client-side headers, regardless of the elasticsearch.requestHeadersWhitelist configuration.
#elasticsearch.customHeaders: {}
# Time in milliseconds for Elasticsearch to wait for responses from shards. Set to 0 to disable.
#elasticsearch.shardTimeout: 30000
# Logs queries sent to Elasticsearch. Requires logging.verbose set to true.
#elasticsearch.logQueries: false
# Specifies the path where Kibana creates the process ID file.
#pid.file: /run/kibana/kibana.pid
# Enables you to specify a file where Kibana stores log output.
#logging.dest: stdout
# Set the value of this setting to true to suppress all logging output.
#logging.silent: false
# Set the value of this setting to true to suppress all logging output other than error messages.
#logging.quiet: false
# Set the value of this setting to true to log all events, including system usage information
# and all requests.
#logging.verbose: false
# Set the interval in milliseconds to sample system and process performance
# metrics. Minimum is 100ms. Defaults to 5000.
#ops.interval: 5000
# Specifies locale to be used for all localizable strings, dates and number formats.
# Supported languages are the following: English - en , by default , Chinese - zh-CN .
i18n.locale: "en"
注:Kibana也可以配集群,本专栏主要讲ES,这里就不展开了。
删除三台ES节点的 data 数据,命令如下:
$ rm -rf /opt/elasticsearch/9200/data/*
文件拥有修改,切换账号到elk,命令如下:
$ sudo chown -R elk:elk /opt/elasticsearch/*
$ su elk
守护进程方式启动三台ES节点,命令如下
$ /opt/elasticsearch/elasticsearch-7.11.1/bin/elasticsearch -d
在 192.168.181.132 节点,启动 Kibana,命令如下:
$ nohup /opt/kibana/kibana-7.11.1-linux-x86_64/bin/kibana &
检查ES集群健康情况,浏览器访问任意ES节点IP http://192.168.181.132:9200/_cluster/health?pretty,图示如下:
ES集群成功启动,健康状况正常,然后查看 Kibana 监测 Elastic 集群情况,访问 http://192.168.181.132:5601/app/home#/tutorial_directory,点击左上角按钮,查看 Stack Monitoring,图示如下:
可以看到ES集群三个节点正常运行中,Kibana单节点也正常运行,我们可以点击Nodes:3 进一步查看运行指标,图示如下:
查看 es-01-9200 节点堆栈内存/IO/CPU等指标的实时情况,图示如下:
IK中文分词器、head插件(可视化集群管理工具),放的篇幅比较靠后,大家可以在集群搭建完成后,先把这两个插件安装上,传送门如下:
ElasticSearch实战(二十七)-可视化集群管理(head插件)
注:建议先安装上,后面在实操的文章中,head插件的可视化功能还是非常方便的。
到此 ElasticSearch集群环境搭建介绍完成。
以上是关于ElasticSearch实战-ElasticSearch集群环境搭建的主要内容,如果未能解决你的问题,请参考以下文章