[root@localhost elk]# docker search elasticsearch
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
elasticsearch Elasticsearch is a powerful open source sear… 6126 [OK]
kibana Kibana gives shape to any kind of data — str… 2629 [OK]
bitnami/elasticsearch Bitnami Docker Image for Elasticsearch 67 [OK]
bitnami/elasticsearch-exporter Bitnami Elasticsearch Exporter Docker Image 7 [OK]
rancher/elasticsearch-conf 2
docker pull elasticsearch:版本号
·
[root@localhost elk]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
elasticsearch 7.17.7 ec0817395263 9 months ago 619MB
nginx latest 605c77e624dd 19 months ago 141MB
redis latest 7614ae9453d1 19 months ago 113MB
mysql latest 3218b38490ce 19 months ago 516MB
rabbitmq latest d445c0adc9a5 19 months ago 220MB
canal/canal-server latest 0c7f1d62a7d8 2 years ago 874MB
[root@localhost elasticsearch]# mkdir -p elasticsearch/data
[root@localhost elasticsearch]# mkdir -p elasticsearch/config
[root@localhost elasticsearch]# mkdir -p elasticsearch/plugins
[root@localhost elk]#chmod 777 elasticsearch/**
在config文件夹下创建elasticsearch.yml文件,并修改其为可读写执行权限。
[root@localhost config]# touch elasticsearch.yml
[root@localhost config]# chmod 777 elasticsearch.yml
[root@localhost config]# tree
.
└── elastisearch.yml
[root@localhost config]# ll
总用量 0
-rwxrwxrwx. 1 root root 0 6月 23 18:22 elastisearch.yml
修改elasticsearch.yml的内容
xpack.security.enabled: 配置es的安全,但是只免费使用1个月。本机使用不设置安全模块。
http:
host: 0.0.0.0
cors:
enabled: true
allow-origin: "*"
xpack:
security:
enabled: false
max_map_count文件包含限制一个进程可以拥有的VMA(虚拟内存区域)的数量,默认值是65536。
sysctl -a|grep vm.max_map_count
sysctl -w vm.max_map_count=262144
测试是否修改
- 9200作为Http协议,主要用于外部通讯。一般都是给工具连接ElasticSearch使用的,java连接ES也需要这个端口。
- 9300是一个自定义的二进制协议,用于集群中各节点之间的通信。用于诸如集群变更、主节点选举、节点加入/离开、分片分配等事项。
- ES_JAVA_OPTS指定容器内的JVM内存配置,建议大于512M。
docker run -itd \
--name es \
--privileged \
--network wn_docker_net \
--ip 172.18.12.70 \
-p 9200:9200 \
-p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms1g -Xmx1g" \
-v /usr/local/softwares/elk/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /usr/local/softwares/elk/elasticsearch/data:/usr/share/elasticsearch/data \
-v /usr/local/software/elk/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
elasticsearch:7.17.7
[root@localhost config]# docker exec -it es bash
root@6fa12b7a6ddb:/usr/share/elasticsearch/config# echo "-Xms4g" >> jvm.options
root@6fa12b7a6ddb:/usr/share/elasticsearch/config# echo "-Xmx4g" >> jvm.options
root@6fa12b7a6ddb:/usr/share/elasticsearch/config# exit
exit
[root@localhost config]# docker restart es
[root@localhost config]# firewall-cmd --zone=public --add-port=9200/tcp --permanent
success
[root@localhost config]# firewall-cmd --zone=public --add-port=9300/tcp --permanent
success
[root@localhost config]# firewall-cmd --reload
success
最好下载和elasticSearch一致的分词器,如果没有则保证大版本一致,例如:7.17.X
上传分词器到: /usr/local/software/elasticsearch-analysis-ik
[root@localhost software]# mkdir elasticsearch-analysis-ik
在容器plugins文件下创建 ik文件夹
tips:v7,.17.7版本一定要解压在plugins**/ik**文件夹下否则报找不到错误。
容器中位置: /usr/share/elasticsearch/plugins/ik
[root@localhost elasticsearch-analysis-ik]# docker cp elasticsearch-analysis-ik-7.17.7.zip es:/usr/share/elasticsearch/plugins/ik
root@6fa12b7a6ddb:/usr/share/elasticsearch/plugins/ik# unzip elasticsearch-analysis-ik-7.17.7.zip
删除elasticsearch-analysis-ik-7.17.7.zip
root@6fa12b7a6ddb:/usr/share/elasticsearch/plugins/ik# rm -rf elasticsearch-analysis-ik-7.17.7.zip
root@6fa12b7a6ddb:/usr/share/elasticsearch/plugins# exit
exit
[root@localhost elasticsearch-analysis-ik]# docker restart es
在Ik文件夹下的config中存储分词器的字典和配置文件
DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置comment>
<entry key="ext_dict">entry>
<entry key="ext_stopwords">entry>
properties>
打开一个分词内容ext_stopwords
新建自定义分词器文件,后缀为.dic
touch extra_my_ik.dic
编辑文件,使用utf-8编码
修改IKAnalyzer.cfg.xml 文件,添加自定义的分词器
DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置comment>
<entry key="ext_dict">extra_my_ik.dicentry>
<entry key="ext_stopwords">entry>
properties>
使用kibana测试