在我之前的文章 “Elastic Stack 8.0 安装 - 保护你的 Elastic Stack 现在比以往任何时候都简单” 我详细地描述了如何在 macOS 安装 Elastic Stack。当时的目的也是为了显示这个按照和之前的 Elastic Stack 7.x 有什么不同的地方。当然最重要的是它的默认安全配置和之前的版本是完全不同。我也在 B 站上传了一个视频。之后,又收到一些反馈,说在那个视频里的安装是在前台运行的。如果 Elasticsearch 是在后台,也即是以服务的方式 ,那么我们该如何得到那些密码及 token 呢?

在今天的文章中,我将详述如何使用 Debian 安装包的形式来进行安装 Elastic Stack 8.1。

如何使用 Debian 安装包安装 Elastic Stack 8.x

如何使用 Debian 安装包安装 Elastic Stack 8.x_哔哩哔哩_bilibili

在哪里下载安装包

可以从我们的网站或我们的 APT 存储库下载 Elasticsearch 的 Debian 软件包。 它可用于在任何基于 Debian 的系统上安装 Elasticsearch,例如 Debian 和 Ubuntu。

该软件包包含免费和订阅功能。 开始 30 天试用以试用所有功能。

可以在下载 Elasticsearch 页面上找到 Elasticsearch 的最新稳定版本。 其他版本可以在过去的版本页面上找到。

注意:Elasticsearch 包含来自 JDK 维护者 (GPLv2+CE) 的 OpenJDK 捆绑版本。 要使用你自己的 Java 版本,请参阅 JVM 版本要求

导入 Elasticsearch PGP key

我们使用带有指纹的 Elasticsearch 签名密钥(PGP 密钥 D88E42B4,可从 https://pgp.mit.edu 获得)对我们所有的包进行签名:

4609 5ACC 8548 582C 1A26 99A9 D27D 666C D88E 42B4

下载并安装公共签名密钥:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

从 APT 存储库安装

在继续之前,你可能需要在 Debian 上安装 apt-transport-https 软件包:

sudo apt-get install apt-transport-https

将存储库定义保存到 /etc/apt/sources.list.d/elastic-8.x.list:

echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

注意:这些指令不使用 add-apt-repository 有几个原因:

  • add-apt-repository 将条目添加到系统 /etc/apt/sources.list 文件,而不是在 /etc/apt/sources.list.d 中干干净净地为每个存储库文件添加
  • add-apt-repository 不是许多发行版上默认安装的一部分,并且需要许多非默认依赖项。
  • 旧版本的 add-apt-repository 总是添加一个 deb-src 条目,这会导致错误,因为我们不提供源包。 如果你添加了 deb-src 条目,你将看到类似以下的错误,直到你删除 deb-src 行:

    Unable to find expected entry 'main/source/Sources' in Release file
    (Wrong sources.list entry or malformed file)
    

你可以使用以下命令安装 Elasticsearch Debian 软件包:

sudo apt-get update && sudo apt-get install elasticsearch

警告:如果同一个 Elasticsearch 存储库存在两个条目,你将在 apt-get update 期间看到如下错误:

Duplicate sources.list entry https://artifacts.elastic.co/packages/8.x/apt/ ...`

检查 /etc/apt/sources.list.d/elasticsearch-8.x.list 中的重复条目或在 /etc/apt/sources.list.d/ 和 /etc/apt/ 中的文件中找到重复条目 source.list 文件。

注意:在基于 systemd 的发行版上,安装脚本将尝试设置内核参数(例如 vm.max_map_count); 你可以通过屏蔽 systemd-sysctl.service 单元来跳过此步骤。

parallels@liuxg:~$ sudo apt-get update && sudo apt-get install elasticsearch
[sudo] password for parallels:
Hit:1 https://artifacts.elastic.co/packages/8.x/apt stable InRelease
Hit:2 http://ports.ubuntu.com/ubuntu-ports focal InRelease
Hit:3 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease
Hit:4 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease
Hit:5 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:elasticsearch
0 upgraded, 1 newly installed, 0 to remove and 142 not upgraded.
Need to get 328 MB of archives.
After this operation, 560 MB of additional disk space will be used.
Get:1 https://artifacts.elastic.co/packages/8.x/apt stable/main arm64 elasticsearch arm64 8.1.0 [328 MB]
Fetched 328 MB in 30s (11.0 MB/s)
Selecting previously unselected package elasticsearch.
(Reading database ... 141426 files and directories currently installed.)
Preparing to unpack .../elasticsearch_8.1.0_arm64.deb ...
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Unpacking elasticsearch (8.1.0) ...
Setting up elasticsearch (8.1.0) ...
--------------------------- Security autoconfiguration information ------------------------------Authentication and authorization are enabled.
TLS for the transport and HTTP layers is enabled and configured.The generated password for the elastic built-in superuser is : kHbQ9_rzSo31vBpCpWdXIf this node should join an existing cluster, you can reconfigure this with
'/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token <token-here>'
after creating an enrollment token on your existing cluster.You can complete the following actions at any time:Reset the password of the elastic built-in superuser with
'/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic'.Generate an enrollment token for Kibana instances with '/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana'.Generate an enrollment token for Elasticsearch nodes with
'/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node'.-------------------------------------------------------------------------------------------------
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemdsudo systemctl daemon-reloadsudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executingsudo systemctl start elasticsearch.service

如上所示,它清楚地显示了超级用户 elastic 的密码:kHbQ9_rzSo31vBpCpWdX。

首先,我们查看 elasticsearch 服务是否已经成功地运行起来了:

parallels@liuxg:~$ service elasticsearch status
● elasticsearch.service - ElasticsearchLoaded: loaded (/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)Active: inactive (dead)Docs: https://www.elastic.co

如上所示,elasticsearch 服务还没有被运行起来。我们一种方式是执行如上所示的命令:

### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemdsudo systemctl daemon-reloadsudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executingsudo systemctl start elasticsearch.service

这样当我们的 Debian/Ubuntu 机器启动后,elasticsearch 服务会被自动启动。我们不再需要手动来启动这个服务了。

另外一种方式是我们手动来启动 elasticsearch 服务:

sudo service elasticsearch start

当我们以这种方式启动后,那么每次 Debian/Ubuntu 机器启动后,我们需要再次使用同样的命令来启动 elasticsearch 服务。我们可以使用如下的命令来查看端口地址 9200 是否已经被侦听:

ss -lntp

或者使用 watch 来监听:

watch -n l ss -lntp

我们使用如下的命令来查看 elasticsearch 服务的状态:

parallels@liuxg:~$ service elasticsearch status
● elasticsearch.service - ElasticsearchLoaded: loaded (/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)Active: active (running) since Wed 2022-03-16 16:21:48 CST; 1min 20s agoDocs: https://www.elastic.coMain PID: 6551 (java)Tasks: 59 (limit: 4576)Memory: 2.3GCGroup: /system.slice/elasticsearch.service├─6551 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkadd>└─6830 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-aarch64/bin/controllerMar 16 16:21:40 liuxg systemd[1]: Starting Elasticsearch...
Mar 16 16:21:48 liuxg systemd[1]: Started Elasticsearch.

显然我们的 elasticsearch 服务已经成功地运行起来了。

我们可以使用如下的命令来检查 Elasticsearch 是否成功地运行起来了:

curl --insecure --user elastic:kHbQ9_rzSo31vBpCpWdX https://localhost:9200
parallels@liuxg:~$ curl --insecure --user elastic:kHbQ9_rzSo31vBpCpWdX https://localhost:9200
{"name" : "liuxg","cluster_name" : "elasticsearch","cluster_uuid" : "0GaowezJRY2f2RGpgYBIOQ","version" : {"number" : "8.1.0","build_flavor" : "default","build_type" : "deb","build_hash" : "3700f7679f7d95e36da0b43762189bab189bc53a","build_date" : "2022-03-03T14:20:00.690422633Z","build_snapshot" : false,"lucene_version" : "9.0.0","minimum_wire_compatibility_version" : "7.17.0","minimum_index_compatibility_version" : "7.0.0"},"tagline" : "You Know, for Search"
}

请注意上面的 --insecure 选项。这是因为我们使用的是自签名的证书,所以我们可以通过这种方式来进行访问。请注意上面的 kHbQ9_rzSo31vBpCpWdX 是超级用户 elastic 的密码。

如果我们想要使用证书来进行访问,首先,我们需要切换到 root 用户,然后使用如下的命令:

root@liuxg:/etc/elasticsearch/certs# ls
http_ca.crt  http.p12  transport.p12
root@liuxg:/etc/elasticsearch/certs# curl --cacert http_ca.crt --user elastic:kHbQ9_rzSo31vBpCpWdX https://localhost:9200
{"name" : "liuxg","cluster_name" : "elasticsearch","cluster_uuid" : "0GaowezJRY2f2RGpgYBIOQ","version" : {"number" : "8.1.0","build_flavor" : "default","build_type" : "deb","build_hash" : "3700f7679f7d95e36da0b43762189bab189bc53a","build_date" : "2022-03-03T14:20:00.690422633Z","build_snapshot" : false,"lucene_version" : "9.0.0","minimum_wire_compatibility_version" : "7.17.0","minimum_index_compatibility_version" : "7.0.0"},"tagline" : "You Know, for Search"
}

在上面,我们可以看到在路径 /etc/elasticsearch/certs 它含有访问所需要的证书。我们或者在普通用户下使用如下的命令来进行访问:

当然我们也可以在浏览器中进行访问:

请注意上面的  192.168.0.9 是我们的 ubuntu 机器的私有 IP 地址。我们可以通过如下的方式来获得:

parallels@liuxg:~$ ifconfig | grep 192inet 192.168.0.10  netmask 255.255.255.0  broadcast 192.168.0.255

我们必须使用 https 的形式来进行访问。在上面的浏览器中,我们打入 thisisunsafe。我们就可以看到:

点击 Sign In:

从上面,我们看出来访问是成功的。

下载 debian 安装包并手动安装

上面介绍的步骤是使用 API 仓库来进行安装的。接下来,我们可以直接从 Elastic 的官方网站下载安装包进行安装。Elasticsearch v8.1.0 的 Debian 包可以从网站下载并安装如下:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.1.0-amd64.deb
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.1.0-amd64.deb.sha512
shasum -a 512 -c elasticsearch-8.1.0-amd64.deb.sha512
sudo dpkg -i elasticsearch-8.1.0-amd64.deb

比较下载的 Debian 包的 SHA 和发布的校验和,应该输出 elasticsearch-{version}-amd64.deb: OK。

使用 systemd 运行 Elasticsearch

要将 Elasticsearch 配置为在系统启动时自动启动,请运行以下命令:

sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service

我们可以通过如下的命令来检查 elasticsearch.service 是否已经启动:

systemctl is-enabled elasticsearch.service
$ systemctl is-enabled elasticsearch.service
disabled

如果我们不想在系统启动时启动这个服务,我们可以使用如下的命令:

sudo systemctl disable elasticsearch.service

Elasticsearch 可以按如下方式启动和停止:

sudo systemctl start elasticsearch.service
sudo systemctl stop elasticsearch.service

这些命令不提供关于 Elasticsearch 是否成功启动的反馈。 相反,此信息将写入位于 /var/log/elasticsearch/ 的日志文件中。

如果你对 Elasticsearch 密钥库进行了密码保护,则需要使用本地文件和 systemd 环境变量向 systemd 提供密钥库密码。 这个本地文件应该在它存在时受到保护,一旦 Elasticsearch 启动并运行,就可以安全地删除它。

echo "keystore_password" > /path/to/my_pwd_file.tmp
chmod 600 /path/to/my_pwd_file.tmp
sudo systemctl set-environment ES_KEYSTORE_PASSPHRASE_FILE=/path/to/my_pwd_file.tmp
sudo systemctl start elasticsearch.service

默认情况下,Elasticsearch 服务不会在 systemd 日志中记录信息。 要启用 journalctl 日志记录,必须从 elasticsearch.service 文件的 ExecStart 命令行中删除 --quiet 选项。

启用 systemd 日志记录后,可以使用 journalctl 命令获得日志记录信息:

为了查看最新的日志:

sudo journalctl -f

要列出 elasticsearch 服务的日记条目:

sudo journalctl --unit elasticsearch

要列出从给定时间开始的 elasticsearch 服务的日志条目:

sudo journalctl --unit elasticsearch --since  "2016-10-30 18:17:16"

删除 Elasticsearch

我们可以使用如下的方法来删除已经安装的 Elasticsearch:

sudo apt remove elasticsearch
sudo apt purge elasticsearch

如果我们在之前已经启动过 elasticsearch 服务,那么就会在 /var/lib/elasticsearch 文件夹中生成相应的文件。那么经过上述命令删除已经安装过的文件,但是 /var/lib/elasticsearch 目录将继续保存下来。在这种情况下,如果我们再次安装 Elasticsearch 的话,那么就不会出现之前的如下信息:

--------------------------- Security autoconfiguration information ------------------------------Authentication and authorization are enabled.
TLS for the transport and HTTP layers is enabled and configured.The generated password for the elastic built-in superuser is : kHbQ9_rzSo31vBpCpWdXIf this node should join an existing cluster, you can reconfigure this with
'/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token <token-here>'
after creating an enrollment token on your existing cluster.You can complete the following actions at any time:Reset the password of the elastic built-in superuser with
'/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic'.Generate an enrollment token for Kibana instances with '/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana'.Generate an enrollment token for Elasticsearch nodes with
'/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node'.-------------------------------------------------------------------------------------------------

在安装的时候,它会出现如下的信息:

parallels@liuxg:~$ sudo apt install elasticsearch
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:elasticsearch
0 upgraded, 1 newly installed, 0 to remove and 36 not upgraded.
Need to get 328 MB of archives.
After this operation, 560 MB of additional disk space will be used.
Get:1 https://artifacts.elastic.co/packages/8.x/apt stable/main arm64 elasticsearch arm64 8.1.0 [328 MB]
Fetched 328 MB in 42s (7,797 kB/s)
Selecting previously unselected package elasticsearch.
(Reading database ... 247263 files and directories currently installed.)
Preparing to unpack .../elasticsearch_8.1.0_arm64.deb ...
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Unpacking elasticsearch (8.1.0) ...
Setting up elasticsearch (8.1.0) ...
--------------------------- Security autoconfiguration information ------------------------------Skipping auto-configuration because security features appear to be already configured.-------------------------------------------------------------------------------------------------
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start au
tomatically using systemdsudo systemctl daemon-reloadsudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executingsudo systemctl start elasticsearch.service
Created elasticsearch keystore in /etc/elasticsearch/elasticsearch.keystore

也就是说它不会出现之前的密码及安全设置了。如果我们使用如下的命令来启动 elasticsearch 服务的话:

sudo service elasticsearch start

那么我们将只能使用 http://localhost:9200 或者 http://privateIP:9200 来进行访问,而不是之前的那种 https 的访问。特别值得注意的是,我们可以使用之前的 elastic 超级用户来进行访问。访问密码是在上一次安装过程中生成的密码。

如何避免安装的 Elasticsearch 被自动升级

您可以选择通过持有安装包来阻止 APT 自动更新包。 这在生产环境中很重要,因为你不想在没有计划的情况下无意触发 Elasticsearch 升级:

sudo apt-mark hold elasticsearch

你可以解除持有包并通过系统的升级而升级:

sudo apt-mark unhold elasticsearch

如何彻底删除之前的 Elasticsearch 安装

在有些时候,我们需要彻底地删除已经安装的 Elasticsearch,那么我们可以使用如下的命令:

sudo apt remove elasticsearch
sudo apt purge elasticsearch
sudo rm -rf /var/lib/elasticsearch

经过上面的命令运行后,我们将回到原点。再次安装 Elasticsearch 时,它将自动帮我们生产相应的安全配置。

更多阅读:How To Install and Configure Elasticsearch | DigitalOcean | DigitalOcean

Elasticsearch: 使用 Debian 安装包来安装 Elasticsearch 8.x相关推荐

  1. Elasticsearch:使用 RPM 安装包来安装 Elastic Stack 8.x

    在我之前的文章 "Elasticsearch: 使用 Debian 安装包来安装 Elasticsearch 8.x",我详述了如何使用 RPM 安装包来安装 Elasticsea ...

  2. LNMP一键安装包详细安装教程

    原文地址 今天主要带给大家的是lnmp一键安装包的安装,逍遥乐一直使用的lnmp一键安装包,方便快捷.这里推荐军哥的lnmp一键安装包,以下是来自军哥lnmp一键安装包安装教程,详情请移步http:/ ...

  3. 【ROS1总结】使用bloom-generat打包ROS包生成debian安装包

    > 说明:<br><br> > 本文首发于 Playfish Blog,转载请保留链接. 前言 在之前的博客中,介绍了ROS包的编写,在本节中将讲述如何将之前写的R ...

  4. CATIA.P3.V5R21兼容版安装包和安装视频分享,CATIA新手必备

    CATIA.P3.V5R21兼容版安装包和安装视频分享,CATIA新手必备 CATIA.P3.V5R21兼容版,支持在XP.windows 7.windows 8.windows 10等多个系统使用. ...

  5. centos mysql安装包_Centos7下安装包方式安装MySQL

    安装包下载地址:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar 第一步:在 /h ...

  6. 安装软件—用安装包形式安装

    安装软件-用安装包形式安装 1.安装依赖包 2.安装nginx 3.编译nginx 4.执行命令 5.执行make命令 6.执行make install命令 7.启动nginx 8.访问nginx 离 ...

  7. wp安装install.php,wordpress安装包怎么安装

    wordpress安装包怎么安装 wordpress安装方法: 1.首先将WordPress安装包解压至一个空文件夹,并上传它.这里通常需要用到FTP工具,个人比较喜欢FileZilla,免费.开源的 ...

  8. Ubuntu下利用安装包手动安装Apache和Php

    前言 首先说一下,Ubuntu中常用的安装软件的方法有两种: 1. apt-get方法 使用apt-get install来安装应用程序算是最常见的一种安装方法,apt-get的基本软件安装命令是: ...

  9. PB安装包,PB安装程序,PB开发工具,powerbuilder安装包,powerbuilder安装程序,powerbuilder开发工具下载地址

    B安装包,PB安装程序,PB开发工具,powerbuilder安装包,powerbuilder安装程序,powerbuilder开发工具下载地址 如果不能打开请复制网址粘贴到浏览器中 http://p ...

最新文章

  1. Leetcode 50. Pow(x, n)
  2. SAP MM 采购附加费计入物料成本之二
  3. Android数据存储方式
  4. cgi,fastcgi,php-cgi,php-fpm之间的关系
  5. 【华科考研机试题】阶乘
  6. java接收c语言的结构体
  7. 获得ABAP report里定义的所有变量及type - GET_GLOBAL_SYMBOLS
  8. python3动态加载模块的方法实现
  9. 应用上云2小时烧掉近50万,创始人:差点破产,简直噩梦
  10. 让你的git bash更好看更实用
  11. Python画图(直方图、多张子图、二维图形、三维图形以及图中图)
  12. 从零学ELK系列(一):为什么要跟我学从零学ELK系列
  13. 写一个函数,输入一个十六进制,输出相应的十进制数。
  14. Gym101237C The Palindrome Extraction Manacher、SAM、倍增
  15. i9-10900K比9900K性能提升了多少?i9-10900K和i9-9900K区别对比评测
  16. android模拟鼠标键盘,有关通过Happy Android模拟器的鼠标和键盘操作进行手机游戏的详细设置的图形教程...
  17. 深信服安服实习生面试心得
  18. Matlab中mod函数使用
  19. 各种零知识证明的比较!
  20. 《计算机网络参考模型》

热门文章

  1. 2021年安全员-B证(陕西省)考试题及安全员-B证(陕西省)考试报名
  2. python:素数伴侣
  3. 注册商标VS购买商标
  4. 研发投入不代表技术实力强,芯片第一归苹果,其他芯片都是组装
  5. 将十二个“一”是十二个异性追求者,请描述一下对它们的感受
  6. Linux小白向 每日学习之网络管理
  7. 云打包苹果证书生成、上架和应用截屏攻略
  8. 微信小程序canvas绘制插件
  9. FatMouse‘s Speed
  10. 性能优化常用工具及经验总结