Centos7 Kubernetes(k8s) 开发服务器(单服务器)部署 elasticsearch 搜索引擎

这几天对开发服务器中的 k8s和相关模块 进行升级,做个记录
开发服务器(单服务器)部署 elasticsearch 搜索引擎

环境,与系统

系统:centos 7.6

内核: 5.1.9-1.el7.elrepo.x86_64

Kubernetes(K8s) 1.14.3

服务器IP:192.168.0.254

服务器IP 说明

如果更改了服务器IP 为其他IP,那么请全局全部替换成你改的IP
fox.风

如何安装 k8s

请看 最近写的一篇文章,

https://blog.csdn.net/fenglailea/article/details/88745642
常用 k8s 命令
https://foxwho.blog.csdn.net/article/details/92137467

服务器资源限制

对CPU,内存都做了限制,请自行针对修改

没有使用持久化存储,这里直接使用宿主机存储,如有需要,请自行增加

目录

请把项目放置到 /www/k8s/foxdev/ 目录下,所有都是基于此目录
或者请看 下面一节的 拉取代码

拉取代码

mkdir -p /www/k8s/
cd /www/k8s/

git clone https://github.com/foxiswho/k8s-nacos-sentinel-rocketmq-zipkin-elasticsearch-redis-mysql.git foxdev

cd foxdev

以下是 独立部署 相关模块

k8s elasticsearch 独立部署

当前版本已经安装了词库,词库内的配置文件,

默认没有启用映射(默认把它给注释掉),如需要自己配置,那么只要开启映射即可。

词库

常用的词库

https://github.com/medcl/elasticsearch-analysis-ik

相关参数说明

端口:9200

端口:9300

目录说明

elasticsearch/logs 日志目录

elasticsearch/data 数据目录

如果你有更多的插件需要加载,那么 请自行配置相关目录

独立部署 elasticsearch 操作

直接执行 根目录create.elk.elasticsearch.start.sh 即可


./create.elk.elasticsearch.start.sh

执行完成后,即可用 elasticsearch 了

案例

创建索引

curl -XPUT http://192.168.0.254:9200/index

输出

{"acknowledged":true,"shards_acknowledged":true,"index":"index"}

创建mapping

curl -XPOST http://192.168.0.254:9200/index/_mapping -H 'Content-Type:application/json' -d'
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_smart"
            }
        }

}'

输出

{"acknowledged":true}

添加几条数据

curl -XPOST http://192.168.0.254:9200/index/_create/1?pretty -H 'Content-Type:application/json' -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}
'

输出略

curl -XPOST http://192.168.0.254:9200/index/_create/2?pretty -H 'Content-Type:application/json' -d'
{"content":"公安部:各地校车将享最高路权"}
'
curl -XPOST http://192.168.0.254:9200/index/_create/3?pretty -H 'Content-Type:application/json' -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
'
curl -XPOST http://192.168.0.254:9200/index/_create/4?pretty -H 'Content-Type:application/json' -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
'
curl -XPOST http://192.168.0.254:9200/index/_create/5?pretty -H 'Content-Type:application/json' -d'
{"content":"考验特朗普的时候到了!美盟友率先出手,普京紧跟2记“重拳”"}
'

查询

curl -XPOST http://192.168.0.254:9200/index/_search?pretty  -H 'Content-Type:application/json' -d'
{
    "query" : { "match" : { "content" : "中国" }},
    "highlight" : {
        "pre_tags" : ["", ""],
        "post_tags" : ["", ""],
        "fields" : {
            "content" : {}
        }
    }
}
'

输出

{
  "took" : 8,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.6650044,
    "hits" : [
      {
        "_index" : "index",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 0.6650044,
        "_source" : {
          "content" : "中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"
        },
        "highlight" : {
          "content" : [
            "中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"
          ]
        }
      },
      {
        "_index" : "index",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 0.6308529,
        "_source" : {
          "content" : "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
        },
        "highlight" : {
          "content" : [
            "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
          ]
        }
      }
    ]
  }
}

Kubernetes 编排文件

elasticsearch-service.yml

apiVersion: apps/v1
kind: StatefulSet
metadata:
  #  namespace: default
  name: elasticsearch
  labels:
    app: elasticsearch
spec:
  serviceName: elasticsearch
  replicas: 1
  selector:
    matchLabels:
      app: elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
    spec:
      containers:
        - name: elasticsearch
          image: foxiswho/elk:elasticsearch-7.1.1
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              cpu: 350m
              memory: 3Gi
            requests:
              cpu: 100m
              memory: 2Gi
          env:
            - name: TZ
              value: Asia/Shanghai
            - name: ES_JAVA_OPTS
              value: -Xmx2000m -Xmx2000m
          ports:
            - containerPort: 9200
            - containerPort: 9300
          volumeMounts:
            - name: vol-logs
              mountPath: /usr/share/elasticsearch/logs
            - name: vol-data
              mountPath: /usr/share/elasticsearch/data
#            - name: vol-plugins-analysis-ik-conf
#              mountPath: /usr/share/elasticsearch/plugins/analysis-ik/config/IKAnalyzer.cfg.xml
            - name: vol-es
              mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
            - name: vol-synonyms
              mountPath: /usr/share/elasticsearch/config/synonyms.txt
      volumes:
        - name: vol-logs
          hostPath:
            path: /www/k8s/foxdev/elasticsearch/logs
            type: Directory
        - name: vol-data
          hostPath:
              path: /www/k8s/foxdev/elasticsearch/data
              type: Directory
#        - name: vol-plugins-analysis-ik-conf
#          hostPath:
#              path: /www/k8s/foxdev/elasticsearch/plugins/analysis-ik/config/IKAnalyzer.cfg.xml
#              type: File
        - name: vol-es
          hostPath:
              path: /www/k8s/foxdev/elasticsearch/config/elasticsearch.yml
              type: File
        - name: vol-synonyms
          hostPath:
              path: /www/k8s/foxdev/elasticsearch/config/synonyms.txt
              type: File

elasticsearch-rc.yml

apiVersion: v1
kind: Service
metadata:
#  namespace: default
  name: elasticsearch
  labels:
    app: elasticsearch
spec:
  type: NodePort
  ports:
    - port: 9200
      targetPort: 9200
      nodePort: 9200
      name: es-9200
    - port: 9300
      targetPort: 9300
      nodePort: 9300
      name: es-9300
  selector:
    app: elasticsearch

create.elk.elasticsearch.start.sh

#!/usr/bin/env bash

DIR=$(pwd)

mkdir -p        ${DIR}/elasticsearch/logs
mkdir -p        ${DIR}/elasticsearch/data
mkdir -p        ${DIR}/elasticsearch/plugins/analysis-ik
chmod -R 777    ${DIR}/elasticsearch/logs
chmod -R 777    ${DIR}/elasticsearch/data
chmod -R 777    ${DIR}/elasticsearch/plugins/analysis-ik

kubectl create -f  ${DIR}/elasticsearch/elasticsearch-service.yml
kubectl create -f  ${DIR}/elasticsearch/elasticsearch-rc.yml

kubectl get pod

echo -e "\n\n\n"

echo " success"

在开发服务器上部署成功,有问题的,可以联系我

源文件

https://github.com/foxiswho/k8s-nacos-sentinel-rocketmq-zipkin-elasticsearch-redis-mysql

你可能感兴趣的:(系统,服务器,平台,docker,虚拟机,kubernetes)