Elasticsearch集群部署

1. 资源准备

1.1 镜像资源

由于资源下载是外网会比较慢,推荐使用华为云提供的镜像:https://mirrors.huaweicloud.com/
elasticsearch-7.10.2-linux-x86_64.tar

1.2 资源规划

系统主机ip角色JDK主机名
centso 7.9192.168.40.137master/data1.8.Xnode1
centso 7.9192.168.40.138master/data1.8.Xnode2
centso 7.9192.168.40.139master/data1.8.Xnode3

1.3 设置主机名

hostnamectl set-hostname node1 && bash
hostnamectl set-hostname node2 && bash
hostnamectl set-hostname node3 && bash

2. 配置JDK环境

2.1 资源准备

由于ES是需要JDK环境才能run,则需要先配置JDK环境。
先到oracle官网上下载linux-64的jdk压缩包(1.8),地址:https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html.
解压文件:

tar zxvf jdk-8u202-linux-i586.tar.gz -C /usr/local

2.2 配置环境变量

配置环境变量:

vim /etc/profile
-----------------在配置文件最后追加-----------------------
#jdk安装目录
export JAVA_HOME=/usr/local/jdk1.8.0_202
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}

--------------------------------------------------------

加载环境变量:

source /etc/profile

2.3 测试环境

测试JDK环境

java -version
---------------报错信息-------------
-bash: /usr/local/jdk1.8.0_202/bin/java: /lib/ld-linux.so.2: bad ELF interpreter
---------------原因分析-------------
glibc是linux系统中最底层的api,几乎其它任何运行库都会依赖于glib,需要安装glibc工具库
yum install glibc.i686
------------重新查看jdk版本---------
[root@localhost ~]# java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) Client VM (build 25.202-b08, mixed mode)

node1、node2、node3 都完成以上操作

3. 前置准备

参考之前那篇:ES部署和问题汇总 ,在部署集群之前先做一下相关准备。

3.1 创建用户

由于elasticsearch部署必须得非root用户,则需要先创建用户:

---------创建用户+设置密码-------------
adduser winter;
passwd winter;
---------- 赋予root权限----------------
vim /etc/sudoers
增加  winter ALL=(ALL) ALL
wq! 保存修改

3.2 修改文件权限

vim /etc/security/limits.conf
-------------在文件末尾追加------------------
* soft nofile 65536
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096
-------------重启后配置生效------------------
reboot

3.3 (内存&并发数)

vim /etc/sysctl.conf
-------------配置文件后面追加----------------
vm.max_map_count=655360
fs.file-max=655360
--------------配置生效--------------------
sysctl -p

3.4 调整进程数

vim /etc/security/limits.d/20-nproc.conf
-----------------配置文件后面追加-------------------------
*          soft    nproc     4096
root       soft    nproc     unlimited

3.5 调整JRE server

--------------查找jre位置------------
find / -name jre
--------------修改jvm.cfg------------
vim /usr/local/jdk1.8.0_202/jre/lib/i386/jvm.cfg
-----------------------------------------------
-server KNOWN   # 将server 放到 client前面
-client IF_SERVER_CLASS -server
-minimal KNOWN

node1、node2、node3 都完成以上操作

4. 安装elasticsearch

4.1 上传资源

将在华为云下载elasticsearch-7.10…tar上传到服务上,并解压:

#创建elasticsearch基础目录elastic 
mkdir /home/elastic
#创建elastic数据和日志目录
mkdir /home/elastic/data
mkdir /home/elastic/logs
--------------------------------------
tar -zxvf elasticsearch-7.10.2-linux-x86_64.tar.gz -C /home/elastic
-------------------------------------

----------------给用户授予es相关文件夹的权限----------------------
chown -R winter:winter /home/elastic
chown -R winter:winter /home/elastic/elasticsearch-7.10.2
chown -R winter:winter /home/elastic/data
chown -R winter:winter /home/elastic/logs


node1、node2、node3 都完成以上操作

4.2 编辑elasticsearch.yml

node1的elasticsearch.yml文件:

vim /home/elastic/elasticsearch-7.10.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: my-es-cluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#节点名称
node.name: node-1
#是不是有资格竞选主节点
node.master: true
#是否存储数据
node.data: true
##最大集群节点数
node.max_local_storage_nodes: 3
#
# 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: /home/elastic/data
#
# Path to log files:
#日志存储路径
path.logs: /home/elastic/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.40.137 
#
# Set a custom port for HTTP:
#对外提供服务的http端口,默认为9200
http.port: 9200
#内部节点之间沟通端口
transport.tcp.port: 9300
#
# 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: ["192.168.40.137:9301", "192.168.40.138:9301" , "192.168.40.139:9301"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#es7.x之后新增的配置,初始化一个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["192.168.40.137", "192.168.40.138" , "192.168.40.139"]
#
# 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: "*"
#解决StartupException
xpack.ml.enabled: false

node2和node3的yml文件同node1基本一致,需要修改就2处:1. node.name ;2. network.host

4.3 开放端口号

#开放9200端口号
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --zone=public --add-port=9300/tcp --permanent
-------------------------刷新防火墙---------------------------
firewall-cmd --reload
-------------------------需要使用root账号----------------------
systemctl start firewalld  -- 如果防火墙没有开启 需要先开启
-------------------------查看开放的端口号----------------------
firewall-cmd --list-ports

4.4 启动ES

再切到ES文件夹的bin目录下:

cd /home/elastic/elasticsearch-7.10.2/bin/
------------------切换用户------------------
su winter
-----------------启动ES  查看是否有报错--------------------
./elasticsearch 

------------后台启动-------------
./elasticsearch -d

node1启动成功后 ,在浏览器上输入:http://192.168.40.137:9200/

在这里插入图片描述


node2启动成功后 ,在浏览器上输入:http://192.168.40.138:9200/

在这里插入图片描述


node3启动成功后 ,在浏览器上输入:http://192.168.40.139:9200/

在这里插入图片描述


以上则表示ES集群部署成功!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值