Dockerized Elasticsearch: How to configure `reindex.remote.whitelist` elastic.yml with variables inside .env file

huangapple go评论73阅读模式
英文:

Dockerized Elasticsearch: How to configure `reindex.remote.whitelist` elastic.yml with variables inside .env file

问题

首先,我应该说我已经搜索了很多关于这个问题的信息并阅读了许多内容,但都没有对我起作用。我需要按照以下方式从远程服务器重新索引索引:

POST _reindex
{
  "source": {
    "remote": {
      "host": "http://THE.GIVEN.IP.ADDRESS:9200"
    },
    "index": "TEST"
  },
  "dest": {
    "index": "TEST"
  }
}

但是我收到了错误消息:

[THE.GIVEN.IP.ADDRESS:9200] not whitelisted in reindex.remote.whitelist

我需要在通过Docker运行的ES实例的elasticsearch.yml中设置reindex.remote.whitelist属性。这是Docker文件的Elasticsearch服务部分:

elasticSearch:
  image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
  container_name: elasticSearch
  environment:
    - discovery.type=single-node
    - reindex.remote.whitelist=${REINDEX_REMOTE_WHITELIST}
  ulimits:
    memlock:
      soft: -1
      hard: -1
  volumes:
    - elasticdata:/usr/share/elasticsearch/data
  ports:
    - 9200:9200
  networks:
    - backend

REINDEX_REMOTE_WHITELIST.env文件中设置,并且命令

docker compose config

会正确地给出这个变量。然而,它不起作用,reindex命令报告错误:

[THE.GIVEN.IP.ADDRESS:9200] not whitelisted in reindex.remote.whitelist

经过Google搜索,我发现我需要在容器的/usr/share/elasticsearch/config目录中的elasticsearch.yml文件的reindex.remote.whitelist属性中包含URL。为此,我修改了docker-compose文件的volumes部分如下:

elasticSearch:
  image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
  container_name: elasticSearch
  environment:
    - discovery.type=single-node
    - reindex.remote.whitelist=${REINDEX_REMOTE_WHITELIST}
  ulimits:
    memlock:
      soft: -1
      hard: -1
  volumes:
    - elasticdata:/usr/share/elasticsearch/data
    - ./docker/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
  ports:
    - 9200:9200
  networks:
    - backend

并添加了./docker/elasticsearch/elasticsearch.yml文件,其内容如下:

cluster.name: "docker-cluster"
network.host: 0.0.0.0
reindex.remote.whitelist: "http://THE.GIVEN.IP.ADDRESS:9200"

重新启动容器,然而,它仍然不起作用,我收到相同的错误。我有两个问题需要解决:

  1. 如何成功重新索引数据?
  2. 如何从.env文件中读取远程IP地址?在项目目录的elasticsearch.yml中硬编码IP地址是一个好的做法吗?

提前感谢。

英文:

First I should say I have searched a lot and read many things about the problem but non worked for me. I need to reindex an index from a remote server as follows

POST _reindex
{
  "source": {
    "remote": {
      "host": "http://THE.GIVEN.IP.ADDRESS:9200"
    },
    "index": "TEST"
  },
  "dest": {
    "index": "TEST"
  }
}

But I get the error

[THE.GIVEN.IP.ADDRESS:9200] not whitelisted in reindex.remote.whitelist

I need to set reindex.remote.whitelist property in elasticsearch.yml of an ES instance running via docker. This is the elastic search service of the docker file

  elasticSearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
    container_name: elasticSearch
    environment:
      - discovery.type=single-node
      - reindex.remote.whitelist=${REINDEX_REMOTE_WHITELIST}
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - elasticdata:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - backend

The REINDEX_REMOTE_WHITELIST is set inside a .env file and the command

> docker compose config

gives me this variable correctly. However it is not working and the reindex command reports error

[THE.GIVEN.IP.ADDRESS:9200] not whitelisted in reindex.remote.whitelist

After googling, I find out I need to include the URL in reindex.remote.whitelist property of elasticsearch.yml file that is located in /usr/share/elasticsearch/config directory of the container. To do so I modified the volume of docker-compose file as follows

  elasticSearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
    container_name: elasticSearch
    environment:
      - discovery.type=single-node
      - reindex.remote.whitelist=${REINDEX_REMOTE_WHITELIST}
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - elasticdata:/usr/share/elasticsearch/data
      - ./docker/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
     ports:
      - 9200:9200
    networks:
      - backend

and added ./docker/elasticsearch/elasticsearch.yml file with the following content

cluster.name: "docker-cluster"
network.host: 0.0.0.0
reindex.remote.whitelist: "http://THE.GIVEN.IP.ADDRESS:9200"

restarted the container, however, it still not working. and I get the same error. I have two things need to solve:

  1. How to successfully reindex the data?
  2. How to read the remove IP address from the .env file? Is this a good practice to hard the IP inside the elasticsearch.yml of the project directory?

Thanks in advance.

答案1

得分: 1

你应该在你的docker-compose设置中只添加主机名,不要包含“http”。以下是我的配置:

版本:'3'

卷:
  elasticsearch_data: {}

服务:
  elasticsearch:
    重启:总是
    镜像:elasticsearch:7.17.10
    环境:
      - 发现类型=单节点
      - "ES_JAVA_OPTS=-Xms4096m -Xmx4096m"
      - reindex.remote.whitelist=my_remote_hostname:443
    卷:
      - elasticsearch_data:/usr/share/elasticsearch/data
    端口:
      - "9200:9200"
英文:

you should add only hostname without "http" in your docker-compose settings. Here is my config:

<pre>
version: '3'

volumes:
elasticsearch_data: {}

services:
elasticsearch:
restart: always
image: elasticsearch:7.17.10
environment:
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms4096m -Xmx4096m"
- reindex.remote.whitelist=my_remote_hostname:443
volumes:
- elasticsearch_data:/usr/share/elasticsearch/data
ports:
- "9200:9200"
</pre>

huangapple
  • 本文由 发表于 2023年6月28日 23:53:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76574833.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定