为什么使用Laravel和Docker会收到“您的群集中没有活动的节点”的信息?

时间:2019-06-30 14:35:55

标签: laravel docker elasticsearch

我尝试使用docker和babenkoivan / scout-elasticsearch-driver在laravel项目上设置elasticsearch。 当我启动docker时,所有工作的容器都包含elasticsearch,但是当我尝试使用

php artisan elastic:create-index "App\TutorialIndexConfigurator"

我收到一个错误:

No alive nodes found in your cluster

此外,当我尝试从docker工作区容器通过curl访问端口9200时,我得到

curl: (7) Failed to connect to localhost port 9200: Connection refused

但是当我从终端进行同样的思考时,我会得到有关docker elasticsearch cluster的信息。我认为这可能是相关的。

我为此问题浪费了三天,但没有任何解决方案,请帮忙。

我试图从laradock做同样的事情,并得出相同的结果。

这是我的docker-compose.yml内容

version: '3.1'

#volumes:
#  elasticsearch:
#    driver: local

volumes:
  esdata1:
    driver: local
  esdata2:
    driver: local
  esdata3:
    driver: local

networks:
  esnet:
  frontend:
  backend:

services:
  nginx:
    image: nginx
    ports:
        - "80:80"
        - "443:443"
    volumes:
      - ./hosts:/etc/nginx/conf.d
      - ./www:/var/www
      - ./logs:/var/log/nginx
    links:
      - php
    networks:
      esnet:
      frontend:
        aliases:
          - api.dev
      backend:
        aliases:
          - api.dev

  mysql:
    image: mysql:5.7

    ports: 
    - "3306:3306"

    volumes:
      - ./mysql:/var/lib/mysql

    environment:
        MYSQL_ROOT_PASSWORD: secret

    networks:
      - esnet
      - frontend
      - backend

  # postgres:
  #   image: postgres

  #   ports: 
  #     - "3306:3306"

  #   environment:
  #       MYSQL_ROOT_PASSWORD: secret

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

  php:
    build: ./images/php

    links:
      - mysql

    volumes:
      - ./www:/var/www

    networks:
      - esnet
      - frontend
      - backend

  workspace:
      build: ./images/workspace
      volumes:
        - ./www:/var/www:cached
      extra_hosts:
        - "dockerhost:10.0.75.1"
      ports:
        - "2222:22"
      tty: true
      networks:
        - esnet
        - frontend
        - backend

  redis:
    image: redis:latest

    volumes:
          - ./www/redis:/data

    ports:
      - "6379:6379"


  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
    container_name: elasticsearch
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - http.cors.enabled=true
      - http.cors.allow-origin=*
      - discovery.zen.minimum_master_nodes=2
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - esnet
      - frontend
      - backend

  lasticsearch2:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
    container_name: elasticsearch2
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "discovery.zen.ping.unicast.hosts=elasticsearch"
      - http.cors.enabled=true
      - http.cors.allow-origin=*
      - discovery.zen.minimum_master_nodes=2
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata2:/usr/share/elasticsearch/data
    networks:
      - esnet
      - frontend
      - backend

  elasticsearch3:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
    container_name: elasticsearch3
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "discovery.zen.ping.unicast.hosts=elasticsearch"
      - http.cors.enabled=true
      - http.cors.allow-origin=*
      - discovery.zen.minimum_master_nodes=2
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata3:/usr/share/elasticsearch/data
    networks:
      - esnet
      - frontend
      - backend

  kibana:
    image: 'docker.elastic.co/kibana/kibana:6.4.2'
    container_name: kibana
    environment:
      SERVER_NAME: kibana.local
      ELASTICSEARCH_URL: http://elasticsearch:9200
    ports:
      - '5601:5601'
    networks:
      - esnet
      - frontend
      - backend

  headPlugin:
    image: 'mobz/elasticsearch-head:5'
    container_name: head
    ports:
      - '9100:9100'
    networks:
      - esnet
      - frontend
      - backend

这是scout_elastic配置

<?php

return [
    'client' => [
        'hosts' => [
            env('SCOUT_ELASTIC_HOST', 'localhost:9200'),
        ],
    ],
    'update_mapping' => env('SCOUT_ELASTIC_UPDATE_MAPPING', true),
    'indexer' => env('SCOUT_ELASTIC_INDEXER', 'single'),
    'document_refresh' => env('SCOUT_ELASTIC_DOCUMENT_REFRESH'),
];

和.env侦察兵配置

SCOUT_DRIVER=elastic

1 个答案:

答案 0 :(得分:0)

我相信您的问题是错误的SCOUT_ELASTIC_HOST
应该是SCOUT_ELASTIC_HOST=http://elasticsearch:9200 就像在kibana服务中一样。不是http://localhost:9200