(十六)从零开始搭建k8s集群——使用KubeSphere管理平台搭建一个高可用的ElasticSearch服务平台

20 篇文章 41 订阅
13 篇文章 7 订阅

前言

Elasticsearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。本节内容我们使用kubesphere管理平台搭建一个k8s环境下的高可用的es集群服务。elasticsearch镜像选用的是最新版本的elasticsearch:8.1.3镜像,配置和以前的版本稍有不同。

正文

  • 创建elasticsearch配置文件

-点击配置中心->配置->创建,填写es的基本配置信息,点击下一步

 -点击添加数据,填写es配置数据

-官方es配置文件

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
#network.host: 192.168.0.1
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false

- 需要的配置说明

#集群名称配置
cluster.name: my-es
#节点角色配置
node.roles: [ data, master ]
#网络配置
network.host: 0.0.0.0
#集群节点配置
discovery.seed_hosts: [ "app-es-v1-0.app-es.app.svc.cluster.local:9300","app-es-v1-1.app-es.app.svc.cluster.local:9300","app-es-v1-2.app-es.app.svc.cluster.local:9300" ]
#集群初始化节点
cluster.initial_master_nodes: [ "app-es-v1-0","app-es-v1-1","app-es-v1-2" ]
#绑定客户端访问端口
http.port: 9200
#绑定集群间通信端口
transport.port: 9300
#安全访问
xpack.security.transport.ssl.enabled: true

 ps:k8s环境中有状态服务的部署pod的服务名称是按照固定规则生成的一个主机服务名称,

(podname).(headless server name).(namespace).svc.cluster.local例如app-es-v1-0.app-es.app.svc.cluster.local,其中app-es-v1-0是pod的节点名称,app-es是服务器名称,app是命名空间,svc.cluster.local为固定写法。后面创建es集群我们需要按照这个规则来命名创建集群。

- 填写es集群配置,点击对号,点击创建

-完成集群配置文件的创建

  •  部署elasticsearch服务

-点击应用负载->服务->创建->有状态服务->填写集群配置基本信息,这里要注意这里的名称就是pod的节点名称,要与前面配置文件的名字一致

 - 点击下一步,选择容器组副本数为3,然后点击添加容器镜像

- 添加集群服务镜像elasticsearch:8.1.3,加载镜像后,选择使用默认暴露端口9200访问服务

- 添加环境变量ES_JAVA_OPTS:-Xms256m -Xmx256m,为es分配初始化和最大JVM内存,es也是一个java服务,这里用于测试,jvm内存设置的小一点,正常要设置为服务器内存的50%左右,完成后勾选主机时区,点对号完成镜像添加,点击下一步 

-点击添加存储卷模板,完成es数据存储的pvc配置

 - 填写pvc存储基本信息,完成es数据存储设置,pvc存储路径映射为:/usr/share/elasticsearch/data,这里要选择添加子路径,以免覆盖其它文件路径,点击对号完成pvc存储卷的添加

 -挂载es配置文件elasticsearch.yml

 -选择已经创建的es配置文件,填写es配置文件路径/usr/share/elasticsearch/config/elasticsearch.yml及其子路径elasticsearch.yml

 - 勾选特定的键和路径,点击对号完成es集群配置文件的添加 

-点击下一步,完成es集群的创建 

-点击创建,es集群创建完毕

  •  验证elasticsearch服务

- 点击任意一台服务器控制台图标进入es容器内

-访问集群节点,查看集群状态

地址:curl http://app-es-v1-0.app-es.app.svc.cluster.local:9200/_cat/nodes?pretty

结语

至此,关于使用kubesphere管理平台搭建一个k8s环境下的高可用的es集群服务就结束了。别忘了,关注、点赞,加收藏哦,我们下期见。。。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

厉害哥哥吖

您的支持是我创作下去的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值