天天看点

分布式elasticsearch7.3.1集群部署

一、集群部署规划

版本选择:

Os版本: CentOS-7-x86_64-DVD-1810

Jdk版本: jdk-8u151

ES版本: elasticsearch-7.3.1

部署节点:

三台虚拟机 :centos-01、centos-02、centos-03

二、基础环境搭建

2.1虚拟机环境网络配置:

vi /etc/sysconfig/network-scripts/ ifcfg-ens33
           

先让它动态分配一个ip地址 :ONBOOT=yes

分布式elasticsearch7.3.1集群部署

重启网卡

service network restart

查看动态分配的ip

ip add

分布式elasticsearch7.3.1集群部署

再设置静态ip地址

BOOTPROTO=static

IPADDR=192.168.98.128

NETMASK=255.255.255.0

GATEWAY=192.168.98.1

分布式elasticsearch7.3.1集群部署

最后再次重启网卡

service network restart

ip add

2.2配置主机和ip的映射关系:

vi /etc/hosts

分布式elasticsearch7.3.1集群部署

2.3关闭防火墙:

查看防火墙状态:

firewall-cmd --state

临时关闭防火墙:

Systemctl stop firewalld.service

分布式elasticsearch7.3.1集群部署

永久关闭防火墙:

Systemctl disable firewalld

分布式elasticsearch7.3.1集群部署

2.4.安装jdk:

上传jdk并解压缩:

tar -zxvf jdk-8u151-linux-x64.tar.gz

分布式elasticsearch7.3.1集群部署

配置环境变量

vi /etc/profile

分布式elasticsearch7.3.1集群部署

export JAVA_HOME=/usr/local/jdk1.8.0_151

export PATH=$PATH:$JAVA_HOME/bin

使配置文件生效:

source /etc/profile

分布式elasticsearch7.3.1集群部署

2.5创建elasticsearch用户

为了安全es不允许使用root用户启动,建议创建一个单独的用户来运行elasticsearch。

创建elasticsearch用户及设置密码:

adduser elasticsearch

passwd elasticsearch

分布式elasticsearch7.3.1集群部署

2.6三台机器elasticsearch用户的免密配置

切换到elasticsearch用户

su elasticsearch

生成本机的公钥:

ssh-keygen -t rsa

分布式elasticsearch7.3.1集群部署

cd ~/.ssh/

将本地的公钥复制为authorized_keys文件。

cp id_rsa.pub authorized_keys

分布式elasticsearch7.3.1集群部署

将本地的公钥复制到其他主机的authorized_keys文件中

ssh-copy-id -i centos-02

分布式elasticsearch7.3.1集群部署

三、部署elasticsearch

3.1上传elasticsearch并解压缩

tar -zxvf elasticsearch-7.3.1-linux-x86_64.tar.gz

分布式elasticsearch7.3.1集群部署

3.2创建elasticsearch的数据存储目录和日志存储目录

mkdir -p /data/elasticsearch/data

mkdir -p /data/elasticsearch/logs

分布式elasticsearch7.3.1集群部署

3.3更改文件的拥有者为elasticsearch用户

chown -R elasticsearch /data/elasticsearch/data

chown -R elasticsearch /data/elasticsearch/logs

chown -R elasticsearch /usr/local/elasticsearch-7.3.1

分布式elasticsearch7.3.1集群部署

3.4 修改es集群的配置参数

centos-01节点:

vi 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: my-elasticsearch
#
# ------------------------------------ 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: /data/elasticsearch/data
#
# Path to log files:
#日志文件存放的位置
path.logs: /data/elasticsearch/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):
#监听地址,用于访问该elasticsearch
network.host: 192.168.98.128
#
# 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]"]
#es7.x之后新增的配置,写入候选节点的设备地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["centos-01", "centos-02","centos-03"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#es7.x之后新增的配置,初始化一个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
#
# 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: "*"
           

centos-02节点修改如下配置:

#节点名称
node.name: node-2
#监听地址,用于访问该elasticsearch
network.host: 192.168.98.129
           

centos-03节点修改如下配置:

#节点名称
node.name: node-3
#监听地址,用于访问该elasticsearch
network.host: 192.168.98.130
           

3.5 一些特殊配置

因启动报错:

分布式elasticsearch7.3.1集群部署

[1]每个进程最大同时打开文件数太小。

解决方法:

vi /etc/security/limits.conf
           

添加

* soft nofile 65536
* hard nofile 65536
           

注:“*”表示给所有用户起作用

[2]最大线程个数太低。

解决方法:

vi /etc/security/limits.conf
           

添加

* soft nproc 4096
* hard nproc 4096
           

[3]每个进程可以拥有的VMA(虚拟内存区域)的数量太低。

解决办法:

vi /etc/sysctl.conf
           

添加

vm.max_map_count=262144
           

记得sysctl –p 生效。

四、启动es

切换到elasticsearch用户

su elasticsearch
           

在三台机器上分别启动es

./bin/elasticsearch
           

后台启动方式

./bin/elasticsearch –d
           
分布式elasticsearch7.3.1集群部署

五、访问es

curl -XGET centos-01:9200

分布式elasticsearch7.3.1集群部署

curl -XGET centos-01:9200/_cat/nodes?v

分布式elasticsearch7.3.1集群部署

六、关闭es

jps | grep Elasticsearch

kill -9 11827

分布式elasticsearch7.3.1集群部署
分布式elasticsearch7.3.1集群部署

七、遇到的错误:

分布式elasticsearch7.3.1集群部署

原因是有两个独立的集群,删除要加入的集群的data目录下的数据。

分布式elasticsearch7.3.1集群部署

八、参考

1、https://www.cnblogs.com/remainsu/p/elasticsearch-711-ji-qun-huan-jing-da-jian.html

2、https://www.cnblogs.com/zhi-leaf/p/8484337.html

3、https://blog.51cto.com/860143/2422797?source=dra

4、https://www.cnblogs.com/nr-zhang/p/9084820.html

继续阅读