欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

ElasticSearch安装教程

时间:2023-04-21
1.下载elasticsearch

进入elasticsearch官网下载:https://www.elastic.co/cn/downloads/past-releases#elasticsearch ,找到自己要用的版本,我要用的是7.3.0,为了方便我把elasticsearch简称es

2.安装es

2.1安装环境说明
Centos7、JAVA_HOME= /data/jdk/jdk1.8.0_181、Elasticsearch7.3.0
linux版本:

[root@izm5e1lllyaje4uovv8cbdz ~]# lsb_release -aLSB Version::core-4.1-amd64:core-4.1-noarchDistributor ID:CentOSDescription:CentOS Linux release 7.4.1708 (Core) Release:7.4.1708Codename:Core

JAVA_HOME:

[root@izm5e1lllyaje4uovv8cbdz ~]# echo $JAVA_HOME/data/jdk/jdk1.8.0_181

Elasticsearch7.3.0:

百度云
链接:https://pan.baidu.com/s/1rilcEzxitcJkbIZ8r3c_DQ
提取码:jstl

2.2 创建新用户
出于安全考虑,es默认不允许以root账号运行,es5之后的都不能使用添加启动参数或者修改配置文件等方法启动了,必须要创建用户。
root用户身份创建用户 esuser

[root@izm5e1lllyaje4uovv8cbdz ~]# adduser esuser[root@izm5e1lllyaje4uovv8cbdz ~]# passwd esuserChanging password for user esuser.New password: BAD PASSWORD: The password is shorter than 8 charactersRetype new password: passwd: all authentication tokens updated successfully.

2.3上传安装包并解压
创建成功后,我们切换到刚刚创建的esuser用户下,进入到 /home/esuser 目录下,
新建一个名为es的目录,并赋予最高权限,进入到es目录下,将下载的安装包上传并解压,或者直接使用wget命令下载安装包:wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.0.tar.gz,解压,如下:

[root@izm5e1lllyaje4uovv8cbdz ~]# su esuser[esuser@izm5e1lllyaje4uovv8cbdz root]$ cd /home/esuser[esuser@izm5e1lllyaje4uovv8cbdz ~]$ ls[esuser@izm5e1lllyaje4uovv8cbdz ~]$ mkdir es[esuser@izm5e1lllyaje4uovv8cbdz ~]$ lses[esuser@izm5e1lllyaje4uovv8cbdz ~]$ chmod 777 es/[esuser@izm5e1lllyaje4uovv8cbdz ~]$ cd es[esuser@izm5e1lllyaje4uovv8cbdz es]$ rz[esuser@izm5e1lllyaje4uovv8cbdz es]$ lselasticsearch-7.3.0-linux-x86_64.tar.gz[esuser@izm5e1lllyaje4uovv8cbdz es]$ [esuser@izm5e1lllyaje4uovv8cbdz es]$ tar -zxvf elasticsearch-7.3.0-linux-x86_64.tar.gz[esuser@izm5e1lllyaje4uovv8cbdz es]$ lselasticsearch-7.3.0 elasticsearch-7.3.0-linux-x86_64.tar.gz[esuser@izm5e1lllyaje4uovv8cbdz elasticsearch-7.3.0]$ lsbin config jdk lib LICENSE.txt logs modules NOTICE.txt plugins README.textile

2.4修改es配置文件elasticsearch.yml

[root@izm5e1lllyaje4uovv8cbdz config]# pwd/home/esuser/es/elasticsearch-7.3.0/config[root@izm5e1lllyaje4uovv8cbdz config]# lselasticsearch.keystore elasticsearch.yml jvm.options log4j2.properties role_mapping.yml roles.yml users users_roles[root@izm5e1lllyaje4uovv8cbdz config]# vim elasticsearch.yml

解压完成后配置文件所有的配置都是注释的,这里我们需要修改几个配置
完整的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-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/esuser/es/elasticsearch-7.3.0/data## Path to log files:#path.logs: /home/esuser/es/elasticsearch-7.3.0/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: 0.0.0.0## 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: ["host1", "host2"]## Bootstrap the cluster using an initial set of master-eligible nodes:#cluster.initial_master_nodes: ["node-1"]## 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

2.4运行es
进入elasticsearch-7.3.0目录下,执行 ./bin/elasticsearch,结果发现报错,如下:

[esuser@izm5e1lllyaje4uovv8cbdz elasticsearch-7.3.0]$ ./bin/elasticsearchfuture versions of Elasticsearch will require Java 11; your Java version from [/data/jdk/jdk1.8.0_181/jre] does not meet this requirement[esuser@izm5e1lllyaje4uovv8cbdz elasticsearch-7.3.0]$ ./bin/elasticsearchJava HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.

以上报错和警告解决方案请参考:Elasticsearch7.3.0启动指定JDK11

解决完了之后在启动es还是报错:

ERROR: [2] bootstrap checks failed[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决方案:修改/etc/sysctl.conf

[root@izm5e1lllyaje4uovv8cbdz /]# vim /etc/sysctl.conf[root@izm5e1lllyaje4uovv8cbdz /]# sysctl -p

添加一行:vm.max_map_count=262144,添加完了执行:sysctl -p,看结果是不是vm.max_map_count = 262144

成功运行的结果是会出现节点一started即可。

[2022-02-25T16:28:29,610][INFO ][o.e.n.Node ] [node-1] started

可能出现localhost:9200 或者127.0.0.1:9200都能访问的情况,但是根据IP:9200就是访问不了,有几个原因:
1)修改elasticsearch.yaml 的 network.host: 0.0.0.0
2)是否开启防火墙,放开9200端口
3)如果是云服务器,需要对专有网络类型的ecs服务器,添加该端口的安全组规则后,重启实例

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。