2013-04-18 292 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