2023-04-19
windows
docker pull elasticsearch:7.14.0
chmod 777 data/
chmod 777 config/
chmod 777 plugins/
# 修改虚拟内存,要不然ES报错起不来
vim /etc/sysctl.conf
追加
vm.max_map_count=262144
# 执行命令立即生效
sudo sysctl -p
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 --restart=always \
-v /taiyusoft/docker/elasticsearch/data:/usr/share/elasticsearch/data \
-v /taiyusoft/docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /taiyusoft/docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-e "discovery.type=single-node" \
-e "ES_JAVA_OPTS=-Xms4096m -Xmx4096m" \
elasticsearch:7.14.0
linux
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 \
-v /taiyusoft/docker/elasticsearch/data:/usr/share/elasticsearch/data \
-v /taiyusoft/docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-e "discovery.type=single-node" \
-e "ES_JAVA_OPTS=-Xms4096m -Xmx4096m" \
elasticsearch:7.14.0
开放防火墙端口
firewall-cmd --zone=public --add-port=9300/tcp --permanent
firewall-cmd --zone=public --add-port=9300/tcp --permanent
systemctl restart firewalld
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 替换成你要设置的新密码。