Elasticsearch-Kibana docker-compose -禁止“elastic”的值

uqcuzwp8  于 2023-10-14  发布在  Kibana
关注(0)|答案(2)|浏览(273)

我想用docker-compose运行elasticsearch和kibana。这是我的docker-compose.yml,我使用docker-compose --env-filedev.env up运行它
Docker Compose

version: '3.1'

services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.1.1
    container_name: elasticsearch
    environment:
      - cluster.name=elasticsearch-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.type=single-node
      - xpack.security.enrollment.enabled=true
      - ELASTICSEARCH_USERNAME=${ELASTICSEARCH_USERNAME}
      - ELASTICSEARCH_PASSWORD=${ELASTICSEARCH_PASSWORD}
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata:/usr/share/elasticsearch/data
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      - esnet
  kibana:
    image: docker.elastic.co/kibana/kibana:8.1.1
    container_name: kibana
    environment:
      - ELASTICSEARCH_HOSTS=${ELASTICSEARCH_HOSTS}
      - ELASTICSEARCH_USERNAME=${ELASTICSEARCH_USERNAME}
      - ELASTICSEARCH_PASSWORD=${ELASTICSEARCH_PASSWORD}
      - xpack.security.enabled=true
    depends_on:
      - elasticsearch
    ports:
      - "5601:5601"
    networks:
      - esnet

volumes:
  esdata:
    driver: local
  postgres-data:
    driver: local

networks:
  esnet:

Stacktrace
Error: [config validation of [elasticsearch].username]: value of "elastic" is forbidden. This is a superuser account that cannot write to system indices that Kibana needs to function. Use a service account token instead
例如,我设法为用户elastic/kibana创建服务帐户令牌,但如何将其设置为docker-compose?是否有一个特定的环境变量,我应该使用?或者有没有一种方法可以让它工作,而不使用服务帐户?

zsbz8rwp

zsbz8rwp1#

我偶然发现了同样的问题,并尝试使用kibana_adminkibana_systembuilt-in users,但这也不起作用。也许你可以为这些用户设置密码,但我不能。elastic用户角色不允许拥有Kibana所需的system-index write-access。这是基于Elastic(Link to Pullrequest)的更改。
您应该改为使用服务帐户,如docs服务帐户中所述。显然,根据创建服务帐户令牌的docs,您必须以某种方式创建Elasticsearch容器并在启动Kibana容器之前创建令牌。Elasticsearch forums也讨论了这一点。
降级和使用以前的ELK版本也是一种可能性,这也是我所做的,因为我只需要本地开发的集群。

jaxagkaj

jaxagkaj2#

您可以在此环境中设置服务帐户令牌:在你的docker-compose中添加“ELASTICESTAL_SERVICEACCOUNTTOKEN”。我设法在我的docker-compose中为Kibana设置了服务帐户令牌,如下所示:

version: '3.6'
services:
 Elasticsearch:
   image: elasticsearch:8.10.2
   container_name: elasticsearch
   restart: always
   volumes:
   - elastic_data:/usr/share/elasticsearch/data/
   environment:
     ES_JAVA_OPTS: "-Xmx256m -Xms256m"
     discovery.type: single-node
     ELASTIC_PASSWORD: elastic123
   ports:
   - '9200:9200'
   - '9300:9300'
   networks:
     - elk
 Logstash:
   image: logstash:8.10.2
   container_name: logstash
   restart: always
   volumes:
   - ./logstash/pipeline:/usr/share/logstash/pipeline:ro
   command: logstash -f /usr/share/logstash/pipeline/logstash.conf
   depends_on:
     - Elasticsearch
   ports:
   - '9600:9600'
   - '5044:5044'
   environment:
     LS_JAVA_OPTS: "-Xmx256m -Xms256m"
     ELASTICSEARCH_USERNAME: elastic
     ELASTICSEARCH_PASSWORD: elastic123
     XPACK_MONITORING_ELASTICSEARCH_USERNAME: elastic
     XPACK_MONITORING_ELASTICSEARCH_PASSWORD: elastic123
     XPACK_MONITORING_ELASTICSEARCH_HOSTS: "elasticsearch:9200"
     XPACK_MONITORING_ENABLED: "true"
   networks:
     - elk

 Kibana:
   image: kibana:8.10.2
   container_name: kibana
   restart: always
   ports:
   - '5601:5601'
   environment:
     - ELASTICSEARCH_URL=http://elasticsearch:9200
     - ELASTICSEARCH_SERVICEACCOUNTTOKEN=MY_TOKEN
   depends_on:
     - Elasticsearch
   networks:
     - elk
volumes:
 elastic_data: {}
networks:
 elk:

我的logstash.conf文件:

input {
    tcp {
        port => "5044"
        type => syslog
        codec => json_lines
    }
}

output {
    stdout { # This will log all messages so that we can confirm that Logstash is receiving them
        codec => rubydebug
    }
    elasticsearch {
        hosts => ["elasticsearch:9200"]
        index => "logstash"
        user => "elastic"
        password => "elastic123"
    }
}

我还使用此命令为kibana创建了服务帐户令牌:

curl -X POST -u elastic:elastic123 "localhost:9200/_security/service/elastic/kibana/credential/token/token1?pretty"

相关问题