英文:
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"
重新启动容器,然而,它仍然不起作用,我收到相同的错误。我有两个问题需要解决:
- 如何成功重新索引数据?
- 如何从
.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:
- How to successfully reindex the data?
- 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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论