Elasticsearch + Kibana 简单安装使用

1.资料来源官网,参考:

https://www.elastic.co/cn/downloads/elasticsearch

https://www.elastic.co/cn/downloads/kibana

2.windows 下安装:

2.1 安装 elasticSearch

 下载:

 解压

2.2 修改配置文件,关闭用户密码校验:

# 配置X-Pack

# Enable security features
xpack.security.enabled: false


xpack.security.enrollment.enabled: true


# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: false
keystore.path: certs/http.p12


# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
cluster.initial_master_nodes: ["WIN-2386FUA5SHN"]


# Allow HTTP API connections from anywhere
# Connections are encrypted and require user authentication
http.host: 0.0.0.0
http.cors:
enabled: true
allow-origin: "*"

 

2.3  

 运行: bin\elasticsearch.bat

 

 

 

查看:http://localhost:9200

 

 

 

1.4 设置elasticsearch密码  默认为:  user: elastic password: changeme

修改 ES/config/elasticsearch.yml 文件

xpack.security.enabled: true
http.cors:
  enabled: true
  allow-origin: "*"
  allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
  1. 重启elasticsearch

  2. elasticsearch 8.9.0 默认情况下,elastic 的用户已存在且已设置了密码,需要执行命令重置密码:
    cmd> elasticsearch-reset-password.bat -u elastic
    warning: ignoring JAVA_HOME=C:\Program Files\Java\jdk1.8.0_144; using bundled JDK
    This tool will reset the password of the [elastic] user to an autogenerated value.
    The password will be printed in the console.
    Please confirm that you would like to continue [y/N]y
    
    
    Password for the [elastic] user successfully reset.
    New value: qh1rG*****************

    打开:http://localhost:9200

 

 2.2 安装 kibana

配置hosts 文件,然后运行 bin\kibana.bat

浏览器: http://localhost:5601

配置连接elasticsearch 地址:

 

  配置多地址登录:

 

 

3. Docker 安装

3.1 docker 安装本博客文章

3.2 拉取镜像

docker pull docker.elastic.co/elasticsearch/elasticsearch:7.6.0
docker pull docker.elastic.co/kibana/kibana:7.6.0

 3.3 创建容器


docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.6.0
docker run --link YOUR_ELASTICSEARCH_CONTAINER_NAME_OR_ID:elasticsearch -p 5601:5601 {docker-repo}:{version}

备注:YOUR_ELASTICSEARCH_CONTAINER_NAME_OR_ID 为 elastic 容器的id:运行第一个命令后,执行:docker ps

 

 最后是:

  docker run --link 2bf16c4ad702:elasticsearch -p 5601:5601 docker.elastic.co/kibana/kibana:7.6.0

3.4 基于 docker-compose.yml

      3.4.1  mkdir  创建一个目录,cd 到目录下面

  3.4.2   创建文件   docker-compose.yml

version: '2.2'
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.6.0
    container_name: es01
    environment:
      - node.name=es01
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es02,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - elastic
  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.6.0
    container_name: es02
    environment:
      - node.name=es02
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data02:/usr/share/elasticsearch/data
    networks:
      - elastic
  es03:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.6.0
    container_name: es03
    environment:
      - node.name=es03
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es02
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data03:/usr/share/elasticsearch/data
    networks:
      - elastic
  kibana:
    image: docker.elastic.co/kibana/kibana:7.6.0
    container_name: kibana
    ports:
       - 5601:5601
    networks:
       - elastic
    environment:
       - SERVER_NAME=kibana.localhost
       - ELASTICSEARCH_HOSTS=http://es01:9200
       - I18N_LOCALE=zh-CN
       - ELASTICSEARCH_USERNAME=elastic
       - ELASTICSEARCH_PASSWORD=mypasword
    depends_on:
       - es01
volumes:
  data01:
    driver: local
  data02:
    driver: local
  data03:
    driver: local

networks:
  elastic:
    driver: bridge

 注:yml文件中,不要有退格,要用空格

elasticsearch启动后自动关闭:减少实例数和内存数目

elasticsearch启动时遇到的错误 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

执行命令:

sysctl -w vm.max_map_count=262144

查看结果:

sysctl -a|grep vm.max_map_count

上述方法修改之后,如果重启虚拟机将失效,所以:

解决办法:

在   /etc/sysctl.conf文件最后添加一行

vm.max_map_count=262144

即可永久修改

 

 

 

在这个配置中,我们创建了三个Elasticsearch的node:es01及es02,es03。节点es01侦听localhost:9200,而es02通过Docker网络与es01对话。同时我们也创建了另外一个kibana的docker。我们可以在environment中配置它所需要的参数。

等我们创建好这个docker-compose.yml文件后,我们在当前的目录下,打入如下的命令:

docker-compose up

或者:

docker-compose up -d

这里的-d选项表示在detached模式下,运行容器在后台。

我们最终可以在浏览器中看见我们的Kibana被启动的样子

如同我们之前的设置一样, 它运行起来的Locale设置的是中文。我们也可以同时看到两个被启动的Elasticsearch的节点:

一旦docker启动后,我们可以通过docker的命令来执行一些命令,比如

docker exec es01 ls /usr/share/elasticsearch

我们可以通过如下的命令进入到docker进行安装等:

docker exec -it es01 /bin/bash

    $ docker exec -it es01 /bin/bash
    [root@ec4d19f59a7d elasticsearch]# ls
    LICENSE.txt  README.textile  config  jdk  logs     plugins
    NOTICE.txt   bin             data    lib  modules
    [root@ec4d19f59a7d elasticsearch]# 

这里的es01是我们的Elasticsearch实例的名称。

posted @ 2020-02-25 14:03  leolzi  阅读(727)  评论(0编辑  收藏  举报