ELK入门(一)-Elasticsearch(docker版)

Elasticsearch

Elasticsearch安装(docker)

下载Elasticsearch
查询镜像
shell 复制代码
[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                    
拉取镜像

docker pull elasticsearch:版本号

·

shell 复制代码
[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
挂载配置
创建挂载文件夹
shell 复制代码
[root@localhost elasticsearch]# mkdir -p elasticsearch/data
[root@localhost elasticsearch]# mkdir -p elasticsearch/config
[root@localhost elasticsearch]# mkdir -p elasticsearch/plugins
修改文件夹权限
shell 复制代码
[root@localhost elk]#chmod 777 elasticsearch/**
elasticsearch.yml

在config文件夹下创建elasticsearch.yml文件,并修改其为可读写执行权限。

shell 复制代码
[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 6月  23 18:22 elastisearch.yml

修改elasticsearch.yml的内容

xpack.security.enabled: 配置es的安全,但是只免费使用1个月。本机使用不设置安全模块。

shell 复制代码
http:
  host: 0.0.0.0
  cors:
    enabled: true
    allow-origin: "*"
xpack:
  security:
    enabled: false
linux环境配置
调整max_map_count

max_map_count文件包含限制一个进程可以拥有的VMA(虚拟内存区域)的数量,默认值是65536。

查询max_map_count值
shell 复制代码
 sysctl -a|grep vm.max_map_count
修改max_map_count值
shell 复制代码
 sysctl -w vm.max_map_count=262144

测试是否修改

创建运行容器
  • 9200作为Http协议,主要用于外部通讯。一般都是给工具连接ElasticSearch使用的,java连接ES也需要这个端口。
  • 9300是一个自定义的二进制协议,用于集群中各节点之间的通信。用于诸如集群变更、主节点选举、节点加入/离开、分片分配等事项。
  • ES_JAVA_OPTS指定容器内的JVM内存配置,建议大于512M。
shell 复制代码
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内存大小
进入容器
shell 复制代码
[root@localhost config]# docker exec -it es bash
进入config文件夹
修改jvm.options默认内存大小
shell 复制代码
root@6fa12b7a6ddb:/usr/share/elasticsearch/config# echo "-Xms4g"  >> jvm.options
root@6fa12b7a6ddb:/usr/share/elasticsearch/config# echo "-Xmx4g"  >> jvm.options
退出、重启容器
shell 复制代码
root@6fa12b7a6ddb:/usr/share/elasticsearch/config# exit                         
exit
[root@localhost config]# docker restart es 
开放9200,9300端口
shell 复制代码
[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
浏览器测试

安装ik分词器

下载分词器

最好下载和elasticSearch一致的分词器,如果没有则保证大版本一致,例如:7.17.X

Releases · medcl/elasticsearch-analysis-ik · GitHub

上传分词器

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

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

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

tips:v7,.17.7版本一定要解压在plugins**/ik**文件夹下否则报找不到错误。

容器中位置: /usr/share/elasticsearch/plugins/ik

shell 复制代码
[root@localhost elasticsearch-analysis-ik]# docker cp elasticsearch-analysis-ik-7.17.7.zip es:/usr/share/elasticsearch/plugins/ik
解压分词器
shell 复制代码
root@6fa12b7a6ddb:/usr/share/elasticsearch/plugins/ik# unzip elasticsearch-analysis-ik-7.17.7.zip

删除elasticsearch-analysis-ik-7.17.7.zip

shell 复制代码
root@6fa12b7a6ddb:/usr/share/elasticsearch/plugins/ik# rm -rf elasticsearch-analysis-ik-7.17.7.zip
重启docker
shell 复制代码
root@6fa12b7a6ddb:/usr/share/elasticsearch/plugins# exit
exit
[root@localhost elasticsearch-analysis-ik]# docker restart es 
使用kibana测试分词器
自定义分词器
分词器的文件结构

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

xml 复制代码
<?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

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

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

shell 复制代码
touch extra_my_ik.dic
编辑文件

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

修改配置文件

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

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>
测试分词

使用kibana测试

相关推荐
AC赳赳老秦2 小时前
知识产权辅助:用 OpenClaw 批量生成专利交底书 / 软著申请材料,自动校验格式与内容合规性
java·人工智能·python·算法·elasticsearch·deepseek·openclaw
历程里程碑3 小时前
4 Git远程协作:从零开始,玩转仓库关联与代码同步(带实操代码讲解)
大数据·c++·git·elasticsearch·搜索引擎·gitee·github
苍煜3 小时前
MySQL分库分表和ES到底怎么选?
数据库·mysql·elasticsearch
摇滚侠5 小时前
Docker 如何查询挂载的目录
运维·docker·容器
摇滚侠8 小时前
DSL 学习 ElasticSearch 主要就是学习 DSL 查询语言
学习·elasticsearch·jenkins
江湖有缘9 小时前
基于Ubuntu系统Docker部署Note Mark:从安装到配置全流程
linux·ubuntu·docker
用户97471381214010 小时前
Elasticsearch 文档版本控制实验手册
elasticsearch
呆萌的代Ma11 小时前
docker内的n8n配置Code节点运行python代码
python·docker·容器
摇滚侠11 小时前
自动补全 黑马 Elasticsearch 全套教程,黑马旅游网案例
大数据·elasticsearch·搜索引擎
逸Y 仙X11 小时前
文章二十一:ElasticSearch 词项查询与调度查询实战
java·大数据·数据库·elasticsearch·搜索引擎