1、下载镜像
输入:docker search elasticSearch
,结果如下 查看 es的版本
2、拉取镜像
docker pull elasticsearch:7.8.1
查看本地镜像
docker images
3、创建本地配置文件的目录
- 创建多个文件夹 mkdir -p elasticsearch/config
- 进入elasticsearch目录 cd
- 创建数据目录 mkdir data
- 创建插件目录 mkdir plugins
- 在config下创建xxxx.yml配置文件
sudo vi elasticsearch.yml
-使用 vi 命令创建并打开
受权 设置任何人都有读、写、运行三项权限,也可以单独给100用户设置,100是docker启动es的帐号 sudo chmod 777 data – 没有权限需要授权
配置文件
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please see the documentation for further information on configuration options:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
# 集群名称,默认是elasticsearch
cluster.name: elasticsearch-one
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# 节点名称,默认从elasticsearch-2.4.3/lib/elasticsearch-2.4.3.jar!config/names.txt中随机选择一个名称
node.name: node-1
#
# Add custom attributes to the node:
#
# node.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
# 可以指定es的数据存储目录,默认存储在es_home/data目录下
# path.data: /path/to/data
#
# Path to log files:
# 可以指定es的日志存储目录,默认存储在es_home/logs目录下
# path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
# 锁定物理内存地址,防止elasticsearch内存被交换出去,也就是避免es使用swap交换分区
# bootstrap.memory_lock: true
#
#
#
# 确保ES_HEAP_SIZE参数设置为系统可用内存的一半左右
# Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory
# available on the system and that the owner of the process is allowed to use this limit.
#
# 当系统进行内存交换的时候,es的性能很差
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
#
# 为es设置ip绑定,默认是127.0.0.1,也就是默认只能通过127.0.0.1 或者localhost才能访问
# es1.x版本默认绑定的是0.0.0.0 所以不需要配置,但是es2.x版本默认绑定的是127.0.0.1,需要配置
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
#
# 为es设置自定义端口,默认是9200
# 注意:在同一个服务器中启动多个es节点的话,默认监听的端口号会自动加1:例如:9200,9201,9202...
# Set a custom port for HTTP:
#设置对外服务的http端口,默认为9200
http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- Discovery ----------------------------------
#
# 当启动新节点时,通过这个ip列表进行节点发现,组建集群
# 默认节点列表:
# 127.0.0.1,表示ipv4的回环地址。
# [::1],表示ipv6的回环地址
#
# 在es1.x中默认使用的是组播(multicast)协议,默认会自动发现同一网段的es节点组建集群,
# 在es2.x中默认使用的是单播(unicast)协议,想要组建集群的话就需要在这指定要发现的节点信息了。
# 注意:如果是发现其他服务器中的es服务,可以不指定端口[默认9300],如果是发现同一个服务器中的es服务,就需要指定端口了。
# Pass an initial list of hosts to perform discovery when new node is started:
#
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
#
#
#
# 通过配置这个参数来防止集群脑裂现象 (集群总节点数量/2)+1
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
# 一个集群中的N个节点启动后,才允许进行数据恢复处理,默认是1
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
#
# ---------------------------------- Various -----------------------------------
# 在一台服务器上禁止启动多个es服务
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# 设置是否可以通过正则或者_all删除或者关闭索引库,默认true表示必须需要显式指定索引库名称
# 生产环境建议设置为true,删除索引库的时候必须显式指定,否则可能会误删索引库中的索引库。
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true
#
#当设置允许跨域,默认为*,表示支持所有域名,如果我们只是允许某些网站能访问,那么可以使用正则表达式。比如只允许本地地址。/https?:\/\/localhost(:[0-9]+)?/
#
http.cors.allow-origin: "*"
#是否支持跨域,默认为false
#
http.cors.enabled: true
#跨域允许设置的头信息,默认为X-Requested-With,Content-Type,Content-Lengt
#
#http.cors.allow-headers: Authorization
#
#这条配置表示开启xpack认证机制
#
#xpack.security.enabled: true
#
#xpack.security.transport.ssl.enabled: true
4、安装
开启镜像并映射端口9200和9300(ElasticSearch的默认端口为9200)
- 9300是tcp通讯端口,集群间和TCPClient都走的它;
- 9200是http协议的RESTful接口,后续的API接口测试都是走的它。
docker run --name escsearchone -p 9200:9200 -p 9300:9300
-e "discovery.type=single-node"
-e ES_JAVA_OPTS="-Xms512m -Xmx1024m"
-v -v /usr/dockerconfig/elasticsearch/essearch_one/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
-v /usr/dockerconfig/elasticsearch/essearch_one/config/jvm.options:/usr/share/elasticsearch/config/jvm.options
-v /usr/dockerconfig/elasticsearch/essearch_one/config:/usr/share/elasticsearch/config
-v /usr/dockerconfig/elasticsearch/essearch_one/data:/usr/share/elasticsearch/data
-v /usr/dockerconfig/elasticsearch/essearch_one/plugins:/usr/share/elasticsearch/plugins
-d es
测试服务是否正常
[root@rqateng customer]# curl 127.0.0.1:9200
{
"name" : "node-1",
"cluster_name" : "elasticsearch-one",
"cluster_uuid" : "W6vpDy_fQsymE4bbRLY8MA",
"version" : {
"number" : "7.10.1",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "1c34507e66d7db1211f66f3513706fdf548736aa",
"build_date" : "2020-12-05T01:00:33.671820Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}