ElasticSearch 安装教程

ElasticSearch 安装教程添加一行:vm.max_map_count=262144,添加完了执行:sysctl-p,看结果是不是vm.max_map_count=262144。出于安全考虑,es默认不允许以root账号运行,es5之后的都不能使用添加启动参数或者修改配置文件等方法启动了,必须要创建用户。创建成功后,我们切换到刚刚创建的esuser用户下,进入到/home/esuser目录下,3)如果是云服务器,需要对专有网络类型的ecs服务器,添加该端口的安全组规则后,重启实例。解决方案:切换su,给用户赋文件权限。…

大家好,欢迎来到IT知识分享网。

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 -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.4.1708 (Core) 
Release:	7.4.1708
Codename:	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 esuser
Changing password for user esuser.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype 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 ~]$ ls
es
[esuser@izm5e1lllyaje4uovv8cbdz ~]$ chmod 777 es/
[esuser@izm5e1lllyaje4uovv8cbdz ~]$ cd es
[esuser@izm5e1lllyaje4uovv8cbdz es]$ rz

[esuser@izm5e1lllyaje4uovv8cbdz es]$ ls
elasticsearch-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]$ ls
elasticsearch-7.3.0  elasticsearch-7.3.0-linux-x86_64.tar.gz
[esuser@izm5e1lllyaje4uovv8cbdz elasticsearch-7.3.0]$ ls
bin  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]# ls
elasticsearch.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 后台启动》进入elasticsearch-7.3.0目录下,执行 ./bin/elasticsearch,结果发现报错,如下:

[esuser@izm5e1lllyaje4uovv8cbdz elasticsearch-7.3.0]$ ./bin/elasticsearch
future 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/elasticsearch
Java 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就是访问不了,有几个原因,见《linux firewall防火墙命令,以及开放端口》:
1)修改elasticsearch.yaml 的 network.host: 0.0.0.0
2)是否开启防火墙,放开9200端口
3)如果是云服务器,需要对专有网络类型的ecs服务器,添加该端口的安全组规则后,重启实例
在这里插入图片描述

常见报错(后续会不断更新):

1.用户权限不够

[esuser@izm5e1lllyaje4uovv8cbdz bin]$ ./elasticsearch
2022-08-29 10:49:52,622 main ERROR RollingFileManager (/home/esuser/es/elasticsearch-7.3.0/logs/elasticsearch_server.json) java.io.FileNotFoundException: /home/esuser/es/elasticsearch-7.3.0/logs/elasticsearch_server.json (权限不够) java.io.FileNotFoundException: /home/esuser/es/elasticsearch-7.3.0/logs/elasticsearch_server.json (权限不够)

解决方案:切换su,给用户赋文件权限

chown -R esuser /home/esuser/es/elasticsearch

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/12928.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信