安装要求:
docker已安装并配置阿里等镜像加速
采用docker-compose部署时,需安装docker-compose
CentOS基本操作指令
docker基本操作指令
https://hub.docker.com/
image-20220215203138721
#拉取镜像文件
docker pull elasticsearch
#说明:此处也可在Tags中选择指定版本的elasticsearch
image-20220215203222814
docker images
#1、创建Elasticsearch配置文件夹
mkdir -p /usr/local/data-docker/elasticsearch/config
#2、创建Elasticsearch数据文件夹
mkdir -p /usr/local/data-docker/elasticsearch/data
#3、创建Elasticsearch插件文件夹(如:ik)
mkdir -p /usr/local/data-docker/elasticsearch/plugins
#说明:目的将CentOS本地的文件夹映射到Elasticsearch容器,以实现容器数据的持久化到CentOS本地,以及通过CentOS本地文件夹内容的修改同步到容器
echo "http.host: 0.0.0.0">>/usr/local/data-docker/elasticsearch/config/elasticsearch.yml
#创建并写入elasticsearch.yml配置,注意:http.host: 0.0.0.0 冒号后有一空格
chmod -R 777 elasticsearch/
docker run --name elasticsearch -p 9200:9200 \
-p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx128m" \
-v /usr/local/data-docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /usr/local/data-docker/elasticsearch/data:/usr/share/elasticsearch/data \
-v /usr/local/data-docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch
参数说明
–name elasticsearch:将Elasticsearch容器命名为 elasticsearch
-p 9200:9200:将容器的9200端口映射到宿主机9200端口
-p 9300:9300:将容器的9300端口映射到宿主机9300端口,目的是集群互相通信
-e “discovery.type=single-node”:单例模式
-e ES_JAVA_OPTS=“-Xms64m -Xmx128m”:配置内存大小
-v /usr/local/data-docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:将配置文件挂载到宿主机
-v /usr/local/data-docker/elasticsearch/data:/usr/share/elasticsearch/data:将数据文件夹挂载到宿主机
-v /usr/local/data-docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins:将插件目录挂载到宿主机(需重启)
-d elasticsearch:后台运行容器,并返回容器ID
version: '2'
services:
elasticsearch:
container_name: elasticsearch
image: elasticsearch
ports:
- "9200:9200"
volumes:
- /usr/local/data-docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /usr/local/data-docker/elasticsearch/data:/usr/share/elasticsearch/data
- /usr/local/data-docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins
environment:
- "ES_JAVA_OPTS=-Xms64m -Xmx128m"
- "discovery.type=single-node"
- "COMPOSE_PROJECT_NAME=elasticsearch-server"
restart: always
docker ps -a
#说明:安装完后,通过如下指令查看elasticsearch是否安装成功 curl http://localhost:9200
展示结果如下:
{
"name" : "550eca5cf3b2",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "1mP9IJU3TUy_C2DZMfKGBg",
"version" : {
"number" : "7.7.0",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "81a1e9eda8e6183f5237786246f6dced26a10eaf",
"build_date" : "2020-05-12T02:01:37.602180Z",
"build_snapshot" : false,
"lucene_version" : "8.5.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
注意:如展示上边内容,说明docker安装elasticsearch成功,如远程访问无法展示上述内容,请关防火墙或防火墙开放9200、9300端口
docker update elasticsearch --restart=always