九、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

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

相关推荐
长弓聊编程12 分钟前
Linux系统使用valgrind分析C++程序内存资源使用情况
linux·c++
cherub.19 分钟前
深入解析信号量:定义与环形队列生产消费模型剖析
linux·c++
梅见十柒42 分钟前
wsl2中kali linux下的docker使用教程(教程总结)
linux·经验分享·docker·云原生
Koi慢热1 小时前
路由基础(全)
linux·网络·网络协议·安全
传而习乎1 小时前
Linux:CentOS 7 解压 7zip 压缩的文件
linux·运维·centos
soulteary1 小时前
突破内存限制:Mac Mini M2 服务器化实践指南
运维·服务器·redis·macos·arm·pika
我们的五年1 小时前
【Linux课程学习】:进程程序替换,execl,execv,execlp,execvp,execve,execle,execvpe函数
linux·c++·学习
IT果果日记1 小时前
ubuntu 安装 conda
linux·ubuntu·conda
Python私教1 小时前
ubuntu搭建k8s环境详细教程
linux·ubuntu·kubernetes
羑悻的小杀马特2 小时前
环境变量简介
linux