Docker 安装Elasticsearch7

Docker 安装Elasticsearch7

1、拉取docker elasticsearch 镜像

docker pull elasticsearch:7.8.0

2、先配置宿主机的 参数,否则无法启动,会报错

在这里插入图片描述
需要配置如下内容:

vim /etc/security/limits.conf
#加入如下内容
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

vim /etc/sysctl.conf
#加入如下内容
vs.max_map_count=262145

刷新配置文件sysctl.conf
sysctl -p

3、先启动简洁版的容器

docker run -id \
--restart=always \
--name=elasticsearch7.8.0 \
-p 9200:9200 \
-p 9300:9300 \
-v /etc/localtime:/etc/localtime \
-e "discovery.type=single-node" \
-e TZ='Asia/Shanghai' \
-e LANG="en_US.UTF-8" \
elasticsearch:7.8.0

4、copy容器中的文件,到宿主机上

docker cp 97d21381af5a4e49e:/usr/share/elasticsearch/config/ /usr/local/elasticsearch7/node0elasticsearch/
docker cp 97d21381af5a4e49e:/usr/share/elasticsearch/data/ /usr/local/elasticsearch7/node0elasticsearch/
docker cp 97d21381af5a4e49e:/usr/share/elasticsearch/logs/ /usr/local/elasticsearch7/node0elasticsearch/
docker cp 97d21381af5a4e49e:/usr/share/elasticsearch/plugins/ /usr/local/elasticsearch7/node0elasticsearch/

5、启动 elasticsearch 容器

docker run \
-tid \
--restart always \
--name elasticsearch-node0 \
--privileged=true \
-p 9200:9200 \
-p 9300:9300 \
-v /usr/local/elasticsearch7/node0/elasticsearch/config/:/usr/share/elasticsearch/config \
-v /usr/local/elasticsearch7/node0/elasticsearch/data/:/usr/share/elasticsearch/data \
-v /usr/local/elasticsearch7/node0/elasticsearch/logs/:/usr/share/elasticsearch/logs \
-v /usr/local/elasticsearch7/node0/elasticsearch/plugins/:/usr/share/elasticsearch/plugins \
-v /etc/localtime:/etc/localtime \
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
-e TZ='Asia/Shanghai' \
-e LANG="en_US.UTF-8"  elasticsearch:7.8.0

注:如果要单节点启动elasticsearch 需要在启动参数重加入-e “discovery.type=single-node”,并且在elasticsearch的配置文件
elasticsearch.yml 中不能存在cluster.initial_master_nodes: [“es-node0”]这个集群节点的配置。


6、elasticsearch.yml相关配置

#集群名称
cluster.name: imooc-elasticsearch
#节点名
node.name: es-node0
#ip绑定(0.0.0.0代表允许所有ip)
network.host: 0.0.0.0
#集群中包含的节点
cluster.initial_master_nodes: ["es-node0"]
#elasticsearch允许跨域配置
http.cors.enabled: true
http.cors.allow-origin: "*"

7、安装elasticsearch-head

注:推荐使用的安装方式是直接从Chrome商店中以浏览器插件的形式安装(最为简洁,切不涉及跨域问题,但是需要VPN才能安装)


docker安装

#下载elasticsearch-head镜像
docker pull mobz/elasticsearch-head:5-alpine
#运行命令
docker run \
-dit \
--restart=always \
--name=elasticsearch-head \
-p 19100:9100 \
-v /etc/localtime:/etc/localtime \
-e TZ='Asia/Shanghai' \
-e LANG="en_US.UTF-8" \
mobz/elasticsearch-head:5-alpine

访问地址为:http://ip:19100

注:docker安装的elasticsearch-head存在跨域的问题,需要在elasticsearch.yml中允许跨域


你可能感兴趣的:(elasticsearch)