docker离线部署ElasticSearch及kibana,并设置密码

一、准备工作

1.操作系统:Linux(麒麟V10)

2.docker

3.docker-compose

4.ES docker镜像

5.kibana docker镜像

docker与docker-compose安装教程:麒麟V10离线安装docker及docker-compose_Truman UP的博客-CSDN博客

二、ES及kibana镜像下载

下载地址:

https://hub.docker.com/_/elasticsearch

https://hub.docker.com/_/kibana

三、镜像导出并上传至服务器

本地启动docker,下载指定版本的ES和kibana镜像

docker pull elasticsearch:7.1.1
docker save -o elasticsearch.tar
docker pull kibana:7.1.1
docker save -o kibana.tar

将2个tar镜像包上传至服务器,并加载镜像至docker

docker load -i elasticsearch.tar
docker load -i kibana.tar
docker images

四、目录及系统设置

#创建目录
mkdir -p /home/es/es01/data
mkdir -p /home/es/es02/data
mkdir -p /home/es/es03/data
mkdir -p /home/es/es01/logs
mkdir -p /home/es/es02/logs
mkdir -p /home/es/es03/logs
#目录权限
cd /home
chmod -R 777 es
#max_map_count文件包含限制一个进程可以拥有的VMA(虚拟内存区域)的数量
sysctl -w vm.max_map_count=262144

五、编写配置文件

cd /home/es/
vi docker-compose.yml

docker-compose.yml文件内容:

version: "2.2"

services:
  es01:
    image: elasticsearch:7.1.1
    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:
      - /home/es/es01/data:/usr/share/elasticsearch/data
      - /home/es/es01/logs:/usr/share/elasticsearch/logs
      - /home/es/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /home/es/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12
    ports:
      - 9200:9200
    networks:
      - elastic

  es02:
    image: elasticsearch:7.1.1
    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:
      - /home/es/es02/data:/usr/share/elasticsearch/data
      - /home/es/es02/logs:/usr/share/elasticsearch/logs
      - /home/es/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /home/es/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12
    ports:
      - 9201:9200
    networks:
      - elastic

  es03:
    image: elasticsearch:7.1.1
    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:
      - /home/es/es03/data:/usr/share/elasticsearch/data
      - /home/es/es03/logs:/usr/share/elasticsearch/logs
      - /home/es/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /home/es/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12
    ports:
      - 9202:9200
    networks:
      - elastic

  kib01:
    depends_on:
      - es01
    image: kibana:7.1.1
    container_name: kib01
    ports:
      - 5601:5601
    environment:
      ELASTICSEARCH_URL: http://es01:9200
      ELASTICSEARCH_HOSTS: http://es01:9200
    volumes:
      - /home/es/kibana.yml:/usr/share/kibana/config/kibana.yml
    networks:
      - elastic

networks:
  elastic:
    driver: bridge
vi elasticsearch.yml

elasticsearch.yml文件内容:

network.host: 0.0.0.0
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.keystore.type: PKCS12
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.type: PKCS12
xpack.security.transport.ssl.keystore.password: 123456
xpack.security.transport.ssl.truststore.password: 123456

network.host 设置允许其他ip访问,解除ip绑定
xpack.security 则是安全相关配置,其中ssl的证书需要自己生成

vi kibana.yml

kibana.yml文件内容:

server.name: kibana
server.host: "0.0.0.0"
elasticsearch.hosts: [ "http://es01:9200" ]
elasticsearch.username: elastic
elasticsearch.password: Elastic@123.
xpack.monitoring.ui.container.elasticsearch.enabled: true

六、生成证书elastic-certificates.p12

#首先运行es实例
docker run -dit --name=es elasticsearch:7.1.1 /bin/bash

#进入实例内部
docker exec -it es /bin/bash

#生成ca: elastic-stack-ca.p12
[root@25dee1848942 elasticsearch]# ./bin/elasticsearch-certutil ca
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.

The "ca" mode generates a new "certificate authority"
This will create a new X.509 certificate and private key that can be used
to sign certificate when running in "cert" mode.

Use the "ca-dn" option if you wish to configure the "distinguished name"
of the certificate authority

By default the "ca" mode produces a single PKCS#12 output file which holds:
    * The CA certificate
    * The CA"s private key

If you elect to generate PEM format certificates (the -pem option), then the output will
be a zip file containing individual files for the CA certificate and private key

#直接回车建
Please enter the desired output file [elastic-stack-ca.p12]: 

#接下来输入证书密码 例如:123456
Enter password for elastic-stack-ca.p12 : 



#再生成cert证书(需输入前面生成的CA密码): elastic-certificates.p12
[root@25dee1848942 elasticsearch]# ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.

The "cert" mode generates X.509 certificate and private keys.

#这个生成elastic-certificates.p12 就是我们需要使用的。复制出证书, ctrl+d退出容器内部

docker cp es:/usr/share/elasticsearch/elastic-certificates.p12 .
# 关闭这个容器
sudo docker kill es
sudo docker rm es

七、设置密码

#启动集群 
docker-compose up -d
#进入es的机器
docker exec -it es01 /bin/bash
#设置密码
[root@a0cf2855bbe3 elasticsearch]# ./bin/elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y

Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [kibana]: 
Reenter password for [kibana]: 
Enter password for [logstash_system]: 
Reenter password for [logstash_system]: 
Enter password for [beats_system]: 
Reenter password for [beats_system]: 
Enter password for [remote_monitoring_user]: 
Reenter password for [remote_monitoring_user]: 

Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

八、验证

ES访问地址:

        http://10.142.33.224:9200/

        http://10.142.33.224:9200/_cat/nodes

Kibana访问地址:

        http://10.142.33.224:5601/

你可能感兴趣的:(docker,elasticsearch,容器)