【elasticsearch】elasticsearch8.0.1使用rpm包安装并启用TLS

news/2024/7/7 6:40:37 标签: elasticsearch

背景

公司的业务需要在加密的情况下使用,为此,研究测试了一下es8是如何启用TLS的。以下是测试使用过程。

x-pack了解

在 Elasticsearch 7.11.0 版本及更高版本中,X-Pack 功能在默认情况下已经整合到 Elastic Stack 的各个组件中,并且具有不同的名称和许可证。以下是 Elastic Stack 中一些主要的 X-Pack 功能和对应的新名称:

  • 安全性(Security):提供了身份验证、授权、加密通信和安全审计等功能,用于保护 Elasticsearch 和 Kibana 的访问和数据安全。

  • 警报(Alerting):用于配置和管理警报规则,当符合特定条件时,发送通知、触发操作或运行自定义脚本。

  • 监控(Monitoring):提供了集群健康状况、节点性能和资源使用情况等实时监控指标,以及用于可视化和分析的监控仪表板。

  • 报告(Reporting):用于生成漂亮的报表和可视化图表,支持将报告导出为 PDF、CSV 或 PNG 格式,并支持计划定期生成和发送报告。

  • 图形探索(Graph Exploration):用于分析和可视化数据之间的关系,帮助发现隐藏的模式和连接。

  • 机器学习(Machine Learning):提供了强大的机器学习功能,用于自动检测异常、预测趋势和进行故障检测。

请注意,具体的功能和名称可能会随着 Elastic Stack 版本的更新而有所变化,请参考官方文档以获取最新的信息和功能详细说明。

基本知识

1、默认情况下,服务器将使用两个端口进行通讯,9200与9300:

  • 9200,用于http通讯,各类restful客户端,例如kibana,浏览器直接访问、agent等等需要通过该端口与服务器连接。
  • 9300,用于elasticsearch服务器集群内各服务器节点间的通讯。

2、如果首次使用yum或者rpm按装elasticsearch服务器,安装程序会自动进行安全配置,并生成几个安全配置需要的文件,如ca的keystore、用于http加密通讯的keystore(http.p12)等,这些最好保留下来,当然,我们也可以用它提供的证书工具在后面自行创建。注意,如果不是首次安装,而又希望系统再次自动生成安全配置,需要先把/var/lib/elasticsearch里的东西删除干净。

3、通过自动安全配置生成的几个文件会放在/usr/share/elasticsearch下:

  • elastic-stack-ca.p12 keystore文件,存储了ca的公共证书及用于签发其他证书的密钥。(默认没有这个文件,可以自己手动生成)
  • transport.p12 包含了传输层密钥和证书,用于elasticsearch节点间加密通讯。
  • http.p12 这个keystore存储着http加密通讯需要的证书和密钥。
  • http_ca.crt 证书文件,用于集群内的http通讯加密。

es安装

环境介绍

单台 centos7部署单节点elasticsearch8.0.1

下载安装

elasticsearch中文下载地址:https://elasticsearch.cn/download/
选择自己需要的版本(windows、Linux、mac等),但需要注意不同版本之间的区别,我此次使用es 8.0.1的rpm包进行测试。

#rpm包下载
[root@k8s-m2 ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.0.1-x86_64.rpm
#直接使用rpm安装
warning: elasticsearch-8.0.1-x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY
Preparing...                          ################################# [100%]
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Updating / installing...
   1:elasticsearch-0:8.0.1-1          ################################# [100%]
warning: ignoring JAVA_HOME=/opt/jdk1.8.0_65; using bundled JDK
warning: ignoring JAVA_HOME=/opt/jdk1.8.0_65; using bundled JDK
--------------------------- 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 : =GAe2y2Rqi0mvxjFMDZk

If 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 systemd
 sudo systemctl daemon-reload
 sudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executing
 sudo systemctl start elasticsearch.service
warning: ignoring JAVA_HOME=/opt/jdk1.8.0_65; using bundled JDK
warning: ignoring JAVA_HOME=/opt/jdk1.8.0_65; using bundled JDK```

正常情况下,该版本的安装会出现以上的一些信息,如果没有,可能是由于不是第一次安装有之前遗留下的一些文件。仔细查看上面的输出信息说明,默认情况下认证已经启用并配置好,节点的加入方式,密码重置,token的生成等。

环境调整
由于es服务需要服务器调整连接数,修改limits.conf文件,如下:

vim /etc/security/limits.conf  
* soft nofile 655350
* hard nofile 655350

调整vm.max_map_coun,检查当前的 vm.max_map_count 值:如果当前的值小于 262144,需要调整。否则,如果当前的值已经达到或超过 262144,那么可以不进行任何更改,当然也可以适量调大一点。

[root@k8s-m2 ~]# sysctl vm.max_map_count
[root@k8s-m2 ~]# echo "vm.max_map_count=655360" >> /etc/sysctl.conf 
[root@k8s-m2 ~]# sysctl -p

jvm使用内存大小调整,默认情况下,es配置使用的是-Xms4g和-Xmx4g,可以按照自己所需进行调整。

启动

[root@k8s-m2 opt]# systemctl start elasticsearch.service
[root@k8s-m2 opt]# systemctl status  elasticsearchelasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2023-10-09 10:44:39 CST; 20min ago
     Docs: https://www.elastic.co
 Main PID: 24259 (java)
    Tasks: 96
   Memory: 4.4G
   CGroup: /system.slice/elasticsearch.service
           ├─24259 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -Djava.security.manager=allow -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile...
           └─24694 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

Oct 09 10:44:12 k8s-m2 systemd[1]: Starting Elasticsearch...
Oct 09 10:44:39 k8s-m2 systemd[1]: Started Elasticsearch.
[root@k8s-m2 opt]# 

常用命令说明

使用yum或者rpm安装时,和es相关的命令存放在/usr/share/elasticsearch/bin目录

#elastic用户命令重置,其他用户类似指定
[root@k8s-m2 opt]# /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic 
#默认生成证书时配置的密码等信息
[root@k8s-m2 opt]# /usr/share/elasticsearch/bin/elasticsearch-keystore list
warning: ignoring JAVA_HOME=/opt/jdk1.8.0_65; using bundled JDK
autoconfiguration.password_hash
keystore.seed
xpack.security.http.ssl.keystore.secure_password
xpack.security.transport.ssl.keystore.secure_password
xpack.security.transport.ssl.truststore.secure_password
#查看具体某项配置的密码
[root@k8s-m2 opt]# /usr/share/elasticsearch/bin/elasticsearch-keystore show xpack.security.http.ssl.keystore.secure_password
warning: ignoring JAVA_HOME=/opt/jdk1.8.0_65; using bundled JDK
0w9Z7YiEQG2rMWprA-8rYQ
#修改具体某项的密码,如果之前已经设置,可以覆盖
[root@k8s-m2 opt]# /usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password

#命令行检查
[root@k8s-m2 certs]# curl --cacert http_ca.crt -u elastic:=GAe2y2Rqi0mvxjFMDZk  -XGET "https://192.168.2.141:9200/"
{
  "name" : "k8s-m2",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "v5HBM6ACRiy31DBZmSa58g",
  "version" : {
    "number" : "8.0.1",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "801d9ccc7c2ee0f2cb121bbe22ab5af77a902372",
    "build_date" : "2022-02-24T13:55:40.601285296Z",
    "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"
}

#更多选项查看,按自己所需查看
[root@k8s-m2 certs]# curl --cacert http_ca.crt -u elastic:=GAe2y2Rqi0mvxjFMDZk  -XGET "https://192.168.2.141:9200/_cat"
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
/_cat/ml/anomaly_detectors
/_cat/ml/anomaly_detectors/{job_id}
/_cat/ml/trained_models
/_cat/ml/trained_models/{model_id}
/_cat/ml/datafeeds
/_cat/ml/datafeeds/{datafeed_id}
/_cat/ml/data_frame/analytics
/_cat/ml/data_frame/analytics/{id}
/_cat/transforms
/_cat/transforms/{transform_id}

kibana连接加密的es

kibana下载安装

[root@k8s-m2 opt]# wget https://artifacts.elastic.co/downloads/kibana/kibana-8.0.1-x86_64.rpm
[root@k8s-m2 opt]# rpm -ivh kibana-8.0.1-x86_64.rpm

生成kibana需要的相关证书

注意在这过程中要输入密码,具体密码为上面/usr/share/elasticsearch/bin/elasticsearch-keystore show xpack.security.http.ssl.keystore.secure_password查看到的密码。

[root@k8s-m2 certs]# pwd
/etc/elasticsearch/certs
[root@k8s-m2 certs]# ll
-rw-rw---- 1 root elasticsearch 1915 Oct  9 09:57 http_ca.crt
-rw-rw---- 1 root elasticsearch 9981 Oct  9 09:57 http.p12
-rw-rw---- 1 root elasticsearch 5822 Oct  9 09:57 transport.p12

# Private Key 私钥
[root@k8s-m2 certs]# openssl pkcs12 -in http.p12 -nocerts -nodes > client.key
# Public Certificate 公共证书
[root@k8s-m2 certs]# openssl pkcs12 -in http.p12 -clcerts -nokeys > client.cer
# CA Certificate 签署公共证书的CA
[root@k8s-m2 certs]# openssl pkcs12 -in http.p12 -cacerts -nokeys -chain > client-ca.cer

[root@k8s-m2 certs]# mkdir /etc/kibana/config/
[root@k8s-m2 certs]# cp /etc/elasticsearch/certs/client* /etc/kibana/config/

主要配置修改

注意:使用的是kibana账户,密码不知道可以用elasticsearch-reset-password(/usr/share/elasticsearch/bin/elasticsearch-reset-password -u kibana)命令进行重置。

server.port: 5601
server.host: "192.168.2.141"
server.publicBaseUrl: "http://192.168.2.141:5601" #最好添加上
elasticsearch.username: "kibana"
elasticsearch.password: "THR__INXYkH_lLCO3vV1"
elasticsearch.ssl.certificate: /etc/kibana/config/client.cer   #相关路径最好写绝对路径
elasticsearch.ssl.key: /etc/kibana/config/client.key
elasticsearch.ssl.certificateAuthorities: /etc/kibana/config/client-ca.cer
elasticsearch.ssl.verificationMode: certificate

kibana启动并检查

[root@k8s-m2 opt]# systemctl start kibana
[root@k8s-m2 opt]# systemctl status kibana -l
#如果kibana异常,可以查看日志进行排查
[root@k8s-m2 opt]# tail -f  /var/log/kibana/kibana.log

kibana访问

使用上面配置的服务器IP+5601地址进行访问。
在这里插入图片描述
账号为elastic,密码为es启动时输出到界面的密码。当然不记得也可以进行修改。

更多关于elasticsearch的知识分享,请前往博客主页。编写过程中,难免出现差错,敬请指出


http://www.niftyadmin.cn/n/5078833.html

相关文章

MyBatis注解开发实现学生管理页面(分页pagehelper,多条件搜索,查看课程信息)

pom.xml <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apache.org/POM/4.0.0 …

S7-1200与力控通过S7协议通讯

测试环境&#xff1a;Win10、力控7.2SP3、1214DCDCDC 博途工控人平时在哪里技术交流博途工控人社群 博途工控人平时在哪里技术交流博途工控人社群 在画面管理中&#xff0c;有种弹出画面&#xff0c;也就是窗口提示画面&#xff0c; 1-PLC端配置 PLC IP设置为192.168.2.10 …

vim多文件的打开与关闭问题

vim命令模式下 &#xff1a; e 文件名字&#xff0c;打开文件&#xff1b; &#xff1a; bd &#xff0c;关闭当前文件

前端页面布局之【Flex布局】详解

目录 &#x1f31f;前言&#x1f31f;浏览器支持&#x1f31f;Flex简介&#x1f31f;Flex基本概念&#x1f31f;容器属性&#x1f31f;项目排列方向&#x1f31f;项目包裹方式&#x1f31f;项目水平对齐方式&#x1f31f;项目的垂直对齐方式&#x1f31f;多行对齐方式 &#x1…

C++ 基础知识 问答题(五)

PART1 1.int型整数的最大值和最小值分别是什么&#xff1f;如何用二进制表示&#xff1f;使用最大值和最小值进行计算时会出现什么问题&#xff1f; 2.类声明成指针相对于声明成对象有什么好处? 3.迭代器可以加减常数吗&#xff1f; 4.动态绑定是如何实现的&#xff1f; …

我的编程初学者之旅:那些愚蠢的代码

我的编程初学者之旅&#xff1a;那些愚蠢的代码 在编程的早期阶段&#xff0c;我犯了许多愚蠢的错误&#xff0c;这些错误让我深感尴尬&#xff0c;但也让我学到了很多。我想分享一些我曾经写过的愚蠢代码&#xff0c;希望它们能帮助其他初学者避免类似的错误。 没有正确理解…

Python Loguru 日志打印

在开发过程中&#xff0c;我们经常需要记录应用程序的运行状态和错误信息。日志是一种重要的工具&#xff0c;可以帮助我们快速定位和解决问题。Python3提供了多种日志库&#xff0c;其中Loguru是一个简单易用的日志库&#xff0c;它提供了丰富的功能和灵活的配置选项&#xff…

SpringBoot 实现EMQ设备的上下线告警

前言 上下线通知 我遇到了一个难题&#xff0c;即在使用EMQ X 4.4.10的开源版本时&#xff0c;我需要实现设备的上下线状态监控&#xff0c;但该4.4.10开源版本并未内置设备上下线提醒模块&#xff0c;只有企业版才内置了该模块。这为我带来了一些技术上的难题&#xff0c;迫…