Elasticsearch 7.2.0 + Kuromoji + Kibana + docker-compose インストールメモ


SnapDishの検索エンジンを強化したいので、Elsasticsearch準備したときのメモ。
kibana.ymlの書き方でまよったけど、なんとか動くようになった。

サーバー環境

Console
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

$ docker-compose -v
docker-compose version 1.22.0, build f46880fe

$ grep vm.max_map_count /etc/sysctl.conf
vm.max_map_count=262144

ディレクトリ構成

Console
/opt/elasticsearch/
├── docker-compose.yml
├── esdata01  # *1
├── esdata02  # *1
├── kibana.yml
├── test_kuromoji_index.sh
└── source
    └── Dockerfile

*1 elasticsearchのデータの保存先、ディレクトリ権限がrootだとエラーになる

ファイル

docker-compose.yml
version: '2.2'
services:
  kibana:
    image: docker.elastic.co/kibana/kibana:7.2.0
    volumes:
      - /opt/elasticsearch/kibana.yml:/usr/share/kibana/config/kibana.yml
    ports:
      - 5601:5601
    networks:
      - esnet
  es01:
    build: source
    container_name: es01
    environment:
      - node.name=es01
      - discovery.seed_hosts=es02
      - cluster.initial_master_nodes=es01,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - /opt/elasticsearch/esdata01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - esnet
  es02:
    build: source
    container_name: es02
    environment:
      - node.name=es02
      - discovery.seed_hosts=es01
      - cluster.initial_master_nodes=es01,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - /opt/elasticsearch/esdata02:/usr/share/elasticsearch/data
    networks:
      - esnet

volumes:
  esdata01:
    driver: local
  esdata02:
    driver: local

networks:
  esnet:
kibana.yml
elasticsearch.hosts:
  - http://es01:9200
  - http://es02:9200
server.name: "[kibanaのドメイン名.com]"
server.port: 5601
server.host: "0.0.0.0"
plugin/Dockerfile
FROM docker.elastic.co/elasticsearch/elasticsearch:7.2.0
# RUN elasticsearch-plugin remove analysis-kuromoji
# RUN elasticsearch-plugin remove analysis-icu
RUN elasticsearch-plugin install analysis-kuromoji
RUN elasticsearch-plugin install analysis-icu
test_kuromoji_index.sh
curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/test_kuromoji_index?pretty -d '
{
  "settings": {
    "analysis": {
      "analyzer": {
        "test_kuromoji_analyzer": {
          "type": "custom",
          "tokenizer": "kuromoji_tokenizer"
        }
      }
    }
  }
}'

Docker操作

Console
$ cd /opt/elasticsearch
$ docker-compose build  # ドッカービルド
$ docker-compose up -d  # 起動
$ docker-compose logs -f  # ログを見る
$ docker-compose down  # 停止

参考
https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html