#docker安装
curl -sSL https://get.daocloud.io/docker | sh
#docker-compose安装
curl -L \
https://get.daocloud.io/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` \
> /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
#查看安装结果
docker-compose -v
elasticsearch
数据、日志存放目录#创建数据/日志目录 这里我们部署3个节点
mkdir /root/app/elasticsearch/data/{node0,node1,node2} -p
mkdir /root/app/elasticsearch/logs/{node0,node1,node2} -p
cd /opt/elasticsearch
#权限
chmod 0777 data/* -R && chmod 0777 logs/* -R
#防止JVM报错
echo vm.max_map_count=262144 >> /etc/sysctl.conf
sysctl -p
在刚刚新建的目录(/root/app/elasticsearch)创建docker-compose.yml文件,基于镜像elasticsearch:7.4.0
ersion: '2.2'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.0
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data/node0:/usr/share/elasticsearch/data
- ./logs/node0:/usr/share/elasticsearch/logs
ports:
- 9200:9200
networks:
- elastic
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.0
container_name: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data/node1:/usr/share/elasticsearch/data
- ./logs/node1:/usr/share/elasticsearch/logs
networks:
- elastic
es03:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.0
container_name: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./logs/node2:/usr/share/elasticsearch/data
- ./logs/node2:/usr/share/elasticsearch/logs
networks:
- elastic
networks:
elastic:
driver: bridge
参数说明:
#启动
docker-compose up -d
#查看
docker-compose ps
可以运行 curl -X GET “localhost:9200/_cat/nodes?v&pretty” 查看集群信息
git clone git://github.com/mobz/elasticsearch-head.git
安装完成 在cmd窗口执行node -v查看node.js的版本号 检查是否安装成功
npm install -g grunt-cli
通过node.js的包管理器npm安装grunt为全局命宁,grunt是基于Node.js的项目构建工具
npm install
cd ~/app/elasticsearch-head
grunt server
#如果后台启动 运行 nohup grunt server &exit
如果是后台运行的elasticsearch-head服务,只能通过kill 端口停止服务
#通过lsof -i找到端口对应的进程(PID)
lsof -i:9100
#kill调对应的进程
kill -9 6076
注意:启动如果报一下错误:
1. >>Local Npm module "grunt-contrib-clean" not found. Is it installed?
2. >> Local Npm module "grunt-contrib-concat" not found. Is it installed?
3. >> Local Npm module "grunt-contrib-watch" not found. Is it installed?
4. >> Local Npm module "grunt-contrib-connect" not found. Is it installed?
5. >> Local Npm module "grunt-contrib-copy" not found. Is it installed?
6. >> Local Npm module "grunt-contrib-jasmine" not found. Is it installed?
Warning: Task "connect:server" not found. Use --force to continue.
在elasticsearch-head目录下运行一下命令:
npm install grunt-contrib-clean --registry=https://registry.npm.taobao.org
npm install grunt-contrib-concat --registry=https://registry.npm.taobao.org
npm install grunt-contrib-watch --registry=https://registry.npm.taobao.org
npm install grunt-contrib-connect --registry=https://registry.npm.taobao.org
npm install grunt-contrib-copy --registry=https://registry.npm.taobao.org
npm install grunt-contrib-jasmine --registry=https://registry.npm.taobao.org
head主控页面是可以显示的,但是显示连接失败,出现了‘集群健康值:未连接’,如何解决这个问题呢?
出现这种错误首先检查配置文件是否开启了跨域(http.cors.enabled)和http.cors.allow-origin,http.cors.enabled:默认是false,表示是否运行跨域;http.cors.allow-origin:当设置允许跨域,默认为*,表示支持所有域名,如果我们只是允许某些网站能访问,那么可以使用正则表达式。比如只允许本地地址。 /https?:\/\/localhost(:[0-9]+)?/
#修改elasticsearch-head/_site/app.js
#找到app-base_uri关键字,并且把localhost修改为自己的ip
连接地址成功换成了自己的IP,集群健康值也变成了绿色
后续文章介绍如何使用…