前期准备
系统允许 Elasticsearch 打开的最大文件数需要修改成 65536
sudo vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
一个进程可以拥有的虚拟内存区域的数量。
sudo vi /etc/sysctl.conf
vm.max_map_count = 262144
如果是centos6出现(重启 linux 使配置生效 )(CentOS7.x 不用改)
max number of threads [1024] for user [judy2] likely too low,increase to at least [4096]
原因
允许最大线程数修该成 4096
sudo vi /etc/security/limits.d/20-nproc.conf
* soft nproc 4096
root soft nproc unlimited
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
修改完以后分发到其他机器
安装
解压安装包
tar -zxvf elasticsearch-7.12.1-linux-x86_64.tar.gz
修改es的jvm.options(根据自己环境配置,不配置它会自动的配置,默认是全部的内存)
-Xms4g
-Xmx4g
修改配置文件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: myapplication
#
# ------------------------------------ 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: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/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 -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
# 其他机器修改为192.168.10.102、192.168.10.103
network.host: 192.168.66.10
# 绑定鉴定的网络接口,监听传入的请求,可以设置为IP地址或者主机名
# 其他机器修改为192.168.10.102、192.168.10.103
network.bind_host: 192.168.66.10
# 发布地址,用于通知集群中的其他节点,和其他节点通讯,不设置的话默认可以自动设置,必须是一个存在的IP地址
# 其他机器修改为192.168.10.102、192.168.10.103
network.publish_host: 192.168.66.10
#发现初始化master节点
cluster.initial_master_nodes: node-1
# ES默认开启了内存地址锁定,为了避免内存交换提高性能,但是Centos6不支持SecComp功能,启动会报错,所以需要将其设置为false
# bootstrap.memory_lock: false
# bootstrap.system_call_filter: false
# 但是:对于只有2个节点的情况,设置为2就有些问题了,一个节点DOWN掉后,肯定连不上台服务器了,这点需要注意
# discovery.zen.minimum_master_nodes: 2
# 数据存储目录
# path.data: /export/server/elasticsearch/data
# 日志存储目录
# path.logs: /export/server/elasticsearch/logs
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
#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.66.10"]
#
#集群单播发现主句,这个配置一般写主节点和备用节点的IP
discovery.zen.ping.unicast.hosts: ["192.168.66.10","192.168.66.20","192.168.66.21"]
#
# 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.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
注意其他节点要改的地方
#每一个节点的独有名称
node.name: node-1
network.host: 192.168.66.10
# 绑定鉴定的网络接口,监听传入的请求,可以设置为IP地址或者主机名
# 其他机器修改为192.168.10.102、192.168.10.103
network.bind_host: 192.168.66.10
# 发布地址,用于通知集群中的其他节点,和其他节点通讯,不设置的话默认可以自动设置,必须是一个存在的IP地址
# 其他机器修改为192.168.10.102、192.168.10.103
network.publish_host: 192.168.66.10
然后分别启动在后面加 -d就是后台启动
./elasticsearch
#后台运行
./elasticsearch -d
测试安装是否成功
http://master:9200/_cat/nodes
集群启停脚本
#!/bin/bash
es_home=/home/bigdata/elasticsearch/elasticsearch-7.12.1
case $1 in
"start") {
for i in master node1 node2
do
echo "==============$i 上 ES 启动=============="
ssh $i "source /etc/profile;${es_home}/bin/elasticsearch >/dev/null 2>&1 &"
done
};;
"stop") {
for i in master node1 node2
do
echo "==============$i 上 ES 停止=============="
ssh $i "ps -ef|grep $es_home |grep -v grep|awk '{print \$2}'|xargs kill" >/dev/null 2>&1
done
};;
esac