欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

docker安裝Elasticsearch7.6集群并設(shè)置密碼的方法步驟

 更新時(shí)間:2021年10月22日 15:35:12   作者:Young丶  
本文主要介紹了docker安裝Elasticsearch7.6集群并設(shè)置密碼,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Elasticsearch從6.8開始, 允許免費(fèi)用戶使用X-Pack的安全功能, 以前安裝es都是裸奔。接下來記錄配置安全認(rèn)證的方法。

為了簡化物理安裝過程,我們將使用docker安裝我們的服務(wù)。

一些基礎(chǔ)配置

es需要修改linux的一些參數(shù)。

設(shè)置vm.max_map_count=262144

sudo vim /etc/sysctl.conf
vm.max_map_count=262144

不重啟, 直接生效當(dāng)前的命令

sysctl -w vm.max_map_count=262144

es的data和logs目錄需要給1000的用戶授權(quán), 我們假設(shè)安裝3個(gè)實(shí)力的es集群,先創(chuàng)建對(duì)應(yīng)的數(shù)據(jù)存儲(chǔ)文件

mkdir -p es01/data
mkdir -p es01/logs
mkdir -p es02/data
mkdir -p es02/logs
mkdir -p es03/data
mkdir -p es03/logs

## es的用戶id為1000,這里暫且授權(quán)給所有人好了
sudo chmod 777 es* -R

關(guān)于版本和docker鏡像

Elasticsearch分幾種licenses,其中Open Source和Basic是免費(fèi)的, 而在6.8之后安全功能才開始集成在es的Basic授權(quán)上。

img

Basic對(duì)應(yīng)docker鏡像為

docker pull docker.elastic.co/elasticsearch/elasticsearch:7.6.2

同時(shí)dockerhub同步為elasticsearch. 我們直接拉取elasticsearch:7.6.2就好。

開始

首先,創(chuàng)建docker-compose.yml

version: '2.2'
services:
  es01:
    image: elasticsearch:7.6.2
    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:
      - ./es01/data:/usr/share/elasticsearch/data
      - ./es01/logs:/usr/share/elasticsearch/logs
      - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - ./elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12
    ports:
      - 9200:9200
    networks:
      - elastic

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

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

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

networks:
  elastic:
    driver: bridge

關(guān)于elasticsearch.yml

內(nèi)容如下

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.audit.enabled: true
  • network.host 設(shè)置允許其他ip訪問,解除ip綁定
  • xpack.security 則是安全相關(guān)配置,其中ssl的證書需要自己生成

關(guān)于證書elastic-certificates.p12

es提供了生成證書的工具elasticsearch-certutil,我們可以在docker實(shí)例中生成它,然后復(fù)制出來,后面統(tǒng)一使用。

首先運(yùn)行es實(shí)例

sudo docker run -dit --name=es elasticsearch:7.6.2 /bin/bash

進(jìn)入實(shí)例內(nèi)部

sudo 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]: 
Enter password for elastic-stack-ca.p12 : 

再生成cert: 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.

這個(gè)生成elastic-certificates.p12 就是我們需要使用的。

復(fù)制出證書, ctrl+d退出容器內(nèi)部

sudo docker cp es:/usr/share/elasticsearch/elastic-certificates.p12 .
# 關(guān)閉這個(gè)容器
sudo docker kill es
sudo docker rm es

如此獲取了證書。

生成密碼

我們首先要啟動(dòng)es集群,去里面生成密碼。

sudo docker-compose up

然后進(jìn)入其中一臺(tái)

sudo docker exec -it es01 /bin/bash

生成密碼用auto, 自己設(shè)置用 interactive

[root@cfeeab4bb0eb elasticsearch]# ./bin/elasticsearch-setup-passwords -h
Sets the passwords for reserved users

Commands
--------
auto - Uses randomly generated passwords
interactive - Uses passwords entered by a user

Non-option arguments:
command              

Option             Description        
------             -----------        
-E <KeyValuePair>  Configure a setting
-h, --help         Show help          
-s, --silent       Show minimal output
-v, --verbose      Show verbose output



[root@cfeeab4bb0eb elasticsearch]# ./bin/elasticsearch-setup-passwords auto
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
The passwords will be randomly generated and printed to the console.
Please confirm that you would like to continue [y/N]y


Changed password for user apm_system
PASSWORD apm_system = YxVzeT9B2jEDUjYp66Ws

Changed password for user kibana
PASSWORD kibana = 8NnThbj0N02iDaTGhidU

Changed password for user logstash_system
PASSWORD logstash_system = 9nIDGe7KSV8SQidSk8Dj

Changed password for user beats_system
PASSWORD beats_system = qeuVaf1VEALpJHfEUOjJ

Changed password for user remote_monitoring_user
PASSWORD remote_monitoring_user = DtZCrCkVTZsinRn3tW3D

Changed password for user elastic
PASSWORD elastic = q5f2qNfUJQyvZPIz57MZ

使用密碼

瀏覽器訪問localhost:9200/9201/9202 需要輸入賬號(hào)

輸入對(duì)應(yīng)的elastic/password就好

瀏覽器訪問localhost:5601

img

忘記密碼

如果生成后忘記密碼了怎么辦, 可以進(jìn)入機(jī)器去修改。

進(jìn)入es的機(jī)器

sudo docker exec -it es01 /bin/bash

創(chuàng)建一個(gè)臨時(shí)的超級(jí)用戶RyanMiao

./bin/elasticsearch-users useradd ryan -r superuser
Enter new password: 
ERROR: Invalid password...passwords must be at least [6] characters long
[root@cfeeab4bb0eb elasticsearch]# ./bin/elasticsearch-users useradd ryan -r superuser
Enter new password: 
Retype new password: 

用這個(gè)用戶去修改elastic的密碼:

curl -XPUT -u ryan:ryan123 http://localhost:9200/_xpack/security/user/elastic/_password -H "Content-Type: application/json" -d '
{
  "password": "q5f2qNfUJQyvZPIz57MZ"
}'

參考 http://codingfundas.com/setting-up-elasticsearch-6-8-with-kibana-and-x-pack-security-enabled/index.html

到此這篇關(guān)于docker安裝Elasticsearch7.6集群并設(shè)置密碼的方法步驟的文章就介紹到這了,更多相關(guān)docker安裝Elasticsearch7.6集群 內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Docker鏡像管理常用操作代碼示例

    Docker鏡像管理常用操作代碼示例

    這篇文章主要介紹了Docker鏡像管理常用操作代碼示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-10-10
  • Docker中Mysql容器無法停止無法刪除問題

    Docker中Mysql容器無法停止無法刪除問題

    這篇文章主要介紹了Docker中Mysql容器無法停止無法刪除問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Docker安裝Redis最新圖文教程(非常全)

    Docker安裝Redis最新圖文教程(非常全)

    Redis是一個(gè)開源的使用ANSI C語言編寫、支持網(wǎng)絡(luò)、可基于內(nèi)存亦可持久化的日志型、Key-Value的NoSQL數(shù)據(jù)庫,這篇文章主要給大家介紹了關(guān)于Docker安裝Redis的相關(guān)資料,需要的朋友可以參考下
    2023-11-11
  • Docker Registry搭建私有鏡像倉庫的實(shí)現(xiàn)方法

    Docker Registry搭建私有鏡像倉庫的實(shí)現(xiàn)方法

    這篇文章主要介紹了Docker Registry搭建私有鏡像倉庫的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • Docker容器應(yīng)用日志查看方法

    Docker容器應(yīng)用日志查看方法

    今天小編就為大家分享一篇關(guān)于Docker容器應(yīng)用日志查看方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • Docker容器的創(chuàng)建、啟動(dòng)、和停止的方法

    Docker容器的創(chuàng)建、啟動(dòng)、和停止的方法

    這篇文章主要介紹了Docker容器的創(chuàng)建、啟動(dòng)、和停止的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-12-12
  • Docker安裝MySQL和Redis的方法步驟

    Docker安裝MySQL和Redis的方法步驟

    這篇文章主要介紹了Docker安裝MySQL和Redis的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Docker手動(dòng)構(gòu)建JDK鏡像的實(shí)現(xiàn)示例

    Docker手動(dòng)構(gòu)建JDK鏡像的實(shí)現(xiàn)示例

    本文主要介紹了 Docker手動(dòng)構(gòu)建JDK鏡像的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-08-08
  • 使用Docker部署war包項(xiàng)目的實(shí)現(xiàn)

    使用Docker部署war包項(xiàng)目的實(shí)現(xiàn)

    這篇文章主要介紹了使用Docker部署war包項(xiàng)目的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • 一文講解如何查看一個(gè)docker鏡像有哪些版本

    一文講解如何查看一個(gè)docker鏡像有哪些版本

    這篇文章主要給大家介紹了關(guān)于如何查看一個(gè)docker鏡像有哪些版本的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用docker具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2024-04-04

最新評(píng)論