我正在尝试让ElasticSearch在Elastic Beanstalk环境中运行.使用Docker镜像,在负载平衡环境中运行一个实例非常简单.但是,当我尝试向群集添加更多实例时,它们无法发现彼此,并且每个新实例都成为new_master.
我的Dockerfile看起来如下
FROM dockerfile/java:oracle-java8
RUN ... # Downloading and installing ElasticSearch
RUN /elasticsearch/bin/plugin install elasticsearch/elasticsearch-cloud-aws/2.5.0
VOLUME ["/data"]
ADD config/elasticsearch.yml /elasticsearch/config/elasticsearch.yml
WORKDIR /data
CMD ["/elasticsearch/bin/elasticsearch"]
EXPOSE 9200
配置config / elasticsearch.yml如下所示:
cluster:
name: elastic-env-dev
cloud:
aws:
region: ap-southeast-2
discovery:
type: ec2
ec2:
tag:
Name: elastic-env-dev
ping_timeout: 120s
EB环境的名称是elastic-env-dev.
http://vladmiller.com/elasticsearch/aws/2015/12/08/deploy-elasticsearch-on-aws-elasticbeanstalk.html
此时(2015年11月14日),经过一段时间后,我会说不可能让ES集群在EB上运行.
问题#1是您必须将docker端口映射到主机,就像您一样
docker run -p 9300:9300 ...
如果您通过.ebextensions添加post appdeploy hook,这将设置iptables端口转发,这可以很容易地解决
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_setup_iptables.sh":
mode: "0755"
owner: root
group: root
content: |
#!/bin/sh
iptables-save | grep -v added_by_ebextension | iptables-restore
DOCKER_IP=$(docker inspect `cat /etc/elasticbeanstalk/.aws_beanstalk.current-container-id` | jq -r .[0].NetworkSettings.IPAddress)
iptables -t nat -A DOCKER -p tcp --dport 9300:9400 -j DNAT --to-destination ${DOCKER_IP} -m comment --comment added_by_ebextension
service iptables save
问题#2您需要调整安全组,确保在SG中的节点之间允许TCP 9300-9400和ICMP流量.
问题#3使用aws-ec2发现插件并将其限制在你的SG,因此没有其他机器被发现
// elasticsearch.yml
cloud.aws:
access_key: YYYYYYYYY
secret_key: XXXXXXXXX
region: us-east-1
discovery.type: ec2
discovery.ec2.ping_timeout: 30s
discovery.ec2.tag.Name: [ENVIRONMENT_NAME]
discovery.ec2.host_type: private_dns
discovery.zen.ping.multicast.enabled: false
问题#4,未解决的是每个ES节点将绑定到内部docker IP地址,类似于172.17.0.3,但是您的主机私有IP是不同的.因此,当节点发现彼此并开始通信时,他们将向其他人报告错误的IP地址.
[2015-11-13 21:50:58,542][TRACE][discovery.zen.ping.unicast] [86ac0ad55d5b] [2] received response from {#zen_unicast_21_#cloud-i-8c317a3b-0#}{10.165.71.177}{ip-10-165-71-177.ec2.internal/10.165.71.177:9300}: [ping_response{node [{86ac0ad55d5b}{U3PF5qOaQCucpK3JfZ3ARA}{172.17.0.3}{172.17.0.3:9300}],id[5],master [null],hasJoinedOnce [false],cluster_name[es-staging]},ping_response{node [{86ac0ad55d5b}{U3PF5qOaQCucpK3JfZ3ARA}{172.17.0.3}{172.17.0.3:9300}],id[7],id[9],id[11],ping_response{node [{89764d1bb185}{yVRC-HmIQoayIuWfi6a09g}{172.17.0.3}{172.17.0.3:9300}],id[30],master [{89764d1bb185}{yVRC-HmIQoayIuWfi6a09g}{172.17.0.3}{172.17.0.3:9300}],hasJoinedOnce [true],cluster_name[es-staging]}]
您可以在ip-10-165-71-177.ec2.internal / 10.165.71.177:9300上看到该节点被发现,但是该节点响应它的IP是172.17.0.3,因此第一个节点而不是连接到EC2私有IP将尝试连接到内部Docker IP
[2015-11-13 21:51:00,037][TRACE][discovery.ec2 ] [86ac0ad55d5b] full ping responses:
--> ping_response{node [{89764d1bb185}{yVRC-HmIQoayIuWfi6a09g}{172.17.0.3}{172.17.0.3:9300}],cluster_name[es-staging]}
[2015-11-13 21:51:00,041][DEBUG][discovery.ec2 ] [86ac0ad55d5b] filtered ping responses: (filter_client[true],filter_data[false])
--> ping_response{node [{89764d1bb185}{yVRC-HmIQoayIuWfi6a09g}{172.17.0.3}{172.17.0.3:9300}],cluster_name[es-staging]}
我们需要以某种方式使ES绑定到主机的IP地址或忽略这些docker IP地址并继续发现的IP.
更新1我怀疑你可以在没有Docker的情况下将ES部署到EB,但是我还没有尝试过这个选项.
更新2我能够让节点发现彼此并尝试通信,但现在它有一个different issue
更新3这是关于如何达到预期效果http://vladmiller.com/elasticsearch/aws/2015/12/08/deploy-elasticsearch-on-aws-elasticbeanstalk.html的故事和示例代码