将最新版的ElasticSearch8与Kibana8在CentOS7上跑起来
背景
以前也搭建体验过基于 ElasticSearch
7.x的服务及集群,不过当时一直在内网环境下运行,也没有进行其认证相关的配置 xpack
,我记得当时写的建议:由于 Elasticsearch
默认未启用内置的安全防御机制,因此在生产环境中不建议直接开放在公网上。否则,就是在网络上裸奔。。。这不, ElasticSearch
8.0来了,默认开启安全防护便是其中一个新特性,根据官方介绍, ElasticSearch
8.0带来的主要特性包括:
- 7.x REST API compatibility(通过头信息配置可兼容7.x REST API)
- Security features are enabled and configured by default(默认启用安全相关的配置:认证、授权、节点间以及与Kibana间的TLS传输)
- Better protection for system indices(更好地保护系统索引)
- New kNN search API(新增kNN搜索API)
- Storage savings for keyword, match_only_text, and text fields(升级的倒排索引,节约存储空间)
- Faster indexing of geo_point, geo_shape, and range fields(对地理信息相关数据更快地索引效率)
- PyTorch model support for natural language processing (NLP)(支持上传训练好的PyTorch模型至ElasticSearch进行自然语言处理)
系统环境
在 CentOS7
上进行安装,虚拟主机信息如下:
[root@hadoop1 local]# uname -a
Linux hadoop1 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@hadoop1 local]# cat /proc/version
Linux version 3.10.0-1127.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Mar 31 23:36:51 UTC 2020
[root@hadoop1 local]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
内存:4G
处理器:2*2
硬盘:100G
下载、安装并启动ElasticSearch8
[root@hadoop1 ~]# cd /usr/local/
[root@hadoop1 local]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.0.0-linux-x86_64.tar.gz
[root@hadoop1 local]# tar -xvf elasticsearch-8.0.0-linux-x86_64.tar.gz
[root@hadoop1 local]# mv elasticsearch-8.0.0 elasticsearch
[root@hadoop1 local]# cd elasticsearch
[root@hadoop1 elasticsearch]# ./bin/elasticsearch
问题1:不可使用root用户直接启动elasticsearch
org.elasticsearch.bootstrap. StartupException: java.lang. RuntimeException: can not run elasticsearch as root
解决方法:添加用户,并赋予对 elasticsearch
目录的权限
# 添加用户es-admin
[root@hadoop1 elasticsearch]# useradd es-admin
# 赋予对elasticsearch目录的权限
[root@hadoop1 elasticsearch]# chown -R es-admin:es-admin /usr/local/elasticsearch
# 切换至es-admin
[root@hadoop1 elasticsearch]# su es-admin
# 尝试启动ElasticSearch
[es-admin@hadoop1 elasticsearch]$ ./bin/elasticsearch
问题2:操作系统的默认配置不满足elasticsearch要求
ERROR: [2] bootstrap checks failed. You must address the points described in the following [2] lines before starting Elasticsearch.
bootstrap check failure [1] of [2]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
bootstrap check failure [2] of [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方法:
- 解决“max file descriptors [4096] for elasticsearch process is too low”问题:
# 先查看系统的默认配置
[es-admin@hadoop1 elasticsearch]$ ulimit -Hn
4096
[es-admin@hadoop1 elasticsearch]$ ulimit -Sn
1024# 切换至root
[es-admin@hadoop1 elasticsearch]$ exit
exit# 编辑vi /etc/security/limits.conf,在最后添加以下内容,注意要退出root用户重新登录后才会生效
[root@hadoop1 elasticsearch]# vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536# 验证我们的操作是否生效
[root@hadoop1 elasticsearch]# ulimit -Hn
65536
[root@hadoop1 elasticsearch]# ulimit -Sn
65536
- 解决“max virtual memory areas vm.max_map_count [65530] is too low”问题:
# 编辑vi /etc/sysctl.conf,在最后添加:
[es-admin@hadoop1 elasticsearch]$ vi /etc/sysctl.conf
vm.max_map_count = 262144# 记得使用sysctl -p刷新配置文件
[root@hadoop1 elasticsearch]# sysctl -p# 切换到es-admin用户
[root@hadoop1 elasticsearch]# su es-admin# 尝试启动
[es-admin@hadoop1 elasticsearch]$ ./bin/elasticsearch
不出意外,可正常启动 ElasticSearch
8.0服务,同时注意控制台打印的这段日志,其中包含了4部分重要信息:
elastic
用户的密码(登录ElasticSearch与Kibana的Web界面时需要~);- HTTP
CA
证书SHA-256
指纹; - 用于Kibana连接当前
ElasticSearch
服务的enrollment token
(注意有效期为30分钟!!); - 说明了如何让其他
ElasticSearch
节点加入当前集群的操作步骤(我会在下一篇介绍ElasticSearch8.0
分布式搜索引擎集群及其高可用测试)。
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ 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`):9SWTTFDuibtaS2*L0NRvHTTP CA certificate SHA-256 fingerprint:75480a9fc93649e2ebd8dd0a9f0721247e8cff32fdbc78abf0b30d7ac9c8e8bdConfigure 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):eyJ2ZXIiOiI4LjAuMCIsImFkciI6WyIxOTIuMTY4LjQ0LjEyNzo5MjAwIl0sImZnciI6Ijc1NDgwYTlmYzkzNjQ5ZTJlYmQ4ZGQwYTlmMDcyMTI0N2U4Y2ZmMzJmZGJjNzhhYmYwYjMwZDdhYzljOGU4YmQiLCJrZXkiOiJWYjg0RW44QnVQdHBqaU9BTUgxZjpnNFpjeUFDWVJYQ2xLRVp2eXF3U3RBIn0=Configure other nodes to join this cluster:
• On this node:⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.⁃ Uncomment the transport.host setting at the end of config/elasticsearch.yml.⁃ Restart Elasticsearch.
• On other nodes:⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
上述问题解决后,在浏览器访问"https://localhost:9200",注意这里使用 HTTPS
协议访问。
输入用户名: elastic
,密码: 9SWTTFDuibtaS2*L0NRv
。登录成功后,经典的启动信息页面:“You Know, for Search”。
下载、安装并启动Kibana8
[root@hadoop1 ~]# cd /usr/local/
[root@hadoop1 local]# wget https://artifacts.elastic.co/downloads/kibana/kibana-8.0.0-linux-x86_64.tar.gz
[root@hadoop1 local]# tar -xvf kibana-8.0.0-linux-x86_64.tar.gz
[root@hadoop1 local]# mv kibana-8.0.0 kibana
[root@hadoop1 local]# cd kibana
[root@hadoop1 kibana]# ./bin/kibana
问题1:不可使用root用户直接启动kibana
Error: Unable to write to UUID file at /usr/local/kibana/data/uuid. Ensure Kibana has sufficient permissions to read / write to this file. Error was: EACCES
解决方法:使用 es-admin
用户(这个是前面新增的,名字可以自己起),赋予对 kibana
目录的权限。
# 赋予对kibana目录的权限
[root@hadoop1 kibana]# chown -R es-admin:es-admin /usr/local/kibana
# 切换至es-admin
[root@hadoop1 kibana]# su es-admin
# 尝试启动Kibana
[es-admin@hadoop1 kibana]$ ./bin/kibana
问题2:默认仅能本地访问kibana服务
解决了前一个问题后, Kibana
成功启动,并在控制台打印出如下内容,仅能本地访问,可我的是 CentOS
系统,没法打开浏览器进行本机访问。
Go to http://localhost:5601/?code=194486 to get started.
解决方法:修改配置,让其他机器也可访问 Kibana
。
# 编辑配置文件,修改server.host: "0.0.0.0"
[es-admin@hadoop1 kibana]$ vi ./config/kibana.yml
server.host: "0.0.0.0"# 尝试启动Kibana
[es-admin@hadoop1 kibana]$ ./bin/kibana
Kibana
成功启动后,使用控制台生成的附加随机码的连接在远程的浏览器上打开,输入第一次启动 ElasticSearch
时,默认生成的 enrollment token
。
问题3:Kibana连接ElasticSearch的enrollment token过期
[2022-02-19T22:16:24.366+08:00][ERROR][plugins.interactiveSetup.elasticsearch] Failed to enroll with host “https://192.168.44.127:9200”: {“error”:{“root_cause”:[{“type”:“security_exception”, “reason”:“unable to authenticate with provided credentials and anonymous access is not allowed for this request”, “additional_unsuccessful_credentials”:“API key: api key is expired”, “header”:{“WWW-Authenticate”:["Basic realm=“security” charset=“UTF-8"”, “Bearer realm=“security””, “ApiKey”]}}], “type”:“security_exception”, “reason”:“unable to authenticate with provided credentials and anonymous access is not allowed for this request”, “additional_unsuccessful_credentials”:“API key: api key is expired”, “header”:{“WWW-Authenticate”:["Basic realm=“security” charset=“UTF-8"”, “Bearer realm=“security””, “ApiKey”]}}, “status”:401}
前面提到,第一次启动 ElasticSearch
时,默认生成的 enrollment token
在30分钟内有效,但是如果从第一次启动 ElasticSearch
服务,到 Kibana
服务启动连接 ElasticSearch
时超过了30分钟,该怎么办呢?(感觉像是断了线的风筝,失去了与组织的单线联系,好慌。。)
这时需要使用E lasticSearch
自带的工具: /bin/elasticsearch-create-enrollment-token
,重新手动生成 Kibana
连接 ElasticSearch
的 enrollment token
。
# 使用ElasticSearch自带的工具:/bin/elasticsearch-create-enrollment-token,后续添加节点到集群内时,同样要用到这个工具~~
[root@hadoop1 elasticsearch]# ./bin/elasticsearch-create-enrollment-token -s kibana
warning: ignoring JAVA_HOME=/usr/local/jdk; using bundled JDK
eyJ2ZXIiOiI4LjAuMCIsImFkciI6WyIxOTIuMTY4LjQ0LjEyNzo5MjAwIl0sImZnciI6Ijc1NDgwYTlmYzkzNjQ5ZTJlYmQ4ZGQwYTlmMDcyMTI0N2U4Y2ZmMzJmZGJjNzhhYmYwYjMwZDdhYzljOGU4YmQiLCJrZXkiOiJWcjlhRW44QnVQdHBqaU9BQjMwTDpCNHlYclhweFNzNmRtWWJaaFBKOWhRIn0=
接着要输入用户名与密码后登录 Kibana
(这里的用户名与密码跟 ElasticSearch
用到的一致),打完收工~
小总结
之所以要实践最新版的 ElasticSearch
8.0,主要还是奔着默认启用安全功能这一新特性来的,毕竟以前关于 ElasticSearch
, Redis
甚至 MongoDB
的勒索事件层出不穷,主要原因还是人们安全意识淡薄或者偷懒没有配置认证功能,然后使用这些服务的默认配置(没有启用最基本的认证功能,更不用说强密码了。。)直接在公网环境运行(裸奔)。。
附:以前写的关于ElasticSearch的内容,包含 ElasticSearch8.0
分布式搜索引擎集群及其高可用测试。
- ElasticSearch入门(一)单节点初体验
- ElasticSearch入门(二)批量导入数据(Postman与Kibana)
- ElasticSearch入门(三)Logstash实现MySQL数据同步至ElasticSearch
- ElasticSearch入门(四)常用插件:Head插件与ik分词器
- ElasticSearch入门(五)SpringBoot2.3.0集成ElasticSearch7.5.2-HighLevelClient
- ElasticSearch入门(六)SpringBoot2.3.0集成ElasticSearch7.5.2-SpringData
- ElasticSearch入门(七)搭建ElasticSearch集群
- 在华为鲲鹏openEuler20.03系统上安装ElasticSearch
- 全栈开发之ElasticSearch8.0分布式搜索引擎集群及其高可用测试
If you have any questions or any bugs are found, please feel free to contact me.
Your comments and suggestions are welcome!
将最新版的ElasticSearch8与Kibana8在CentOS7上跑起来相关推荐
- 服务器信号满格但上不了网,新版tplink路由器wifi信号满格上不了网怎么办?
经常有人在微信向鸿哥咨询这个问题: 为什么路由器的无线信号满格,并且手机.笔记本电脑也可以连接上wifi信号,但是却上不了网? 鸿哥与这些用户一对一沟通后发现,绝大部分用户是因为路由器上网设置不成功引 ...
- 最新版CAD都有些啥功能(上)
最新版CAD 2021版已经可以下载使用了,让我们来看看本次更新都新增了哪些功能吧!篇幅较长,咱们拆分成上下两期来讲. AutoCAD 2021中文版新功能 一.简化的"修剪和延伸" ...
- paypal创建订单后怎么获得id_5步创建Facebook商店(最新版教程)学习如何在Facebook上卖货...
请按照以下步骤设置Facebook商店: 步骤1:转到您的Facebook页面并配置Shop页面. 步骤2:设置您的商店详细信息. 步骤3:配置付款. 步骤4:将产品添加到您的Facebook商店. ...
- java1.8 xp_最新版Java8怎么在XP系统电脑上安装?
好好好我认输 回答数:165 | 被采纳数:129 2018-09-23 15:21:21 Java目前推出了最新版本Java1.8,相比较之前的Java7多了一些特性,环境变量的配置也有了一些变 ...
- 新版iTunes Connect如何删除一个已上传的built。重新上传
无法删除,解决办法是重新上传一个版本:修改一下build的版本号,其余的不用修改,重新上传. 然后在build栏目选择你想要的版本 来源:http://www.cocoachina.com/ask/q ...
- unity新版Video_Player在Android 9.0版本上不能播放视频
具体问题 我当前版本1.2,video_player0.10.0+2,在安卓7-8版本中测试暂无问题,但是在安卓9版本手机上无法播放URL地址的视频. 问题原因 安卓上从9.0(API level28 ...
- ElasticSearch报错:FORBIDDEN/12/index read-only / allow delete (api)无法写入
背景 一个两年前的读书笔记项目,在本地开发环境启动后,搜索服务的后端日志 ElasticSearch 报错:FORBIDDEN/12/index read-only / allow delete (a ...
- CentOS 8安装 GVM20.08
Centos 8 安装GVM 20.08 参考链接1:https://sadsloth.net/post/install-gvm-20_08-src-on-debian/ 参考链接2:https:// ...
- Docker下elasticsearch8部署、扩容、基本操作实战(含kibana)
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本篇记录了用docker搭建ElasticS ...
最新文章
- 学完python还需要学什么语言好_python基础学完了之后还需要学习什么
- get与post请求问题
- 汇编语言答案-王爽第三版
- java day08【String类、static关键字、Arrays类、 Math类】
- vue 浏览器地址是ip_Vue实战041:获取当前客户端IP地址详解(内网和外网)
- 2016年移动广告聚合平台浅析
- AMOS从零到基本操作入门(转载)
- 为什么要学习Linux内核,如何学习?
- 最原始的yuv图像叠加文字的实现--手动操作像素
- 碎片化知识管理工具Memos
- Excel常用数据分析技能(PowerBI)
- 收录查询 搜狗收录批量查询工具
- 工具篇之HBuilderX使用教程
- 象棋联机java代码_java实现简单网络象棋游戏
- 软件测试用例设计方法(一)
- kerberos搭建
- UGUI IPointerUpHandler事件失灵
- 国家常用代号 for Mysql数据库
- 用Python制作简单的俄罗斯方块游戏
- 软件工程学习笔记(五)~面向对象测试
热门文章
- R语言实现多维尺度分析(Multidimensional Scaling,MDS)
- 为什么Eureka比ZooKeeper更适合做服务发现?
- 运动目标检测之光流法(4)LK金字塔论文翻译
- [学习SLAM]深度学习+视觉SLAM 的可行性/方向
- java中bad request_IIS服务器返回Bad Request (Invalid Hostname)解决办法
- 时间序列预测:指数平滑法及python实现
- SCIM输入法架构分析(上)
- IT男的情商修炼,看电视剧也可以提升情商
- php读取移动硬盘数据,给移动硬盘加个wifi的方法
- 【R语言】箱线图的绘制