专业编程基础技术教程

网站首页 > 基础教程 正文

docker安装elasticSearch(docker安装win10)

ccvgpt 2024-07-20 12:00:44 基础教程 14 ℃

前置条件

安装好docker

一、启动并运行Elasticsearch

运行以下命令以启动Elasticsearch 7.15.2版本:

docker安装elasticSearch(docker安装win10)

[root@localhost config]# docker run -d --name es7 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -v /usr/share/elasticsearch/config:/usr/share/elasticsearch/config elasticsearch:7.15.2

参数解释:

  • -d: 后台运行容器。
  • --name es7: 容器命名为es7。
  • -p: 端口映射,分别映射HTTP访问和节点间通信端口。
  • -e: 设置环境变量,配置为单节点模式和JVM内存。
  • -v: 挂载宿主机配置目录到容器内。


二、在宿主机上访问Elasticsearch

使用如下命令访问:[root@localhost ~]# curl localhost:9200



三、启用账号密码验证

  1. 配置文件修改

将在配置文件中/usr/share/elasticsearch/config/elasticsearch.yml添加xpack.security.enabled: true,

cluster.name: "docker-cluster"
network.host: 0.0.0.0
xpack.security.enabled: true
  1. 设置密码

进入到es容器中,命令为:docker exec -it es7 /bin/bash

[root@localhost config]# docker exec -it es7 /bin/bash
# 设置密码 按照提示设置最终密码
bash-4.4# ./bin/elasticsearch-setup-passwords interactive
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]

四、在其他机器上远程访问es服务

若要从其他机器访问Elasticsearch服务,请使用安装Elasticsearch的物理机IP(例如:192.168.188.101)和端口9200进行测试,如使用POST请求进行测试。确保防火墙和网络设置允许远程访问。



Tags:

最近发表
标签列表