1、下载镜像文件(elasticsearch:7.4.2、 kibana:7.4.2)
[root@localhost ~]# docker pull elasticsearch:7.4.2
Trying to pull repository docker.io/library/elasticsearch ...
7.4.2: Pulling from docker.io/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 docker.io/elasticsearch:7.4.2
[root@localhost ~]# docker pull kibana:7.4.2
Trying to pull repository docker.io/library/kibana ...
7.4.2: Pulling from docker.io/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 docker.io/kibana:7.4.2
2、Docker ps 命令
语法
docker ps [OPTIONS]
OPTIONS说明:
-a :显示所有的容器,包括未运行的。
-f :根据条件过滤显示的内容。
--format :指定返回值的模板文件。
-l :显示最近创建的容器。
-n :列出最近创建的n个容器。
--no-trunc :不截断输出。
-q :静默模式,只显示容器编号。
-s :显示总的文件大小。实例
列出所有在运行的容器信息。
输出详情介绍:
CONTAINER ID: 容器 ID。
IMAGE: 使用的镜像。
COMMAND: 启动容器时运行的命令。
CREATED: 容器的创建时间。
STATUS: 容器状态。状态有7种:
created(已创建)
restarting(重启中)
running(运行中)
removing(迁移中)
paused(暂停)
exited(停止)
dead(死亡)
PORTS: 容器的端口信息和使用的连接类型(tcp\udp)。
NAMES: 自动分配的容器名称。
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6970b0fa8bd7 mysql "docker-entrypoint..." 3 days ago Up 3 days 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
4c06d40d9f6f redis "docker-entrypoint..." 3 days ago Up 3 days 0.0.0.0:6379->6379/tcp laughing_golick
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/redis latest f9b990972689 5 days ago 104 MB
docker.io/mysql latest a7a67c95e831 9 days ago 541 MB
docker.io/openjdk latest 0ce6496aae74 3 weeks ago 497 MB
docker.io/kibana 7.4.2 230d3ded1abc 6 months ago 1.1 GB
docker.io/elasticsearch 7.4.2 b1179d41a7b4 6 months ago 855 MB
3、创建elasticsearch挂载目录
[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 ~]# cd /mydata/elasticsearch/config/
[root@localhost config]# cat elasticsearch.yml
http.host:0.0.0.0
[root@localhost config]#
4、启动elasticsearch
[root@localhost elasticsearch]# chmod -R 777 /mydata/elasticsearch/
[root@localhost elasticsearch]# 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
3c08ff07bc2cb17a0a4a8a874f68a5817edf31d694b16abd76b4228a63478c60
[root@localhost elasticsearch]#
显示出正在运行的容器列表:
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16490fb73d9f kibana:7.4.2 "/usr/local/bin/dumb…" 9 hours ago Up 9 hours 0.0.0.0:5601->5601/tcp kibana
c1552e61aa80 elasticsearch:7.4.2 "/usr/local/bin/dock…" 9 hours ago Up 9 hours 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
[root@localhost ~]#
ps:
搭建过程中,我出现过两个问题:
问题1:刚开始我把路径/usr/share/elasticsearch/data 不小心写成了usr/share/elasticsearch/data,结果报如下错误:
[root@localhost elasticsearch]# 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
docker: Error response from daemon: invalid volume specification: '/mydata/elasticsearch/plugins:usr/share/elasticsearch/plugins': invalid mount config for type "bind": invalid mount path: 'usr/share/elasticsearch/plugins' mount path must be absolute.
See 'docker run --help'.
问题2:启动成功后,然后闪退,查看日志,发现如下错误:
[root@localhost config]# docker logs elasticsearch
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
2020-05-08 02:04:58,259 main ERROR No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2
Exception in thread "main" SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: ParsingException[Failed to parse object: expecting token of type [START_OBJECT] but found [VALUE_STRING]];
原因:
[root@localhost ~]# echo “http.host: 0.0.0.0”>>/mydata/elasticsearch/config/elasticsearch.yml
刚开始将一段配置写入到elasticsearch.yml中是,http.host: 0.0.0.0我敲成了http.host:0.0.0.0,中间没加空格,key-value之间需要有空格的。
至此,elasticsearch安装成功!
5、启动kibana
[root@localhost config]# docker run --name kibana -e ELASTICSEARCH_HOSTS=http://192.168.24.128:9200 -p 5601:5601 \
> -d kibana:7.4.2
16490fb73d9fac6261f5e4127cefaf5441f5f4f2f2c70cfce2a6613f61e0bb40
访问http://192.168.24.128:5601/,即可查看