docker安裝ES & Kibana

安裝Elasticsearch

安裝

docker run -it --name elasticsearch -d -p 9200:9200 -p 9300:9300 -p 5601:5601 elasticsearch

官方的鏡像的網(wǎng)絡(luò)設(shè)置是允許外部訪問的即network.host=0.0.0.0

如果要制定es配置可用通過-E{param=value}指定,或者通過-v "$PWD/config":/usr/share/elasticsearch/config 映射配置文件地址

-p 5601:5601 是kibana的端口地址 (我這里kibana的container共用elasticsearch的網(wǎng)絡(luò),所以這樣設(shè)置)

驗證

> curl http://localhost:9200
{
    "name": "OwHPNzY",
    "cluster_name": "elasticsearch",
    "cluster_uuid": "WeiDMjJARv2DHMcCrQgS6g",
    "version": {
    "number": "5.6.4",
    "build_hash": "8bbedf5",
    "build_date": "2017-10-31T18:55:38.105Z",
    "build_snapshot": false,
    "lucene_version": "6.6.1"
},
    "tagline": "You Know, for Search"
}

安裝Kibana

安裝

docker run -it -d -e ELASTICSEARCH_URL=http://127.0.0.1:9200 --name kibana --network=container:elasticsearch kibana

--network 指定容器共享elasticsearch容器的網(wǎng)絡(luò)棧 (使用了--network 就不能使用-p 來暴露端口)

驗證

訪問 http://localhost:5601

image

安裝Elasticsearch-head

v5.x以后不支持plugin需要獨立部署

安裝

git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start

驗證

訪問 http://localhost:9100/

image

直接配置elasticsearch服務(wù)有跨域問題,所以加了nginx代理

nginx 服務(wù)配置

server {
        listen       9201;
        server_name  localhost;
    location / {
        add_header Access-Control-Allow-Origin *;
                add_header Access-Control-Allow-Headers Origin,X-Requested-With,Content-Type,Accept;
                add_header Access-Control-Allow-Methods GET,POST,PUT,PATCH,OPTIONS,DELETE;
            add_header Cache-Control no-store;
        proxy_pass http://127.0.0.1:9200;
    }
}

安裝中文分詞器

./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.0.0/elasticsearch-analysis-ik-6.0.0.zip

集群部署

當(dāng)然我們也可以使用docker-compose的方式進行集群部署
docker-compose.yml文件內(nèi)容如下

version: '3.7'
services:
  elasticsearch:
    image: elasticsearch
    container_name: elasticsearch
    hostname: elasticsearch
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - esnet
  elasticsearch2:
    image: elasticsearch
    container_name: elasticsearch2
    hostname: elasticsearch2
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "discovery.zen.ping.unicast.hosts=[elasticsearch,elasticsearch2,elasticsearch3]"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata2:/usr/share/elasticsearch/data
    networks:
      - esnet
  elasticsearch3:
    image: elasticsearch
    container_name: elasticsearch3
    hostname: elasticsearch3
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "discovery.zen.ping.unicast.hosts=[elasticsearch,elasticsearch2,elasticsearch3]"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata3:/usr/share/elasticsearch/data
    networks:
      - esnet    
  kibana:
    image: kibana
    container_name: kibana
    ports:
      - 5601:5601
    environment:
      - ELASTICSEARCH_URL=http://elasticsearch:9200
    networks:
      - esnet

volumes:
  esdata1:
    driver: local
  esdata2:
    driver: local
  esdata3:
    driver: local  
networks:
  esnet:

執(zhí)行docker-compose up -d 啟動

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容