小说精品屋-plus基于Docker安装ElasticSearch7.9.3环境

爷,独闯天下 提交于 2021-01-03 15:33:40

​1. Docker-ce安装(Centos7环境)

①移除旧版本

yum remove docker \                  docker-client \                  docker-client-latest \                  docker-common \                  docker-latest \                  docker-latest-logrotate \                  docker-logrotate \                  docker-selinux \                  docker-engine-selinux \                  docker-engine

安装必要的系统工具

yum install -y yum-utils device-mapper-persistent-data lvm2

添加软件源信息

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

更新 yum 缓存

yum makecache fast

安装 Docker-ce

yum -y install docker-ce

启动 Docker 后台服务

systemctl start docker

⑦设置Docker开机自启动

systemctl enable docker

2. ElasticSearch安装

①拉取镜像

docker pull elasticsearch:7.9.3

②查看镜像

docker images

③创建所需文件夹和文件

mkdir -p /mydata/elasticsearch/configmkdir -p /mydata/elasticsearch/dataecho "http.host: 0.0.0.0">>/mydata/elasticsearch/config/elasticsearch.yml

④文件夹赋权

chmod -R 777 /mydata/elasticsearch/

⑤创建并启动elasticsearch容器

docker run --name elasticsearch -p 9200:9200 \ -p 9300:9300 \ -e "discovery.type=single-node" \ -e ES_JAVA_OPTS="-Xms64m -Xmx128m" \ -v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \ -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \ -v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \ -d elasticsearch:7.9.3

⑥设置elasticsearch容器自启动

docker update elasticsearch --restart=always

⑦安装IK中文分词器

cd /mydata/elasticsearch/plugins/wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.9.3/elasticsearch-analysis-ik-7.9.3.zipmkdir ikunzip -d ik/ elasticsearch-analysis-ik-7.9.3.zip docker restart elasticsearch

3.Kibana

①拉取镜像

docker pull kibana:7.9.3

②创建并启动kibana容器

docker run -tid \--restart=always \-p 15601:5601 \-v /etc/localtime:/etc/localtime \-e TZ='Asia/Shanghai' \-e LANG="en_US.UTF-8" \kibana:7.9.3

③Copy容器中的文件到宿主机上,并给文件夹授权

mkdir -p /mydata/kibana/docker cp <容器ID>:/usr/share/kibana/config/ /mydata/kibana/docker cp <容器ID>:/usr/share/kibana/data/ /mydata/kibana/docker cp <容器ID>:/usr/share/kibana/plugins/ /mydata/kibanachmod -R 777 /mydata/kibana

删除容器

docker rm -f <容器ID>

⑤修改kibana.yml配置文件

## ** THIS IS AN AUTO-GENERATED FILE **## Default Kibana configuration for docker targetserver.name: kibanaserver.host: "0.0.0.0"elasticsearch.hosts: [ "http://192.168.0.105:9200" ]monitoring.ui.container.elasticsearch.enabled: true

⑥重新创建并启动kibana容器

docker run -tid \--restart=always \-p 15601:5601 \-v /mydata/kibana/config/:/usr/share/kibana/config/ \-v /mydata/kibana/data/:/usr/share/kibana/data/ \-v /mydata/kibana/plugins/:/usr/share/kibana/plugins/ \-v /etc/localtime:/etc/localtime \-e TZ='Asia/Shanghai' \-e LANG="en_US.UTF-8" \kibana:7.9.3

⑦查看kibana启动日志

docker logs <容器ID>

注意:kibana的启动时间较长,需要查看日志确保kibana启动成功后再访问,否则一开始访问失败并不能说明kibana的安装配置有问题。

4.放行端口号

firewall-cmd --zone=public --add-port=9200/tcp --permanentfirewall-cmd --zone=public --add-port=15601/tcp --permanentsystemctl  restart firewalld.service

5.访问Kibana

http://ip:15601

6.创建索引

PUT /novel{  "mappings" : {        "properties" : {      "id" : {        "type" : "long"      },      "authorId" : {        "type" : "long"      },      "authorName" : {        "type" : "text",        "analyzer": "ik_smart",        "boost": 1.5      },      "bookName" : {        "type" : "text",        "analyzer": "ik_smart",        "boost": 2      },      "bookDesc" : {        "type" : "text",        "analyzer": "ik_smart",        "boost": 0.1      },      "bookStatus" : {        "type" : "short"      },      "catId" : {        "type" : "integer"      },      "catName" : {        "type" : "text",        "analyzer": "ik_smart",        "boost": 1.0      },      "lastIndexId" : {        "type" : "long"      },      "lastIndexName" : {        "type" : "text",        "analyzer": "ik_smart",        "boost": 0.1      },      "lastIndexUpdateTime" : {        "type": "keyword"      },      "picUrl" : {        "type" : "keyword",        "index" : false,        "doc_values" : false      },      "score" : {        "type" : "float"      },      "wordCount" : {        "type" : "integer"      },      "workDirection" : {        "type" : "short"      },      "visitCount" : {        "type": "long"      }        }  }}

7.开启搜索引擎功能

spring:  elasticsearch:    #是否开启搜索引擎,1:开启,0:不开启    enable: 0    jest:      #es的访问URI      uris: http://127.0.0.1:9200
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!