elasticsearch集群搭建

elasticsearch集群部署

1、前期准备

虚拟机centos7安装

https://blog.csdn.net/qq_44714603/article/details/88829423

centos7安装elasticsearch

官网下载Linux压缩包

https://www.elastic.co/cn/downloads/elasticsearch

放置/opt/elasticsearch目录下,解压:

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

再/bin目录下启动(其中应该会有很多错误,比如jvm大小的设置等等,jvm内存默认为4g,本地的话应该适当改小,其他百度解决即可):

./elasticsearch

另外centos7需要安装Java8才能启动elasticsearch,我安装的centos7已经内嵌Java8了,所以省略这一步。

检查启动效果:

在这里插入图片描述

下载可视化插件elasticsearch-head

直接下载到宿主机,打通虚拟机和宿主机的网络,让宿主机的head插件访问虚拟机的elasticsearch。

下载npm:

教程

下载elasticsearch-head:

教程

配置宿主机和虚拟机的网络端口映射:
在这里插入图片描述

启动elasticsearch-head,直接访问localhost:9100

在这里插入图片描述

克隆第一台centos7,并彼此ping通网络

先要将虚拟机centos7关闭,在虚拟机上右击–>管理–>克隆–>克隆自虚拟机中当前状态–>克隆方法:创建完整克隆–>填写虚拟机名称和存储目录–>点击完成等待克隆成功。

启动克隆的新的虚拟机,修改hostname

vi /etc/hostname

重启虚拟机hostname生效

修改IP地址

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

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="5dbf7422-5bd2-42b5-87ca-ca339717fe20"
DEVICE="ens33"
IPADDR=192.168.100.3   /*需要修改,只改最后一个数字*/
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
ONBOOT=yes

修改hosts文件

vi /etc/hosts

#添加一下映射
192.168.100.3 elasticsearch-01		
192.168.100.5 elasticsearch-02
192.168.100.7 elasticsearch-03

重启网络,然后互相pingIP地址测试连通性:

systemctl restart network
配置elasticsearch集群

前提:可以成为主节点数应该是集群总结点N/2+1,所以应该将两个节点设置为node.master: true。另外elasticsearch-01、elasticsearch-02、elasticsearch-03分别是master节点、client路由节点、和data数据节点,client节点不存储数据。

修改各虚拟机的elasticsearch的配置文件elasticsearch.yml

elasticsearch-01:

# ======================== 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: elasticsearch
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-01
node.master: true
node.data: true
#
# 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:
#
network.host: 192.168.100.3
#
# 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]"]
#
transport.port: 9300
discovery.seed_hosts: ["192.168.100.3:9300", "192.168.100.5:9300", "192.168.100.7:9300"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-01"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

http.cors.enabled: true 
http.cors.allow-origin: "*"

elasticsearch-02需要改动的配置:

node.name: node-02
node.master: true
node.data: false
network.host: 192.168.100.5
#cluster.initial_master_nodes: ["node-01"]

elasticsearch-03需要改动的配置:

node.name: node-03
node.master: false
node.data: true
network.host: 192.168.100.7
#cluster.initial_master_nodes: ["node-01"]

修改完成启动分别启动master、client、data节点,启动前先将克隆的两个节点中的data目录删除。

启动完成后再利用head插件查看集群状态。

在这里插入图片描述

到此elasticsearch集群搭建完成。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值