首页 > 系统相关 >基于Ubuntu 24.04 LTS安装elasticsearch-8.14.3+Kibanna

基于Ubuntu 24.04 LTS安装elasticsearch-8.14.3+Kibanna

时间:2024-07-14 12:31:26浏览次数:11  
标签:LTS opt elastic 24.04 Kibana Kibanna elasticsearch 8.14 Elasticsearch

1.安装Elasticsearch

1.1 下载Elasticsearch

# 1. 更新包索引
sudo apt update

# 2. 升级已安装的软件包
sudo apt upgrade -y

# 3. 进入 /opt 目录
cd /opt

# 4. 下载Elasticsearch压缩包
sudo wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.14.3-linux-x86_64.tar.gz

# 5. 下载校验文件
sudo wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.14.3-linux-x86_64.tar.gz.sha512

# 6. 校验下载的文件
sudo shasum -a 512 -c elasticsearch-8.14.3-linux-x86_64.tar.gz.sha512 

# 7. 解压缩下载的文件
sudo tar -xzf elasticsearch-8.14.3-linux-x86_64.tar.gz

# 8. 进入解压后的目录
cd elasticsearch-8.14.3

1.2  运行时遇到错误

运行指令

./bin/elasticsearch

遇到错误

[2024-07-14T08:38:12,606][ERROR][o.e.b.Elasticsearch      ] [liber-VMware-Virtual-Platform] fatal exception while booting Elasticsearchjava.lang.RuntimeException: can not run elasticsearch as root
        at [email protected]/org.elasticsearch.bootstrap.Elasticsearch.initializeNatives(Elasticsearch.java:286)
        at [email protected]/org.elasticsearch.bootstrap.Elasticsearch.initPhase2(Elasticsearch.java:169)
        at [email protected]/org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:74)

See logs for more details.

ERROR: Elasticsearch did not exit normally - check the logs at /opt/elasticsearch-8.14.3/logs/elasticsearch.log

ERROR: Elasticsearch died while starting up, with exit code 1
root@liber-VMware-Virtual-Platform:/opt/elasticsearch-8.14.3# 
 

解决方案

# 1. 创建一个新的用户并设置密码
adduser elasticuser

# 2. 更改Elasticsearch目录的所有者
chown -R elasticuser:elasticuser /opt/elasticsearch-8.14.3

# 3. 切换到新用户并启动Elasticsearch
su elasticuser

# 4. 重新启动
./bin/elasticsearch

1.3  运行的结果

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.

ℹ️  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  SYV2_Rgz6LlSIQH7fkG5
# 解释: 系统为 elastic 用户生成了一个随机密码。你可以使用这个密码进行登录和管理。如果需要重置密码,可以使用 `bin/elasticsearch-reset-password -u elastic` 命令。

ℹ️  HTTP CA certificate SHA-256 fingerprint:
  7a1ff37ac53755fa454be746a9bd1befba6ffebde3222acaf16120add82618da
# 解释: 这是 HTTP CA 证书的 SHA-256 指纹,用于验证证书的真实性。你可以在需要时使用此指纹来验证证书。

ℹ️  Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTkyLjE2OC4xNjMuMTI5OjkyMDAiXSwiZmdyIjoiN2ExZmYzN2FjNTM3NTVmYTQ1NGJlNzQ2YTliZDFiZWZiYTZmZmViZGUzMjIyYWNhZjE2MTIwYWRkODI2MThkYSIsImtleSI6IkxBVzNycEFCcjlmUFhPNjRyQ25hOjZWUWpnbVk1UkVxenkzcGt6X201TWcifQ==
# 解释: 系统生成了一个注册令牌(enrollment token),用于在 Kibana 中配置和连接到 Elasticsearch 集群。令牌有效期为 30 分钟。你可以启动 Kibana,然后在浏览器中输入该令牌进行配置。

ℹ️  Configure other nodes to join this cluster:
• On this node:
  ⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.
  # 解释: 使用命令 `bin/elasticsearch-create-enrollment-token -s node` 创建一个节点注册令牌。

  ⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.
  # 解释: 在 `config/elasticsearch.yml` 文件中取消注释 `transport.host` 设置。

  ⁃ Restart Elasticsearch.
  # 解释: 重启 Elasticsearch 以应用更改。

• On other nodes:
  ⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.
  # 解释: 在其他节点上,使用生成的注册令牌和命令 `bin/elasticsearch --enrollment-token <token>` 启动 Elasticsearch,使其加入到集群中。

操作:复制同IP标签,进行访问验证,验证指令

curl -u elastic:SYV2_Rgz6LlSIQH7fkG5 -X GET "https://localhost:9200/" -k

注解

  • -u elastic:SYV2_Rgz6LlSIQH7fkG5:使用用户名elastic和相应的密码进行基本身份验证。
  • -X GET:指定HTTP请求方法为GET。
  • "https://localhost:9200/":目标URL,即Elasticsearch的本地地址。
  • -k:跳过SSL证书验证(因为我们使用的是自签名证书)

1.4  开启远程访问

1.远程访问的配置

#编辑配置文件
nano /opt/elasticsearch-8.14.3/config/elasticsearch.yml

# 取消注释并设置network.host为0.0.0.0以允许所有网络接口访问
network.host: 0.0.0.0

# 确保http.port设置为默认的9200端口
http.port: 9200

 操作:键盘:CTRL+X 保存Y确认,重新启动elasticsearch

2.防火墙的配置

如果你的Ubuntu服务器上启用了防火墙(UFW),需要允许外部访问Elasticsearch的默认端口(9200):

# 1. 添加防火墙规则
ufw allow 9200/tcp
# 2. 重新加载防火墙
ufw reload

3.验证远程访问地址,协议要HTTPS

curl -u elastic:SYV2_Rgz6LlSIQH7fkG5 -X GET "https://192.168.163.129:9200/" -k

Ubuntu下的验证: 

浏览器下的验证:

点击高级,继续访问,然后输入生成的用户名和密码即可。

最后验证的结果:

1.5  创建systemd服务(可选)

1.创建服务 

# 创建Elasticsearch的systemd服务文件
nano /etc/systemd/system/elasticsearch.service

 2. 添加以下内容到文件

[Unit]
# Unit节描述了服务的元数据和依赖关系

Description=Elasticsearch
# Description: 服务的描述信息,用于描述这个服务的用途

Documentation=https://www.elastic.co
# Documentation: 提供了一个指向相关文档的链接

Wants=network-online.target
# Wants: 指定服务的启动依赖目标,确保网络在线

After=network-online.target
# After: 确保服务在指定的目标(网络在线)之后启动

[Service]
# Service节定义了服务的行为和运行参数

Environment=ES_HOME=/opt/elasticsearch-8.14.3
# Environment: 设置Elasticsearch的主目录环境变量

Environment=ES_PATH_CONF=/opt/elasticsearch-8.14.3/config
# Environment: 设置Elasticsearch配置文件路径环境变量

Environment=PID_DIR=/var/run/elasticsearch
# Environment: 设置Elasticsearch的PID文件存放目录环境变量

Environment=ES_SD_NOTIFY=true
# Environment: 设置Elasticsearch服务通知设置

WorkingDirectory=/opt/elasticsearch-8.14.3
# WorkingDirectory: 设置服务的工作目录

User=elasticuser
# User: 指定以哪个用户身份运行服务,这里设置为elasticuser

Group=elasticuser
# Group: 指定以哪个用户组身份运行服务,这里设置为elasticuser

ExecStart=/opt/elasticsearch-8.14.3/bin/elasticsearch
# ExecStart: 指定启动服务的命令,这里是启动Elasticsearch

StandardOutput=journal
# StandardOutput: 指定标准输出的目标,这里设置为journal

StandardError=inherit
# StandardError: 指定标准错误输出的目标,这里设置为inherit,继承标准输出

Restart=always
# Restart: 指定服务的重启策略,这里设置为always,表示服务崩溃后总是重启

LimitNOFILE=65535
# LimitNOFILE: 设置文件描述符的限制,这里设置为65535

[Install]
# Install节定义了安装的相关设置

WantedBy=multi-user.target
# WantedBy: 指定服务在哪个目标下可用,这里设置为multi-user.target,表示服务可以在多用户系统下运行

3.重新加载 systemd 守护进程

systemctl daemon-reload

4.启动并启用 Elasticsearch 服务

# 启动服务
systemctl start elasticsearch
# 设置自启
systemctl enable elasticsearch

5.验证 Elasticsearch 运行状态

systemctl status elasticsearch

参考文档:

在 Linux 或 MacOS 上从存档安装 Elasticsearch 

Linux环境下安装Elasticsearch,史上最详细的教程来啦~_linux elasticsearch-CSDN博客

2.安装Kibana

2.1 下载Kibanna

# 1. 更新包索引
apt update

# 2. 升级已安装的软件包
apt upgrade -y

# 3. 进入 /opt 目录
cd /opt

# 4. 下载Kibana压缩包
curl -O https://artifacts.elastic.co/downloads/kibana/kibana-8.14.3-linux-x86_64.tar.gz

# 5. 下载校验文件并验证压缩包
curl https://artifacts.elastic.co/downloads/kibana/kibana-8.14.3-linux-x86_64.tar.gz.sha512 | shasum -a 512 -c -

# 6. 解压缩下载的文件
tar -xzf kibana-8.14.3-linux-x86_64.tar.gz

# 7. 进入解压后的目录
cd kibana-8.14.3/

# 8. 修改配置文件
nano config/kibana.yml

配置文件内容:

# 设置 Kibana 服务的监听端口为 5601

server.port: 5601
# 设置 Kibana 服务的监听地址
server.host: "0.0.0.0"

# 配置 Kibana 连接的 Elasticsearch 实例地址
elasticsearch.hosts: ["http://localhost:9200"]

# 设置 Kibana 的界面语言为简体中文
i18n.locale: "zh-CN

# 9. 创建用户
adduser kibanauser

# 10. 更改Kibana目录的所有者
chown -R kibanauser:kibanauser /opt/kibana-8.14.3

# 11. 切换用户
su kibanauser

# 12. 运行
./bin/kibana

 

2.2 登录Kibanna

生成新的注册令牌:

# 执行指令
/opt/elasticsearch-8.14.3/bin/elasticsearch-create-enrollment-token  --scope kibana

 操作:先粘贴注册令牌,再点击配置Elastic

配置验证码,从Kibanna的启动界面寻找

然后进行验证码验证:

等待配置完成出现该页面,用户名密码同Elasticsearch访问的完全一样:

登录成功的页面:

2.3 默认分词器

  1.测试代码 



#创建索引
PUT /my-default-index
{
  "mappings": {
    "properties": {
      "content": {
        "type": "text"
      }
    }
  }
}
#添加文档
POST /my-default-index/_doc/1
{
  "content": "我的世界我做主"
}

#测试分词
POST /my-default-index/_analyze
{
  "text": "我的世界我做主"
}
#执行搜索
GET /my-default-index/_search
{
  "query": {
    "match": {
      "content": "世界"
    }
  }
}


2.测试分词结果

3.执行搜索结果

参考文档:

Kibanna安装

标签:LTS,opt,elastic,24.04,Kibana,Kibanna,elasticsearch,8.14,Elasticsearch
From: https://blog.csdn.net/qq_71387716/article/details/140411530

相关文章

  • saltStack自动化工具
    目录SaltStack自动化工具核心概念1.Master和Minion2.State3.Pillar4.Grains5.Modules6.Runner7.Reactor工作流程安装和配置1.配置hosts解析2.配置yum源3.saltstack安装3.1master节点3.2minion节点4.配置saltstack4.1master节点配置4.2配置minion节点5.接受认证......
  • Nessus Professional 10.7 Auto Installer for Ubuntu 24.04 (updated Jul 2024)
    NessusProfessional10.7AutoInstallerforUbuntu24.04(updatedJul2024)发布Nessus试用版自动化安装程序,支持macOSSonoma、RHEL9和Ubuntu24.04请访问原文链接:https://sysin.org/blog/nessus-auto-install-for-ubuntu/,查看最新版。原创作品,转载请保留出处。Ness......
  • Xubuntu24.04之设置高性能模式两种方式(二百六十一)
    简介:CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!优质专栏:Audio工程师进阶系列【原创干货持续更新中……】......
  • Ubuntu 22.04.4 LTS 安装 FreeRADIUS 3.0 和 Daloradius 2.2 搭建radius 认证服务器
    1ubuntu安装LAMP环境(安装nginx代替apache):Ubuntu22.04.4LTS安装phpapacheLAMP环境nginx-CSDN博客2安装freeradiussudoaptupdatesudoapt-getinstalllibmysqld-devsudoapt-getinstallfreeradius#先安装libmysqld-dev,否则启动可能报错Couldnotlink......
  • Numerical Results of T3DFP-N1 and irT3DFP-N1
    ......
  • Ubuntu 22.04.4 LTS 安装 php apache LAMP 环境nginx
    1安装php-fpmaptupdateapt-getinstallphp-fpm#配置php-fpm服务启动systemctlenablephp8.1-fpmsystemctlstartphp8.1-fpm#查看服务systemctlstatusphp8.1-fpm#查看版本root@iZbp1g7fmjea77vsqc5hmmZ:~#php-vPHP8.1.2-1ubuntu2.18(cli)(built:......
  • CobaltStrike的内网安全
    1.上线机器的Beacon的常用命令2.信息收集和网站克隆3.钓鱼邮件4.CS传递会话到MSF5.MSF会话传递到CS1上线机器的Beacon的常用命令介绍:CobaltStrike分为服务端和客户端,一般我们将服务端放在kali,客户端可以在物理机上面,或者虚拟机都可以启动服务端,首先创建一个监听(注意,这......
  • 最有效的ResultSet转换为JSON?
    最有效的ResultSet转换为JSON? 原文链接: https://cloud.tencent.com/developer/information/%E6%9C%80%E6%9C%89%E6%95%88%E7%9A%84ResultSet%E8%BD%AC%E6%8D%A2%E4%B8%BAJSON%EF%BC%9F-article最有效的ResultSet转换为JSON的方法是使用Java中的Jackson库。Jackson是一个......
  • Ubuntu24.04配置支持asp.net framework 4.0的apache服务器
    参考《在Linux(Ubuntu/openSUSE/CentOS)下配置ASP.NET(Apache+Mono)》,但由于操作系统版本不一样,部分命令要修改1、安装apachesudoapt-getinstallapache22、安装mono及apache支持模块,这里安装很正常,并没有文中提到的卡死情况,应该是已经修复这个bug了。sudoaptinstallmon......
  • 为Ubuntu-24.04-live-server-amd64磁盘扩容
    系列文章目录Ubuntu-24.04-live-server-amd64安装界面中文版文章目录系列文章目录前言一、检查系统本身情况1.用lsblk命令查看自己系统磁盘是什么状态2.用df-h命令查看文件系统的磁盘空间使用情况3.解决Ubuntu-24.04磁盘空间只能用一半的问题3-1扩展逻辑卷:3-2.......