九、Linux二进制安装ElasticSearch集群

目录

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

九、Linux二进制安装ElasticSearch集群

1 下载

官方下载:官方下载

百度网盘:网盘下载

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

java 复制代码
一、关闭防火墙
关闭
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.conf

1、添加以下内容(带上*号)
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
 
2、继续修改另一个配置文件
vi /etc/sysctl.conf

3、添加以下内容
vm.swappiness=1
vm.max_map_count=655360

4、刷新配置文件
sysctl -p

修改时区(时区有问题时使用)
rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

5、新增目录
mkdir /opt/elk

6、新建es用户
useradd esuser
passwd esuser 
输入重复密码: PassW0rd_1234

7、 为用户赋权限 
chown esuser:esuser -R /opt/elk

3 ElasticSearch单机(7.16.2)

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

4 ElasticSearch集群(8.14.2)

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

java 复制代码
tar -zxvf /opt/elasticsearch-8.14.2-linux-x86_64.tar.gz -C /opt/elk

4.2 新增数据目录

java 复制代码
mkdir /opt/elk/elasticsearch-8.14.2/data

4.3 修改配置文件

java 复制代码
vi /opt/elk/elasticsearch-8.14.2/config/elasticsearch.yml
java 复制代码
# ======================== 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用户重新执行一遍

java 复制代码
chown esuser:esuser -R /opt/elk

切换用户

java 复制代码
su esuser
java 复制代码
/opt/elk/elasticsearch-8.14.2/bin/elasticsearch

开始启动会在这卡一会,稍等一下就行

启动成功后验证:

java 复制代码
http://192.168.200.163:9200/_cluster/health?pretty
java 复制代码
http://192.168.200.163:9200/_cat/nodes?v&pretty

4.5 ES集群设置密码

4.5.1 主节点配置
java 复制代码
/opt/elk/elasticsearch-8.14.2/bin/elasticsearch-certutil ca

进入到es文件目录。可以看到生成的文件

java 复制代码
cd /opt/elk/elasticsearch-8.14.2
java 复制代码
/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目录

java 复制代码
cd /opt/elk/elasticsearch-8.14.2
mv elastic-* config/

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

java 复制代码
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

java 复制代码
/opt/elk/elasticsearch-8.14.2/bin/elasticsearch-keystore create
4.5.2 从节点配置

此时主节点有三个文件

java 复制代码
cd /opt/elk/elasticsearch-8.14.2/config/

将这三个配置文件复制到其他从节点的/opt/elk/elasticsearch-8.14.2/config/下,

复制后会发现权限变成了root的。

java 复制代码
su root
java 复制代码
chown esuser:esuser -R /opt/elk
java 复制代码
su esuser
java 复制代码
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 修改配置文件
java 复制代码
vi /opt/elk/elasticsearch-8.14.2/config/elasticsearch.yml

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

java 复制代码
# ======================== 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: true

xpack.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 启动 并设置密码

启动

java 复制代码
/opt/elk/elasticsearch-8.14.2/bin/elasticsearch

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

java 复制代码
http://192.168.200.161:9200/

打开主节点的服务器(这一步需要集群是正常运行的)

java 复制代码
/opt/elk/elasticsearch-8.14.2/bin/elasticsearch-reset-password --username elastic --interactive



4.6 设置https访问

java 复制代码
vi /opt/elk/elasticsearch-8.14.2/config/elasticsearch.yml

集群配置的最后三行,注释给取消就行

重启es

java 复制代码
https://192.168.200.161:9200/

5 设置开机自启

java 复制代码
su root
java 复制代码
vi  /etc/systemd/system/elasticsearch.service
java 复制代码
systemctl daemon-reload
java 复制代码
systemctl start elasticsearch.service

systemctl stop elasticsearch.service

systemctl enable elasticsearch.service

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

相关推荐
云飞云共享云桌面35 分钟前
8位机械工程师如何共享一台图形工作站算力?
linux·服务器·网络
Peter_chq1 小时前
【操作系统】基于环形队列的生产消费模型
linux·c语言·开发语言·c++·后端
一坨阿亮2 小时前
Linux 使用中的问题
linux·运维
dsywws3 小时前
Linux学习笔记之vim入门
linux·笔记·学习
幺零九零零4 小时前
【C++】socket套接字编程
linux·服务器·网络·c++
wclass-zhengge4 小时前
Docker篇(Docker Compose)
运维·docker·容器
李启柱4 小时前
项目开发流程规范文档
运维·软件构建·个人开发·设计规范
小林熬夜学编程5 小时前
【Linux系统编程】第四十一弹---线程深度解析:从地址空间到多线程实践
linux·c语言·开发语言·c++·算法
Elastic 中国社区官方博客5 小时前
释放专利力量:Patently 如何利用向量搜索和 NLP 简化协作
大数据·数据库·人工智能·elasticsearch·搜索引擎·自然语言处理
力姆泰克5 小时前
看电动缸是如何提高农机的自动化水平
大数据·运维·服务器·数据库·人工智能·自动化·1024程序员节