2013-12-22 62 views
16

我已经在服务器上安装了MongoDb和ElasticSearch。使用https://github.com/richardwilly98/elasticsearch-river-mongodb我已将ElasticSearch和MongoDb连接在一起。一旦执行该命令如何使用弹性搜索修复群集健康黄色

curl -XPUT 'http://127.0.0.1:9200/_river/mongodb/_meta' -d '{ 
     "type": "mongodb", 
     "mongodb": { 
     "db": "my_database", 
     "collection": "my_collection" 
    }, 
     "index": { 
     "name": "mainindex", 
     "type": "string", 
     "bulk": { 
      "concurrent_requests": 1 
     } 
    } 
}' 

和我去http://x.x.x.x:9200/_plugin/head/我看到消息::

我创建使用一个新的索引簇健康:黄色(1,6)。

cluster health: yellow (1, 6)

enter image description here

回答

21

群集是由具有elasticsearch.yml你可能使用了在一开始这些设置这样的弹性搜索配置

里面默认的相同的群集名称配置:

################################### Cluster ################################### 

# Cluster name identifies your cluster for auto-discovery. If you're running 
# multiple clusters on the same network, make sure you're using unique names. 
# 
# cluster.name: elasticsearch 


#################################### Node ##################################### 

# Node names are generated dynamically on startup, so you're relieved 
# from configuring them manually. You can tie this node to a specific name: 
# 
# node.name: "Franz Kafka" 

这里你需要配置唯一的

cluster.name: "MainCluster"

和每个机器和/或我nstance不同的唯一

node.name: "LocalMachine1"

你现在需要这个elasticsearch.yml复制到另一台机器(在同一个网络),或在同一个地方如elasticsearch_2.yml编辑它:

node.name: "LocalMachine2"

和群集准备去

如果未配置elastiscsearch会(根据文档3000)使用随机奇迹的性格,所以不改变node.name应该还可以

对于在同一台机器上运行两个节点, 您必须进行配置,例如elasticsearch_2.yml复制上面的更改。 此外,您必须拥有数据和日志路径 的副本,例如(自制具体路径:)

cp -r /usr/local/var/elasticsearch /usr/local/var/elasticsearch_2 
cp -r /usr/local/var/log/elasticsearch /usr/local/var/log/elasticsearch_2 

可能看起来像

#################################### Paths #################################### 

# Path to directory containing configuration (this file and logging.yml): 
# 
# path.conf: /path/to/conf 

# Path to directory where to store index data allocated for this node. 
# 
path.data: /usr/local/var/elasticsearch_2/ 
# 
# Can optionally include more than one location, causing data to be striped across 
# the locations (a la RAID 0) on a file level, favouring locations with most free 
# space on creation. For example: 
# 
# path.data: /path/to/data1,/path/to/data2 

# Path to temporary files: 
# 
# path.work: /path/to/work 

# Path to log files: 
# 
path.logs: /usr/local/var/log/elasticsearch_2/ 

确保您没有本地主机回环设备上运行elasicsearch

127.0.0.1

只是注释掉如果不是这样(自制做补丁ist这种方式)

############################## Network And HTTP ############################### 

# Elasticsearch, by default, binds itself to the 0.0.0.0 address, and listens 
# on port [9200-9300] for HTTP traffic and on port [9300-9400] for node-to-node 
# communication. (the range means that if the port is busy, it will automatically 
# try the next port). 

# Set the bind address specifically (IPv4 or IPv6): 
# 
# network.bind_host: 192.168.0.1 

# Set the address other nodes will use to communicate with this node. If not 
# set, it is automatically derived. It must point to an actual IP address. 
# 
# network.publish_host: 192.168.0.1 

# Set both 'bind_host' and 'publish_host': 
# 
# network.host: 127.0.0.1 

现在你可以这样开始弹性搜索:

bin/elasticsearch -D es.config=/usr/local/Cellar/elasticsearch/1.0.0.RC1/config/elasticsearch.yml 

第一个节点和主(因为开始第一)

然后

bin/elasticsearch -D es.config=/usr/local/Cellar/elasticsearch/1.0.0.RC1/config/elasticsearch_2.yml 

现在,你应该拿2运行的节点

+0

感谢您的反馈,我试着按照你的过程,但我仍然陷入麻烦。一个问题是:当我重新启动服务时,我创建的索引消失了,我需要重新索引。第二期并不是所有文件都被索引......按时它只有5500的1000个,而另一个时间是5500的5000个。你可以为我设置这个东西,也许通过远程会话,所以我可以看到在哪里我做错了事。显然你会得到奖励。 –

+0

供参考:我在一台机器上运行两个节点。 –

8

看起来你没有为副本碎片去一个节点。您可以将副本计数降低到0或将第二个节点添加到群集,以便主节点和副本碎片可以安全地放置在不同的节点上。

在elasticsearch.yml默认配置大概是这样的:

index.number_of_shards: 5 
index.number_of_replicas: 1 

的想法是,如果你的节点崩溃,集群中的其他节点将有碎片的副本。由于您只有一个节点,群集没有放置副本的位置,因此处于黄色状态。

+0

我们如何将节点添加到集群? – Sekai

+0

你可以启动另一个指向不同配置文件的jvm进程,所以想象你已经在/ opt/elasticsearch中安装了es代码,你可以在/ opt/es-1中拥有config /,data /,/ logs,dirs /选择/ ES-2。您可以使用-Des.config = <..file..>创建一个新节点,从指向任意数量配置的命令行启动es – mconlin

+0

我是否只需要指定第二个节点的集群名称,以便它可以加入?如果是的话我该怎么办? – Sekai

1

我发布了一个答案,因为我在寻找si的解决方案时遇到了这个问题类似问题。

我有一个开发环境,我只需要1个Elasticsearch节点,因此不需要所有索引的副本。

为了解决集群健康:黄问题,我只是做了index.number_of_replicas: 1

PUT /_settings 
{ 
    "index" : { 
     "number_of_replicas" : 0 
    } 
}