1.0ElasticSearch安装
# 拉取ES镜像
docker pull elasticsearch:6.5.0
# 设置vm.max_map_count大小
sysctl -w vm.max_map_count=262144
# 启动容器
docker run --name elasticsearch -d -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" -p 9200:9200 -p 9300:9300 elasticsearch:6.5.0
1.1启动容器是的坑
报错信息如下
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
临时解决办法(重启虚拟机会失效):
1.切换到root用户,执行命令:
sysctl -w vm.max_map_count=262144
2.查看结果:
sysctl -a|grep vm.max_map_count
3.显示:
vm.max_map_count = 262144
永久解决办法
在/etc/sysctl.conf文件最后添加一行:vm.max_map_count=262144
重启虚拟机
1.2ES容器中配置文件
# 自动生成的集群名称
cluster.name: "docker-cluster"
network.host: 0.0.0.0
# 设置访问端口
transport.tcp.port: 9300
http.port: 9200
# 解决跨域请求
http.cors.enabled: true
http.cors.allow-origin: "*"
# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
discovery.zen.minimum_master_nodes: 1
2.0安装ES-Head
#拉取镜像
docker pull mobz/elasticsearch-head:5
#启动容器
docker run -d -p 9100:9100 mobz/elasticsearch-head:5
# 访问9100 端口
2.1 ES-Head访问 406
1. 页面数据查询报406错误
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
2. 解决方法:
# 进入docker es-head容器
# 命令 docker exec -it 容器ID /bin/bash
[root@localhost ~]# docker exec -it es-head /bin/bash
进入head安装目录;
cd进入_site/目录,编辑vendor.js 共有两处
# 如果提示找不到vim方法,请参考下面的 [附: Docker容器vim安装]
[root@localhost ~]# vim _site/vendor.js
6886行: /contentType: “application/x-www-form-urlencoded改成
contentType: "application/json;charset=UTF-8"
7573行: var inspectData = s.contentType === “application/x-www-form-urlencoded” && 改成
var inspectData = s.contentType === "application/json;charset=UTF-8" &&
3. 附: Docker容器vim安装
# 更新源
[root@localhost ~]# apt-get update
# 先更新,防止提示:Unable to locate package vim
[root@localhost ~]# apt-get install vim