Elasticsearch 安装与配置(一)

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

netkiller-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值