elasticsearch + kibana 8.9.0集群安装(一次成功)

一直想在本地安装一下elasticsearch集群,折腾了好久才弄完,记录一下过程。

安装环境:虚拟机,3台centos7

下载安装包

新建/softw文件夹,然后执行

shell 复制代码
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.9.0-linux-x86_64.tar.gz

集群规划

服务器 角色 ip
yueyue master\data 192.168.80.120
yueyue2 master\data 192.168.80.121
yueyue3 master\data 192.168.80.122

创建用户(每台执行)

es是不能使用root启动,为了安全。 需要每台机器都执行:

shell 复制代码
# 新增 es 用户 
useradd es 
# 为 es 用户设置密码 
passwd es # 密码为 es

调整操作系统参数(每台执行)

  1. es要求进程最大打开文件数数量为最低65536,每台都执行:
shell 复制代码
vi /etc/security/limits.conf 
* soft nofile 65536 
* hard nofile 65536
  1. 修改/etc/sysctl.conf文件,增加配置vm.max_map_count=262144
shell 复制代码
vi /etc/sysctl.conf 
# 最后增加一行: 
vm.max_map_count = 262144 
# 退出执行 
sysctl -p

安装软件(每台执行)

解压安装

shell 复制代码
tar -xvf /softw/elasticsearch-8.9.0-linux-x86_64.tar.gz -C /opt

自带的jdk,版本很高:openjdk20

更改环境变量,使用自带的jdk

shell 复制代码
vi /etc/profile 
# 做如下修改: 
export JAVA_HOME=/opt/elasticsearch-8.9.0/jdk 
export ES_HOME=/opt/elasticsearch-8.9.0 
export PATH=$ES_HOME/bin:$PATH

配置es

  1. 创建数据文件,证书目录, 并修改 Elasticsearch 文件拥有者 (每台执行)
shell 复制代码
# 创建数据文件目录 
mkdir /opt/elasticsearch-8.9.0/data 
# 创建证书目录 
mkdir /opt/elasticsearch-8.9.0/config/certs 
#切换目录 
cd /opt/elasticsearch-8.9.0 
# 修改文件拥有者 chown -R es:es /opt/elasticsearch-8.9.0
  1. 在第一台服务器节点yueyue 设置集群多节点通信密钥
shell 复制代码
# 切换用户 
su - es 
# 签发 ca 证书,过程中需按两次回车键,生成目录:es的home:/opt/elasticsearch-8.9.0/ 
cd /opt/elasticsearch-8.9.0/bin 
./elasticsearch-certutil ca 
# 两次回车即可 

# 用 ca 证书签发节点证书,过程中需按三次回车键,生成目录:es的home:/opt/elasticsearch-8.9.0/ 
./elasticsearch-certutil cert --ca elastic-stack-ca.p12 
# 将生成的证书文件移动到 config/certs 目录中 
mv /opt/elasticsearch-8.9.0/elastic-stack-ca.p12 /opt/elasticsearch-8.9.0/elastic-certificates.p12 /opt/elasticsearch-8.9.0/config/certs
  1. 在第一台服务器节点 yueyue 设置集群多节点 HTTP 证书
shell 复制代码
# 签发 Https 证书 
cd /opt/elasticsearch-8.9.0/bin 
./elasticsearch-certutil http 
# Generate a CSR? [y/N] 输入N 
# Use an existing CA? [y/N] 输入y 
# CA Path: 输入 /opt/elasticsearch-8.9.0/config/certs/elastic-stack-ca.p12 # Password for elastic-stack-ca.p12: 无需密码,直接回车 
# For how long should your certificate be valid? [5y] 输入5y 
# Generate a certificate per node? [y/N] 输入N 
# Enter all the hostnames that you need, one per line:输入yueyue、yueyue2、yueyue3,每个一行 
# Is this correct [Y/n] 输入Y 
# Enter all the IP addresses that you need, one per line. 输入:三台机器的ip:192.168.80.120-122 
# Is this correct [Y/n] 输入 Y 
# Do you wish to change any of these options? [y/N] 输入N 
# 连续两次enter 
# Zip file written to /opt/elasticsearch-8.9.0/elasticsearch-ssl-http.zip

解压证书(这里一定要把证书分发到其他节点):

shell 复制代码
# 解压 
cd /opt/elasticsearch-8.9.0 
unzip elasticsearch-ssl-http.zip 
# 移动证书 
mv ./elasticsearch/http.p12 ./kibana/elasticsearch-ca.pem ./config/certs 

# 将证书分发到其他节点 
cd /opt/elasticsearch-8.9.2/config/certs 
scp * yueyue2:/opt/elasticsearch-8.9.0/config/certs 
scp * yueyue3:/opt/elasticsearch-8.9.0/config/certs
  1. 修改yueyue节点主配置文件:./config/elasticsearch.yml
yml 复制代码
# 设置 ES 集群名称
cluster.name: es-study
# 设置集群中当前节点名称
node.name: es-yueyue
# 节点属性
node.roles: [master,data]
# 设置数据,日志文件路径
path.data: /opt/elasticsearch-8.9.0/data
path.logs: /opt/elasticsearch-8.9.0/logs
# 设置网络访问节点
# network和端口号一定要配置,如果怕安全问题,把host设置成访问此elasticsearch服务器的ip地址,就是设置成唯一访问。 可以配置成 network.host: 0.0.0.0
network.host: 192.168.80.120
# 设置网络访问端口
http.port: 9200
discovery.seed_hosts:
  - 192.168.80.120
  - 192.168.80.121
  - 192.168.80.122
cluster.initial_master_nodes:
  - es-yueyue
  - es-yueyue2
  - es-yueyue3
# 安全认证
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
 enabled: true # 注意第一个空格
 keystore.path: /opt/elasticsearch-8.9.0/config/certs/http.p12
 truststore.path: /opt/elasticsearch-8.9.0/config/certs/http.p12
xpack.security.transport.ssl:
 enabled: true
 verification_mode: certificate
 keystore.path: /opt/elasticsearch-8.9.0/config/certs/elastic-certificates.p12
 truststore.path: /opt/elasticsearch-8.9.0/config/certs/elastic-certificates.p12
# 此处需注意,es-yueyue 为上面配置的节点名称
http.host: [_local_, _site_]
ingest.geoip.downloader.enabled: false
xpack.security.http.ssl.client_authentication: none

启动es

shell 复制代码
# es 用户启动 
/opt/elasticsearch-8.3.2/bin/elasticsearc

第一次成功启动后,会显示密码,请记住,访问时需要。只有第一次才有

shell 复制代码
ℹ️  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  iRw+3g9Z2y29alnE_w_P
  
❌ Unable to generate an enrollment token for Kibana instances, try invoking `bin/elasticsearch-create-enrollment-token -s kibana`.

❌ An enrollment token to enroll new nodes wasn't generated. To add nodes and enroll them into this cluster:
• On this node:
  ⁃ Create an enrollment token with `bin/elasticsearch-create-enrollment-token -s node`.
  ⁃ Restart Elasticsearch.
• On other nodes:
  ⁃ Start Elasticsearch with `bin/elasticsearch --enrollment-token <token>`, using the enrollment token that you generated.

修改密码:

shell 复制代码
bin/elasticsearch-reset-password -u elastic -i
# 输入:es

登录网页 https://192.168.80.120:9200

因为配置了安全协议,所以使用 https 协议进行访问,但由于证书是自己生成的,并不可靠,所以会有安全提示

输入账号: es es

其他节点配置

安装文件、配置文件和证书前期已经copy完了,这里只需要修改配置文件即可 yueyue2修改 config/elasticsearch.yml

shell 复制代码
vi config/elasticsearch.yml
# 设置节点名称
node.name: yueyue2
# 设置网络访问主机
network.host: 192.168.80.121

yueyue3修改 config/elasticsearch.yml

shell 复制代码
vi config/elasticsearch.yml
# 设置节点名称
node.name: yueyue3
# 设置网络访问主机
network.host: 192.168.80.122

启动集群

启动前每台节点需要关一下防火墙不然访问不了

shell 复制代码
systemctl stop firewalld

每台节点依次启动(无顺序要求,只要多于2台,就可以启动集群,这就是es的无主模式,自动识别集群,选举master):

shell 复制代码
/opt/elasticsearch-8.3.2/bin/elasticsearch -d

访问https://192.168.80.120:9200/_cat/nodes?v

kibana安装

在/softw文件夹下下载安装包

shell 复制代码
wget https://artifacts.elastic.co/downloads/kibana/kibana-8.9.0-linux-x86_64.tar.gz

解压安装

shell 复制代码
tar -xvf /softw/kibana-8.9.0-linux-x86_64.tar.gz -C /opt

修改文件拥有者

shell 复制代码
chown -R es:es /opt/kibana-8.9.0

修改/config/kibana.yml

yml 复制代码
# 改成自己节点的ip
server.host: "192.168.80.120"

本来想用token的方式初始化kibana的,但是在运行下面命令生成token的时候

shell 复制代码
./bin/elasticsearch-create-enrollment-token -s kibana --url "https://192.168.80.120:9200"

不知道为什么会出现下面的错误:

shell 复制代码
ERROR: Unable to create an enrollment token. Elasticsearch node HTTP layer SSL configuration Keystore doesn't contain any PrivateKey entries where the associated certificate is a CA certificate

试了segmentfault.com/q/101000004... 里的解决方案也不行 于是换了手动初始化的方式,运行下面的命令生成初始化账号的密码:

shell 复制代码
/opt/elasticsearch-8.9.0/bin/elasticsearch-reset-password -u kibana_system

然后启动kibana

shell 复制代码
/opt/kibana-8.9.0/bin/kibana

选择configure manually

填入elasticsearch的地址,然后输入刚才生成的kibana_system账号和密码,等待初始化完成即可

相关推荐
bubble小拾4 小时前
ElasticSearch高级功能详解与读写性能调优
大数据·elasticsearch·搜索引擎
不能放弃治疗5 小时前
重生之我们在ES顶端相遇第 18 章 - Script 使用(进阶)
elasticsearch
hengzhepa6 小时前
ElasticSearch备考 -- Search across cluster
学习·elasticsearch·搜索引擎·全文检索·es
Elastic 中国社区官方博客7 小时前
Elasticsearch:使用 LLM 实现传统搜索自动化
大数据·人工智能·elasticsearch·搜索引擎·ai·自动化·全文检索
慕雪华年8 小时前
【WSL】wsl中ubuntu无法通过useradd添加用户
linux·ubuntu·elasticsearch
Elastic 中国社区官方博客10 小时前
使用 Vertex AI Gemini 模型和 Elasticsearch Playground 快速创建 RAG 应用程序
大数据·人工智能·elasticsearch·搜索引擎·全文检索
alfiy11 小时前
Elasticsearch学习笔记(四) Elasticsearch集群安全配置一
笔记·学习·elasticsearch
alfiy12 小时前
Elasticsearch学习笔记(五)Elastic stack安全配置二
笔记·学习·elasticsearch
丶21361 天前
【大数据】Elasticsearch 实战应用总结
大数据·elasticsearch·搜索引擎
闲人编程1 天前
elasticsearch实战应用
大数据·python·elasticsearch·实战应用