【问题标题】:How do I supply configuration to elastic beanstalk tomcat如何为弹性 beantalk tomcat 提供配置
【发布时间】:2012-08-29 04:03:31
【问题描述】:

在本地部署到 tomcat 时,我对 server.xml 进行了此更改(如下),有没有办法可以将其提供给 Elastic Beanstalk?

<Connector connectionTimeout="20000" port="8080" 
       protocol="org.apache.coyote.http11.Http11NioProtocol" 
       redirectPort="8443"/>'

谢谢 '

【问题讨论】:

    标签: java tomcat amazon-elastic-beanstalk


    【解决方案1】:

    您现在可以在不提供自定义 AMI 的情况下执行此操作。按照以下说明操作:http://aws.typepad.com/aws/2012/10/customize-elastic-beanstalk-using-configuration-files.html

    为了在 webapp 中提供自定义服务器 xml 创建 .ebextensions 文件夹,将自定义 server.xml 文件放在那里并添加一个文件:server-update.config内容:

    container_commands:
      replace-config:
      command: cp .ebextensions/server.xml /etc/tomcat7/server.xml
    

    【讨论】:

    • 您好,我尝试这样做,但收到以下错误消息:“应用程序版本 gd377807-dirty 中的配置文件 .ebextensions/server-update.config 包含无效的 YAML 或 JSON。YAML异常:在扫描下一个标记时,在“”第 2 行第 3 列中发现无法启动任何标记的字符 '\t':replace-config: ^,JSON 异常:位置 0 处的意外字符 (c)。 . 更新配置文件。
    • 这是因为 YAML 不支持在行首使用 TAB (\t) 字符,您只能使用空格
    • @sebsto,哇。我希望我能提供不止一个“加一”。
    • @Maciej Walkowiak 我收到替换配置失败的错误消息。我在 web-inf 文件夹中创建了 .ebextensions 并添加了两个文件 server.xml 和 server-update.config。当我检查日志时,我发现无法读取 .ebextensions/server.xml 中的文件可能是什么问题
    • 您也可以调用位于 .ebextensions 文件夹中的 bash 脚本
    【解决方案2】:

    在不替换整个 Tomcat server.xml 文件的情况下实现此目的的另一种方法是在您的 .ebextensions 文件夹中使用以下内容(例如 tomcat.config

    files:
      "/tmp/update_tomcat_server_xml.sh":
        owner: root
        group: root
        mode: "000755"
        content: |
          #! /bin/bash
          CONFIGURED=`grep -c '<Connector port="8080" URIEncoding="UTF-8"' /etc/tomcat7/server.xml`
          if [ $CONFIGURED = 0 ]
            then
              sed -i 's/Connector port="8080"/Connector port="8080" URIEncoding="UTF-8"/' /etc/tomcat7/server.xml
              logger -t tomcat_conf "/etc/tomcat7/server.xml updated successfully"
              exit 0
            else
              logger -t tomcat_conf "/etc/tomcat7/server.xml already updated"
              exit 0
          fi
    
    container_commands:
      00_update_tomcat_server_xml:
        command: sh /tmp/update_tomcat_server_xml.sh
    

    此配置创建一个脚本 (files) 然后运行它 (container_command)。该脚本检查server.xml 中的UIREncoding="UTF8" 字符串,如果找不到,则使用sed 命令将其添加。

    这个解决方案的好处是,如果您升级您的 Tomcat 版本(例如从 7 到 8),那么您不必担心更新各种 WAR 文件中的 server.xml

    此外,此示例用于添加 UIREncoding 参数,但脚本很容易适应添加原始问题中的 &lt;Connector ... /&gt;' 属性。

    【讨论】:

    • 配置 URIEncoding 确实是一种聪明的方式。
    • 我可以在不向我的代码库中添加 .ebextensions 的情况下执行此操作吗?我没有,我已经在 Beanstalk 中配置了 tomcat 实例。如果可能的话,我不想对代码本身进行任何更改。
    • 如果您使用的是 ElasticBeanstalk,推荐使用 .ebextensions。
    猜你喜欢
    • 2014-03-19
    • 2016-01-16
    • 2016-09-01
    • 2020-11-13
    • 2019-03-01
    • 2023-03-12
    • 2017-07-15
    • 2020-10-05
    相关资源
    最近更新 更多