docker-compose installs ES7.14 and Kibana7.14 (with account and password)

1. docker-compose installs ES7.14.0 and kibana7.14.0

1. Download the image

1.1, ES mirror

docker pull elasticsearch:7.14.0

1.2, kibana mirror

docker pull kibana:7.14.0

2. Install ES and kibana with docker-compose

2.1. Create configuration file directories and files

#Create a directory

mkdir -p /home/es-kibana/config

mkdir -p /home/es-kibana/data

mkdir -p /home/es-kibana/plugins

#Authorize the mounting directory

chmod 777 -R /home/es-kibana/config

chmod 777 /home/es-kibana/es-data/data

chmod 777 /home/es-kibana/es-data/logs

chmod 777 /home/es-kibana/es-data/plugins

2.2, ES configuration file

1. elasticesearch.yml

cluster.name: “docker-cluster”
network.host: 0.0.0.0

discovery.zen.minimum_master_nodes: 1
discovery.type: single-node

xpack.security.enabled: true #This item opens the account password

2.jvm.options
## JVM configuration

################################################ ##############
## IMPORTANT: JVM heap size
################################################ ##############
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################ ##############

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms1g
-Xmx1g
-XX: +IgnoreUnrecognizedVMOptions
################################################ ##############
## Expert settings
################################################ ##############
##
## All settings below this section are considered
## expert settings. Don't tamper with them unless
## you understand what you are doing
##
################################################ ##############

## GC configuration
-XX: + UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX: + UseCMSInitiatingOccupancyOnly

## G1GC Configuration
# NOTE: G1GC is only supported on JDK version 10 or later.
# To use G1GC uncomment the lines below.
# 10-:-XX:-UseConcMarkSweepGC
# 10-:-XX:-UseCMSInitiatingOccupancyOnly
# 10-:-XX: + UseG1GC
# 10-:-XX:InitiatingHeapOccupancyPercent=75

## optimizations

# pre-touch memory pages used by the JVM during initialization
-XX: +AlwaysPreTouch

##basic

# explicitly set the stack size
-Xss1m

# set to headless, just in case
-Djava.awt.headless=true

# ensure UTF-8 encoding by default (e.g. filenames)
-Dfile.encoding=GBK

# use our provided JNA always versus the system one
-Djna.nosys=true

# turn off a JDK optimization that throws away stack traces for common
# exceptions because stack traces are important for debugging
-XX:-OmitStackTraceInFastThrow

# flags to configure Netty
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0

# log4j 2
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true

-Djava.io.tmpdir=${ES_TMPDIR}

## heap dumps

# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX: + HeapDumpOnOutOfMemoryError

# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=data

# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p.log

## JDK 8 GC logging

8:-XX: + PrintGCDetails
8:-XX: + PrintGCDateStamps
8:-XX: + PrintTenuringDistribution
8:-XX: + PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX: + UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m

# JDK 9 + GC logging
9-:-Xlog:gc*,gc + age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
# due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise
# time/date parsing will break in an incompatible way for some date patterns and locals
9-:-Djava.locale.providers=COMPAT

# temporary workaround for C2 bug with JDK 10 on hardware with AVX-512
10-:-XX:UseAVX=2

Mainly these three configuration items

2.3, kibana configuration

i18n.locale: zh-CN

server.host: “0.0.0.0”

server.shutdownTimeout: “5s”

elasticsearch.hosts: [ “http://10.1.1.197:9200” ]

monitoring.ui.container.elasticsearch.enabled: true

elasticsearch.username: “elastic”
elasticsearch.password: “xxx”

2.4, #Create docker-compose.yml file (important)

version: '3'

services:
    elasticsearch:
        image: elasticsearch:7.14.0
        container_name: es7-14
        restart: unless-stopped
        volumes:
          - ./es-data/data:/usr/share/elasticsearch/data
          - ./es-data/logs:/usr/share/elasticsearch/logs
          # Directory to mount the word segmenter
          #- ./es-data/plugins:/usr/share/elasticsearch/plugins
          - ./config/jvm.options:/usr/share/elasticsearch/config/jvm.options
          - ./config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
        ports:
          - "9100:9100"
          - "9200:9200"

        networks:
          -es
    kibana:
        image: kibana:7.14.0
        container_name: kibana7-14
        ports:
          - "5601:5601"
        volumes:
          - ./config/kibana.yml:/usr/share/kibana/config/kibana.yml
        depends_on:
          -elasticsearch
        networks:
          -es
        
networks:
    es:
        driver: bridge

2.5, #Self-check whether there are any grammatical problems in what you write

docker-compose config -q

2.6, #Start and Stop

docker-compose up -d

docker-compose down

Restart

docker-compose restart container id

3. ES set account password

3.1. Check that elasticesearch.yml is configured

xpack.security.enabled: true #This item enables the account password (just configure this item)

3.2, Commands to set username and password

Reference: [Selected] ElasticSearch7.14 sets up built-in users and uses username and password to access

Here you need to set passwords for four users, elastic, kibana, logstash_system, beats_system. (interactive manual setting, auto automatically generates password)

bin/elasticsearch-setup-passwords interactive

#Enter the es container operation steps

$docker exec -it es7-14 /bin/bash

#Create password manually
$bin/elasticsearch-setup-passwords interactive

3. Access ES and kibana

3.1. Access ES

http://10.1.1.197:9200/

You need to enter your account and password to log in

3.2. Visit kibana

http://10.1.1.197:5601/

Note 1: To set the password configuration file, just configure this.

xpack.security.enabled: true #This item enables the account password (just configure this item)

Then enter the container to configure the password bin/elasticsearch-setup-passwords interactive and it will be available.

Note 2: The password may be lost after docker-compose down, so it is best to use docker stop container id and docker start container id.

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Cloud native entry-level skills treeHomepageOverview 16,744 people are learning the system