Elasticsearch 安装与配置
8.1.1. Docker 8.8.1
创建卷
docker volume create es-data docker volume create es-plugins
拉取镜像
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.8.1
HTTP 但节点模式
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 \ -e ES_JAVA_OPTS="-Xms1g -Xmx1g" \ -e xpack.security.enabled=false \ -e discovery.type=single-node \ -v es-data:/usr/share/elasticsearch/data \ -v es-plugins:/usr/share/elasticsearch/plugins \ docker.elastic.co/elasticsearch/elasticsearch:8.8.1
测试安装是否成功
[root@netkiller ~]# curl http://localhost:9200 { "name" : "89eb025a8f53", "cluster_name" : "docker-cluster", "cluster_uuid" : "BXH81Lt-QuS6ZqIQh0ocPw", "version" : { "number" : "8.8.1", "build_flavor" : "default", "build_type" : "docker", "build_hash" : "f8edfccba429b6477927a7c1ce1bc6729521305e", "build_date" : "2023-06-05T21:32:25.188464208Z", "build_snapshot" : false, "lucene_version" : "9.6.0", "minimum_wire_compatibility_version" : "7.17.0", "minimum_index_compatibility_version" : "7.0.0" }, "tagline" : "You Know, for Search" }
HTTPS 模式
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \ -e ES_JAVA_OPTS="-Xms1g -Xmx1g" \ -e discovery.type=single-node \ -e ELASTIC_PASSWORD=elastic \ -v es-data:/usr/share/elasticsearch/data \ -v es-plugins:/usr/share/elasticsearch/plugins \ docker.elastic.co/elasticsearch/elasticsearch:8.8.1 docker exec -it elasticsearch /usr/share/elasticsearch/bin/elasticsearch-reset-password docker cp elasticsearch:/usr/share/elasticsearch/config/certs/http_ca.crt . curl --cacert http_ca.crt -u elastic https://localhost:9200
8.1.2. IK 分词
安装 IK 分词,方法一
https://github.com/medcl/elasticsearch-analysis-ik/releases
下载 zip 解压,复制到 plugins 目录 wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.7.0/elasticsearch-analysis-ik-8.7.0.zip docker cp ik elasticsearch:/usr/share/elasticsearch/plugins
方法二
docker container rm elasticsearch docker volume rm es-data docker volume rm es-plugins docker volume create es-data docker volume create es-plugins docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \ -e ES_JAVA_OPTS="-Xms1g -Xmx1g" \ -e xpack.security.enabled=false \ -e discovery.type=single-node \ -v es-data:/usr/share/elasticsearch/data \ -v es-plugins:/usr/share/elasticsearch/plugins \ docker.elastic.co/elasticsearch/elasticsearch:8.7.0 docker exec -it elasticsearch ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.7.0/elasticsearch-analysis-ik-8.7.0.zip docker restart elasticsearch curl -XPOST -H 'Content-Type: application/json' -d '{"analyzer": "ik_smart","text": "我是中国人,我热爱我的祖国"}' http://localhost:9200/_analyze
分词演示
[root@sfzito ~]# curl -s -XPOST -H 'Content-Type: application/json' -d '{"analyzer": "ik_smart","text": "我是中国人,我热爱我的祖国"}' http://localhost:9200/_analyze |jq { "tokens": [ { "token": "我", "start_offset": 0, "end_offset": 1, "type": "CN_CHAR", "position": 0 }, { "token": "是", "start_offset": 1, "end_offset": 2, "type": "CN_CHAR", "position": 1 }, { "token": "中国人", "start_offset": 2, "end_offset": 5, "type": "CN_WORD", "position": 2 }, { "token": "我", "start_offset": 6, "end_offset": 7, "type": "CN_CHAR", "p