使用Docker部署ElasticSearch与kibana

使用Docker部署ElasticSearch与kibana

  • 部署ElasticSearch
    • 1.拉取ElasticSearch
    • 2.创建挂载目录
    • 3.创建并启动容器
    • 4.访问`http://IP:9200/`
    • 5.配置IK分词器
    • 6.测试分词器
  • 部署kibana
    • 1.拉取kibana
    • 2.创建并启动容器
    • 3.访问`http://IP:5601/`
    • 4.语言设置

部署ElasticSearch

1.拉取ElasticSearch

docker pull elasticsearch:7.4.2

2.创建挂载目录

mkdir -p /usr/local/docker/elasticsearch/config
mkdir -p /usr/local/docker/elasticsearch/data
mkdir -p /usr/local/docker/elasticsearch/plugins

# 配置任何远程机器都可以访问
echo "http.host: 0.0.0.0" >> /usr/local/docker/elasticsearch/config/elasticsearch.yml
 
# 保证权限
chmod -R 777 /usr/local/docker/elasticsearch/

3.创建并启动容器

# 9200 http请求端口 9300:集群通信端口
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
# 单节点运行
-e "discovery.type=single-node" \
# 设置初始内存和最大内存,否则导致过大启动不了ES
-e ES_JAVA_OPTS="-Xms250m -Xmx512m" \
# 数据挂载
-v /usr/local/docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /usr/local/docker/elasticsearch/data:/usr/share/elasticsearch/data \
-v /usr/local/docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.4.2
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms250m -Xmx512m" \
-v /usr/local/docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /usr/local/docker/elasticsearch/data:/usr/share/elasticsearch/data \
-v /usr/local/docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.4.2

4.访问http://IP:9200/

使用Docker部署ElasticSearch与kibana_第1张图片

5.配置IK分词器

访问:https://github.com/medcl/elasticsearch-analysis-ik/releases,下载与ES版本相符合的elasticsearch-analysis-ikIK分词器

下载与解压

cd es/plugins
mkdir ik
cd ik

wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.4.2/elasticsearch-analysis-ik-7.4.2.zip
 
unzip elasticsearch-analysis-ik-7.4.2.zip

rm elasticsearch-analysis-ik-7.4.2.zip 

列出系统的分词器

cd  es/bin

elasticsearch plugin list

6.测试分词器

默认分词器

POST http://127.0.0.1:9200/_analyze
{
  "analyzer": "standard",
  "text": "世界你好啊"
}

ik_smart分词器

POST http://127.0.0.1:9200/_analyze
{
  "analyzer": "ik_smart",
  "text": "世界你好啊"
}

ik_max_word分词器

POST http://127.0.0.1:9200/_analyze
{
  "analyzer": "ik_max_word",
  "text": "世界你好啊"
}

部署kibana

1.拉取kibana

docker pull kibana:7.4.2

2.创建并启动容器

http://IP:9200 指向ES地址

docker run --name kibana -e ELASTICSEARCH_HOSTS=http://IP:9200 -p 5601:5601 -d kibana:7.4.2

3.访问http://IP:5601/

4.语言设置

kibana默认为英文界面

使用Docker部署ElasticSearch与kibana_第2张图片
进入容器

docker exec -it kibana /bin/bash

配置kibana安装目录下的config目录的kibana.yml文件,新增或修改

i18n.locale: "en"

将en修改为zh-CN即可

i18n.locale: "zh-CN"
bash-4.2$ ls
LICENSE.txt  NOTICE.txt  README.txt  bin  built_assets  config  data  node  node_modules  optimize  package.json  plugins  src  webpackShims  x-pack
bash-4.2$ cd config/
bash-4.2$ ls
kibana.yml
bash-4.2$ vi kibana.yml 

在kibana.yml文件添加中文语言设置

#
# ** THIS IS AN AUTO-GENERATED FILE **
#

# Default Kibana configuration for docker target
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
xpack.monitoring.ui.container.elasticsearch.enabled: true

i18n.locale: "zh-CN"

配置后重启Kibana

使用Docker部署ElasticSearch与kibana_第3张图片

你可能感兴趣的:(#,Docker,elasticsearch,docker,搜索引擎,Kibana)