(编辑:jimmy 日期: 2024/11/9 浏览:2)
安装docker
你要安装完成docker,不再说明了。
安装Elasticsearch
注意:使用版本为 7.6.2,你可以选择其他版本
拉取镜像
docker pull elasticsearch:7.6.2
启动容器
docker run --restart=always -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
--name='elasticsearch' --cpuset-cpus="1" -m 2G -d elasticsearch:7.6.2
说明:
1. -v /opt/hanlp:/opt/hanlp如果使用了hanlp的分词,所以需要挂载词库
2. ES_JAVA_OPTS可以设置参数
3. 单节点启动
访问地址:http://172.18.63.211:9200
插件安装
安装ik 分词器
下载对应的版本:elasticsearch-analysis-ik
为什么安装IK,轻量级。配置好词库也是可以用来中文分词,HanLP重量级,内置算法较多,不适合单独分词使用。
# 离线安装,下载对应插件zip # https://github.com/medcl/elasticsearch-analysis-ik docker cp /opt/elasticsearch-analysis-ik-7.6.2.zip elasticsearch:/opt docker exec -it elasticsearch bash cd plugins/ mkdir analysis-ik unzip -d /usr/share/elasticsearch/plugins/analysis-ik/ /opt/elasticsearch-analysis-ik-7.6.2.zip exit docker restart elasticsearch
自定义词库
自定义字典
远程词库
常用维护命令
# 查看所有索引信息 GET /_cat/indices"htmlcode">docker exec -it kibana bash vi config/kibana.yml ######################## # 指定es的地址 elasticsearch.hosts: ["http://172.18.63.211:9200"] # 中文化 i18n.locale: "zh-CN" # 修改外网访问 可选 server.host: "0.0.0.0" exit ######################## docker restart kibana打开地址:http://172.18.63.211:5601
测试分词工具
POST _analyze { "text": "检测甘蓝型油菜抗磺酰脲类除草剂基因BnALS3R的引物与应用", "analyzer": "hanlp" }新增索引库
PUT achievement { "settings": { "number_of_shards": 1, "number_of_replicas": 1 } } PUT achievement/_mapping { "properties": { "id": { "type": "text" }, "owner": { "type": "text" }, "title": { "type": "text", "analyzer": "hanlp" }, "description": { "type": "text", "analyzer": "hanlp" }, "update_time":{ "type": "date" } } }数据同步Logstash
用于收集、解析和转换日志,同步数据等。
安装
docker pull logstash:7.5.0
配置文件目录
mkdir -p /usr/local/logstash/config cd /usr/local/logstash/config touch logstash.yml vi log4j2.properties #####添加以下内容 logger.elasticsearchoutput.name = logstash.outputs.elasticsearch logger.elasticsearchoutput.level = debug ##### vi pipelines.yml #### - pipeline.id: logstash-match path.config: "/usr/share/logstash/config/*.conf" pipeline.workers: 3 ####同时需要将MySQL的驱动包放入配置文件中。
再创建配置文件即可
这里给一个例子,是定时同步mysql数据到es中的。*
# logstash-mysql-es.conf input{ jdbc{ jdbc_driver_class => "com.mysql.cj.jdbc.Driver" jdbc_connection_string => "jdbc:mysql://172.18.63.211:3306/open_intelligence" jdbc_user => "docker" jdbc_password => "docker@12345" jdbc_paging_enabled => true jdbc_page_size => 10000 jdbc_fetch_size => 10000 connection_retry_attempts => 3 connection_retry_attempts_wait_time => 1 jdbc_pool_timeout => 5 use_column_value => true tracking_column => "update_time" tracking_column_type => "timestamp" record_last_run => true last_run_metadata_path => "/usr/share/logstash/mysql/goods_achievement" statement => "select * from goods_achievement where update_time > :sql_last_value" schedule => "* */30 * * * *" } } filter{ mutate { split => { "feature1" => ";" } } mutate { split => { "feature2" => ";" } } mutate { split => { "feature3" => ";" } } } output { elasticsearch { document_id => "%{id}" index => "goods_achievement" hosts => ["http://172.18.63.211:9200"] } }启动
docker run -d -p 5044:5044 -p 9600:9600 -it -e TZ=Asia/Shanghai --name logstash --restart=always -v /usr/local/logstash/config/:/usr/share/logstash/config/ -v /usr/local/logstash/mysql/:/usr/share/logstash/mysql/ --privileged=true logstash:7.6.2如果报错了
Error: com.mysql.cj.jdbc.Driver not loaded. :jdbc_driver_library is not set, are you sure you included the proper driver client libraries in your classpath?
可以尝试将驱动器即mysql-connector-java-xxxx-bin.jar拷贝到 logstash目录\logstash-core\lib\jars 下
如:
cd /usr/local/logstash/config
docker cp mysql-connector-java-8.0.17.jar logstash:/usr/share/logstash/logstash-core/lib/jars
检测配置文件
bin/logstash -f /usr/local/logstash/config/mysql-es-patent.conf -t
完成,你可以进行开发了。
以上这篇在Docker中安装Elasticsearch7.6.2的教程就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。