当前位置: 首页 > news >正文

九、Linux二进制安装ElasticSearch集群

目录

  • 九、Linux二进制安装ElasticSearch集群
    • 1 下载
    • 2 安装前准备(单机,集群每台机器都需要配置)
    • 3 ElasticSearch单机(7.16.2)
    • 4 ElasticSearch集群(8.14.2)
      • 4.1 解压文件(先将下载文件放到/opt下)
      • 4.2 新增数据目录
      • 4.3 修改配置文件
      • 4.4 启动ES(三台机器都启动)
      • 4.5 ES集群设置密码
        • 4.5.1 主节点配置
        • 4.5.2 从节点配置
        • 4.5.3 修改配置文件
        • 4.5.4 启动 并设置密码
      • 4.6 设置https访问
    • 5 设置开机自启

九、Linux二进制安装ElasticSearch集群

1 下载

官方下载:官方下载
百度网盘:网盘下载
在这里插入图片描述

2 安装前准备(单机,集群每台机器都需要配置)

一、关闭防火墙
关闭
systemctl stop firewalld
永久关闭
systemctl disable firewalld.service
也可以开放需要的端口
firewall-cmd --zone=public --add-port=5601/tcp --permanent二、安装必要环境
yum install -y gcc git wget vim ntp lsof
yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel三、修改系统配置文件
vim /etc/security/limits.conf1、添加以下内容(带上*号)
* hard nofile 131072
* soft nproc 2048
* hard nproc 40962、继续修改另一个配置文件
vi /etc/sysctl.conf3、添加以下内容
vm.swappiness=1
vm.max_map_count=6553604、刷新配置文件
sysctl -p修改时区(时区有问题时使用)
rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime5、新增目录
mkdir /opt/elk6、新建es用户
useradd esuser
passwd esuser 
输入重复密码: PassW0rd_12347、 为用户赋权限 
chown esuser:esuser -R /opt/elk

3 ElasticSearch单机(7.16.2)

之前写过一版单机版本:ElasticSearch单机安装

4 ElasticSearch集群(8.14.2)

4.1 解压文件(先将下载文件放到/opt下)

tar -zxvf /opt/elasticsearch-8.14.2-linux-x86_64.tar.gz -C /opt/elk

在这里插入图片描述

4.2 新增数据目录

mkdir /opt/elk/elasticsearch-8.14.2/data

4.3 修改配置文件

vi /opt/elk/elasticsearch-8.14.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: cluster-es
#
# ------------------------------------ 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: /opt/elk/elasticsearch-8.14.2/data
#
# Path to log files:
#
path.logs: /opt/elk/elasticsearch-8.14.2/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: 0.0.0.0
#
# 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.200.161", "192.168.200.162","192.168.200.163"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["192.168.200.161"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false
# 不设置密码
xpack.security.enabled: false
xpack.security.transport.ssl.enabled: false
xpack.security.http.ssl.enabled: false
http.cors.enabled: true
http.cors.allow-origin: "*"

4.4 启动ES(三台机器都启动)

启动前先确定esuser 有/opt/elk目录操作的权限
在这里插入图片描述
如果不是,就使用root用户重新执行一遍

chown esuser:esuser -R /opt/elk

切换用户

su esuser
/opt/elk/elasticsearch-8.14.2/bin/elasticsearch

开始启动会在这卡一会,稍等一下就行
在这里插入图片描述
在这里插入图片描述
启动成功后验证:
在这里插入图片描述

http://192.168.200.163:9200/_cluster/health?pretty

在这里插入图片描述

http://192.168.200.163:9200/_cat/nodes?v&pretty

在这里插入图片描述

4.5 ES集群设置密码

4.5.1 主节点配置
/opt/elk/elasticsearch-8.14.2/bin/elasticsearch-certutil ca

在这里插入图片描述
进入到es文件目录。可以看到生成的文件

cd /opt/elk/elasticsearch-8.14.2

在这里插入图片描述

/opt/elk/elasticsearch-8.14.2/bin/elasticsearch-certutil cert --ca /opt/elk/elasticsearch-8.14.2/elastic-stack-ca.p12 

会弹出三次提示,分别是输入密码,输出文件,输入密码,第一次密码是输入上一步设置的密码,也是123456,输出文件可以直接回车,默认就行。最后一次叫输入密码,什么都不要输入,直接回车就行,否则启动的时候会报错输入刚刚的密码,最后生成elastic-stack-ca.p12密码不要写,直接回车 不然会报错xpack Caused by: java.io.IOException: keystore password was incorrect

在这里插入图片描述
在这里插入图片描述
最后一共会有两个文件
在这里插入图片描述
移动文件到config目录

cd /opt/elk/elasticsearch-8.14.2
mv elastic-* config/

给文件复制权限(当前操作的用户是esuser,如果你的是root,请执行上面的赋权。切换到esuser进行操作)

chmod 777 /opt/elk/elasticsearch-8.14.2/config/elastic-certificates.p12 
chmod 777 /opt/elk/elasticsearch-8.14.2/config/elastic-stack-ca.p12  

创建keystore

/opt/elk/elasticsearch-8.14.2/bin/elasticsearch-keystore create

在这里插入图片描述

4.5.2 从节点配置

此时主节点有三个文件

cd /opt/elk/elasticsearch-8.14.2/config/

在这里插入图片描述
将这三个配置文件复制到其他从节点的/opt/elk/elasticsearch-8.14.2/config/下,
复制后会发现权限变成了root的。

su root
chown esuser:esuser -R /opt/elk
su esuser
chmod 777 /opt/elk/elasticsearch-8.14.2/config/elastic-certificates.p12 
chmod 777 /opt/elk/elasticsearch-8.14.2/config/elastic-stack-ca.p12  

4.5.3 修改配置文件
vi /opt/elk/elasticsearch-8.14.2/config/elasticsearch.yml

注意修改 node.name: node-1 就行

# ======================== 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: cluster-es
#
# ------------------------------------ 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: /opt/elk/elasticsearch-8.14.2/data
#
# Path to log files:
#
path.logs: /opt/elk/elasticsearch-8.14.2/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: 0.0.0.0
#
# 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.200.161", "192.168.200.162","192.168.200.163"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["192.168.200.161"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false
# ------------------------------------------------------------------------------------------------------
# 不设置密码
#xpack.security.enabled: false
#xpack.security.transport.ssl.enabled: false
#xpack.security.http.ssl.enabled: false
#http.cors.enabled: true
#http.cors.allow-origin: "*"
# ------------------------------------------------------------------------------------------------------
# 开启x-pack权限认证(三台服务器都添加如下内容并重启)
xpack.license.self_generated.type: basic
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
#开启密码认证
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: truexpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /opt/elk/elasticsearch-8.14.2/config/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /opt/elk/elasticsearch-8.14.2/config/elastic-certificates.p12#配置https的,如果启动不了,可以先注释下面的配置,启动成功后,设置完密码后再打开这些配置重新启动
#xpack.security.http.ssl.enabled: true
#xpack.security.http.ssl.keystore.path: /opt/elk/elasticsearch-8.14.2/config/elastic-certificates.p12
#xpack.security.http.ssl.truststore.path: /opt/elk/elasticsearch-8.14.2/config/elastic-certificates.p12
4.5.4 启动 并设置密码

启动

/opt/elk/elasticsearch-8.14.2/bin/elasticsearch

启动完成后,浏览器登陆。发现没有密码。这时我们要去设置密码

http://192.168.200.161:9200/

在这里插入图片描述
打开主节点的服务器(这一步需要集群是正常运行的)

/opt/elk/elasticsearch-8.14.2/bin/elasticsearch-reset-password --username elastic --interactive

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4.6 设置https访问

vi /opt/elk/elasticsearch-8.14.2/config/elasticsearch.yml

集群配置的最后三行,注释给取消就行
在这里插入图片描述
重启es

https://192.168.200.161:9200/

在这里插入图片描述

5 设置开机自启

su root
vi  /etc/systemd/system/elasticsearch.service
systemctl daemon-reload
systemctl start elasticsearch.servicesystemctl stop elasticsearch.servicesystemctl enable elasticsearch.service

启动过程会有点慢,耐心等待一下

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【JavaScript】解决 JavaScript 语言报错:Uncaught SyntaxError: Unexpected token
  • Qt QWebSocket网络编程
  • Nginx -Web服务器/反向代理/负载均衡
  • Selenium WebDriver中的显式等待与隐式等待:深入理解与应用
  • LabVIEW学习-LabVIEW储存Excel表格
  • 新版k8s拉取镜像失败问题
  • Python基础学习笔记——异常
  • python实现openssl的EVP_BytesToKey及AES_256_CBC加解密算法
  • “存算分离“和“湖仓一体“
  • Ansible 安装及使用说明
  • (补充)IDEA项目结构
  • Linux重要知识点
  • JMeter案例分享:通过数据验证的错误,说说CSV数据文件设置中的线程共享模式
  • Flutter和React Native(RN)的比较
  • 【无需公网IP】在树莓派上搭建Web站点
  • #Java异常处理
  • 【Linux系统编程】快速查找errno错误码信息
  • 0基础学习移动端适配
  • Android开源项目规范总结
  • Effective Java 笔记(一)
  • HashMap剖析之内部结构
  • JavaScript设计模式系列一:工厂模式
  • Js基础知识(一) - 变量
  • Laravel Telescope:优雅的应用调试工具
  • Perseus-BERT——业内性能极致优化的BERT训练方案
  • 大快搜索数据爬虫技术实例安装教学篇
  • 一个项目push到多个远程Git仓库
  • Mac 上flink的安装与启动
  • 从如何停掉 Promise 链说起
  • ​LeetCode解法汇总307. 区域和检索 - 数组可修改
  • ​经​纬​恒​润​二​面​​三​七​互​娱​一​面​​元​象​二​面​
  • # include “ “ 和 # include < >两者的区别
  • # wps必须要登录激活才能使用吗?
  • # 手柄编程_北通阿修罗3动手评:一款兼具功能、操控性的电竞手柄
  • #图像处理
  • (52)只出现一次的数字III
  • (python)数据结构---字典
  • (Redis使用系列) Springboot 使用redis实现接口幂等性拦截 十一
  • (二十五)admin-boot项目之集成消息队列Rabbitmq
  • (附源码)计算机毕业设计ssm高校《大学语文》课程作业在线管理系统
  • (附源码)计算机毕业设计SSM疫情下的学生出入管理系统
  • (免费领源码)Java#ssm#MySQL 创意商城03663-计算机毕业设计项目选题推荐
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (贪心 + 双指针) LeetCode 455. 分发饼干
  • (原創) 如何將struct塞進vector? (C/C++) (STL)
  • .NET Core WebAPI中使用Log4net 日志级别分类并记录到数据库
  • .NET/C# 使用反射调用含 ref 或 out 参数的方法
  • .NET开源全面方便的第三方登录组件集合 - MrHuo.OAuth
  • .NET框架类在ASP.NET中的使用(2) ——QA
  • .net与java建立WebService再互相调用
  • @data注解_SpringBoot 使用WebSocket打造在线聊天室(基于注解)
  • @Documented注解的作用
  • @RequestBody与@RequestParam
  • @软考考生,这份软考高分攻略你须知道
  • [.NET 即时通信SignalR] 认识SignalR (一)