K8s系列---【KubeSphere部署ElasticSearch】

KubeSphere部署ElasticSearch

1.ES容器启动

# 创建数据目录
mkdir -p /mydata/es-01 
chmod 777 -R /mydata/es-01 # 容器启动 docker run --restart=always -d -p 9200:9200 -p 9300:9300 \ -e "discovery.type=single-node" \ -e ES_JAVA_OPTS="-Xms512m -Xmx512m" \ -v es-config:/usr/share/elasticsearch/config \ -v /mydata/es-01/data:/usr/share/elasticsearch/data \ --name es-01 \ elasticsearch:7.13.4
注意:如果启动后访问"ip:9200"不成功,"docker rm -f es-01"删除现有容器,再执行"chmod 777 -R /mydata/es-01"命令,然后再重启执行上面创建容器的命令。

2.ES部署分析

注意: 子路径挂载,配置修改后,k8s不会对其Pod内的相关配置文件进行热更新,需要自己重启Pod。

3.创建ES配置文件es-conf

这里需要注意,es一般修改这两个配置文件,这里一个es-conf对应两个键值对。 

elasticsearch.yml

cluster.name: "docker-cluster"
network.host: 0.0.0.0

jvm.options

这里可以先用docker创建一个es,登进容器,进入"/usr/share/elasticsearch/config"目录,用"cat jvm.options"命令查看内容,并复制粘贴。

################################################################
##
## JVM configuration
##
################################################################
##
## WARNING: DO NOT EDIT THIS FILE. If you want to override the
## JVM options in this file, or set any additional options, you
## should create one or more files in the jvm.options.d
## directory containing your adjustments.
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/jvm-options.html
## for more information.
##
################################################################



################################################################
## IMPORTANT: JVM heap size
################################################################
##
## The heap size is automatically configured by Elasticsearch
## based on the available memory in your system and the roles
## each node is configured to fulfill. If specifying heap is
## required, it should be done through a file in jvm.options.d,
## and the min and max should be set to the same value. For
## example, to set the heap to 4 GB, create a new file in the
## jvm.options.d directory containing these lines:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################


################################################################
## Expert settings
################################################################
##
## All settings below here are considered expert settings. Do
## not adjust them unless you understand what you are doing. Do
## not edit them in this file; instead, create a new file in the
## jvm.options.d directory containing your adjustments.
##
################################################################

## GC configuration
8-13:-XX:+UseConcMarkSweepGC
8-13:-XX:CMSInitiatingOccupancyFraction=75
8-13:-XX:+UseCMSInitiatingOccupancyOnly

## G1GC Configuration
# NOTE: G1 GC is only supported on JDK version 10 or later
# to use G1GC, uncomment the next two lines and update the version on the
# following three lines to your version of the JDK
# 10-13:-XX:-UseConcMarkSweepGC
# 10-13:-XX:-UseCMSInitiatingOccupancyOnly
14-:-XX:+UseG1GC

## JVM temporary directory
-Djava.io.tmpdir=${ES_TMPDIR}

## heap dumps

# generate a heap dump when an allocation from the Java heap fails; heap dumps
# are created in the working directory of the JVM unless an alternative path is
# specified
-XX:+HeapDumpOnOutOfMemoryError

# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=data

# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p.log

## JDK 8 GC logging
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m

# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m

 添加完数据,点击创建,完成配置项配置!

4.创建有状态工作负载

搜索镜像,配置端口和资源

 

 配置环境变量

这里一定要注意,下面的两对键值对一定一定不要带引号,血的教训!

discovery.type  =  single-node

ES_JAVA_OPTS  =  -Xms512m -Xmx512m

 挂载pvc,"/usr/share/elasticsearch/data"

挂载配置文件

 注意:es的conf目录下有很多配置文件,我们只提出来了两个。但是又不能把其余的配置文件覆盖掉,所以下面的配置要按图来配置。

只读:"/usr/share/elasticsearch/config/elasticsearch.yml"

子路径:"elasticsearch.yml"

选择特定的键和路径:key(elasticsearch.yml)对应es-conf配置项中的配置文件的key,value对应子路径的名字,将来会把子路径elasticsearch.yml的内容替换成配置文件中elasticsearch.yml的内容。

 

只读:"/usr/share/elasticsearch/config/jvm.options"

子路径:"jvm.options"

 

剩下的点击下一步就行,再点击创建。

5.创建对外的服务发现

 

设置外网访问,点击创建

 

至此,es创建成功!

验证:浏览器访问任何一个k8s的ip+服务发现的对外端口,能出来如下页面,证明搭建成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值