0
点赞
收藏
分享

微信扫一扫

日常遇到Maven出现依赖版本/缓存问题通用思路。

悲催博士僧 2024-02-21 阅读 12

Elasticsearch

Elasticsearch安装(docker)

下载Elasticsearch
查询镜像
[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                    
拉取镜像

image-20230622225933747·

[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/**
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 623 18:22 elastisearch.yml
http:
  host: 0.0.0.0
  cors:
    enabled: true
    allow-origin: "*"
xpack:
  security:
    enabled: false
linux环境配置
调整max_map_count
查询max_map_count值
 sysctl -a|grep vm.max_map_count
修改max_map_count值
 sysctl -w vm.max_map_count=262144

测试是否修改

image-20230629151143142
创建运行容器
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
修改ES内存大小
进入容器
[root@localhost config]# docker exec -it es bash
进入config文件夹
image-20230623193626510

image-20230623193729179

修改jvm.options默认内存大小
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 
开放9200,9300端口
[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
浏览器测试

image-20230729220630026

安装ik分词器

下载分词器
image-20230624205127343 image-20230624205354726
上传分词器

上传分词器到: /usr/local/software/elasticsearch-analysis-ik

[root@localhost software]# mkdir elasticsearch-analysis-ik
拷贝分词器到es容器的plugins/ik中

在容器plugins文件下创建 ik文件夹

tips:v7,.17.7版本一定要解压在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
root@6fa12b7a6ddb:/usr/share/elasticsearch/plugins/ik# rm -rf elasticsearch-analysis-ik-7.17.7.zip
image-20230629162724933
重启docker
root@6fa12b7a6ddb:/usr/share/elasticsearch/plugins# exit
exit
[root@localhost elasticsearch-analysis-ik]# docker restart es 
使用kibana测试分词器

image-20230624215557035

自定义分词器
分词器的文件结构

在Ik文件夹下的config中存储分词器的字典和配置文件

image-20230629163322984

<?xml version="1.0" encoding="UTF-8"?>
<!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>
        <!--用户可以在这里配置远程扩展字典 -->
        <!-- <entry key="remote_ext_dict">words_location</entry> -->
        <!--用户可以在这里配置远程扩展停止词字典-->
        <!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>       

打开一个分词内容ext_stopwords

image-20230629164136117

添加自定义分词器
新建分词器文件

新建自定义分词器文件,后缀为.dic

touch extra_my_ik.dic
编辑文件

编辑文件,使用utf-8编码

image-20230629164415653
修改配置文件

修改IKAnalyzer.cfg.xml 文件,添加自定义的分词器

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
        <comment>IK Analyzer 扩展配置</comment>
        <!--添加自定义的词库extr_my_ik.dic -->
        <entry key="ext_dict">extra_my_ik.dic</entry>
         <!--用户可以在这里配置自己的扩展停止词字典-->
        <entry key="ext_stopwords"></entry>
        <!--用户可以在这里配置远程扩展字典 -->
        <!-- <entry key="remote_ext_dict">words_location</entry> -->
        <!--用户可以在这里配置远程扩展停止词字典-->
        <!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>

测试分词
image-20230629171330048

举报

相关推荐

0 条评论