美文网首页dockerdocker
docker安装Elasticsearch(7.4.2)

docker安装Elasticsearch(7.4.2)

作者: _意义 | 来源:发表于2019-11-27 10:56 被阅读0次

1.拉取镜像

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

2.启动容器,设置部分参数是为了支持跨域访问。

docker run -d --name elasticsearch  -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e http.cors.enabled=true -e http.cors.allow-origin="*" -e http.cor
s.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization -e http.cors.allow-credentials=true elasticsearch:7.4.2

3.通过localhost:9200 访问,会返回集群状态信息,证明安装成功。

{
  "name" : "828ba9d616ea",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "h01186kPQZ6LIxZQWIwbGg",
  "version" : {
    "number" : "7.4.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",
    "build_date" : "2019-10-28T20:40:44.881551Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

4.chrome安装head插件--ElasticSearch Head。
5.此刻你会发现Elasticsearch是裸奔的,现在添加基本安全验证。
5.1 进入容器

 docker exec -it 容器ID  bash

5.2 进入到Elasticsearch安装目录

   cd  /usr/share/elasticsearch

5.3使用下列命令生成证书

   bin/elasticsearch-certutil cert -out config/elastic-certificates.p12 -pass ""

此时目录下会多出2个文件:elastic-certificates.p12 和 elasticsearch.keystore。
修改文件所属用户和权限:

   chown elasticsearch ./elastic-certificates.p12 ./ elasticsearch.keystore
   chmod 660 ./elastic-certificates.p12 ./ elasticsearch.keystore

5.4 修改配置,打开config/elasticsearch.yml,添加以下内容:

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
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

5.5 重启容器

docker restart 容器ID

5.6 进入容器

docker exec -it 容器ID  bash

执行

elasticsearch-setup-passwords auto

请记住生成的密码。

Changed password for user apm_system
PASSWORD apm_system = t7R97a1jwydHo1EraxNX

Changed password for user kibana
PASSWORD kibana = b9VLaZrh3q3G05OgeKhc

Changed password for user logstash_system
PASSWORD logstash_system = 0Y1oBhEfZUqnQNDNvF5L

Changed password for user beats_system
PASSWORD beats_system = a9II6E3mYCSzpnggNlxA

Changed password for user remote_monitoring_user
PASSWORD remote_monitoring_user = 0AlWhN0X92INjx1GaZJb

Changed password for user elastic
PASSWORD elastic = IyKmRPh2I3EkK47OGiwI

如果想自己设置密码,请执行

elasticsearch-setup-passwords interactive

5.7 打开浏览器,访问localhost:9200 会提示你输入用户名密码。至此,密码设置完成。

相关文章

网友评论

    本文标题:docker安装Elasticsearch(7.4.2)

    本文链接:https://www.haomeiwen.com/subject/cwouwctx.html