版本:elasticsearch-6.2.4,环境:2台linux(192.168.13.111、12.168.13.222) jdk1.8(必须)
解压elasticsearch-6.2.4.tar.gz
解压后进入目录:
config目录里面是配置文件
elasticsearch.yml # els的配置文件
jvm.options # JVM相关的配置,内存大小等等
log4j2.properties # 日志系统定义
数据存放目录自行配置即可;
elasticsearch.yml配置内容:
cluster.name: my-application # 集群名称,默认elasticsearch,多个节点一样的名字,同名的自动组成集群
node.name: es111# 节点名称,仅仅是描述名称,用于在日志中区分
path.data: /var/lib/elasticsearch # 数据的默认存放路径
path.logs: /var/log/elasticsearch # 日志的默认存放路径
network.host: 192.168.13.111 # 当前节点的IP地址 默认是192.168.0.1,也是localhost
http.port: 9200 # 对外提供服务的端口,9300为集群服务的端口
discovery.zen.ping.unicast.hosts: ["192.168.13.111", "192.168.13.222"]
# 集群个节点IP地址,也可以使用els、els.shuaiguoxia.com等名称,需要各节点能够解析
discovery.zen.minimum_master_nodes: 1 # 为了避免脑裂,集群节点数最少为 半数+1,我本机只有2台,就1了。一般集群环境部署台数都是奇数
bootstrap.memory_lock: false 这个设置为false,再加上下面的bootstrap设置。不然有可能启动报错,一个小坑
bootstrap.system_call_filter: false
第一个坑:配置值前面必须要有一个空格,es格式问题。不然报错
配置完成的elasticsearch.yml(192.168.13.222):
# ======================== 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: es222
#
# 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: /elasticsearch-6.2.4/data
#
# Path to log files:
#
path.logs: /elasticsearch-6.2.4/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# 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.13.222
#
# 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 new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.unicast.hosts: ["192.168.13.222", "192.168.13.111"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes: 1
#
# For more information, consult the zen discovery 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
配置完成的elasticsearch.yml(192.168.13.111):
# ======================== 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: es111
#
# 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: /elasticsearch-6.2.4/data
#
# Path to log files:
#
path.logs: /elasticsearch-6.2.4/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# 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.13.111
#
# 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 new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["192.168.13.111", "192.168.13.222"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes: 1
#
# For more information, consult the zen discovery 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
JVM配置:没有特殊需要的话,默认不变即可,进去看了看,默认写得4g。稍微改动。根据自己需求来改
启动Elasticsearch
进入bin目录下,执行elasticsearch
启动报错:
第二个坑:不能用root用户来启动elasticsearch
创建一个用户es,用它来启动,注意给用户权限
chmod -v u+w /etc/sudoers (增加 sudoers 文件的写的权限,默认为只读)
添加用户给予root权限 es
chmod -v u-w /etc/sudoers 删除sudoers 文件写权限
又报错:
Exception in thread "main" java.nio.file.AccessDeniedException: /root/home/searchengine/elasticsearch-6.2.4/config/jvm.options
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
at java.nio.file.Files.newByteChannel(Files.java:361)
at java.nio.file.Files.newByteChannel(Files.java:407)
at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
at java.nio.file.Files.newInputStream(Files.java:152)
at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:58)
文件没有权限,切换到root用户下,给es用户文件权限
chown -R es:es /usr/local/elasticsearch-6.2.4
报错:ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
切换到root用户修改/etc/security/limits.conf在最后添加:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
继续启动
继续报错:ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
继续切换到root用户,修改配置/etc/sysctl.conf
加入配置:vm.max_map_count=655360,退出保存
执行命令:sysctl -p
继续切换到es用户继续启动(哈哈哈)。不出意外,应该可以了。该出现的问题差不多都出现了
结果浏览器访问不了,关闭防火墙:systemctl stop firewalld.service 继续访问
成功
查看主节点,随便登录其中一个节点,可以查看主节点
带*的就是主节点,就是上面的es222.在同一网段同一集群名称下,会自动发现集群。