# docker-elasticsearch **Repository Path**: tao_huangtao/docker-elasticsearch ## Basic Information - **Project Name**: docker-elasticsearch - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-02-06 - **Last Updated**: 2025-02-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 在k8s中部署elastic search es 6.8 ## 创建配置文件 ``` --- apiVersion: v1 data: elasticsearch.yml: | cluster.name: "${NAMESPACE}" node.name: "${POD_NAME}" network.host: 0.0.0.0 node.master: true # datanode节点 node.data: true # 存储数据 discovery.zen.ping.unicast.hosts: ["es-0.es.bigdata.svc.kn.pengbei.net","es-1.es.bigdata.svc.kn.pengbei.net","es-2.es.bigdata.svc.kn.pengbei.net"] # master 的服务名称 kind: ConfigMap metadata: name: bigdata-es namespace: bigdata ``` ## 创建无头服务 ``` --- apiVersion: v1 kind: Service metadata: labels: k8s-app: es name: es namespace: bigdata spec: clusterIP: None type: ClusterIP sessionAffinity: None ports: - name: out port: 9200 protocol: TCP targetPort: 9200 - name: in port: 9300 protocol: TCP targetPort: 9300 selector: app: es ``` ## 创建有状态容器 ``` --- apiVersion: apps/v1 kind: StatefulSet metadata: labels: app: es name: es namespace: bigdata spec: replicas: 3 selector: matchLabels: app: es serviceName: es template: metadata: labels: app: es spec: containers: - env: - name: NAMESPACE valueFrom: fieldRef: apiVersion: v1 fieldPath: metadata.namespace - name: POD_NAME valueFrom: fieldRef: apiVersion: v1 fieldPath: metadata.name - name: path.data value: /data/$(POD_NAME) image: 'hub.pengbei.tech:18080/bigdata/elasticsearch:6.8.13_ik_xpack' imagePullPolicy: Always name: es ports: - containerPort: 9200 protocol: TCP - containerPort: 9300 protocol: TCP resources: limits: cpu: '6' memory: 20Gi requests: cpu: '1' memory: 10Gi volumeMounts: - mountPath: /usr/share/elasticsearch/config/elasticsearch.yml name: es-config subPath: elasticsearch.yml - mountPath: /data name: data dnsPolicy: ClusterFirst imagePullSecrets: - name: pengbei-registry-secret initContainers: - command: - /bin/sh - '-c' - |- sysctl -w net.core.somaxconn=65535 sysctl -w net.ipv4.ip_local_port_range="1024 65535" sysctl -w fs.file-max=1048576 sysctl -w fs.inotify.max_user_instances=16384 sysctl -w fs.inotify.max_user_watches=524288 sysctl -w fs.inotify.max_queued_events=16384 sysctl -w vm.max_map_count=262144 image: 'hub.pengbei.tech:18080/bigdata/busybox:latest' imagePullPolicy: IfNotPresent restartPolicy: Always volumes: - name: data persistentVolumeClaim: claimName: es-3-pvc - configMap: defaultMode: 420 name: bigdata-es name: es-config ``` # 验证集群是否正常 ### 查看节点 ``` curl es:9200/_cat/nodes ``` ### 查看集群状态 ``` curl es:9200/_cluster/health?pretty ``` ### 查看安装的查看 ``` curl es:9200/_cat/plugins ``` ### 测试分词器 ``` curl -XPOST -H 'Content-Type: application/json' es:9200/_analyze --data '{"text":"朋辈是一家人工智能公司","analyzer":"ik_smart"}' ``` ### 写入数据 ``` curl -XPOST -H 'Content-Type: application/json' es:9200/df/df/1 --data '{"a":1}' curl -XGET es:9200/df/df/1 ``` ### es 6更多配置参考 ``` cluster.name: omt-es node.name: ${HOSTNAME} node.master: false node.data: true node.ingest: false path.data: /data/es/data,/disk1/elastic/data6,/disk2/elastic/data6 path.logs: /data/es/logs bootstrap.memory_lock: true network.bind_host: 0.0.0.0 network.publish_host: 172.16.2.66 http.port: 9200 transport.tcp.port: 9300 discovery.zen.ping.unicast.hosts: ["172.16.2.63:9300", "172.16.2.64:9300","172.16.2.65:9300","172.16.2.66:9300"] discovery.zen.minimum_master_nodes: 2 bootstrap.system_call_filter: false http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-methods: OPTIONS,HEAD,GET,POST,PUT,DELETE http.cors.allow-headers: X-Requested-With,Content-Type,Content-Length,Authorization,Content-Encoding,Accept-Encoding http.enabled: true cluster.routing.allocation.same_shard.host: true gateway.recover_after_nodes: 2 gateway.expected_nodes: 4 gateway.recover_after_time: 5m action.destructive_requires_name: true cluster.routing.allocation.node_initial_primaries_recoveries: 8 discovery.zen.fd.ping_timeout: 180s discovery.zen.fd.ping_retries: 8 discovery.zen.fd.ping_interval: 30s discovery.zen.ping_timeout: 120s #discovery.zen.ping.multicast.enabled: false ```