hopeless-dream

导航

elasticsearch安装

安装过程

安装jdk

下载jdk,地址:https://www.oracle.com/technetwork/java/javase/downloads/

# mkdir /opt/{softwares,modules} -p
上传jdk包到modules下
# tar xfz jdk
-8u191-linux-x64.tar.gz -C /opt/softwares/ # echo -ne "export JAVA_HOME=/opt/softwares/jdk1.8.0_191\nexport JRE_HOME=${JAVA_HOME}/jre\nexport CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH\nexport JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin\nexport PATH=$PATH:${JAVA_PATH}" >> /etc/profile # tail -5 /etc/profile export JAVA_HOME=/opt/softwares/jdk1.8.0_191 export JRE_HOME=/opt/softwares/jdk1.8.0_191/jre export CLASSPATH=.:/opt/softwares/jdk1.8.0_191/lib:/opt/softwares/jdk1.8.0_191/jre/lib:.:/opt/softwares/jdk1.8.0_191/lib:/jre/lib:.:/lib:/lib: export JAVA_PATH=/opt/softwares/jdk1.8.0_191/bin:/opt/softwares/jdk1.8.0_191/jre/bin export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin::/bin:/bin:/opt/softwares/jdk1.8.0_191/bin:/jre/bin # . /etc/profile 验证 # java -version java version "1.8.0_191" Java(TM) SE Runtime Environment (build 1.8.0_191-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

安装elasticsearch

调整内核参数

1、修改最大文件数和锁内存限制

# echo -ne "elastic  -  hard  nproc  unlimited\nElastic  -  soft  nproc  unlimited\nelastic  -  nofile       262144\nelastic  -  memlock      unlimited\nelastic  -  fsize        unlimited\nelastic  -  as           unlimited" >> /etc/security/limits.conf
# tail -6 /etc/security/limits.conf
elastic  -  hard  nproc  unlimited
Elastic  -  soft  nproc  unlimited
elastic  -  nofile       262144
elastic  -  memlock      unlimited
elastic  -  fsize        unlimited
elastic  -  as           unlimited

2、修改进程的最大内存限制

# vim /etc/sysctl.conf 

vm.max_map_count = 262144
vm.swappiness = 1
~                  

3、修改用户最大线程数

# vim /etc/security/limits.d/20-nproc.conf
*          soft    nproc     4096
root       soft    nproc     unlimited

创建用户

elasticsearch不能使用root用户启动,所以创建普通用户elastic

# useradd  elastic

安装elasticsearch

安装包下载地址:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.0-linux-x86_64.tar.gz

解压

tar xfz modules/elasticsearch-7.12.0-linux-x86_64.tar.gz -C /opt/softwares/

修改配置文件jvm.options和elasticsearch.yml

配置文件在config目录下:

  1. jvm.options配置文件主要修改-Xms4g 和 -Xmx4g参数即可
  2. elasticsearch.yml文件内容如下:

 master节点配置文件

# ---------------------------------- Cluster & Node -----------------------------------
cluster.name: my-es          # 集群名称
node.name: es-1              # 节点名称

# ---------------------------------- Network ------------------------------------------
network.host: 10.0.0.31
transport.tcp.port: 9300     # 集群节点间通信端口

  cluster.initial_master_nodes: ["10.0.0.31:9300"]


http.port: 9200              # 集群节点对外提供的通信端口

# ----------------------------------- Paths -------------------------------------------
# 日志路径配置,需要提前创建好
path.data: /data/es
path.logs: /data/logs

# --------------------------------- Discovery -----------------------------------------
discovery.zen.ping.unicast.hosts: ["10.0.0.31","10.0.0.32","10.0.0.33"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 80s

# ---------------------------------- Gateway ------------------------------------------
gateway.recover_after_nodes: 3

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

# ----------------------------------- Memory -----------------------------------------
## 以下配置在centos6系统上需要设置为false,因为2.6.23内核版本以后才支持
bootstrap.memory_lock: true
bootstrap.system_call_filter: false

# ---------------------------------- Customer setting --------------------------------
node.master: true
node.data: false
node.ingest: true    #预处理节点,默认开启
xpack.security.enabled: false
xpack.graph.enabled: false
xpack.watcher.enabled: false
cluster.routing.allocation.disk.watermark.low: 80%
cluster.routing.allocation.disk.watermark.high: 90%
cluster.routing.allocation.same_shard.host: true

 data节点配置文件

# ---------------------------------- Cluster  & Node-----------------------------------
cluster.name: my-es
node.name: es-2

# ---------------------------------- Network -----------------------------------------
networ.host: 10.0.0.32
http.cors.allow-origin: "*"
http.enable: false

# ----------------------------------- Paths ------------------------------------------
path.data: /data/es
path.logs: /data/logs

# --------------------------------- Discovery ----------------------------------------
discovery.zen.ping_timeout: 80s
discovery.zen.ping.unicast.hosts: ["10.0.0.31","10.0.0.32","10.0.0.33"]
discovery.zen.minimum_master_nodes: 2

# ---------------------------------- Gateway -----------------------------------------
gateway.recover_after_nodes: 3

# ----------------------------------- Memory -----------------------------------------
bootstrap.memory_lock: true
bootstrap.system_call_filter: false

# ---------------------------------- Customer setting --------------------------------
node.master: false
node.data: true
node.ingest: true
xpack.security.enabled: false
xpack.graph.enabled: false
xpack.watcher.enabled: false
cluster.routing.allocation.disk.watermark.low: 80%
cluster.routing.allocation.disk.watermark.high: 90%
cluster.routing.allocation.same_shard.host: true

client节点配置

# ---------------------------------- Cluster & Node -----------------------------------
cluster.name: my-es
node.name: es-3

# ---------------------------------- Network ------------------------------------------
network.host: 10.0.0.33
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"

# ----------------------------------- Paths -------------------------------------------
path.logs: /data/logs

# --------------------------------- Discovery -----------------------------------------
discovery.zen.ping_timeout: 80s
discovery.zen.ping.unicast.hosts: ["10.0.0.31","10.0.0.32","10.0.0.33"]
discovery.zen.minimum_master_nodes: 2

# ---------------------------------- Gateway ------------------------------------------
gateway.recover_after_nodes: 3


# ----------------------------------- Memory ------------------------------------------
bootstrap.memory_lock: true
bootstrap.system_call_filter: false

# ---------------------------------- Customer setting ---------------------------------
node.master: false
node.data: false
node.ingest: true
xpack.security.enabled: false
xpack.graph.enabled: false
xpack.watcher.enabled: false
cluster.routing.allocation.disk.watermark.low: 80%
cluster.routing.allocation.disk.watermark.high: 90%
cluster.routing.allocation.same_shard.host: true

其他配置(可选)

tcp重传配置

sysctl -w net.ipv4.tcp_retries2=5 或者修改/etc/sysctl.conf

授权

# chown -R elastic.elastic /opt/softwares/elasticsearch-7.12.0/

创建数据目录和日志目录

# mkdir /data/{es,logs} -p

# chown -R elastic.elastic /data

将安装目录和数据目录拷贝到其他节点后,启动es

[elastic@es1 logs]$ bin/elasticsearch -d

 

es中的节点作用介绍 

1. 客户端节点

  当主节点和数据节点配置都设置为false的时候,该节点只能处理路由请求,处理搜索,分发索引操作等,从本质上来说该客户节点表现为智能负载平衡器。独立的客户端节点在一个比较大的集群中是非常有用的,他协调主节点和数据节点,客户端节点加入集群可以得到集群的状态,根据集群的状态可以直接路由请求。

2. 数据节点

  数据节点主要是存储索引数据的节点,主要对文档进行增删改查操作,聚合操作等。数据节点对cpu,内存,io要求较高, 在优化的时候需要监控数据节点的状态,当资源不够的时候,需要在集群中添加新的节点。

3. 主节点

  主资格节点的主要职责是和集群操作相关的内容,如创建或删除索引,跟踪哪些节点是群集的一部分,并决定哪些分片分配给相关的节点。稳定的主节点对集群的健康是非常重要的,默认情况下任何一个集群中的节点都有可能被选为主节点,索引数据和搜索查询等操作会占用大量的cpu,内存,io资源,为了确保一个集群的稳定,分离主节点和数据节点是一个比较好的选择。  

4.建议

  在一个生产集群中我们可以对这些节点的职责进行划分,建议集群中设置3台以上的节点作为master节点,这些节点只负责成为主节点,维护整个集群的状态。再根据数据量设置一批data节点,这些节点只负责存储数据,后期提供建立索引和查询索引的服务,这样的话如果用户请求比较频繁,这些节点的压力也会比较大,所以在集群中建议再设置一批client节点(node.master: false node.data: false),这些节点只负责处理用户请求,实现请求转发,负载均衡等功能。

 

 

报错

[2021-03-20T21:15:10,559][WARN ][o.e.c.c.ClusterFormationFailureHelper] [es-2] master not discovered yet, this node has not previously joined a bootstrapped (v7+) 
cluster, and [cluster.initial_master_nodes] is empty on this node

需要指定master_node

在es配置文件中加入如下配置,指定初始化时的集群master节点
cluster.initial_master_nodes: ["10.0.0.31:9300"]

 

posted on 2021-04-05 19:25  hopeless-dream  阅读(92)  评论(0编辑  收藏  举报