elasticsearch win7集群配置python测试

来源:互联网 发布:长沙黑马程序员 编辑:程序博客网 时间:2024/05/29 13:26

准备  elasticsearch-2.4.4 包

解压到D:\soft\elasticsearch-2.4.4

在elasticsearch-2.4.4的data下新建2个文件夹分别为data和logs


win local ip配置

C:\Windows\System32\drivers\etc\hosts

在hosts文件添加 

192.168.1.103


elasticsearch.yml  配置  master node

# ======================== 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 see the documentation for further information on configuration options:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: es_cn
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: es02
#
# Add custom attributes to the node:
#
# node.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: D:\soft\elasticsearch-2.4.4\data\data\data
#
# Path to log files:
#
path.logs: D:\soft\elasticsearch-2.4.4\data\data\logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: false
#
# Make sure that the `ES_HEAP_SIZE` environment variable 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 -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.1.103
#
# Set a custom port for HTTP:
#
http.port: 9200


# 为节点之间的通信设置一个自定义端口(默认为9300)
transport.tcp.port: 9300


#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.multicast.enabled: true
discovery.zen.ping.unicast.hosts: ["192.168.1.103:9300"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
#
# ---------------------------------- Various -----------------------------------
#
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true


node.master: true
node.data: true


http.cors.enabled: true
http.cors.allow-origin: "*"


浏览器访问

http://192.168.1.103:9200/

{  "name" : "es02",  "cluster_name" : "es_cn",  "cluster_uuid" : "E8h8jC24QBGJVUdzAvoNfw",  "version" : {    "number" : "2.4.4",    "build_hash" : "fcbb46dfd45562a9cf00c604b30849a6dec6b017",    "build_timestamp" : "2017-01-03T11:33:16Z",    "build_snapshot" : false,    "lucene_version" : "5.5.2"  },  "tagline" : "You Know, for Search"}


子节点配置

复制elasticsearch-2.4.4到D:\soft\elasticsearch-2.4.4_2

elasticsearch.yml  修改配置   node

# ======================== 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 see the documentation for further information on configuration options:# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>## ---------------------------------- Cluster -----------------------------------## Use a descriptive name for your cluster:#cluster.name: es_cn## ------------------------------------ Node ------------------------------------## Use a descriptive name for the node:#node.name: es03## Add custom attributes to the node:## node.rack: r1## ----------------------------------- Paths ------------------------------------## Path to directory where to store the data (separate multiple locations by comma):#path.data: D:\soft\elasticsearch-2.4.4_2\data\data\data## Path to log files:#path.logs: D:\soft\elasticsearch-2.4.4_2\data\data\logs## ----------------------------------- Memory -----------------------------------## Lock the memory on startup:#bootstrap.memory_lock: false## Make sure that the `ES_HEAP_SIZE` environment variable 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 -----------------------------------## Set the bind address to a specific IP (IPv4 or IPv6):#network.host: 192.168.1.103## Set a custom port for HTTP:#http.port: 9201# 为节点之间的通信设置一个自定义端口(默认为9300)transport.tcp.port: 9301## For more information, see the documentation at:# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>## --------------------------------- Discovery ----------------------------------## Pass an initial list of hosts to perform discovery when new node is started:# The default list of hosts is ["127.0.0.1", "[::1]"]#discovery.zen.ping.multicast.enabled: truediscovery.zen.ping.unicast.hosts: ["192.168.1.103:9300"]## Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):##discovery.zen.minimum_master_nodes: 3## For more information, see the documentation at:# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>## ---------------------------------- Gateway -----------------------------------## Block initial recovery after a full cluster restart until N nodes are started:## gateway.recover_after_nodes: 3## For more information, see the documentation at:# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>## ---------------------------------- Various -----------------------------------## Disable starting multiple nodes on a single system:## node.max_local_storage_nodes: 1## Require explicit names when deleting indices:## action.destructive_requires_name: truenode.master: falsenode.data: truehttp.cors.enabled: truehttp.cors.allow-origin: "*"

访问http://192.168.1.103:9201/

{  "name" : "es03",  "cluster_name" : "es_cn",  "cluster_uuid" : "E8h8jC24QBGJVUdzAvoNfw",  "version" : {    "number" : "2.4.4",    "build_hash" : "fcbb46dfd45562a9cf00c604b30849a6dec6b017",    "build_timestamp" : "2017-01-03T11:33:16Z",    "build_snapshot" : false,    "lucene_version" : "5.5.2"  },  "tagline" : "You Know, for Search"}


python curd操作

1,确定是否操作成功

2,是否自动同步


python文件编写

#!/usr/bin/python# -*- coding: UTF-8 -*-from datetime import datetimefrom elasticsearch import Elasticsearchimport jpype#调用javajvmPath = jpype.getDefaultJVMPath()jpype.startJVM(jvmPath)jpype.java.lang.System.out.println("hello world!")jpype.shutdownJVM()# 连接elasticsearch,默认是9200es = Elasticsearch("192.168.1.103:9201")#es = Elasticsearch([{'host':'192.168.176.135','port':9200},{'host':'192.168.176.136','port':9200}])# 插入数据,(这里省略插入其他两条数据,后面用)#es.index(index="my-index", doc_type="test-type", id=01, body={"any": "data01", "timestamp": datetime.now()})# {u'_type':u'test-type',u'created':True,u'_shards':{u'successful':1,u'failed':0,u'total':2},u'_version':1,u'_index':u'my-index',u'_id':u'1}# 也可以,在插入数据的时候再创建索引test-indexes.index(index="test-index", doc_type="test-type", id=42, body={"any": "data", "timestamp": datetime.now()})# 查询数据,两种get and search# get获取res = es.get(index="my-index", doc_type="test-type", id=01)print(res)# {u'_type': u'test-type', u'_source': {u'timestamp': u'2016-01-20T10:53:36.997000', u'any': u'data01'}, u'_index': u'my-index', u'_version': 1, u'found': True, u'_id': u'1'}print(res['_source'])# {u'timestamp': u'2016-01-20T10:53:36.997000', u'any': u'data01'}


测试查看














原创粉丝点击