elasticsearch 8 集群搭建

下载 https://elasticsearch.cn/download/


vim /etc/security/limits.conf
* hard nofile 65536
* soft nofile 65536
* hard nproc  4096
* soft nproc  4096

vim /etc/sysctl.conf
vm.max_map_count=262144


useradd elastic
groups elastic
chown -R elastic:elastic /data/sll/elasticsearch-8.3.1

su elastic

./elasticsearch -d
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: myes
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-2
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: 192.168.106.213
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: ["192.168.106.211", "192.168.106.213"]
#
node.roles: [master,data] 
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
# --------------------------------- Readiness ----------------------------------
#
# Enable an unauthenticated TCP readiness endpoint on localhost
#
#readiness.port: 9399
# Enable security features
xpack.security.enabled: false
#
#
# ---------------------------------- Various -----------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false

http://192.168.106.213:9200/_cat/master?v
http://192.168.106.213:9200/_cat/nodes?v
http://192.168.160.17:9200/_cat/indices?v
http://192.168.160.17:9200/_cat/shards?v
http://192.168.160.17:9200/_cat/health?v

import json
import time

from elasticsearch import Elasticsearch

es = Elasticsearch('http://192.168.160.17:9200')
print(es)


def es_search_recall_index(address, routing, hn_index='hn_index', recall_number=100):
    body = {"size": recall_number,
            "query": {"match": {"address": address}},
            }
    try:
        res = es.search(index=hn_index, body=body, routing=routing)
    except Exception as e:
        print(e)
    return res


if __name__ == '__main__':
    addr = '西关大街143'
    res = es_search_recall_index(addr, routing='630100', hn_index='hn_index_location', recall_number=20)
    print(res)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容