ElasticSearch-7.4.2版本集群搭建

安装JDK

下载

wget https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz

解压

tar -xvf jdk-8u201-linux-x64.tar.gz

配置java环境变量

vi /etc/profile

在文件的末尾添加 把JAVA_HOME添加到PATH中

export JAVA_HOME=/usr/java/jdk1.8.0_201

export PATH=${JAVA_HOME}/bin:${PATH}   

// wq 保存退出

// 使配置的环境变量生效

source /etc/profile   

// 检测Java命令是否可用,出现以下内容可用

java -vesion

java version "1.8.0_201"

Java(TM) SE Runtime Environment (build 1.8.0_201-b09)

Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

安装ElasticSearch

[root@Centos-52 home]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.2-linux-x86_64.tar.gz

--2019-11-25 13:41:54--  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.2-linux-x86_64.tar.gz

Resolving artifacts.elastic.co (artifacts.elastic.co)... 151.101.230.222, 2a04:4e42:36::734

Connecting to artifacts.elastic.co (artifacts.elastic.co)|151.101.230.222|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 288775500 (275M) [application/x-gzip]

Saving to: ‘elasticsearch-7.4.2-linux-x86_64.tar.gz’

100%[=======================================================================================================================================================================================>] 288,775,500 4.42MB/s  in 2m 5s 

2019-11-25 13:43:59 (2.21 MB/s) - ‘elasticsearch-7.4.2-linux-x86_64.tar.gz’ saved [288775500/288775500]

[root@Centos-52 home]# tar -xvf elasticsearch-7.4.2-linux-x86_64.tar.gz

配置文件

config目录下有三个文件分别是:

elasticsearch.yml es的配置

jvm.options jvm参数控制

log4j2.properties 日志规则配置

只需要修改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: es7-cluster

node.master: true

node.data: true

#

# ------------------------------------ Node ------------------------------------

#

# Use a descriptive name for the node:

#

node.name: es7-node-1

#

# 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: /home/elastic_data/es/data

#

# Path to log files:

#

path.logs: /home/elastic_data/es/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: 192.168.0.51

#

# Set a custom port for HTTP:

#

http.port: 9200

#

# 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.0.51", "192.168.0.52", "192.168.0.53"]

#

# Bootstrap the cluster using an initial set of master-eligible nodes:

#

cluster.initial_master_nodes: ["es7-node-1", "es7-node-2", "es7-node-3"]

#

# 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

# 是否支持跨域,在使用head插件时需要此配置

http.cors.enabled: true

# “*” 表示支持所有域名

http.cors.allow-origin: "*"

其他两个节点的配置需要修改node.name、network.host,node.name 分别为:

es7-node-2,es7-node-3,network.host分别为主机的ip

创建es用户

[root@Centos-51 home]# groupadd es

[root@Centos-51 home]# useradd es -g es -p es

[root@Centos-51 home]# groups es

es : es

[root@Centos-51 home]#

切换目录权限

[root@Centos-51 home]# chown -R es:es /home/elasticsearch-7.4.2

[root@Centos-51 home]# chown -R es:es /home/elastic_data/

启动es

./elasticsearch

./elasticsearch -d

es 默认会前台运行,第一次启动可以直接用命令运行,这样可以看到输出日志,能够比较及时的发现问题,能够正常运行后可以在命令后面加上 -d ,让es在 后台运行

启动异常-1

future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk1.8.0_181/jre] does not meet this requirement

jdk版本太低,下载jdk11,进行安装

wget https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz

修改Elasticsearch的启动文件,使它指向我们下载的JDK11

修改elasticsearch启动文件,增加下面红色部分配置

启动异常-2

OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.

这是提醒你 cms 垃圾收集器在 jdk9 就开始被标注为 @deprecated

修改jvm.options

将 -XX:+UseConcMarkSweepGC 改为 -XX:+UseG1GC

启动异常-3

Exception in thread "main" org.elasticsearch.bootstrap.BootstrapException: java.nio.file.AccessDeniedException: /home/elasticsearch-7.4.2/config/elasticsearch.keystore

Likely root cause: java.nio.file.AccessDeniedException: /home/elasticsearch-7.4.2/config/elasticsearch.keystore

at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)

at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)

at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)

at

发现elasticsearch.keystore文件所属用户是root,不知道为什么在切换目录所有权中没有切换过来

切换目录的所属用户,重新启动

启动异常-4

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

原因:新建es账户后,系统分配的内存太低

解决:切换到root用户  执行命令:

sysctl -w vm.max_map_count=262144

查看结果:

sysctl -a|grep vm.max_map_count

显示:

vm.max_map_count = 262144

上述方法修改之后,如果重启虚拟机将失效,所以:

在/etc/sysctl.conf文件最后添加一行,即可永久修改   

vm.max_map_count=262144

执行命令sysctl -p重启

集群环境验证

在浏览器访问

http://192.168.0.51:9200/_cat/nodes

如下表示集群搭建成功

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,457评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,837评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,696评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,183评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,057评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,105评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,520评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,211评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,482评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,574评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,353评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,213评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,576评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,897评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,174评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,489评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,683评论 2 335

推荐阅读更多精彩内容