docker安装Elasticsearch

扫测资讯 2024-12-08 12:07   28 0

公网即可拉取镜像,这个镜像是可以拉得到的,版本号根据自己需要的来

docker pull docker.elastic.co/elasticsearch/elasticsearch:7.17.15

运行命令,xxxxxxxxxxxxxxxxxxxxxxxx_password 为自己的密码

docker run -d --name elasticsearch \
  -e "discovery.type=single-node" \
  -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" \
  -e "xpack.security.enabled=true" \
  -e "ELASTIC_PASSWORD=xxxxxxxxxxxxxxxxxxxxxxxx_password" \
  -p 9200:9200 -p 9300:9300 \
  docker.elastic.co/elasticsearch/elasticsearch:7.17.15

测试访问

curl -u elastic:xxxxxxxxxxxx_password http://localhost:9200

保存镜像

docker save -o elasticsearch_7.17.15.tar docker.elastic.co/elasticsearch/elasticsearch:7.17.15

加载镜像

docker load -i  elasticsearch_7.17.15.tar

nginx代理

server {
    listen 9200;
    server_name xxx;# 配置代理到 Elasticsearch
    
	location / {
	    proxy_pass http://172.16.17.333:9200;  # 代理到 Elasticsearch
	    proxy_set_header Host $host;
	    proxy_set_header X-Real-IP $remote_addr;
	    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	    proxy_set_header X-Forwarded-Proto $scheme;
	    proxy_set_header Authorization "Basic $(echo -n 'elastic:xxxxxxxx_password' | base64)";  # 添加 Elasticsearch 基本认证头
	    proxy_read_timeout 90;
	}
}

如果nginx没有 base64
自己base64 去加密 elastic:xxxxxxxx_password