首页 > 其他分享 >docker安装elasticsearch和kibana

docker安装elasticsearch和kibana

时间:2024-04-22 18:34:56浏览次数:36  
标签:Copy kibana elasticsearch docker password data

来源:https://www.cnblogs.com/baoshu/p/16128127.html

安装目标

使用docker安装elastic searchkibana,版本均为7.17.1

安装es

1. docker pull#

去dockerhub看具体版本,这里用7.17.1

Copy
docker pull elasticsearch:7.17.1
docker pull kibana:7.17.1

2. 临时安装生成文件#

Copy
 docker run -d --name elasticsearch  -p 9200:9200 -p 9300:9300 -e  "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms256m -Xmx256m" elasticsearch:7.17.1

参数说明

  • -d 后台启动
  • –name 起别名即:NAMES
  • -p 9200:9200 将端口映射出来
    elasticsearch的9200端口是供外部访问使用;9300端口是供内部访问使用集群间通讯
  • -e "discovery.type=single-node"单节点启动
  • -e ES_JAVA_OPTS="-Xms256m -Xmx256m" 限制内存大小

确保成功启动

Copy
docker ps

3. 设置外部数据卷#

  1. 执行
Copy
mkdir -p /data/elasticsearch/{config,data,logs,plugins}
yml
  1. 将容器内文件拷贝出来
Copy
docker cp elasticsearch:/usr/share/elasticsearch/config /data/elasticsearch
docker cp elasticsearch:/usr/share/elasticsearch/logs /data/elasticsearch
docker cp elasticsearch:/usr/share/elasticsearch/data /data/elasticsearch
docker cp elasticsearch:/usr/share/elasticsearch/plugins /data/elasticsearch
  1. 设置elasticsearch.yml的内容
Copy
vi /data/elasticsearch/config/elasticsearch.yml
  • 确保有以下几个配置,原有的配置可以不改动
Copy
cluster.name: "docker-cluster"
network.hosts:0.0.0.0
# 跨域
http.cors.allow-origin: "*"
http.cors.enabled: true
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

4. 停止并删除临时容器#

Copy
docker stop elasticsearch
docker rm elasticsearch

5. 重新起容器并挂载外部文件夹#

Copy
docker run -d --name elasticsearch \
-p 9200:9200 \
-p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" \
-v /data/elasticsearch/logs:/usr/share/elasticsearch/logs \
-v /data/elasticsearch/data:/usr/share/elasticsearch/data \
-v /data/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /data/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
elasticsearch:7.17.1

等docker容器起来一分钟左右,再访问9200 端口,会返回

因为安装的是V7版本的,默认没开启x-pack(v8默认开启),所以能直接访问

Copy
[root@iZuf6ai62xce7wexx4wwi9Z config]# curl "http://localhost:9200"
{
  "name" : "6a1036c69d59",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "0zgLiGhESGKQYTYy9gH4iA",
  "version" : {
    "number" : "7.17.1",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "e5acb99f822233d62d6444ce45a4543dc1c8059a",
    "build_date" : "2022-02-23T22:20:54.153567231Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
[root@iZuf6ai62xce7wexx4wwi9Z config]#

安装kibana

1. 运行临时容器#

Copy
docker run -d --name kibana -p 5601:5601 kibana:7.17.1

2. 创建本地挂载文件#

Copy
mkdir -p /data/kibana/config
docker cp kibana:/usr/share/kibana/config /data/kibana/

在本地就能看到拷贝出来的kibana.yml文件,

Copy
vim /data/kibana/config/kibana.yml

修改配置为

Copy
#
# ** THIS IS AN AUTO-GENERATED FILE **
#

# Default Kibana configuration for docker target
server.host: "0"
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://localhost:9100" ] # 记得修改ip
monitoring.ui.container.elasticsearch.enabled: true
i18n.locale: "zh-CN"

3. 停掉临时容器并重新启动#

  1. 停掉旧的
Copy
docker stop kibana
docker rm kibana
  1. 重新启动挂载了地址的新的容器
Copy
docker run -d --name kibana -p 5601:5601 -v /data/kibana/config:/usr/share/kibana/config kibana:7.17.1

4. 进入elasticsearch容器获取token#

  1. 访问kibana发现需要token

  2. 进入es容器获取token

Copy
docker exec -it {elastic_search_container_id} /bin/bash
bin/elasticsearch-create-enrollment-token --scope kibana
  1. 拷贝token到kibana的ui上输入

5. 进入kibana容器获取验证码#

  1. 进入kibana容器获取token
Copy
docker exec -it kibana /bin/bash

# 执行生成验证码命令
bin/kibana-verification-code 

6. 重置elastic密码#

进入es容器

Copy
docker exec -it {elastic_search_container_id} /bin/bash
bin/elasticsearch-reset-password --username elastic -i

后面就使用elastic账户和密码登录kibana

为es和kibana设置密码

  1. es开启x-pack
Copy
vim /data/elasticsearch/config/elasticsearch.yml

增加以下xpack.security.enabled

Copy
cluster.name: "docker-cluster-01"
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

# 此处开启xpack
xpack.security.enabled: true

重启es容器

Copy
docker restart elasticsearch
  1. 进入es容器修改密码
Copy
docker exec -ti elasticsearch /bin/bash
/usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive

然后会分别让重置以下的密码,这里重置成123456

Copy
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,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]:
passwords must be at least [6] characters long
Try again.
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana_system]:
Reenter password for [kibana_system]:
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_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]
  1. 重置完毕之后带上用户就可以访问了
Copy
[root@k8s-master ~]# curl localhost:9200 -u elastic
Enter host password for user 'elastic':
{
  "name" : "cd52e7fbacd1",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "0S-V9zElSie_zXtcDRssAQ",
  "version" : {
    "number" : "8.1.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "31df9689e80bad366ac20176aa7f2371ea5eb4c1",
    "build_date" : "2022-03-29T21:18:59.991429448Z",
    "build_snapshot" : false,
    "lucene_version" : "9.0.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}
[root@k8s-master ~]#

修改kibana的密码#

  1. 修改配置文件
Copy
vi /data/kibana/config/kibana.yml
Copy
#
# ** THIS IS AN AUTO-GENERATED FILE **
#

# Default Kibana configuration for docker target
server.host: "0"
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://172.17.0.3:9200" ]
monitoring.ui.container.elasticsearch.enabled: true
i18n.locale: "zh-CN"
# 此处设置elastic的用户名和密码
elasticsearch.username: elastic
elasticsearch.password: "123456"

  1. 重启容器
Copy
docker restart kibana

安装elastic-head

Copy
docker run -d \
--name=elasticsearch-head \
-p 9100:9100 \
mobz/elasticsearch-head:5-alpine
  1. 连接集群 不能连localhost:9200,而是
Copy
http://{ip}:9200/
  1. 后续带x-pack的认证信息的访问
  • url上带上用户名密码
Copy
http://{ip}:9100/?auth_user=elastic&auth_password=123456
  分类: elasticsearch

标签:Copy,kibana,elasticsearch,docker,password,data
From: https://www.cnblogs.com/gaoyanbing/p/18151196

相关文章

  • docker安装redis
    下载最新的官方镜像dockerpullredis:latest在/app/redis下新建redis.conf:#开启密码验证(可选)requirepass123#允许redis外地连接,需要注释掉绑定的IP#bind127.0.0.1#关闭保护模式(可选)protected-modeno#注释掉daemonizeyes,或者配置成daemonizeno。因为该配......
  • docker - [06] 安装部署Tomcat
    题记部分   一、官方测试镜像官方文档给出以下命令,一般用来测试,用完即删,下载并运行镜像,退出镜像就会自动删除镜像?亲测不会自动删除dockerrun-it--rmtomcat:9.0使用快捷键:Ctrl+P+Q可以让其在后台运行(这里执行Ctrl+C之后,dockerimages还是有tomcat镜像) ......
  • docker - [05] 部署Nginx
    题记部分 一、查找镜像dockersearchnginx 二、拉取镜像dockerpullnginx 三、启动镜像Nginx默认端口号为80,可以在启动时指定Nginx使用的端口号(例如3344)那么容器外部访问Nginx使用3344端口,而容器内部则是80,两个端口号形成映射关系。dockerrun-d--namen......
  • docker下安装gitlab配置以及备份
    安装dockerrun--detach--publish443:443--publish9980:80--publish9922:22--namegitlab--restartalways--volume/srv/gitlab/config:/etc/gitlab--volume/srv/gitlab/logs:/var/log/gitlab--volume/srv/gitlab/data:/var/opt/gitlab--shm-siz......
  • 【Docker系列】Section 1: Docker and Container Fundamentals①
    本篇是根据《KubernetesandDocker–AnEnterpriseGuide》整理出来的,原著作者:ScottSurovich|MarcBoorshtein,大家可以关注一下。Whothisbookisfor❓我们创建这本书是为了帮助DevOps人员团队扩展他们的技能,超越Kubernetes的基础知识。它是根据我们在多个企业环境......
  • OpenEuler22.03 SP3离线安装Docker
    下载Docker离线安装包下载地址:https://download.docker.com/linux/static/stable/下面以安装docker-23.0.5.tgz为例。安装Docker解压docker-23.0.5.tgz[root@mccp~]#tar-zxvfdocker-23.0.5.tgzdocker/docker/docker-proxydocker/containerd-shim-runc-v2docker/ctrdocker......
  • 使用 Docker 部署 FRP
    服务端编写配置文件vim~/.config/frp/frps.tomlbindPort=7000#WebDashboard[webServer]addr="0.0.0.0"port=7500user="xxx"password="xxx"启动Docker容器dockerrun-d--restartalways--networkhost--namefrps-v~/.con......
  • ElasticSearch 7.17.20本地源码调试
    目录使用本地安装gradle下载相关依赖本地编译本地调试使用本地安装gradle下载相关依赖在gradle安装目录下的init.d目录中,创建初始化脚本init.gradle,添加如下脚本,将其中的maven仓库源全部换成国内镜像allprojects{repositories{defREPOSITORY_URL='http://m......
  • docker安装rabbitmq
    拉取镜像dockerpullrabbitmq:3.12.12运行容器cd/usr/local/dockerdockerrun-d--namerabbitmq3.12.12-p5672:5672-p15672:15672-v`pwd`/data:/var/lib/rabbitmq--hostnamemyRabbit-eRABBITMQ_DEFAULT_VHOST=my_vhost-eRABBITMQ_DEFAULT_USER=admin-e......
  • docker Java 应用堆内存配置
    引言本文主要是讲解InitialRAMPercentage、MinRAMPercentage,MaxRAMPercentage三个JVM参数之间的区别。参数由Java8update191引入,主要是用于配置运行在物理机或者容器中的Java应用堆内存大小。InitialRAMPercentage-XX:InitialRAMPercentage用于配置堆的初始化......