问题描述
我需要为在Tomcat 8中运行的Amazon Elastic Beanstalk应用程序设置Java的DNS缓存TTL(networkaddress.cache.ttl),因为EB可以随时启动和停止服务器实例,所以我不能简单地编辑Tomcat配置文件和服务器,并希望更改继续存在.
I need to set Java's DNS cache TTL (networkaddress.cache.ttl) for an Amazon Elastic Beanstalk app running in Tomcat 8. Because EB can start and stop server instances at any time, I can't simply edit a Tomcat config file and the server and expect the change to persist.
我尝试设置networkaddress.cache.ttl和sun.net.inetaddr.ttl环境变量,但是它们没有效果.亚马逊表示,调用 java.security.Security.setProperty("networkaddress.cache.ttl","60");
如果您在Tomcat中运行应用程序将无法使用"( http://aws.amazon.com/articles/4035 ).设置TTL的好方法是什么?
I tried setting the networkaddress.cache.ttl and sun.net.inetaddr.ttl environment variables, but those had no effect. Amazon says calling java.security.Security.setProperty("networkaddress.cache.ttl" , "60");
"will not work if you run your application inside of Tomcat" (http://aws.amazon.com/articles/4035). What's a good way to set the TTL?
推荐答案
问题是我做错了.设置sun.net.inetaddr.ttl环境变量即可.您可以在Elastic Beakstalk配置文件中执行此操作:
The problem is that I was doing it wrong. Setting the sun.net.inetaddr.ttl environment variable works. You can do this in your Elastic Beakstalk config file:
option_settings:
- namespace: aws:elasticbeanstalk:application:environment
option_name: sun.net.inetaddr.ttl
value: 60
60 seconds is the value recommended by Amazon
对我来说似乎更好的另一种选择是创建并使用java.security文件:
Another option that seems a little nicer to me is to create and use a java.security file:
option_settings:
- namespace: aws:elasticbeanstalk:application:environment
option_name: java.security.properties
value: /etc/myapp/java.security
container_commands:
00create_config_dir:
command: 'mkdir -p /etc/myapp'
ignoreErrors: true
01create_java_security_file:
command: 'echo "networkaddress.cache.ttl=60" > /etc/myapp/java.security'
ignoreErrors: true
这篇关于在Elastic Beanstalk中设置networkaddress.cache.ttl的推荐方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!