zl程序教程

您现在的位置是:首页 >  工具

当前栏目

docker中安装es和kibana

2023-06-13 09:17:03 时间

一、安装 ElasticSearch

1.拉取镜像

[root@localhost ~]# docker pull elasticsearch:7.4.2
7.4.2: Pulling from library/elasticsearch
d8d02d457314: Pull complete
f26fec8fc1eb: Pull complete
8177ad1fe56d: Pull complete
d8fdf75b73c1: Pull complete
47ac89c1da81: Pull complete
fc8e09b48887: Pull complete
367b97f47d5c: Pull complete
Digest: sha256:543bf7a3d61781bad337d31e6cc5895f16b55aed4da48f40c346352420927f74
Status: Downloaded newer image for elasticsearch:7.4.2
docker.io/library/elasticsearch:7.4.2

2.查看镜像

[root@localhost ~]# docker images
REPOSITORY           TAG       IMAGE ID       CREATED         SIZE
mysql                5.7       d410f4167eea   6 weeks ago     495MB
redis                latest    3e12e2ceb68f   6 weeks ago     117MB
nacos/nacos-server   2.0.3     433eb51fef8d   17 months ago   1.05GB
elasticsearch        7.4.2     b1179d41a7b4   3 years ago     855MB

3.创建目录及配置文件

[root@localhost ~]# mkdir -p /mydata/elasticsearch/config
[root@localhost ~]# mkdir -p /mydata/elasticsearch/data
[root@localhost ~]# echo "http.host : 0.0.0.0" > /mydata/elasticsearch/config/elasticsearch.yml
[root@localhost ~]# cat /mydata/elasticsearch/config/elasticsearch.yml
http.host : 0.0.0.0
[root@localhost ~]#

4.启动elasticSearch

[root@localhost ~]# docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \-e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx128m" -v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data -v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:7.4.2
b1ab9addb1f23443e0c3f03d8fde6f2667ae5ce98243a4304e14f316d2e4358a

5.注意:

- elasticsearch.yml 文件中的冒号前后有空格

- /mydata/elasticsearch/ 目录需要设置权限,暴力些给个 777 最为省事

6.测试启动

直接通过IP地址和端口号进行访问即可:http://192.168.56.101:9200/

访问后可以看到 ES 输出一些基本的信息

二、安装 Kibana

1.镜像拉取

[root@localhost ~]# docker pull kibana:7.4.2
7.4.2: Pulling from library/kibana
d8d02d457314: Already exists
bc64069ca967: Pull complete
c7aae8f7d300: Pull complete
8da0971e3b41: Pull complete
58ea4bb2901c: Pull complete
b1e21d4c2a7e: Pull complete
3953eac632cb: Pull complete
5f4406500758: Pull complete
340d85e0d1c7: Pull complete
1768564d16fb: Pull complete
Digest: sha256:355f9c979dc9cdac3ff9a75a817b8b7660575e492bf7dbe796e705168f167efc
Status: Downloaded newer image for kibana:7.4.2
docker.io/library/kibana:7.4.2

2.启动

[root@localhost ~]# docker run --name kibana -e ELASTICSEARCH=http://es_ip:9200 -p 5601:5601 -d kibana:7.4.2
2ec9c0ee6027300199a0b90a2a725d5651b74322a93831226c2ce5a9357e8db2

其中 es_ip 这里修改为 ES 所在容器的IP 地址,查看的方式如下:

docker inspect --format '{{ .NetworkSettings.IPAddress }}' ES容器

有时可能会启动失败,原因是找不到 ES,进入 Kibana 容器,然后查看配置

vi config/kibana.yml,

修改配置

elasticsearch.hosts: [ "http://172.17.0.3:9200" ]

3.访问192.168.56.101:5601即可。