linux配置elasticsearch7.6.2教程
相关资源下载地址
- 拼音分词器:https://github.com/medcl/elasticsearch-analysis-pinyin/releases;
- ik分词器:https://github.com/medcl/elasticsearch-analysis-ik/releases
- elasticsearch: https://www.elastic.co/cn/downloads/past-releases#elasticsearch (需要选择版本下载)
其他的插件版本根据下载的es版本来定,避免版本之间的不兼容导致插件无效。
java环境配置
- oracle官网下载jdk11+(es其他版本的未使用,详情不知,但是目前从es官网下载的7.x版本都提示要jdk11+);
- 上传到服务器的/usr/local/java,没有文件夹自己创建;
- 解压tar -zxvf jdkXXXXXX.gz;
- vi /etc/profile,在末尾加入如下内容:
# java环境配置
export JAVA_HOME=/usr/local/java/jdk11.0.9
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
- 立即生效环境配置:source /etc/profile;
java -version
查看java本,javac
查看java编译环境,如果执行命令过程中,提示权限不足:
chmod +x -R /usr/local/java/
-R表示递归整个文件夹下所有层级文件及文件夹;
配置elasticsearch7.x
- 官网下载最新或指定版本;
- 解压到linux系统中的/usr/local下;
- 由于es不允许使用超管用户启动程序,所以得新建一个用户;
- 新增用户命令:
useradd zces
; - 修改密命令码:
passwd zces
输入密码即可; - 将/usr/local/elasticsearch-7.6.2文件夹的权限给zces用户:
chown -R zces:zces /usr/local/elasticsearch-7.6.2
7.修改/usr/local/elasticsearch-7.6.2/config/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: data-server
#
# ------------------------------------ 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):
# 这里配置的是es存储数据的位置
path.data: /usr/local/elasticsearch-7.6.2/data
#
# Path to log files:
# 这里配置的是es日志输入位置
path.logs: /usr/local/elasticsearch-7.6.2/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):
# 这里设置es host 需要配置可外网访问,将下面的注释去掉,然后host地址改:
#network.host: 192.168.0.1
#
# Set a custom port for HTTP:
# 这里配置es的运行端口
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", "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: "*"
- 添加ik中文分词器,直接下载ik分词器包(根据es版本下载,切勿随意下载版本,避免加载不了ik分词器),解压到/usr/local/elasticsearch-7.6.2/plugins文件夹,并将文件夹名称改为ik即可,启动时看到日志日志中看到:
loaded plugin [analysis-ik]
表示加载ik中文分词成功;pinyin分词器使用方式一致(解压后命名为:pinyin); - 使用命令:su zces切换用户,然后:cd /usr/local/elasticsearch-7.6.2/bin执行:./elasticsearch 即可运行;
- 如果想设置远程可访问,需要elasticsearch.yml文件中的
# network.host: 192.168.0.1 改为 network.host: 0.0.0.0 即:放开注释,并改为不限制IP
# cluster.initial_master_nodes: ["node-1", "node-2"] 改为:cluster.initial_master_nodes: ["node-1", "node-2"] 即:放开注释
es默认端口为9200,需要更改在elasticsearh.yml中更改host即可。
如果想外网访问,关闭防火墙或者配置防火墙ip白名单或使用nginx代理,如果是直接开放端口,而且使用的云服务器,那么还需前往云服务平台配置出入站规则,放开指定端口即可。
启动如果失败,注意查看日志,如果错误日志为:
ERROR: [1] bootstrap checks failed [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
将用户从zces切换到root用户,su root
并输入密码即可,然后执行:vi /etc/sysctl.conf
编辑文件,在最后一行加入:
vm.max_map_count=262144 # 设置虚拟机最大map数,如果设置的map数不够,es启动会因为分配到的可运行内存不足而运行失败
执行命令:sysctl -p
查看结果,然后再次执行步骤9即可;