Elasticsearch基础篇(二):Elasticsearch在windows和liunx上的安装部署

前言

本文基于官方文档:Installing Elasticsearch
基于官方给出的几种不同环境不同的安装方式,本文将会选择在

  • Install Elasticsearch with .zip on Windows
    使用.zip文件在Windows上安装Elasticsearch

  • Install Elasticsearch from archive on Linux or MacOS
    在Linux或macOS上从存档文件安装Elasticsearch

  • Install Elasticsearch with Docker (此种方式待定)
    使用Docker安装Elasticsearch

在这里插入图片描述

1. Windows环境部署Elasticsearch

1.1 下载并解压Elasticsearch压缩包

在这里插入图片描述

Unzip it with your favourite unzip tool. This will create a folder called elasticsearch-7.9.3,which we will refer to as %ES_HOME%. In a terminal window,cd to the %ES_HOME% directory,for instance:

将解压目录作为es的home目录,在 elasticsearch-7.9.3文件夹地址栏输入cmd 进入命令行

在这里插入图片描述

1.2 命令行启动elasticsearch

  • 启动elasticsearch

    Running Elasticsearch from the command line.Elasticsearch can be started from the command line as follows:
    从命令行运行Elasticsearch,可以按以下方式从命令行启动Elasticsearch:

    .\bin\elasticsearch.bat
    
  • 启动页面

    在这里插入图片描述

  • 启动成功页面

    在这里插入图片描述

1.3 验证是否成功启动elasticsearch

Checking that Elasticsearch is running
You can test that your Elasticsearch node is running by sending an HTTP request to port 9200 on localhost:
检查Elasticsearch是否正在运行
可以通过向本地主机的端口9200发送HTTP请求来测试您的Elasticsearch节点是否正在运行:

win+r输入cmd回车后输入下列请求url

curl -X GET "localhost:9200/?pretty"

表示启动成功

在这里插入图片描述


或者在浏览器地址栏输入:localhost:9200

在这里插入图片描述

1.4 关闭Elasticsearch

  • Ctrl+C停止Elasticsearch

    By default,Elasticsearch runs in the foreground,prints its logs to STDOUT,and can be stopped by pressing Ctrl-C.
    默认情况下,Elasticsearch在前台运行,将日志打印到标准输出(STDOUT),可以通过按下Ctrl-C来停止它。

    在这里插入图片描述

  • 验证是否已经关闭(直接关闭上面的命令行窗口也可以停止es)

    在这里插入图片描述

1.5 在Windows上安装Elasticsearch作为服务

Elasticsearch can be installed as a service to run in the background or start automatically at boot time without any user interaction. This can be achieved through the elasticsearch-service.bat script in the bin\ folder which allows one to install,remove,manage or configure the service and potentially start and stop the service,all from the command-line.
Elasticsearch可以安装为服务,在后台运行或在启动时自动启动,而无需任何用户交互。这可以通过bin\文件夹中的elasticsearch-service.bat脚本实现,该脚本允许您从命令行安装、删除、管理或配置服务,并且还可以潜在地启动和停止服务。

e:\elasticsearch-7.9.3\bin>elasticsearch-service.bat

Usage: elasticsearch-service.bat install|remove|start|stop|manager [SERVICE_ID]

在这里插入图片描述

The script requires one parameter (the command to execute) followed by an optional one indicating the service id (useful when installing multiple Elasticsearch services).
该脚本需要一个参数(要执行的命令),后面可以跟一个可选参数来指示服务ID(在安装多个Elasticsearch服务时很有用)

以下是elasticsearch-service.bat脚本可用的命令及其描述:

命令 描述
install 安装Elasticsearch作为服务
remove 移除已安装的Elasticsearch服务(如果已启动则停止服务)
start 启动Elasticsearch服务(如果已安装)
stop 停止Elasticsearch服务(如果已启动)
manager 打开用于管理已安装服务的GUI界面
  • 指定服务名安装
    安装为服务,服务ID(务必唯一):elasticsearch-9200-test
    elasticsearch-service.bat install elasticsearch-9200-test
    
  • 命令行启动或停止服务
    • 启动服务
      elasticsearch-service.bat start elasticsearch-9200-test
      

      在这里插入图片描述

    • 停止服务
      elasticsearch-service.bat stop elasticsearch-9200-test
      

      在这里插入图片描述

  • 服务页面启动或停止服务
    win+r回车输入services.msc进入服务列表,右击选择启动或者停止

    在这里插入图片描述

  • 设置为开机自启
    右击服务名,点击属性,选择启动类型为自动

    在这里插入图片描述

2. Liunx环境部署Elasticsearch

安装 Elasticsearch 7.17.11 并配置

本文介绍如何在 Linux 操作系统上下载、安装 Elasticsearch 7.17.11,并进行必要的配置。在centos或者是unbuntu中配置启动的流程基本一致,开放端口处的脚本不相同。

1. 下载es数据库并上传到服务器

首先,访问 Elasticsearch 下载页面 并下载 Elasticsearch 7.17.11

在这里插入图片描述


点击 “下载” 并将下载的文件上传到服务器指定目录中

在这里插入图片描述

在服务器上,使用以下命令解压 Elasticsearch:

tar -zxvf elasticsearch-7.17.11-linux-x86_64.tar.gz

在这里插入图片描述

2. 创建 Elasticsearch 用户和组

创建一个名为 “es” 的用户和一个名为 “es” 的群组,然后将用户添加到该群组中:

# 新建群组es
 groupadd es
# 新建用户es并指定群组为es
 useradd -g es es
# 设置用户密码 
 passwd es  
# usermod 将用户添加到某个组group
 usermod -aG root es

3. 系统配置

3.1 修改文件句柄数和线程数

为了防止 Elasticsearch 用户拥有的可创建文件描述符权限过低而导致错误,需要修改文件句柄数和线程数。编辑 /etc/security/limits.conf 文件并添加以下内容:

# 文件句柄
es  soft nofile 65536
es  hard nofile 65536
# 线程
es  soft nproc 4096
es  hard nproc 4096

保存退出后,需要重新启动系统

以上配置是为了解决:

报错问题:max file descriptors [4096] for elasticsearch process is too low,increase to at least [65535]
问题描述:elasticsearch用户拥有的可创建文件描述的权限太低,至少需要65536;

3.2 修改虚拟内存

编辑 /etc/sysctl.conf 文件并添加以下内容:

vm.max_map_count=262144

保存退出后,刷新配置文件:

sysctl -p

验证是否修改成功:

sysctl vm.max_map_count

以上配置是为了解决:
报错问题:max virtual memory areas vm.max_map_count [65530] is too low,increase to at least [262144]

3.3 关闭交换空间(Swap)

官方建议:把内存的一半给Lucene+不要超过32G+关闭swap
ES建议要关闭 swap 内存交换空间,禁用swapping。因为当内存交换到磁盘上,一个100微秒的操作可能变成 10毫秒,然后100 微秒的操作时延累加起来,可以看出 swapping 对于性能的影响是致命的

vim /etc/fstab

注释含有swap一行

在这里插入图片描述


注释前:

在这里插入图片描述

保存退出后需要系统重启!

注释后:

在这里插入图片描述

4. 修改 Elasticsearch 配置

编辑 Elasticsearch 配置文件 conf/elasticsearch.yml 并根据你的需求进行配置,以下是一些示例配置项:

# 禁用了 es 的机器学习功能(Machine Learning)减少资源消耗
xpack.ml.enabled: false
# 设置 Elasticsearch 集群的名称
cluster.name: es-single
# 设置当前 Elasticsearch 节点的名称
node.name: node
# 数据目录
path.data: /home/es/path/node/data
# 日志目录
path.logs: /home/es/path/node/logs
# 当前主机的 IP
network.host: 192.168.0.10
# 暴露的 HTTP 端口
http.port: 11700
# 暴露的 Transport 端口
transport.port: 11710
# 设置节点发现的种子主机列表
discovery.seed_hosts: ["192.168.0.10:11710"]
# 设置初始的主节点列表,新节点将联系这些主节点以加入集群
cluster.initial_master_nodes: ["node"]

5. 设置目录权限

设置 Elasticsearch 数据目录所属的用户和组:

chown -R es:es /mnt/data/elasticsearch-7.17.11

6. 启动 Elasticsearch 服务

注意当前目录是在 ../elasticsearch-7.17.11

创建启动和停止 Elasticsearch 服务的脚本:

startes-single.sh

#!/bin/bash
cd "$(dirname "$0")"
# -d:后台(daemon)方式运行 Elasticsearch
./bin/elasticsearch -d -p pid

stopes-single.sh

#!/bin/bash
cd "$(dirname "$0")"
if [ -f "pid" ]; then
  pkill -F pid
fi

给这两个脚本赋予执行权限:

chmod 755 startes-single.sh stopes-single.sh
chown es:es startes-single.sh stopes-single.sh

然后,以 Elasticsearch 用户身份启动 Elasticsearch 服务:

su - es
cd /mnt/data/elasticsearch-7.17.11
./startes-single.sh

7. 开放防火墙端口

CentOS

# 查看防火墙状态
systemctl status firewalld
# 查看开放的端口
firewall-cmd --query-port=9200/tcp
# 添加端口
firewall-cmd --zone=public --add-port=9200/tcp --permanent
# 重载防火墙
firewall-cmd --reload
# 再次查看端口是否已经开放
firewall-cmd --query-port=9200/tcp

Ubuntu

# 查看防火墙状态
sudo ufw status
# 开放端口 9200
sudo ufw allow 9200/tcp
# 查看已添加的规则
sudo ufw status numbered
# 查看防火墙状态
sudo ufw status

原文地址:https://blog.csdn.net/qq_29864051/article/details/131446118

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


文章浏览阅读774次,点赞24次,收藏16次。typescript项目中我们使用typings-for-css-modules-loader来替代css-loader实现css modules。1、typings-for-css-modules-loader加载器介绍 Webpack加载器,用作css-loader的替代产品,可动态生成CSS模块的TypeScript类型这句话是什么意思呢?就是编译时处理css文件...
文章浏览阅读784次。react router redux antd eslint prettier less axios_react+antd+redux+less
文章浏览阅读3.9k次,点赞5次,收藏11次。需要删除.security-7索引文件。把在第1步中的被注释的配置打开。之后就是按照提示输入密码。执行bin目录下的文件。_failed to authenticate user 'elastic' against
文章浏览阅读1.2k次,点赞23次,收藏24次。Centos 8 安装es_centos8 yum elasticsearch
文章浏览阅读3.2k次。设置完之后,数据会⾃动同步到其他节点。修改密码时,将第⼀步配置删除,然后重启。单独使⽤⼀个节点⽣成证书;执⾏设置⽤户名和密码的命令。执⾏完上⾯命令以后就可以在。⽂件,在⾥⾯添加如下内容。这个⽂件复制到其他节点下。其中⼀个节点设置密码即可。依次对每个账户设置密码。全部节点都要重启⼀遍。需要在配置⽂件中开启。个⽤户分别设置密码,⽬录下,证书⽂件名为。功能,并指定证书位置。_es设置账号和密码
文章浏览阅读1.9k次,点赞2次,收藏7次。针对多数据源写入的场景,可以借助MQ实现异步的多源写入,这种情况下各个源的写入逻辑互不干扰,不会由于单个数据源写入异常或缓慢影响其他数据源的写入,虽然整体写入的吞吐量增大了,但是由于MQ消费是异步消费,所以不适合实时业务场景。不易出现数据丢失问题,主要基于MQ消息的消费保障机制,比如ES宕机或者写入失败,还能重新消费MQ消息。针对这种情况,有数据强一致性要求的,就必须双写放到事务中来处理,而一旦用上事物,则性能下降更加明显。可能出现延时问题:MQ是异步消费模型,用户写入的数据不一定可以马上看到,造成延时。_mysql同步es
文章浏览阅读3.6w次,点赞48次,收藏44次。【程序员洲洲送书福利-第十九期】《C++ Core Guidelines解析》
文章浏览阅读1.3k次。当我们在开发Vue应用时,经常需要对表单进行校验,以确保用户输入的数据符合预期。Vue提供了一个强大的校验规则机制,通过定义rules规则,可以方便地对表单进行验证,并给出相应的错误提示。_vue ruler校验
文章浏览阅读2k次,点赞16次,收藏12次。Linux内核源码下载地址及方式_linux源码下载
文章浏览阅读1k次。这样在每天自动生成的索引skywalking_log_xxx就会使用上述模版来生成,timestamp会被设置成date类型。然后此时在–>索引管理–>kibana–>索引模式添加skywalking_log*索引时就会有时间字段了。在通过skywalking将日志收集到es后,由于skywalking收集的日志(skywalking_log索引)没有date类型的字段导致在es上再索引模式中没有时间范围的查询。skywalking收集的日志有时间戳字段timestamp,只是默认为long类型。_skywalking timestamp
文章浏览阅读937次,点赞18次,收藏21次。1.初始化git仓库,使用git int命令。2.添加文件到git仓库,两步走:2.1 使用命令,注意,可反复多次使用,添加多个文件;2.2 使用命令,完成。此笔记是我个人学习记录笔记,通过廖雪峰的笔记进行学习,用自己能理解的笔记记录下来,如果侵权,联系删。不存在任何盈利性质,单纯发布后,用于自己学习回顾。
文章浏览阅读786次,点赞8次,收藏7次。上述示例中的 origin 是远程仓库的名称,https://github.com/example/repository.git 是远程仓库的 URL,(fetch) 表示该远程仓库用于获取更新,(push) 表示该远程仓库用于推送更新。你可以选择在本地仓库创建与远程仓库分支对应的本地分支,也可以直接将本地仓库的分支推送到远程仓库的对应分支。将 替换为远程仓库的名称(例如 origin), 替换为要推送的本地分支的名称, 替换为要推送到的远程分支的名称。_git remote 智能切换仓库
文章浏览阅读1.5k次。配置eslint校验代码工具_eslint 实时校验
文章浏览阅读1.2k次,点赞28次,收藏26次。Git入门基础介绍,什么是Git,如何使用Git,以及Git的工作的基本原理
文章浏览阅读2.7k次。基于官方给出的几种不同环境不同的安装方式,本文将会选择在使用.zip文件在Windows上安装Elasticsearch在Linux或macOS上从存档文件安装ElasticsearchInstall Elasticsearch with Docker (此种方式待定)使用Docker安装Elasticsearch。_elasticsearch安装部署windows
文章浏览阅读3.3k次,点赞5次,收藏11次。【Linux驱动】内核模块编译 —— make modules 的使用(单模块编译、多模块编译)_make modules
文章浏览阅读1k次。docker启动es报错_max virtual memory areas vm.max_map_count [65530] is too low, increase to at
文章浏览阅读4.2k次,点赞2次,收藏6次。使用docker单机安装elasticsearch后再安装kibana时找不到es。_unable to retrieve version information from elasticsearch nodes. security_ex
文章浏览阅读1.1k次。日志处理对于任何现代IT系统都是关键部分,本教程专为新手设计,通过详细解释Logstash的三大核心组件,为您展示如何从零开始搭建强大的日志处理系统。您还将学习如何同步MySQL数据到Elasticsearch,并通过一个"Hello World"示例快速入门。无论您是完全的新手还是有一些基础,本教程都将引导您顺利掌握Logstash的基本操作和高级应用。_logstash mysql
文章浏览阅读1.1w次,点赞5次,收藏25次。执行这条指令之后,你的本地项目就与远程Git仓库建立了连接,你就可以开始对你的代码进行版本追踪和协作开发了。使用“git remote add origin”指令,可以轻松地将本地项目连接到远程Git仓库。git remote set-url origin 执行这条指令之后,Git就会将已经添加的名为“origin”的仓库删除。git remote add origin 其中,是你的远程Git仓库的网址。_git remote add origin