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

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

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

问题

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

  1. POST _reindex
  2. {
  3. "source": {
  4. "remote": {
  5. "host": "http://THE.GIVEN.IP.ADDRESS:9200"
  6. },
  7. "index": "TEST"
  8. },
  9. "dest": {
  10. "index": "TEST"
  11. }
  12. }

但是我收到了错误消息:

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

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

  1. elasticSearch:
  2. image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
  3. container_name: elasticSearch
  4. environment:
  5. - discovery.type=single-node
  6. - reindex.remote.whitelist=${REINDEX_REMOTE_WHITELIST}
  7. ulimits:
  8. memlock:
  9. soft: -1
  10. hard: -1
  11. volumes:
  12. - elasticdata:/usr/share/elasticsearch/data
  13. ports:
  14. - 9200:9200
  15. networks:
  16. - backend

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

  1. docker compose config

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

  1. [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部分如下:

  1. elasticSearch:
  2. image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
  3. container_name: elasticSearch
  4. environment:
  5. - discovery.type=single-node
  6. - reindex.remote.whitelist=${REINDEX_REMOTE_WHITELIST}
  7. ulimits:
  8. memlock:
  9. soft: -1
  10. hard: -1
  11. volumes:
  12. - elasticdata:/usr/share/elasticsearch/data
  13. - ./docker/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
  14. ports:
  15. - 9200:9200
  16. networks:
  17. - backend

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

  1. cluster.name: "docker-cluster"
  2. network.host: 0.0.0.0
  3. 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

  1. POST _reindex
  2. {
  3. "source": {
  4. "remote": {
  5. "host": "http://THE.GIVEN.IP.ADDRESS:9200"
  6. },
  7. "index": "TEST"
  8. },
  9. "dest": {
  10. "index": "TEST"
  11. }
  12. }

But I get the error

  1. [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

  1. elasticSearch:
  2. image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
  3. container_name: elasticSearch
  4. environment:
  5. - discovery.type=single-node
  6. - reindex.remote.whitelist=${REINDEX_REMOTE_WHITELIST}
  7. ulimits:
  8. memlock:
  9. soft: -1
  10. hard: -1
  11. volumes:
  12. - elasticdata:/usr/share/elasticsearch/data
  13. ports:
  14. - 9200:9200
  15. networks:
  16. - 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

  1. [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

  1. elasticSearch:
  2. image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
  3. container_name: elasticSearch
  4. environment:
  5. - discovery.type=single-node
  6. - reindex.remote.whitelist=${REINDEX_REMOTE_WHITELIST}
  7. ulimits:
  8. memlock:
  9. soft: -1
  10. hard: -1
  11. volumes:
  12. - elasticdata:/usr/share/elasticsearch/data
  13. - ./docker/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
  14. ports:
  15. - 9200:9200
  16. networks:
  17. - backend

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

  1. cluster.name: "docker-cluster"
  2. network.host: 0.0.0.0
  3. 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”。以下是我的配置:

  1. 版本:'3'
  2. 卷:
  3. elasticsearch_data: {}
  4. 服务:
  5. elasticsearch:
  6. 重启:总是
  7. 镜像:elasticsearch:7.17.10
  8. 环境:
  9. - 发现类型=单节点
  10. - "ES_JAVA_OPTS=-Xms4096m -Xmx4096m"
  11. - reindex.remote.whitelist=my_remote_hostname:443
  12. 卷:
  13. - elasticsearch_data:/usr/share/elasticsearch/data
  14. 端口:
  15. - "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:

确定