docker-compose 安装elasticsearch + kibana

郎宏逸
2023-12-01

准备工作

1. 创建目录

# 创建目录
#es
mkdir -p /opt/apps/es/elasticsearch/config
mkdir -p /opt/apps/es/elasticsearch/data
mkdir -p /opt/apps/es/elasticsearch/plugins

# kibana
mkdir -p /opt/apps/es/kibana/config


2.创建配置文件

   

vi /opt/apps/es/elasticsearch/config/elasticsearch.yml

http.port: 9200
http.host: 0.0.0.0

http.cors.enabled: true
http.cors.allow-origin: "*"

vi /opt/apps/es/kibana/config/elasticsearch.yml

server.name: kibana
# kibana的主机地址 0.0.0.0可表示监听所有IP
server.host: "0.0.0.0"
# kibana访问es的URL
elasticsearch.hosts: [ "http://localhost:9200" ]
#elasticsearch.username: 'kibana'
#elasticsearch.password: '123456'
# 显示登陆页面
#xpack.monitoring.ui.container.elasticsearch.enabled: true
# 语言
#i18n.locale: "zh-CN"

3.docker-compose

vi /opt/apps/es/docker-compose.yml

version: '3'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
    container_name: elasticsearch
    environment:
      - "discovery.type=single-node"
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    volumes:
      - ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - ./elasticsearch/data:/usr/share/elasticsearch/data 
      - ./elasticsearch/plugins:/usr/share/elasticsearch/plugins
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
      - 9200:9200
      - 9300:9300
    restart: always
    network_mode: 'host'
  kibana:
    image: docker.elastic.co/kibana/kibana:7.9.3
    volumes:
      - ./kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml
    environment:
      - ELASTICSEARCH_URL=http://localhost:9200
    ports:
      - 5601:5601
    restart: always
    network_mode: 'host'

4. 编写重启命令

vi /opt/apps/es/restart.sh

echo "===prepare docker registry==="
docker-compose stop
echo "===starting new docker-compose==="
docker-compose up -d
echo "===complete==="

5. 增加文件夹权限

chmod -R 777 /opt/apps/es/elasticsearch/data

6. 启动 es 和 kibana

sh /opt/apps/es/restart.sh

7. 访问

es:   http://ip:9200/

kibana:  http://ip:5601/

8. 安装IK分词器

# 进到es plugins的目录
cd /opt/apps/es/elasticsearch/plugins/

# 创建ik 目录
mkdir ik

# 进到ik
cd /opt/apps/es/elasticsearch/plugins/ik

# 下载分词器
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.9.3/elasticsearch-analysis-ik-7.9.3.zip

# 解压分词器
unzip elasticsearch-analysis-ik-7.9.3.zip

#重启es
docker restart 容器id


 

 类似资料: