赞
踩
说明一下为什么要安装desktop版本的docker,因为docker作为工具使用,我们需要的是开箱即用,没有必要非得整那种dockerserver什么的手动进行安装,一大堆配置很麻烦,这个desktop很适合新手使用,查看管理镜像和容器非常方便
创建挂载文件夹
$ mkdir -p ~/es/data
$ mkdir -p ~/es/plugins
$ mkdir -p ~/es/logs
$ cd ~
$ pwd
创建docker专属网络
$ docker network create elastic
90c5589fffadaaa93e0e66c917458607e81b79d837647ee80eb38c4922d2162f
端口说明
9200:外部访问使用
9300:集群间相互通信使用
$ docker run -d \
--name es \
--net elastic \
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
-e "discovery.type=single-node" \
-v es-data:/Users/mrhan/es/data \
-v es-plugins:/Users/mrhan/es/plugins \
-v es-logs:/Users/mrhan/es/logs \
--privileged \
-p 9200:9200 \
-p 9300:9300 \
elasticsearch:8.11.3
83048519c39945c30c2bf34465a20500e73fc559ba4f5f5178a366ea2786def5
启动成功后会在desktop中看到已经启动的容器
也可以通过命令行查看正在运行中的容器
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
83048519c399 elasticsearch:8.11.3 "/bin/tini -- /usr/l…" 3 minutes ago Up 3 minutes 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp es
这里需要输入默认的账号密码,但是由于我们是通过docker启动,好像没有看到他的日志,不要慌,我们有两种办法可以解决这个问题,一个就是重置密码,一个就是关闭登录校验
建议重置密码不要关闭登录校验
#执行以下命令进入容器
$ docker exec -it es /bin/bash
#进入容器之后执行以下命令:bin/elasticsearch-reset-password -u elastic
elasticsearch@83048519c399:~$ bin/elasticsearch-reset-password -u elastic
WARNING: Owner of file [/usr/share/elasticsearch/config/users] used to be [root], but now is [elasticsearch]
WARNING: Owner of file [/usr/share/elasticsearch/config/users_roles] used to be [root], but now is [elasticsearch]
This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y
Password for the [elastic] user successfully reset.
New value: O+PLWc9U=UUFDIOc1P6K
以上输出的结果表明elastic账号的密码已经被重置为O+PLWc9U=UUFDIOc1P6K
接下来正常登录就会看到如下结果
账号:elastic
密码:O+PLWc9U=UUFDIOc1P6K
elasticsearch@db7a23c3ac34:~$ ls
LICENSE.txt README.asciidoc config jdk logs plugins
NOTICE.txt bin data lib modules
elasticsearch@db7a23c3ac34:~$ cd config
elasticsearch@db7a23c3ac34:~/config$ ls
certs jvm.options role_mapping.yml
elasticsearch-plugins.example.yml jvm.options.d roles.yml
elasticsearch.keystore log4j2.file.properties users
elasticsearch.yml log4j2.properties users_roles
elasticsearch@db7a23c3ac34:~/config$ vi elasticsearch.yml
打开文件如下:
cluster.name: "docker-cluster" network.host: 0.0.0.0 #----------------------- BEGIN SECURITY AUTO CONFIGURATION ----------------------- # # The following settings, TLS certificates, and keys have been automatically # generated to configure Elasticsearch security features on 27-12-2023 06:53:43 # # -------------------------------------------------------------------------------- # Enable security features #是否需要账号密码 xpack.security.enabled: true #注册时是否需要账号密码 xpack.security.enrollment.enabled: true # Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents xpack.security.http.ssl: enabled: true keystore.path: certs/http.p12 # Enable encryption and mutual authentication between cluster nodes xpack.security.transport.ssl: enabled: true verification_mode: certificate keystore.path: certs/transport.p12 truststore.path: certs/transport.p12 #----------------------- END SECURITY AUTO CONFIGURATION -------------------------
修改上述文件中的以下配置为false就可以了,然后重启服务
xpack.security.enabled: false
xpack.security.enrollment.enabled: false
访问地址不需要账号密码:https://127.0.0.1:9200/
至此es安装成功!!!
$ docker run -d \
--name kibana \
--net elastic \
-p 5601:5601 \
kibana:8.11.3
261b2a93006751bb2aba76482676d85c9e69617a9b467977891ca455582388e6
访问kibana页面:http://localhost:5601/
这里发现需要填写一个token
这里发现需要填写一个token,这个token生成命令如下
$ docker exec -it es /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana
eyJ2ZXIiOiI4LjExLjMiLCJhZHIiOlsiMTcyLjE4LjAuMjo5MjAwIl0sImZnciI6IjQzNDJiYTg0MGM1NmFmYjRmMTIxYTk1NDc4NDA0NmQ0M2JjMmEzZjAzNGMwMWNlMmI0NGM2NmEzMzBkZGQyMTIiLCJrZXkiOiJZdWVJcW93QlJFTnpLN3ZxdFR1XzpWTDFEZXlMM1FFMnowbUZMTXVpUmR3In0=
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
261b2a930067 kibana:8.11.3 "/bin/tini -- /usr/l…" 8 minutes ago Up 8 minutes 0.0.0.0:5601->5601/tcp kibana
83048519c399 elasticsearch:8.11.3 "/bin/tini -- /usr/l…" 24 minutes ago Up 24 minutes 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp es
#这里要将261b2a930067替换成自己电脑上的kibana的container Id
~/es docker exec -it 261b2a930067 bash
kibana@261b2a930067:~$ bin/kibana-verification-code
Kibana is currently running with legacy OpenSSL providers enabled! For details and instructions on how to disable see https://www.elastic.co/guide/en/kibana/8.11/production.html#openssl-legacy-provider
Your verification code is: 350 931
接下来会看到登录页面登录前文es的账号密码即可
账号:elastic
密码:O+PLWc9U=UUFDIOc1P6K
登录成功之后会看到欢迎界面,至此es和kibana已经全部安装链接成功,后续使用一般点击explore on my own 自行使用就可以了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。