Docker安装elasticsearch/es

2023-04-19

docker pull elasticsearch:7.17.7

docker run -d --name elasticsearch --network-alias elasticsearch -p 9200:9200 -p 9300:9300 ^
-v c:/docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml ^
-v c:/docker/elasticsearch/data:/usr/share/elasticsearch/data ^
-v c:/docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins ^
elasticsearch:7.17.7





elasticsearch.yml

# 修改网络请求可以被所有外网访问到

http.host: 0.0.0.0

# 开启es跨域

http.cors.enabled: true

http.cors.allow-origin: "*"




# 设置密码

xpack.security.enabled: true

xpack.security.transport.ssl.enabled: true




安装ik分词器

docker exec -it es bash

elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.9.3/elasticsearch-analysis-ik-7.9.3.zip




es默认分词器对中文分词非常不友好,会把一句话拆成每一个字(想要了解可以去查下资料)




es设置密码

docker exec -it elasticsearch bash




bin/elasticsearch-setup-passwords interactive




es修改密码

curl -XPUT -u user:password 'http://localhost:9200/_security/user/elastic/_password' -H "Content-Type: application/json" -d'
{
  "password": "newpassword"
}


请将 user 替换成具有管理员权限的用户名,password 替换成用户名的登录密码,newpassword 替换成你要设置的新密码。