无法从池中获得新连接

时间:2017-02-20 12:35:24

标签: ruby elasticsearch docker docker-compose

我使用elasticsearch Ruby gem和docker compose为我的容器 从我的Ruby应用程序启动后,我收到此错误:

  

Elasticsearch :: Transport :: Transport ::错误:无法从池中获取新连接。   web_1 | /usr/local/bundle/gems/elasticsearch-transport-2.0.0/lib/elasticsearch/transport/transport/base.rb:249:in perform_request' web_1 | /usr/local/bundle/gems/elasticsearch-transport-2.0.0/lib/elasticsearch/transport/transport/http/faraday.rb:20:in perform_request'   web_1 | /usr/local/bundle/gems/elasticsearch-transport-2.0.0/lib/elasticsearch/transport/client.rb:128:in perform_request' web_1 | /usr/local/bundle/gems/elasticsearch-api-2.0.0/lib/elasticsearch/api/namespace/common.rb:21:in perform_request'   web_1 | /usr/local/bundle/gems/elasticsearch-api-2.0.0/lib/elasticsearch/api/actions/cluster/health.rb:52:in health' web_1 | /usr/src/app/lib/search_model/adapters/elastic_search_adapter.rb:11:in初始化'

initialize方法如下所示:

  def initialize(params={})
    @client = Elasticsearch::Client.new params[:config].merge(host: ::ENV['ELASTICSEARCH_HOST'])
    client.transport.reload_connections!
    client.cluster.health # <-- Line 11
  end

任何想法我做错了什么?

[编辑] 要检查es服务器是否可用,我在启动skript中执行此操作:

until nc -vz $ELASTICSEARCH_HOST 9200; do
 echo "Elasticsearch is not ready, sleeping..."
 sleep 1
done

这是docker-compose文件:

version: '2.1'
services:
  # postgres:
  #   image: postgres
  redis:
    image: redis:alpine
    command: redis-server /usr/local/etc/redis/redis.conf
    volumes:
      - .conf/redis/redis.conf:/usr/local/etc/redis/redis.conf
    expose:
      - "6379"
  elastic:
    image: elasticsearch:alpine
    expose:
      - "9200"
      - "9300"
    volumes:
      - elastic:/usr/share/elastic/data
      - .conf/elastic/synonyms:/usr/share/elasticsearch/config/synonyms
  web:
    build: .
    command: sh bin/docker-start.sh
    environment:
      - ELASTICSEARCH_HOST=elastic
      - RACK_ENV=production
    volumes:
      - .:/usr/src/app
    ports:
      - 4300:2300
    healthcheck:
      test: nc -vz elastic 9200 && nc -vz elastic 9200
      interval: 10s
      timeout: 5s
      retries: 6
    depends_on:
      - redis
      - elastic
    links:
      - redis
      - elastic

volumes:
  elastic: {}

0 个答案:

没有答案