2013-04-18 218 views
1

我有一个运行在aws弹性beanstalk上的应用程序。该应用程序需要一个配置文件,我为了在ec2实例上手动进行测试而放置该文件。AWS Elastic Beanstalk配置文件

问题是,当autoscaler决定扩展到更多实例时,应用程序在新实例上没有任何配置文件。

我阅读了关于为实例创建模板的信息。我可以把我的配置文件放在实例上,然后它会被复制到新的实例中。 这有一个很大的缺点,因为如果我想在运行时更改配置,我必须在所有实例上执行此操作。

有没有一个选项,我可以解决这个问题?

回答

2

嗯,我看到两个选项: 1.当您更改配置文件时,您需要在EB上进行环境更新。在这种情况下,所有节点都将使用新版本的配置文件进行更新。 2.而不是文件把你的配置设置到一些数据库,如simpledb或dynamodb。从我的角度来看,如果您想在运行时更改设置,则此解决方案更适合您的情况。

+0

谢谢你,这是解决方案,我正在寻找。唯一的缺点是速度取决于服务器必须处理多少个请求。我使用缓存服务器解决了这个问题,并且每10分钟更新一次缓存服务器。 – andre

0

我同意Vadim911,数据库将是一个更简单的解决方案。

但是您可以在环境中设置应用程序时使用类似于此的操作。

WEB-INF/.ebextensions/commands.config

commands: 
    replace-file: 
    command: cp .ebextensions/file.xml /folder/file.xml 

来源:infoq

0

如果我们要更深层次:)多少,而不是 “命令” 使用 “文件” 更好:

files: 
    /folder/file.xml: 
     mode: 000XXX 
     owner: root 
     group: users 
     content: | 
      <xml>I'm XML</xml> 
0

我建议你把你的配置文件放在像s3桶这样的安全位置。使敏感信息远离您的存储库。

尝试这样:

# .ebexetensions/safe-config-install.config 

files: 
    "/tmp/cron-fetch-config.sh": 
    mode: "000755" 
    owner: root 
    group: root 
    content: | 
     #!/usr/bin/env bash 
     for f in /etc/profile.d/*.sh; do source $f; done; 

     python -c "import boto;boto.connect_s3().get_bucket('my-private-bucket').get_key('secretfolder/secretfile.xml').get_contents_to_filename('/var/app/current/path/to/config.xml'); 

container_commands: 
    install-config: 
    command: python -c "import boto;boto.connect_s3().get_bucket('my-private-bucket').get_key('secretfolder/secretfile.xml').get_contents_to_filename('/var/app/ondeck/path/to/config.xml'); 

commands: 
    setup-cron-for-config: 
    command: echo -e "* * * * * root /tmp/cron-fetch-config.sh\n" > /etc/cron.d/my_cron