返回介绍

PART Ⅰ : 容器云OPENSHIFT

PART Ⅱ:容器云 KUBERNETES

PART Ⅲ:持续集成与持续部署

PART Ⅴ:日志/监控/告警

PART Ⅵ:基础

PART Ⅶ:数据存储、处理

PART VIII:CODE

PART X:HACKINTOSH

PART XI:安全

Elasticsearch 容器化部署

发布于 2024-06-08 21:16:47 字数 11245 浏览 0 评论 0 收藏 0

docker pull docker.io/elasticsearch/elasticsearch:6.6.1
#或者
docker pull docker.elastic.co/elasticsearch/elasticsearch:6.6.1

修改系统

echo "vm.max_map_count=262144" >> /etc/sysctl.conf
sysctl -w vm.max_map_count=262144

Docker单节点部署

docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.io/elasticsearch/elasticsearch:6.6.1

Docker compose集群部署

version: '2.2'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
    container_name: elasticsearch
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - esnet
  elasticsearch2:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
    container_name: elasticsearch2
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "discovery.zen.ping.unicast.hosts=elasticsearch"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata2:/usr/share/elasticsearch/data
    networks:
      - esnet

volumes:
  esdata1:
    driver: local
  esdata2:
    driver: local
networks:
  esnet:

DeploymentConfig

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  labels:
    app: elasticsearch
  name: elasticsearch
spec:
  replicas: 1
  selector:
    app: elasticsearch
    deploymentconfig: elasticsearch
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: elasticsearch
        deploymentconfig: elasticsearch
    spec:
      containers:
        - env:
            - name: discovery.type
              value: single-node
            - name: cluster.name
              value: curiouser
            - name: bootstrap.memory_lock
              value: 'true'
            - name: path.repo
              value: /usr/share/elasticsearch/snapshots-repository
            - name: TZ
              value: Asia/Shanghai
            - name: ES_JAVA_OPTS
              value: '-Xms1g -Xmx2g'
            - name: xpack.monitoring.collection.enabled
              value: 'true'
            - name: xpack.security.enabled
              value: 'true'
            - name: ELASTIC_USERNAME
              value: "elastic"
            - name: "ELASTIC_PASSWORD"
              value: "elastic"  
          image: 'docker.elastic.co/elasticsearch/elasticsearch:7.1.1'
          imagePullPolicy: IfNotPresent
          livenessProbe:
            failureThreshold: 3
            initialDelaySeconds: 90
            periodSeconds: 10
            successThreshold: 1
            tcpSocket:
              port: 9200
            timeoutSeconds: 1
          name: elasticsearch
          ports:
            - containerPort: 9200
              protocol: TCP
            - containerPort: 9300
              protocol: TCP
          readinessProbe:
            failureThreshold: 3
            initialDelaySeconds: 80
            periodSeconds: 10
            successThreshold: 1
            tcpSocket:
              port: 9200
            timeoutSeconds: 1
          resources:
            limits:
              cpu: '2'
              memory: 3Gi
            requests:
              cpu: '1'
              memory: 2Gi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /usr/share/elasticsearch/data
              name: elasticsearch-data
            - mountPath: /usr/share/elasticsearch/snapshots-repository
              name: elasticsearch-snapshots-repository
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
        - name: elasticsearch-data
          persistentVolumeClaim:
            claimName: elasticsearch-data
        - name: elasticsearch-snapshots-repository
          persistentVolumeClaim:
            claimName: elasticsearch-snapshots-repository
  test: false
  triggers:
    - type: ConfigChange

SVC

apiVersion: v1
kind: Service
metadata:
  labels:
    app: elasticsearch
  name: elasticsearch
spec:
  ports:
  - name: 9200-tcp
    port: 9200
    protocol: TCP
    targetPort: 9200
  - name: 9300-tcp
    port: 9300
    protocol: TCP
    targetPort: 9300
  selector:
    deploymentconfig: elasticsearch
  sessionAffinity: None
  type: ClusterIP

数据目录PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    volume.beta.kubernetes.io/storage-class: nfs-client-storageclass
  name: elasticsearch-data
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi

snapshot repository存储目录PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    volume.beta.kubernetes.io/storage-class: nfs-client-storageclass
  name: elasticsearch-snapshots-repository
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi

Deployment

kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    elastic-app: elasticsearch
    role: master
  name: elasticsearch-master
  namespace: elk
spec:
  replicas: 1
  revisionHistoryLimit: 10
  strategy:
    type: Recreate
  selector:
    matchLabels:
      elastic-app: elasticsearch
      role: master
  template:
    metadata:
      labels:
        elastic-app: elasticsearch
        role: master
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: kubernetes.io/hostname
                    operator: In
                    values:
                      - node1.k8s.curiouser.com
      initContainers:
        - name: init-scheduler
          image: busybox:latest
          imagePullPolicy: IfNotPresent
          command: ['sh', '-c', 'chmod -R 777 /usr/share/elasticsearch/data /usr/share/elasticsearch/snapshots-repository && chown -R 1000.0 /usr/share/elasticsearch/data /usr/share/elasticsearch/snapshots-repository']
          volumeMounts:
            - name: elasticsearch-data
              mountPath: /usr/share/elasticsearch/data
            - name: elasticsearch-snapshots-repository
              mountPath: /usr/share/elasticsearch/snapshots-repository
      containers:
        - name: elasticsearch-master-data
          image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 9200
              protocol: TCP
            - containerPort: 9300
              protocol: TCP
          env:
            - name: "cluster.name"
              value: "Curiouser"
            - name: "bootstrap.memory_lock"
              value: "false"
            - name: discovery.type
              value: single-node
            - name: "node.master"
              value: "true"
            - name: "node.data"
              value: "true"
            - name: "node.ingest"
              value: "false"
            - name: xpack.monitoring.collection.enabled
              value: "true"
            - name: "xpack.monitoring.elasticsearch.collection.enabled"
              value: "true"
            - name: "xpack.security.enabled"
              value: "true"
            - name: "path.repo"
              value: "/usr/share/elasticsearch/snapshots-repository"
            - name: "ES_JAVA_OPTS"
              value: "-Xms2048m -Xmx2048m"
            - name: TZ
              value: Asia/Shanghai
            - name: "xpack.monitoring.exporters.my_local.type"
              value: "local"
            - name: "xpack.monitoring.exporters.my_local.use_ingest"
              value: "false"
          resources:
            requests:
              memory: "2Gi"
              cpu: "2"
            limits:
              memory: "4096Mi"
              cpu: "3"
          readinessProbe:
            failureThreshold: 1
            initialDelaySeconds: 60
            periodSeconds: 60
            successThreshold: 1
            tcpSocket:
              port: 9200
            timeoutSeconds: 1
          livenessProbe:
            failureThreshold: 1
            initialDelaySeconds: 60
            periodSeconds: 60
            successThreshold: 1
            tcpSocket:
              port: 9200
            timeoutSeconds: 1
          volumeMounts:
            - name: elasticsearch-data
              mountPath: "/usr/share/elasticsearch/data"
            - name: elasticsearch-snapshots-repository
              mountPath: "/usr/share/elasticsearch/snapshots-repository"
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      schedulerName: default-scheduler
      volumes:
        - name: elasticsearch-data
          persistentVolumeClaim:
            claimName: elasticsearch-data
        - name: elasticsearch-snapshots-repository
          persistentVolumeClaim:
            claimName: elasticsearch-snapshots-repository

PersistentVolumeClaim

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    volume.beta.kubernetes.io/storage-class: cephfs
  labels:
    app: elasticsearch
  name: elasticsearch-data
  namespace: elk
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 20Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    volume.beta.kubernetes.io/storage-class: cephfs
  labels:
    app: elasticsearch
  name: elasticsearch-snapshots-repository
  namespace: elk
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 30Gi

Service

kind: Service
apiVersion: v1
metadata:
  labels:
    elastic-app: elasticsearch-service
  name: elasticsearch
  namespace: elk
spec:
  ports:
    - port: 9200
      targetPort: 9200
      protocol: TCP
  selector:
    elastic-app: elasticsearch
  type: ClusterIP

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文