java 我如何为弹性 beantalk tomcat 提供配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12264432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 08:14:22  来源:igfitidea点击:

How do I supply configuration to elastic beanstalk tomcat

javatomcatamazon-elastic-beanstalk

提问by MikeW

when deploying locally to tomcat, I make this change (below) to server.xml, is there a way I can supply this to Elastic Beanstalk?

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

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

thanks '

谢谢 '

回答by Maciej Walkowiak

You can do it now without providing custom AMI. Follow instructions in: http://aws.typepad.com/aws/2012/10/customize-elastic-beanstalk-using-configuration-files.html

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

In order to provide custom server xml create .ebextensions folder in webapp, put there custom server.xmlfile and add one more file: server-update.configwith content:

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

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

回答by bobmarksie

Another way to implement this without replacing the entire Tomcat server.xmlfile is using the following in your .ebextensionsfolder (e.g. tomcat.config)

在不替换整个 Tomcatserver.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

This config creates a script (files) and then runs it (container_command). The script checks the server.xmlfor the UIREncoding="UTF8"string and if it doesn't find it, it then adds it in using the sedcommand.

此配置创建一个脚本 ( files),然后运行它 ( container_command)。该脚本检查server.xmlUIREncoding="UTF8"字符串,如果没有找到它,它然后将它使用的sed命令。

The nice thing about this solution is that if you upgrade your version of Tomcat (e.g. from 7 to 8) then you don't have to worry about updating the server.xmlin your various WAR files.

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

Also, this example is for adding the UIREncodingparameter but the script is very easily adapted to add <Connector ... />'property from the original question.

此外,此示例用于添加UIREncoding参数,但该脚本很容易修改以添加<Connector ... />'来自原始问题的属性。