一,踩过的坑
1,不能用root账户启动elasticsearch集群
在安装docker时使用的是root账户,启动elasticsearch集群时,会报错。
2,ssh不能连接服务器
自己折腾了半天,最后提工单,阿里小哥帮忙解决,必须称赞下小哥,响应快,解决也快。遇到服务器方面的问题,超过2个小时不能解决,就不要自己搞了,除非你的目的就是折腾服务器。像我这种目的在于学习elasticsearch,就不要在其他方面耗费太多时间,要有的放矢。
3,kibana不能连接es集群
配置文件不对,需要指定master节点。
environment:
- ELASTICSEARCH_HOSTS=http://es01:9200
# 需要将Kibana配置文件中的小写转换成大写,然后这个才能用于变量,才能被设置到
- I18N_LOCALE=zh-CN
- xpack.monitoring.ui.container.elasticsearch.enabled=false
4,安装docker-compose
试图通过python-pip安装,但python-pip安装不了,折腾了一个小时,果断放弃。
curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
二,配置文件
1,目录结构
/usr/local/elasticsearch
docker-compose.yml
data
es01
es02
es03
config
es01
elasticsearch.yml
es02
elasticsearch.yml
es03
elasticsearch.yml
logs
es01
es02
es03
2,docker-compose.yml
version: '2'
services:
cerebro:
image: lmenezes/cerebro:0.8.4
container_name: cerebro
ports:
- "9000:9000"
command:
- -Dhosts.0.host=http://elasticsearch:9200
networks:
- esnet
kibana:
image: kibana:7.3.0
container_name: kibana
environment:
- ELASTICSEARCH_HOSTS=http://es01:9200
# 需要将Kibana配置文件中的小写转换成大写,然后这个才能用于变量,才能被设置到
- I18N_LOCALE=zh-CN
- xpack.monitoring.ui.container.elasticsearch.enabled=false
ports:
- 5601:5601
networks:
- esnet
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
container_name: es01
restart: always
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data/es01:/usr/share/elasticsearch/data
- ./config/es01/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ./logs/es01:/usr/share/elasticsearch/logs
ports:
- 9200:9200
- 9300:9300
networks:
- esnet
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
container_name: es02
restart: always
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data/es02:/usr/share/elasticsearch/data
- ./config/es02/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ./logs/es02:/usr/share/elasticsearch/logs
depends_on:
- es01
networks:
- esnet
es03:
image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
container_name: es03
restart: always
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data/es03:/usr/share/elasticsearch/data
- ./config/es03/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ./logs/es03:/usr/share/elasticsearch/logs
depends_on:
- es01
networks:
- esnet
networks:
esnet:
3,es0既master节点的配置文件elasticsearch.yml
cluster.name: es-cluster
node.name: es01
node.master: true
node.data: false
path.data: /usr/share/elasticsearch/data
path.logs: /usr/share/elasticsearch/logs
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["es01", "es02", "es03"]
cluster.initial_master_nodes: ["es01","es02","es03"]
http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.security.enabled: false
xpack.security.transport.ssl.enabled: false
4,data节点的配置文件elasticsearch.yml
```clike
cluster.name: es-cluster
node.name: es02
node.master: false
node.data: true
path.data: /usr/share/elasticsearch/data
path.logs: /usr/share/elasticsearch/logs
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["es01", "es02", "es03"]
cluster.initial_master_nodes: ["es01", "es02", "es03"]
http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.security.enabled: false
xpack.security.transport.ssl.enabled: false
5,启动集群
docker-compose up