Cenots7 安装ElasticSearch8.13.1 集群 和 Kibana8.13.1

2,749 阅读7分钟

1、集群规划

准备三台 Centos7 虚拟机,用于配置 Elasticsearch 集群。 启动集群后,每台虚拟机的进程如下

主机IP192.168.2.221192.168.2.222192.168.2.223
主机名centos221centos222centos221
进程名称Elasticsearch(es-node-1)Elasticsearch(es-node-2)Elasticsearch(es-node-3)

设置3台主机名(可选,若不设置主机名,以下凡是使用主机名的地方替换为相应的主机IP即可)

  • 设置192.168.2.221 主机名

    hostnamectl set-hostname centos221
    
  • 设置192.168.2.222 主机名

    hostnamectl set-hostname centos222
    
  • 设置192.168.2.223 主机名

    hostnamectl set-hostname centos223
    

查看主机名

hostnamectl

image.png

给3台主机 /etc/hosts文件添加分别添加以下内容:(若不设置主机名,此步骤省略)

# 修改/etc/hosts文件
vi /etc/hosts

# 以下为新添加的内容
192.168.2.221 centos221
192.168.2.222 centos222
192.168.2.223 centos223

2、下载ElasticSearch

以下两种下载方式选一种即可:

1)官网下载然后上传到服务器

ElasticSearch官网下载

image.png

2)在3台服务器上直接使用命令下载

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.13.1-linux-x86_64.tar.gz

3、安装 ElasticSearch (192.168.2.221主机)

登录 192.168.2.221服务器 执行以下操作

3.1 解压文件

解压缩文件到自定义路径,笔者解压路径为: /opt/module/。 解压后,软件路径为: /opt/module/elasticsearch-8.13.1

# 在elasticsearch-8.13.1-linux-x86_64.tar.gz压缩包所在目录执行解压命令
# 创建自定义目录
mkdir -p  /opt/module/
# 解压
tar -xzvf elasticsearch-8.13.1-linux-x86_64.tar.gz -C /opt/module/

image.png

解压后的 Elasticsearch 的目录结构如下

image.png

目录含义
bin可执行脚本目录
config配置目录
jdk内置JDK命令
lib类库
logs日志目录
modules模块目录
plugins插件目录

当前安装 ES 版本为 8.13.1,自带 JDK,所以当前 Centos 虚拟机节点无需配置 Java 环境

3.2 创建 centos 新用户 es, 数据文件,证书目录, 并修改 Elasticsearch 文件拥有者

# 新增es用户
useradd es
# 为es用户设置密码
passwd es

# 创建数据文件目录 
mkdir /opt/module/elasticsearch-8.13.1/data 

# 创建证书目录 
mkdir /opt/module/elasticsearch-8.13.1/config/certs 

#切换目录 
cd /opt/module/elasticsearch-8.13.1 

# 修改文件拥有者 
chown -R es:es /opt/module/elasticsearch-8.13.1

3.3 在第一台服务器节点 es-node-1 设置集群多节点通信密钥

# 切换用户 
su es 

# 签发 ca 证书,过程中需按两次回车键 
bin/elasticsearch-certutil ca 

# 用 ca 证书签发节点证书,过程中需按三次回车键 
bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 

# 将生成的证书文件移动到 config/certs 目录中
mv elastic-stack-ca.p12 elastic-certificates.p12 config/certs

image.png

image.png

3.4 在第一台服务器节点 es-node-1 设置集群多节点 HTTP 证书

# 签发 Https 证书 
bin/elasticsearch-certutil http 
# 以下是每次要求输入时,需要输入的内容

image.png

指定证书路径 certs/elastic-stack-ca.p12

image.png

无需输入密码

image.png

设置证书失效时间

image.png

无需每个节点配置证书

image.png

输出连接到第一个节点的所有主机名称

image.png

输出连接到第一个节点的所有主机 IP 地址

image.png

不改变证书选项配置

image.png

不给证书加密,按键输入两次回车

image.png

解压刚刚生成的 zip 包

# 解压文件
unzip elasticsearch-ssl-http.zip

image.png

将解压后的证书文件移动到 config/certs 目录中

# 移动文件
mv elasticsearch/http.p12 kibana/elasticsearch-ca.pem config/certs

image.png

3.5 修改主配置文件:/opt/module/elasticsearch-8.13.1/config/elasticsearch.yml

# 设置 ES 集群名称
cluster.name: es-cluster
# 设置集群中当前节点名称
node.name: es-node-1
# 设置数据,日志文件路径
path.data: /opt/module/elasticsearch-8.13.1/data
path.logs: /opt/module/elasticsearch-8.13.1/log
# 设置网络访问节点
network.host: centos221
# 设置网络访问端口
http.port: 9200
# 初始节点
discovery.seed_hosts: ['centos221']
# 安全认证
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
    enabled: true
    keystore.path: /opt/module/elasticsearch-8.13.1/config/certs/http.p12
    truststore.path: /opt/module/elasticsearch-8.13.1/config/certs/http.p12
xpack.security.transport.ssl:
    enabled: true
    verification_mode: certificate
    keystore.path: /opt/module/elasticsearch-8.13.1/config/certs/elastic-certificates.p12
    truststore.path: /opt/module/elasticsearch-8.13.1/config/certs/elastic-certificates.p12
# 此处需注意,es-node-1 为上面配置的节点名称
cluster.initial_master_nodes: ['es-node-1']
http.host: [_local_, _site_]
ingest.geoip.downloader.enabled: false
xpack.security.http.ssl.client_authentication: none

3.6 启动ES软件

# 启动 ES 软件
bin/elasticsearch

# 后台启动ES
bin/elasticsearch -d

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

image.png

注意:9300 端口为 Elasticsearch 集群间组件的通信端口,9200 端口为浏览器访问的 http 协议 RESTful 端口。

3.7 启动报错

[ERROR][o.e.b.Elasticsearch      ] [es-node-1] node validation exception
[2] bootstrap checks failed. You must address the points described in the following [2] lines before starting Elasticsearch. For more information see [https://www.elastic.co/guide/en/elasticsearch/reference/8.13/bootstrap-checks.html]
bootstrap check failure [1] of [2]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]; for more information see [https://www.elastic.co/guide/en/elasticsearch/reference/8.13/_file_descriptor_check.html]
bootstrap check failure [2] of [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]; for more information see [https://www.elastic.co/guide/en/elasticsearch/reference/8.13/_maximum_map_count_check.html]

  • max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

    # 在root用户下追加配置
    vi /etc/security/limits.conf 
    # 配置内容   *表示所有用户生效
    * soft nofile 65536
    * hard nofile 65536
    
    # 重新登录即可生效
    # 可使用命令查看是否生效
    ulimit  -H -n
    

    image.png

  • max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    #修改文件
    sudo vi /etc/sysctl.conf
    
    # 在/etc/sysctl.conf 文件末尾添加以下参数
    vm.max_map_count = 262144
    

    重新加载/etc/sysctl.conf配置

     sysctl -p
    

    image.png

  • 出现下面图片也可以按照指定方式进行配置

    image.png

    # 为Kibana实例生成注册令牌
    bin/elasticsearch-create-enrollment-token -s kibana
    

3.8 访问服务器节点 https://虚拟机IP:9200

image.png

选择继续即可,输入用户名:elastic和3.6生成的密码即可登录

image.png

image.png

4、集群中其他节点(192.168.2.222 和 192.168.2.223)安装ES

将192.168.2.221 证书文件config/elasticsearch.yml文件直接拷贝到 192.168.2.222 和 192.168.2.223 相应文件夹,其他步骤完全相同(去除生成证书步骤3.3、3.4),配置文件中修改如下内容即可

4.1 192.168.2.222 centos222 主机

# 设置节点名称
node.name: es-node-2 

# 设置网络访问主机
network.host: centos222 # 或使用主机IP:192.168.2.222

4.2 192.168.2.222 centos222 主机

# 设置节点名称
node.name: es-node-3

# 设置网络访问主机
network.host: centos223 # 或使用主机IP:192.168.2.223

4.3 依次启动集群的三台服务器节点, 不要忘记切换用户后再启动

centos221:

# 后台启动服务
bin/elasticsearch -d

centos222:

# 后台启动服务
bin/elasticsearch -d

centos223:

# 后台启动服务
bin/elasticsearch -d

5、安装Kibana

Elasticsearch 下载的版本是 8.13.1,这里我们选择同样 8.13.1 版本的Kibana,以下两种下载方式,选其中一种即可

1)官网下载然后上传到192.168.2.221服务器

下载地址:www.elastic.co/cn/download…

Past Releases:www.elastic.co/cn/download…

image.png

2)登录192.168.2.221服务器 命令行下载

wget https://artifacts.elastic.co/downloads/kibana/kibana-8.13.1-linux-x86_64.tar.gz

5.1 解压文件

解压缩文件到自定义路径为:/opt/module,解压后,软件路径为: /opt/module/kibana-8.13.1/

# 解压缩 
tar -zxvf kibana-8.13.1-linux-x86_64.tar.gz -C /opt/module

解压后的 kibana 的目录结构如下:

image.png

5.2 给 Kibana 生成证书文件

# 在 ES 服务器中生成证书,输入回车即可 
cd /opt/module/elasticsearch-8.13.1 
bin/elasticsearch-certutil csr -name kibana -dns 192.168.2.221 

# 解压文件
unzip csr-bundle.zip 

# 将解压后的文件移动到 kibana 的 config 目录中
cd /opt/module/elasticsearch-8.13.1/kibana
mv kibana.csr kibana.key /opt/module/kibana-8.13.1/config/ 

# 生成 crt 文件 
cd /opt/module/kibana-8.13.1/config
openssl x509 -req -in kibana.csr -signkey kibana.key -out kibana.crt

image.png

image.png

image.png

5.3 修改配置文件:/opt/module/kibana-8.13.1/config/kibana.yml

服务主机名ES 服务主机地址需根据实际情况改为192.168.2.221主机的主机IP

# 服务端口
server.port: 5601
# 服务主机名
server.host: 192.168.2.221
# 国际化 - 中文
i18n.locale: 'zh-CN'
# ES 服务主机地址
elasticsearch.hosts: ['https://192.168.2.221:9200']
# 访问 ES 服务的账号密码
elasticsearch.username: 'kibana'
elasticsearch.password: 'RBiGCrKVjlQ-earQOLb2'
elasticsearch.ssl.verificationMode: none
elasticsearch.ssl.certificateAuthorities: ['/opt/module/elasticsearch-8.13.1/config/certs/elasticsearch-ca.pem']
server.ssl.enabled: true
server.ssl.certificate: /opt/module/kibana-8.13.1/config/kibana.crt
server.ssl.key: /opt/module/kibana-8.13.1/config/kibana.key

5.4 修改软件目录拥有者

# 切换目录 
chown -R es:es /opt/module/kibana-8.13.1/

5.5 切换用户,启动软件

# 切换用户 
su es 

# 启动软件 
cd /opt/module/kibana-8.13.1/
bin/kibana 

# 也可以后台启动 
nohup /opt/module/kibana-8.13.1/bin/kibana >logs/kibana.log 2>&1 &

启动报错

[2024-04-09T10:52:48.235+08:00][ERROR][elasticsearch-service] Unable to retrieve version information from Elasticsearch nodes. security_exception
        Root causes:
                security_exception: unable to authenticate user [kibana] for REST request [/_nodes?filter_path=nodes.*.version%2Cnodes.*.http.publish_address%2Cnodes.*.ip]

说明kibana.yml中的配置elasticsearch.password错误,若忘记可重置kibana用户密码

 cd /opt/module/elasticsearch-8.13.1/

# 重置Kibana用户密码
bin/elasticsearch-reset-password --batch --user kibana

image.png

5.6 Kibana应用

image.png

image.png

image.png