一、ES的安裝
1、系統引數配置,修改vi /etc/sysctl.conf,追加內容
vm.max_map_count=655360
2、容器安裝
docker run -di --name=es -p 9200:9200 -p 9300:9300 elasticsearch:6.8.12
3、進行跨域配置,先進入容器
docker exec -it es /bin/bash
修改容器中/usr/share/elasticsearch/config/elasticsearch.yml檔案,新增配置如下
cluster.name: "elasticsearch" http.cors.enabled: true http.cors.allow-origin: "*" network.host: 0.0.0.0 discovery.zen.minimum_master_nodes: 1
引數說明:
cluster.name:叢集服務名字
http.cors.enabled:開啟跨域
http.cors.allow-origin: 允許跨域域名,*代表所有域名
network.host: 外部訪問的IP
discovery.zen.minimum_master_nodes: 最小主節點個數
4、安裝完成後,重啟容器`docker restart es`,再訪問`http://192.168.32.130:9200/`效果如下:
{ "name": "Ke8Ljah", "cluster_name": "elasticsearch", "cluster_uuid": "QLeYJtTITxmRP29fbFpgbA", "version": { "number": "6.8.12", "build_flavor": "default", "build_type": "docker", "build_hash": "7a15d2a", "build_date": "2020-08-12T07:27:20.804867Z", "build_snapshot": false, "lucene_version": "7.7.3", "minimum_wire_compatibility_version": "5.6.0", "minimum_index_compatibility_version": "5.0.0" }, "tagline": "You Know, for Search" }
5、IK分詞器安裝
分詞器下載地址:https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v6.8.0下載後,將壓縮包解壓並將加壓的檔案放到ik目錄下,並拷貝到elasticsearch的plugins目錄下即可,用如下命令拷貝:
docker cp ik es:/usr/share/elasticsearch/plugins/
重啟es:
docker restart es
6、es-head安裝
docker run -d -p 9100:9100 docker.io/mobz/elasticsearch-head:5
安裝完成後訪問`http://192.168.32.130:9100/就可以,並且最後要完成下面三個步驟
1、進入`head`安裝目錄;
2、`cd _site/`
3、編輯`vendor.js` 共有兩處
①、6886行 `"application/x-www-form-urlencoded`,改成:` "application/json;charset=UTF-8"`
②、7574行 `"application/x-www-form-urlencoded"`改成:` "application/json;charset=UTF-8"`
最後附上es官方地址:https://spring.io/projects/spring-data-elasticsearch