linux手动安装es

时间:2024-05-09 16:16:07

docker下载

docker pull elasticsearch:7.9.3
docker pull kibana:7.9.3
  • 检查安装目录下存在文件夹/data/elasticsearch/data ,如果缺少,请创建目录并设置权限,否则会因为无权限访问而启动失败。
# 创建目录
mkdir /data/elasticsearch/data/

# 创建并改变该目录权限
chmod 777 /data/elasticsearch/data

docker-compose文件

version: '2.1'
services:
  ad_elasticsearch:
    image: elasticsearch:7.9.3
    container_name: ad_elasticsearch
    restart: always
    environment:
      - "cluster.name=elasticsearch" #设置集群名称为elasticsearch
      - "discovery.type=single-node" #以单一节点模式启动
      - "ES_JAVA_OPTS=-Xms512m -Xmx1024m" #设置使用jvm内存大小
    volumes:
      - ./data:/usr/share/elasticsearch/data:rw
      - ./logs:/user/share/elasticsearch/logs:rw
      - ./esplugins:/usr/share/elasticsearch/plugins
    ports:
      - 9200:9200
      - 9300:9300

  kibana:
    image: kibana:7.9.3
    container_name: ad_kibana
    links:
      - ad_elasticsearch:elasticsearch #可以用es这个域名访问elasticsearch服务
    depends_on:
      - ad_elasticsearch #kibana在elasticsearch启动之后再启动
    environment:
      - "elasticsearch.hosts=http://elasticsearch:9200" #设置访问elasticsearch的地址
    ports:
      - 5601:5601

yml文件配置完毕以后,接下来指定文件运行容器。

docker-compose -f docker-compose.yml up -d

启动完毕以后应该可以看到一系列的容器出现start状态。 可以查看容器的日志。

# 查看全部的docker-compose 日志
docker-compose logs

需要安装中文分词器IKAnalyzer,并重新启动。

注意下载与Elasticsearch对应的版本。安装目录已经存在elasticsearch-analysis-ik-7.9.3.zip,需要解压到指定目录。

# 在安装目录的esplugin中创建文件夹
cd esplugin && mkdir analysis-ik

# 退出到安装目录
cd ..

# 解压缩到指定文件夹
unzip elasticsearch-analysis-ik-7.9.3.zip -d ./esplugin/analysis-ik/
docker restart ad_elasticsearch

Ingest Attachment Processor Plugin是一个文本抽取插件,本质上是利用了Elasticsearchingest node功能,提供了关键的预处理器attachment

docker exec -it ad_elasticsearch /bin/sh

进入容器后,在安装目录下运行以下命令即可安装。

./bin/elasticsearch-plugin install ingest-attachment

重新启动服务

docker restart ad_elasticsearch

设置通道索引

PUT /_ingest/pipeline/attachment
{
    "description": "Extract attachment information",
    "processors": [
        {
            "attachment": {
                "field": "content",
                "ignore_missing": true
            }
        },
        {
            "remove": {
                "field": "content"
            }
        }
    ]
}

建立文档索引

PUT /docwrite
{
  "mappings" : {
      "properties" : {
        "ancestors" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "attachment" : {
          "properties" : {
            "content" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              },
              "analyzer" : "ik_smart"
            },
            "content_length" : {
              "type" : "long"
            },
            "content_type" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "language" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "authObjs" : {
          "properties" : {
            "authId" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "authType" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "docId" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "parkId" : {
              "type" : "long"
            },
            "receiveUserId" : {
              "type" : "long"
            }
          }
        },
        "content" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "createDeptId" : {
          "type" : "long"
        },
        "createTime" : {
          "type" : "date"
        },
        "createUserId" : {
          "type" : "long"
        },
        "description" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "docFormat" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "docId" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "docName" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          },
          "analyzer" : "ik_smart"
        },
        "docOwner" : {
          "type" : "long"
        },
        "docSize" : {
          "type" : "long"
        },
        "docUrl" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "encry" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "hasRecycle" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "parentId" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "parkId" : {
          "type" : "long"
        },
        "updateDeptId" : {
          "type" : "long"
        },
        "updateTime" : {
          "type" : "date"
        },
        "updateUserId" : {
          "type" : "long"
        }
      }
    }
}