Linux离线安装ES

1. Elasticsearch支持一览表


 2. 安装Java环境


  • Elasticsearch 8.x.x 之后不再支持 jdk1.8,支持度最高的是jdk17

 3. 下载Elasticsearch


  • 本次选择7.x.x的最新版本下载

  • 选择Linux X86_64操作系统

4. 解压elasticsearch文件


  •  将文件解压到 /usr/local/ 目录下
tar -zxvf elasticsearch-7.17.22-linux-x86_64.tar.gz -C /usr/local/

ll /usr/local/elasticsearch-7.17.22/

 4.1 查看目录

4.2 查看自带jdk版本

cd /usr/local/elasticsearch-7.17.22/jdk/bin/

./java -version

5. 配置es最大虚拟内存

  • 直接启动可能会报以下错误,需要配置最大虚拟内存区域(root用户配置)

6. 新建elasticsearch用户


  • elasticsearch不能用root用户启动
# 创建es用户
useradd -d /esuser esuser

# 设置es用户密码
passwd esuser

# 赋权给es用户
chown -R esuser.esuser /usr/local/elasticsearch-7.17.22/

# 查看赋权是否成功
ll /usr/local/elasticsearch-7.17.22/

# 切换到es用户
su - esuser

# 创建数据和日志目录
mkdir -p /esuser/elasticsearch/{data,logs}

7. 编辑单机配置文件


vim /usr/local/elasticsearch-7.17.22/config/elasticsearch.yml
# 集群名称
cluster.name: my-application

# 节点名称
node.name: node-1

# ES数据存储目录
path.data: /esuser/elasticsearch/data

# ES日志存储目录
path.logs: /esuser/elasticsearch/logs

# 本机ip
network.host: 192.168.81.10

# http端口号
http.port: 9200

# ES集群发现ip
discovery.seed_hosts: ["192.168.81.10"]

8. 单机启动elasticsearch


cd /usr/local/elasticsearch-7.17.22/bin/

# 以日志打印到控制台方式启动
./elasticsearch

# 后台运行启动
./elasticsearch -d

9. 验证

9.1 Linux验证

curl http://192.168.81.10:9200/

9.2 浏览器验证

10. 单机集群启动


10.1 编辑配置文件

# 备份配置文件
cp elasticsearch.yml elasticsearch.yml.back

# 编辑配置文件
vim elasticsearch.yml

# 填入以下内容
# 集群名称
cluster.name: dzf_example

# 节点名称,通常一台物理服务器就是一个节点
#node.name: node-1

# ES数据存储目录,可以设置多个存储路径,用逗号隔开
#path.data: /esuser/elasticsearch/data

# ES日志存储目录
#path.logs: /esuser/elasticsearch/logs

# 设置绑定主机的ip地址,设置为0.0.0.0表示绑定任何ip,允许外网访问,生产环境建议设置为具体的ip
network.host: 192.168.81.10

# 设置对外服务的http端口,默认为9200
#http.port: 9200

# 提供的TCP客户端服务端口号(集群结点之间通信端口)
#transport.tcp.port: 9300

# 设置允许跨域
http.cors.enabled: true
http.cors.allow-origin: "*"

# ES集群发现ip和端口,注意逗号后面要有空格
# 写入候选主节点的设备地址,在开启服务后可以被选为主节点
#discovery.seed_hosts: ["host1", "host2"]
discovery.seed_hosts: ["192.168.81.10:9300", "192.168.81.10:9301", "192.168.81.10:9302", "192.168.81.10:9303"]

# 初始化可参与master选举的节点,注意逗号后面要有空格
#cluster.initial_master_nodes: ["node-1", "node-2"]
cluster.initial_master_nodes: ["node-0", "node-1", "node-2", "node-3"]

# 最大集群节点数
#node.max_local_storage_nodes: 3
#是不是有资格主节点
#node.master: true
#是否存储数据
#node.data: true

10.2 启动

# 创建存放日志和数据的目录
mkdir -p /esuser/esCluster/{data0,logs0,data1,logs1,data2,logs2,data3,logs3}

# 启动命令
/usr/local/elasticsearch-7.17.22/bin/elasticsearch  -d -E path.data=/esuser/esCluster/data0 -E path.logs=/esuser/esCluster/logs0 -E node.name=node-0 -E http.port=9200 -E transport.tcp.port=9300

/usr/local/elasticsearch-7.17.22/bin/elasticsearch  -d -E path.data=/esuser/esCluster/data1 -E path.logs=/esuser/esCluster/logs1 -E node.name=node-1 -E http.port=9201 -E transport.tcp.port=9301

/usr/local/elasticsearch-7.17.22/bin/elasticsearch  -d -E path.data=/esuser/esCluster/data2 -E path.logs=/esuser/esCluster/logs2 -E node.name=node-2 -E http.port=9202 -E transport.tcp.port=9302

/usr/local/elasticsearch-7.17.22/bin/elasticsearch  -d -E path.data=/esuser/esCluster/data3 -E path.logs=/esuser/esCluster/logs3 -E node.name=node-3 -E http.port=9203 -E transport.tcp.port=9303

# 查看es状态
ps -ef | grep elasticsearch
curl http://192.168.81.10:9200

10.3 写成启动脚本

vim esstart.sh

# 填入以下内容
#!/bin/bash

# 删除历史目录
rm -rf /esuser/esCluster/*

# 新建目录
mkdir -p /esuser/esCluster/{data0,logs0,data1,logs1,data2,logs2,data3,logs3}

# 启动
/usr/local/elasticsearch-7.17.22/bin/elasticsearch  -d -E path.data=/esuser/esCluster/data0 -E path.logs=/esuser/esCluster/logs0 -E node.name=node-0 -E http.port=9200 -E transport.tcp.port=9300

/usr/local/elasticsearch-7.17.22/bin/elasticsearch  -d -E path.data=/esuser/esCluster/data1 -E path.logs=/esuser/esCluster/logs1 -E node.name=node-1 -E http.port=9201 -E transport.tcp.port=9301

/usr/local/elasticsearch-7.17.22/bin/elasticsearch  -d -E path.data=/esuser/esCluster/data2 -E path.logs=/esuser/esCluster/logs2 -E node.name=node-2 -E http.port=9202 -E transport.tcp.port=9302

/usr/local/elasticsearch-7.17.22/bin/elasticsearch  -d -E path.data=/esuser/esCluster/data3 -E path.logs=/esuser/esCluster/logs3 -E node.name=node-3 -E http.port=9203 -E transport.tcp.port=9303

# 赋予执行权限
chmod +x esstart.sh

  • 关闭之前启动的集群

  • 脚本启动

10.4 验证,两种都可以

安装elasticsearch-head更直观查看集群

浏览器查看集群

http://ip:9200/_cat/nodes?pretty

11. 集群启动


11.1 修改集群配置文件

# 备份配置文件
cp elasticsearch.yml  elasticsearch.keystore

# 修改配置文件
vim elasticsearch.yml
# ---------------------------------- Cluster -----------------------------------
#
# 集群名称
#
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# 节点名称,通常一台物理服务器就是一个节点,
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# ES数据存储目录,可以设置多个存储路径,用逗号隔开
#
path.data: /home/esuser/data/elasticsearch
#
# ES日志存储目录:
#
path.logs: /home/esuser/logs/elasticsearch
#
# ----------------------------------- 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 -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 设置绑定主机的ip地址,设置为0.0.0.0表示绑定任何ip,允许外网访问,生产环境建议设置为具体的ip
network.host: 192.168.81.10
#
# Set a custom port for HTTP:
# 设置对外服务的http端口,默认为9200
http.port: 9200

# 提供的TCP客户端服务端口号(集群结点之间通信端口)
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]"]
# ES集群发现ip和端口
discovery.seed_hosts: ["192.168.81.10:9300","192.168.81.11:9300","192.168.81.12:9300"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
# 初始化可参与master选举的节点
cluster.initial_master_nodes: ["192.168.81.10", "192.168.81.11","192.168.81.12"]
# 集群ping过程的超时等待时间
discovery.zen.ping_timeout: 120s
# 客户端连接节点超时时间
client.transport.ping_timeout: 60s

# 是否支持跨域,默认为false
# http.cors.enabled:true
# 当设置允许跨域,默认为*,表示支持所有域名
# http.cors.allow-origin:"*"

11.2 启动 Elasticsearch

/usr/local/elasticsearch-7.17.22/bin/elasticsearch –d

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值