首页 > 其他分享 > Elasticsearch搜索功能的实现(四)--使用ECK安装Elasticsearch开发环境

Elasticsearch搜索功能的实现(四)--使用ECK安装Elasticsearch开发环境

时间:2023-04-18 23:11:40浏览次数:37  
标签:service elastic created -- ECK version Elasticsearch elasticsearch k8s

一、ECK安装ES

1、在k8s 集群上安装 ECK

1.1 安装自定义资源

root@DESKTOP-H5OMIME:~# kubectl create -f https://download.elastic.co/downloads/eck/2.6.1/crds.yaml
customresourcedefinition.apiextensions.k8s.io/agents.agent.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/apmservers.apm.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/beats.beat.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/elasticmapsservers.maps.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/elasticsearchautoscalers.autoscaling.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/elasticsearches.elasticsearch.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/enterprisesearches.enterprisesearch.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/kibanas.kibana.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/stackconfigpolicies.stackconfigpolicy.k8s.elastic.co created

1.2 安装RBAC规则

root@DESKTOP-H5OMIME:~# kubectl apply -f https://download.elastic.co/downloads/eck/2.6.1/operator.yaml
namespace/elastic-system created
serviceaccount/elastic-operator created
secret/elastic-webhook-server-cert created
configmap/elastic-operator created
clusterrole.rbac.authorization.k8s.io/elastic-operator created
clusterrole.rbac.authorization.k8s.io/elastic-operator-view created
clusterrole.rbac.authorization.k8s.io/elastic-operator-edit created
clusterrolebinding.rbac.authorization.k8s.io/elastic-operator created
service/elastic-webhook-server created
statefulset.apps/elastic-operator created
validatingwebhookconfiguration.admissionregistration.k8s.io/elastic-webhook.k8s.elastic.co created

1.3 监控操作日志

root@DESKTOP-H5OMIME:~# kubectl -n elastic-system logs -f statefulset.apps/elastic-operator
{"log.level":"info","@timestamp":"2023-02-17T14:04:55.201Z","log.logger":"manager","message":"maxprocs: Updating GOMAXPROCS=1: determined from CPU quota","service.version":"2.6.1+62f2e278","service.type":"eck","ecs.version":"1.4.0"}
{"log.level":"info","@timestamp":"2023-02-17T14:04:55.202Z","log.logger":"manager","message":"Setting default container registry","service.version":"2.6.1+62f2e278","service.type":"eck","ecs.version":"1.4.0","container_registry":"docker.elastic.co"}
{"log.level":"info","@timestamp":"2023-02-17T14:04:55.202Z","log.logger":"manager","message":"Setting up scheme","service.version":"2.6.1+62f2e278","service.type":"eck","ecs.version":"1.4.0"}
{"log.level":"info","@timestamp":"2023-02-17T14:04:55.202Z","log.logger":"manager","message":"Operator configured to manage all namespaces","service.version":"2.6.1+62f2e278","service.type":"eck","ecs.version":"1.4.0"}
{"log.level":"info","@timestamp":"2023-02-17T14:04:56.004Z","log.logger":"controller-runtime.metrics","message":"Metrics server is starting to listen","service.version":"2.6.1+62f2e278","service.type":"eck","ecs.version":"1.4.0","addr":":0"}
{"log.level":"info","@timestamp":"2023-02-17T14:04:56.008Z","log.logger":"manager","message":"Setting up controllers","service.version":"2.6.1+62f2e278","service.type":"eck","ecs.version":"1.4.0"}
{"log.level":"info","@timestamp":"2023-02-17T14:04:56.009Z","log.logger":"manager","message":"Automatic management of the webhook certificates enabled","service.version":"2.6.1+62f2e278","service.type":"eck","ecs.version":"1.4.0"}
.....

2、部署Elasticsearch集群

2.1 拉取镜像

docker pull elasticsearch:8.5.0

2.2 构建自定义 elasticsearch 镜像

下载 es版本 对应 ik 分词器和拼音 插件

wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.5.0/elasticsearch-analysis-ik-8.5.0.zip
wget https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v8.5.0/elasticsearch-analysis-pinyin-8.5.0.zip

2.3 编写Dockerfile

FROM elasticsearch:8.5.0
COPY ./elasticsearch-analysis-ik-8.5.0.zip /home/
COPY ./elasticsearch-analysis-pinyin-8.5.2.zip /home/
RUN bin/elasticsearch-plugin install --batch file:/home/elasticsearch-analysis-ik-8.5.0.zip
RUN bin/elasticsearch-plugin install --batch file:/home/elasticsearch-analysis-pinyin-8.5.0.zip

2.4 构建定制elasticsearch镜像

docker build --tag elasticsearch-ik:8.5.0 .

2.5 快速部署一个单节点集群

命名空间 estest

指定镜像版本

禁用证书认证

root@DESKTOP-H5OMIME:~# cat <<EOF | kubectl apply -f -
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: quickstart
  namespace: estest
spec:
  version: 8.5.0
  image: elasticsearch-ik:8.5.0
  nodeSets:
  - name: default
    count: 1
    config:
      node.store.allow_mmap: false
  http:
    tls:
      selfSignedCertificate:
        disabled: true
EOF

2.6 监控集群创建进程

root@DESKTOP-H5OMIME:~/test# kubectl get elasticsearch -n estest
NAME         HEALTH    NODES   VERSION   PHASE             AGE
quickstart   unknown           8.5.0     ApplyingChanges   8s

等待创建

root@DESKTOP-H5OMIME:~/test# kubectl get elasticsearch -n estest
NAME         HEALTH   NODES   VERSION   PHASE   AGE
quickstart   green    1       8.5.0    Ready   55s

2.7 查看镜像状态

kubectl get pods --selector='elasticsearch.k8s.elastic.co/cluster-name=quickstart' -n estest

NAME                      READY   STATUS    RESTARTS   AGE
quickstart-es-default-0   1/1     Running   0          79s

2.8 查看pod 日志

kubectl logs -f quickstart-es-default-0 -n estest

2.9 查看集群service 信息

root@DESKTOP-H5OMIME:~/test# kubectl get service quickstart-es-http -n estest
NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
quickstart-es-http   ClusterIP   10.107.199.80   <none>        9200/TCP   103s

2.10 对外暴露访问端口(临时,当控制台关闭则访问失效)

kubectl port-forward service/quickstart-es-http 9200 -n estest

2.11 获取访问凭证并赋值变量

PASSWORD=$(kubectl get secret quickstart-es-elastic-user -n estest -o  go-template='{{.data.elastic | base64decode}}')

2.12 本地终端访问

root@DESKTOP-H5OMIME:~# curl -u "elastic:$PASSWORD" -k "https://127.0.0.1:9200"
{
  "name" : "quickstart-es-default-0",
  "cluster_name" : "quickstart",
  "cluster_uuid" : "NsTB77UlQlyPQCfsAqPzQw",
  "version" : {
    "number" : "8.5.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "180c9830da956993e59e2cd70eb32b5e383ea42c",
    "build_date" : "2023-01-24T21:35:11.506992272Z",
    "build_snapshot" : false,
    "lucene_version" : "9.4.2",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

3、部署Kibana 实例

3.1 拉取镜像

docker pull kibana:8.5.0

3.2 部署kibana 指定命名空间与镜像版本

cat <<EOF | kubectl apply -f -
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
  name: quickstart
  namespace: estest
spec:
  version: 8.5.0
  image: kibana:8.5.0
  count: 1
  elasticsearchRef:
    name: quickstart
EOF

3.3 监控 Kibana 健康状态与创建进程

kubectl get kibana -n estest

3.4 查看pod 状态

kubectl get pod --selector='kibana.k8s.elastic.co/name=quickstart' -n estest

3.5 查看Service集群IP

kubectl get service quickstart-kb-http -n estest

3.6 对外暴露访问端口(临时,当控制台关闭则访问失效)

kubectl port-forward service/quickstart-kb-http 5601 -n estest

3.7 获取elastic登录用户的密码

kubectl get secret quickstart-es-elastic-user -n estest -o=jsonpath='{.data.elastic}' | base64 --decode; echo

3.8 web 访问 https://127.0.0.1:5601

访问管理页面

image

image

查看es 索引情况

image

查询页面

image

查看分词效果

#测试细分分词
POST /_analyze
{
  "analyzer": "ik_max_word",
  "text":"中华人民共和国台湾特别行政区"
}

image

#测试分词
POST /_analyze
{
  "analyzer": "ik_smart",
  "text":"中华人民共和国台湾特别行政区"
}

image

4、卸载

4.1 卸载elasticsearch

root@DESKTOP-H5OMIME:~# cat <<EOF | kubectl delete -f -
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: quickstart
  namespace: estest
spec:
  version: 8.5.0
  image: elasticsearch-ik:8.5.0
  nodeSets:
  - name: default
    count: 1
    config:
      node.store.allow_mmap: false
  http:
    tls:
      selfSignedCertificate:
        disabled: true
EOF

4.2 卸载kibana

cat <<EOF | kubectl delete -f -
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
  name: quickstart
  namespace: estest
spec:
  version: 8.5.0
  image: kibana:8.5.0
  count: 1
  elasticsearchRef:
    name: quickstart
EOF

4.4 卸载ECK

kubectl delete -f https://download.elastic.co/downloads/eck/2.6.1/crds.yaml
kubectl delete -f https://download.elastic.co/downloads/eck/2.6.1/operator.yaml

标签:service,elastic,created,--,ECK,version,Elasticsearch,elasticsearch,k8s
From: https://www.cnblogs.com/gdwkong/p/17331596.html

相关文章

  • docker拉取国外镜像到国内个人镜像库
    日常的生产开发中,免不了从国外拉取镜像,但有个问题,我们可能访问不到那个镜像源,因此需要使用代理https://labs.play-with-docker.com具体步骤使用dockerhub账号登录上述代理执行pull下载你要的镜像sudodockerpullregistry.k8s.io/ingress-nginx/controller:v1.3.0sudodo......
  • 【五期邹昱夫】CCF-A(NeurIPS'19)Deep leakage from gradients.
    "Zhu,Ligeng,ZhijianLiu,andSongHan."Deepleakagefromgradients."Advancesinneuralinformationprocessingsystems32(2019)."  本文从公开共享的梯度中获得私有训练数据。首先随机生成一对“伪”输入和标签,然后执行正常的向前和向后操作。在从伪数据导出......
  • pyenv-win-master\pyenv-win\libexec\pyenv-install.vbs(161, 5) Microsoft VBScri
    Windows10运行pyenvinstall3.11.2提示pyenv-win-master\pyenv-win\libexec\pyenv-install.vbs(161,5)MicrosoftVBScript运行时错误:文件未找到解决问题C:\Users\larry>pyenv--versionpyenv3.1.1C:\Users\larry>pyenvinstall3.11.2::[Info]:: Mirror:http......
  • OI 数论中的上界估计与时间复杂度证明
    预备0.1渐进符号其实不少高等数学/数学分析教材在讲解无穷小的比较时已经相当严谨地介绍过大O、小O记号,然而各种历史习惯记法的符号滥用(abuseofnotation)[1]直到现在都让笔者头疼.Thesenotationsseemtobeinnocent,butcanbecatastrophicwithoutcarefulm......
  • #A. 选夏令营旗手
    #A.选夏令营旗手【问题描述】一年一度的江苏省“信息与未来”小学生夏令营活动又开始了。与每年一样,组织者又设计安排了许多有趣的活动,其中第一项依然是挑选本次夏令营的旗手!由于这是一个非常具有荣誉感的角色,所以报名参加夏令营旗手角逐的营员仍然非常多,营委会于是规定:将N个......
  • 变编程一小时2023.4.18
    1.#include<iostream>usingnamespacestd;classShape{ public: virtualdoublearea()const=0;};classCircle:publicShape{ public: Circle(doubler):radius(r) { } virtualdoublearea()const { return3.14159*radius*radius; } protected: dou......
  • 每日八股文之Java
    1、请你说说多线程得分点:线程和进程的关系、为什么使用多线程进程是操作系统资源调度的基本单位,线程是处理器任务调度和执行的基本单位,一个进程可以创建多个线程,每个线程有自己独立的程序计数器,本地方法栈和虚拟机栈,线程之间共享进程的堆和方法区。线程之间是通过时间片算法......
  • Codeforces Round 866 (Div. 2)
    A.Yura'sNewName一个简单的dp,状态是\(f[i][0/1]\)表示前\(i\)位变成合法的且最后一位是^或_的最小代价。如果是_只能从^转移过来,如果是^则都可以转移过来#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ strings; cin>>s; intn=s.size(); if(n=......
  • django查询一周内的数据,一月内的数据,一年内的数据
    首先是当前时间的确定,对于年月日,orm模型都有对应的方法直接查询,周是没有方法直接查询的,我是没有找到这个方法,只能间接的查询。cur_time=datetime.datetime.now()#如果数据库保存的是UTC时间,程序不会蹦但是会提示你这不是本地时间now_time_utc=datetime.datetime.utcnow......
  • 每日团队小结
    昨天对opencv,ocr学习和使用了今天对程序的编写,servlet编写,以及对接口调用部署的浏览器找不到自己写的servlet ......