elasticsearch集群部署windows+linux双系统搭建(代码片段)

Roninaxious Roninaxious     2023-01-11     503

关键词:


一、windows部署

如果已经使用过,删除其中的data和logs文件夹中的内容

新建一个es-cluster文件夹,用于存放集群中的三个ES结点

1.结点1(master)配置

首先打开node-1文件夹->config目录下-》bin目录下的elasticsearch.yml文件

2.改变以下内容

不要在配置文件中加入中文注释,启动会失败

# ======================== 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		//结点名
node.master: true			//既做为master
node.data: true				//也做为data
#
# 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: localhost    //ip地址,我在本地搭建
#
# Set a custom port for HTTP:
#
http.port: 9200				//ES启动端口
transport.tcp.port: 9201	//通信端口,因为各个结点之间要进行通信
#
# 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: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation 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
http.cors.enabled: true			//跨域设置
http.cors.allow-origin: "*"

2.结点2配置

打开node-2文件夹-》conf-》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:
#
cluster.name: my-application  //集群名要一致
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-2		//结点名不一致
node.master: true
node.data: true
#
# 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: localhost
#
# Set a custom port for HTTP:
#
http.port: 9300
transport.tcp.port: 9301
discovery.seed_hosts: ["localhost:9201"]  //这是为了发现其他结点
discovery.zen.fd.ping_timeout: 1m	//9201代表了master(node-1)的通信端口
discovery.zen.fd.ping_retries: 5
#
# 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: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation 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
http.cors.enabled: true
http.cors.allow-origin: "*"

3.结点3配置

# ======================== 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-3
node.master: true
node.data: true
#
# 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: localhost
#
# Set a custom port for HTTP:
#
http.port: 9400
transport.tcp.port: 9401
discovery.seed_hosts: ["localhost:9201","localhost:9301"]  //发现结点1和结点2(9201是node-1的通信端口,9301是node-2的通信端口
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
#
# 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: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation 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
http.cors.enabled: true
http.cors.allow-origin: "*"

4.使用postman进行测试

依次启动node-1,node-2,node-3




二、Linux单节点部署

(1)cd到/usr/local目录下,新建es文件夹,cd到es文件夹下

cd /usr/local/
mkdir es
cd es

(2)下载ElasticSearch

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.1-linux-x86_64.tar.gz
ES下载教程https://blog.csdn.net/Kevinnsm/article/details/120604537?spm=1001.2014.3001.5501


(3)解压缩

tar -zxvf elasticsearch-7.10.1-linux-x86_64.tar.gz

(4)改变文件名为es

mv elasticsearch-7.10.1 es

(5)🌞新建ES用户

📜Linux环境下ElasticSearch不能以root用户启动,所以需要新建用户

🧊创建用户名为es的用户,输入useradd es

🧊为es用户设置密码,passwd es(密码要满足大于8位且含有大小写字母已经数字,否者会匹配失败)

(6)🌞修改文件目录的所有者

chown:表示修改文件的所有者和所属组
chown [-R] 所有者:所属组 文件或目录
chown -R es:es /usr/local/es/es


(7)🌞修改elasticsearch.yml文件内容
在文件末尾加入以下内容

cluster.name: elasticsearch
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: [“node-1”]


(8)🌞修改 /etc/security/limits.conf中的内容

由于es生成得内容比较多,所以需要修改相关配置


在文件末尾加入
es soft nofile 65535
es hard nofile 65535

加粗样式(9)🌞修改20-nproc.conf文件

vim /etc/security/limits.d/20-nproc.conf


(10)🌞修改/etc/sysctl.conf文件

vim /etc/sysctl.conf

在文件底部加入vm.max_map_count = 655360

重新加载

sysctl -p

(11)🌞切换到es用户下,启动ElasticSearch

启动脚本在bin目录下


在es用户下启动报错是因为ElasticSearch在第一次启动过程中,会动态的生成一些文件,因为是刚生成的,所以es用户没有相应权限。则需要再次设置文件所有权
1.切换到root用户下(在es用户下是无法改变文件所有权的)
2.执行chown -R es:es /usr/local/es/es/


(12)🌞再次切换到es目录,启动即可


(13)🌞访问ip:9200即可

如果是云服务器需要开放9200端口

三、Linux集群部署

持续更新中…

elasticsearch——windows下es集群部署&linux下es单节点集群部署(代码片段)

...要是说一下windows下部署ES集群、Linux下单节点部署。单台Elasticsearch服务器提供服务,往往都有最大的负载能力,超过这个阈值,服务器性能就会大大降低甚至不可用,所以生产环境中,一般都是运行在指定服... 查看详情

windows部署elasticsearch+kibana8.0指南

...。一、Windows 单节点集群部署1、步骤1:下载并解压elasticsearch、kibana安装包。2、步骤2:启动elasticsearch。注意!!!!!不要修改任何配置, 查看详情

谈一谈elasticsearch的集群部署

??Elasticsearch天生就支持分布式部署,通过集群部署可以提高系统的可用性。本文重点谈一谈Elasticsearch的集群节点相关问题,搞清楚这些是进行Elasticsearch集群部署和拓扑结构设计的前提。关于如何配置集群的配置文件不会在本文... 查看详情

谈一谈elasticsearch的集群部署(代码片段)

  Elasticsearch天生就支持分布式部署,通过集群部署可以提高系统的可用性。本文重点谈一谈Elasticsearch的集群节点相关问题,搞清楚这些是进行Elasticsearch集群部署和拓扑结构设计的前提。关于如何配置集群的配置文件... 查看详情

elasticsearch8集群搭建安全功能配置详述(代码片段)

ElasticStack产品栈包含Beats、APM、Elasticsearch、ElasticsearchHadoop、Kibana、Logstash,这些产品常被作为一个整体搭配使用,其部署需要使用同样的版本,这样子能够有效简化部署操作。本文主要记录Elasticsearch8.4.3的安装过程,... 查看详情

基于kubernetes集群部署elasticsearch集群(代码片段)

在k8s中部署elasticsearch集群文章目录在k8s中部署elasticsearch集群1.部署分析2.准备镜像并推送至Harbor仓库3.创建StorageClass动态PV资源4.编写es集群configmap资源5.编写es集群statfulset资源6.编写es集群svc资源7.创建所有资源8.查看资源的状态8.1... 查看详情

centos7下elasticsearch集群部署记录

 Elasticsearch是一个分布式搜索服务,提供RestfulAPI,底层基于Lucene,采用多shard的方式保证数据安全,并且提供自动resharding的功能,github等大型的站点也都采用Elasticsearch作为其搜索服务。废话在此就不多赘述了,下面记录下Cen... 查看详情

elasticsearch集群部署(代码片段)

...1、检索2、如果用MySQL来做关键词检索3、倒排索引ELK简介ElasticSearch集群部署01、集群规划+集群网络配置02、CentOS7创建新用户+免密登录(可选)03、安装JDK04、环境变量(可选)05、ES的下载、上传、解压、修... 查看详情

elasticsearch集群部署

先说下我用的版本:elasticsearch5.2.2对于初学者来说,我觉得elasticsearch负载均衡没啥好介绍的,在不涉及到elasticsearch优化的前提下,其实还是蛮简单的。之所以要写下来,是为了帮助跟我一样笨的同学少走弯路、少踩坑。为什么... 查看详情

如何快速部署一个elasticsearch集群?

...a;无敌码农 来源:无敌码农今天的文章给大家介绍下Elasticsearch这一目前在“搜索”和“分析”领域使用十分广泛的技术组件。并演示如何快速构建一个Elasticsearch集群。Elasticsearch概述Elasticsearch是一款非常强大的开源“搜索... 查看详情

elasticsearch7.8.0版本环境——集群部署(win10系统)

目录一、Elasticsearch7.8.0版本官网下载步骤二、部署集群步骤2.1、复制三个elasticsearch服务2.2、修改每个服务的elasticsearch.yml配置文件三、启动集群步骤四、测试集群步骤4.1、查看各节点集群状态4.2、节点集群状态返回的status属性解... 查看详情

elasticsearch集群部署

Elasticsearch是一个分布式的RESTful风格的搜索和数据分析引擎,能够解决不断涌现出的各种用例。作为ElasticStack的核心,它集中存储您的数据,帮助您发现意料之中以及意料之外的情况。资源准备:由于资源有限,准备两个节点,有... 查看详情

2022elasticsearch-7.17.6集群部署(代码片段)

目录0.环境系统1.安装es集群2.配置es集群2.1.修改es配置文件2.2.修改JVM配置3.系统配置4.启动es集群0.环境系统1.安装es集群下载及安装wgethttps://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.6-x86_64.rpmwgethttps://artifacts.elastic.co 查看详情

elk中的elasticsearch集群的部署

本文内容背景ES集群中第一个master节点ESslave节点本文总结Elasticsearch(以下简称ES)搭建集群的经验。以Elasticsearch-rtf-2.2.1版本为例。我搭过三个集群:研究ELK时搭了一个;测试环境搭了一个;生产环境搭了一个。回想起来,搭建... 查看详情

elasticsearch5.0集群部署及故障测试

...http://hnr520.blog.51cto.com/4484939/18670331.修改配置文件cat elasticsearch.ymlcluster.name: hnrt 查看详情

elasticsearch常见的集群部署方式

参考技术A在开发环境,一个节点可以承担多种角色;生产环境中,需要根据数据量,写入和查询的吞吐量,选择合适的部署方式,建议设置单一角色的节点(dedicatednode);一个节点在默认情况下会同时扮演:MasterNode,DataNode和Ing... 查看详情

elasticsearch集群部署

Elastic的底层是开源库Lucene。但是,你没法直接用Lucene,必须自己写代码去调用它的接口。Elastic是Lucene的封装,提供了RESTAPI的操作接口,开箱即用。Elastic的底层是开源库。但是,你没法直接用Lucene,必须自己写代码去调用它的... 查看详情

树莓派部署elasticsearch6集群(代码片段)

欢迎访问我的GitHub本篇概览今天在两个树莓派3B上部署了Elasticsearch6.7.1版本的集群,和在一般Linux服务器上部署区别不大,现在把过程小结一下,希望能给您一些参考;环境信息树莓派操作系统是64位Ubuntu,该系统的安装步骤请参... 查看详情