JVM (Java ä»®æ³ãã·ã³) ã«ã¯ DNS ã®åå解決ã®çµæããã£ãã·ã¥ããæåãåãã£ã¦ããããã£ãã·ã¥ããã ããªãããã®ã ããã©ããã®ãã£ãã·ã¥ã§ã¯ DNS ã® TTL ãç¡è¦ãã¦ãã£ãã·ã¥ãããããåå解決ã®çµæãå¤ãã£ã¦ã JVM ããã®æ¥ç¶å
ãåãæ¿ããã¾ã§ã«ï¼TTL ããæ³å®ãããæé以ä¸ã«ï¼æéããããããããã¯å
¨ãåãæ¿ãããªãã¨ãããã¨ãããããã®æåããã®å¶å¾¡ã«ã¤ãã¦èª¿ã¹ãã®ã§ããã®è©±ãããã
ï¼ä»¥ä¸ã®è©±é¡ã§ã¯ Oracle JDK ããã³ OpenJDK ã対象ã«ãã¦è«ããã®ã§ããã以å¤ã® JVM å®è£
ã§ã©ããªã£ã¦ããã¯èª¿ã¹ã¦ããªããé©ç¨ã§ããç®æãããã°ããã§ãªãç®æãããããï¼
èæ¯ã»è§£èª¬
ãããã®ããã©ã«ãå¤ã¯åå解決æåæ㯠ã»ãã¥ãªãã£ã¼ããã¼ã¸ã£ã¼ãã¤ã³ã¹ãã¼ã«ããã¦ããå ´åã®ããã©ã«ãå¤ã¯ -1 (ãã£ã¨) ã§ãã»ãã¥ãªãã£ã¼ããã¼ã¸ã£ã¼ãã¤ã³ã¹ãã¼ã«ããã¦ããªãå ´åã¯å®è£
åºæ ã失ææ㯠ããã©ã«ã: 10ç§
ï¼ãããã Oracle Java SE 7 のドキュメントããï¼ã¨ãªã£ã¦ãããæåæã® "å®è£
åºæ" ã®å¤ã¯ OpenJDK ã®å®è£
ã§ã¯30ç§ã¨ãªã£ã¦ããã Oracle JDK ã§ãå¾è¿°ã®è¨å®ãã¡ã¤ã«ã®ã³ã¡ã³ããè¦ãéã30ç§ã¨ãªã£ã¦ãããã¤ã¾ããã»ãã¥ãªãã£ããã¼ã¸ã£ãç¡å¹ã«ãªã£ã¦ããç°å¢ãåæã«ããã¨ããã® JVM ã® DNS ãã£ãã·ã¥ã¯ä»¥ä¸ã®ãããªæåããã:
- åå解決ã«æåããã¨ãããã®çµæãDNS ã¬ã³ã¼ãã® TTL ã«é¢ä¿ãªã JVM ããã»ã¹å ã§30ç§ãã£ãã·ã¥ãã
- åå解決ã«å¤±æããã¨ãããã®çµæãDNS åãåããã® SOA TTL ã«é¢ä¿ãªã JVM ããã»ã¹å ã§10ç§ãã£ãã·ã¥ãã
ãã®æåã«ã¤ãã¦ã¯ä»¥ä¸ã®ãã¼ã¸ã®è§£èª¬ã詳ããã®ã§ãã¡ãã«è²ã:
Java/Socket, InetAddressにおけるDNS名前解決の仕組みと networkaddress.cache.ttl - Glamenv-Septzen.net
ä¸è¨ã¯ã»ãã¥ãªãã£ããã¼ã¸ã£ãç¡å¹ãªç°å¢ãä¾ç¤ºããããã©ãæå¹ãªå ´å㯠positive cache ã¯ããã»ã¹å ã§æ°¸é ã«ä¿æãã㦠expire ããªããããªãã¡ä¸åº¦åå解決ã«æåããã¨ããã®å¾ DNS ã¬ã³ã¼ãã«å¤æ´ããã£ã¦ãå ¨ãåæ ãããªããã¨ã«ãªãã
ãã®ãã£ãã·ã¥æ©æ§ã¯ DNS ãã¤ãºãã³ã°ã¸ã®å¯¾çãæå³ãã¦ããããã ãã©ãç¹ã« AWS ãªã©ã®ãã¡ã¤ã³åã§ã¢ãã¬ã¹ãæä¾ããã¦ãã DNS TTL ã®çããããã¯ã¼ã¯ãªã½ã¼ã¹ã« Java ããæ¥ç¶ãã¦ããå ´åã«å¤§ããªåé¡ã¨ãªãããã¨ãã°ãã§ã¤ã«ãªã¼ãã¼ã DNS ãã¼ã¹ã§è¡ããã Amazon RDS ï¼ãªã©ï¼ãå©ç¨ããå ´åããã§ã¤ã«ãªã¼ãã¼ãã復æ§ã¾ã§ã®ãã¦ã³ã¿ã¤ã ããã®ãã£ãã·ã¥å¯¿å½ã®å伸ã³ãã¨ãããã¨ã«ãªããç¹ã« AWS Aurora 㯠DNS TTL ã5ç§ã¨ãã«ãªã£ã¦ããã®ã§ãããã30ç§ãã£ãã·ã¥ããã®ã¯ç´æçã«ããã¾ãçãè¯ãã¨ã¯æããªããå¿è«æ°¸é ã«ä¿æãããã¨æ¨åãèµ·ããã
ãã£ãã·ã¥ãå®å
¨ã«ç¡å¹ã«ãã㨠getnamebyaddr
ã®çºè¡ã³ã¹ãã«ããããã©ã¼ãã³ã¹ãä½ä¸ãããã¨ãæ³åããããï¼ããã©ã¼ãã³ã¹æ¤è¨¼ã¯ãã¦ããªãï¼ããã®è¦³ç¹ãæ°ã«ããå ´åã§ãããããæ°ç§ç¨åº¦ãã£ãã·ã¥ããã°ååã§ãããã¨ã¯äºæ³ã§ããã
ãã£ãã·ã¥æ©æ§ã®å¶å¾¡ææ³
ãããããæ¬é¡ããã®æåãã«ã¹ã¿ãã¤ãºããæ¹æ³èªä½ã¯ããã¤ãåå¨ãã¦ããã以ä¸ã® Qiita ã¨ã³ããªã§ææ³ã解説ããã¦ãããææ³ãã®ãã®ã¯ãã®ã¨ã³ããªéãã§ããã¨æãããã©è»½ãç´¹ä»ãã¦ãããã¼ãã®æå ã§æ¤è¨¼ãæ¤è¨ããéã®ææãè¨ãã
$JAVA_HOME/lib/security/java.security ã«è¨è¿°
ã»ãã¥ãªãã£ããªã·ã¼ãã¡ã¤ã«ã®ä¸ã® networkaddress.cache.ttl
㨠networkaddress.cache.negative.ttl
ãæ¸ãæããã¨ããæ¹æ³ãJava8 ã® Oracle JDK ã ã¨å®ä½ã¯ /etc/java-8-oracle/security/java.security
ã«ãªãããã
ãã®è¨å®å¤ãå¤æ´ããã¨åããã¹ãå
ã§åãä»ã® JVM ããã»ã¹ã«ãå½±é¿ãã¦ãã¾ãã®ã ããã©ããããåé¡ã«ãªãã®ã¯åä¸ãã¹ãå
ã§ç°ãªãè¤æ°ã® Java ã¢ããªã±ã¼ã·ã§ã³ãåããã¦ããããã¤ãããã® DNS ãã£ãã·ã¥ TTL è¦ä»¶ãç°ãªãå ´åãããã§ããããã¾ããããããã¨ã¯ãªãã ããã¨æã£ã¦ããã
java.security.Security.setProperty() ã§æå®
ã¢ããªã±ã¼ã·ã§ã³ã³ã¼ãå
é¨ã§ Security.setProperty
ãçºè¡ãã¦å¤ãæ¸ãæããç©ã
å½ç¶ã¢ããªã±ã¼ã·ã§ã³ã³ã¼ãã«è§¦ããå±é¢ã§ãã使ããªãã®ã§ Elasticsearch ãªã©ã®ããã«ã¦ã§ã¢ã®å¶å¾¡ã«ã¯ä½¿ããªããéã«èªåã§éçºãã¦ããã¢ããªã±ã¼ã·ã§ã³ã®å ´åãã³ã¼ãã¬ã¤ã¤ã§å¶å¾¡ã§ããã®ã§ä¸è¦æãåºããããªãããå人çã«ã¯ãã®ææ³ã¯ããããããã®ã§å¯è½ãªéãé¿ãããã¨èãã¦ããã
Qiita ã®ã¨ã³ããªã«ãããããã«ããã®æ¹æ³ã使ãå ´å㯠InetAddressCachePolicy
ã¯ã©ã¹ãã©ããã§ãã¼ããããããå
ã®ã¿ã¤ãã³ã°ã§å¤ãã»ããããå¿
è¦ããããmain ã¡ã½ããã®ããã¨ã³ããªã¼ãã¤ã³ããé²åºãã¦ããã¢ããªã±ã¼ã·ã§ã³ã§ã¯ã¾ã å¯è½ãããããªãããã¢ããªã±ã¼ã·ã§ã³ãã¬ã¼ã ã¯ã¼ã¯ã«ä¹ã£ã¦ããã¢ããªã±ã¼ã·ã§ã³ã®å ´åã¯ãã®ãããªèªæãªã¨ã³ããªã¼ãã¤ã³ããåå¨ããªãå ´åãããããã¬ã¼ã ã¯ã¼ã¯å
é¨ã§ã®ãã¼ãé åºã«ä¾åããã®ã¯é常ã«ã¹ãªãªã³ã°ã ã¨æãã
ã¾ããããã¯ä»ã®æ¹æ³ã«ãå
±éããã®ã ãã©ãç¹ã«ã»ãã¥ãªãã£ããã¼ã¸ã£ç¡å¹æã®30ç§ãã£ãã·ã¥ã¯ã¢ããªã±ã¼ã·ã§ã³ã®è¡¨é¢çãªæåã ãè¦ã¦ãã¦ãè¨å®æ¼ãã«æ°ä»ãã¥ããã¨ããåé¡ããããåæè¨å®æã«æ£ããè¨å®ã§ãã¦ããã¨ãã¦ãä¾ãã°ä¸è¿°ã®ãããªãã¬ã¼ã ã¯ã¼ã¯å
é¨ã®ãã¼ãé åºãå¤ãã£ã¦æ£ããè¨å®ã§ããªããªã£ãéã«ãããæ¤ç¥ããã®ã¯é常ã«é£ããã
èµ·åãªãã·ã§ã³ã«æå®
java
ããã»ã¹ã®èµ·åãªãã·ã§ã³ã«-Dsun.net.inetaddr.ttl=XXX
ããããã¯-Dsun.net.inetaddr.negative.ttl=YYY
ãæå®ãããã®ãããã¯These properties may not be supported in future releases.ã¨ããã¥ã¡ã³ãããã¦ãããï¼ç¾å®çã«ã¯ã¾ã ãã°ãã使ããã ããããã©ï¼æ°è¦ã®å©ç¨ãæ¨å¥¨ãããç©ã§ã¯ãªããéã«è¨ãã° JDK ã®ãã¼ã¸ã§ã³ã¢ãããããªãã¨æ±ºãã¦ããç°å¢ã§ããã°é¸æè¢ã«ä¸ãããããããªãã
追è¨
JVM ã® DNS ãã£ãã·ã¥ãå¶å¾¡ãã - 平常é転b.hatena.ne.jp
- [Java]
-Djava.security.manager -Djava.security.policy= JVMèµ·åæãªãã·ã§ã³ã¯deprecatedãããªããã? cf, <a href="http://bit.ly/2tjBmlY" target="_blank" rel="noopener nofollow">http://bit.ly/2tjBmlY</a>
2018/03/06 15:49
éæ¨å¥¨ã«ãªã£ã¦ããã®ã¯ã sun.net.inetaddr.ttl
ããã³ sun.net.inetaddr.negative.ttl
ãã©ã¡ã¼ã¿ã§ãã java ããã»ã¹ã« -D
ãªãã·ã§ã³ã渡ããã¨èªä½ã¯åé¡ããã¾ããã確ãã«èª¤è§£ãæããããªãæç« ã ã£ãã®ã§ããã§è£è¶³ãã¾ãã
ããã§ä¸ã¤è¨åãã¦ããããã®ã ããã©ãSecurity.setProperty()
ã java.security ãã¡ã¤ã«ã§ã®è¨å®é
ç®ã§ãã networkaddress.cache.ttl
ã¯ãã®èµ·åãªãã·ã§ã³çµç±ã§æ¸¡ããã¨ã¯ã§ããªããããã¯ããã¥ã¡ã³ãã«ãè¨è¼ããã¦ããã®ã ãã©ãã¤ã³ã¿ã¼ãããä¸ã§å¯è½ã¨è¨åãã¦ããè¨èª¬ããã£ãã®ã§æ³¨æãã¦ãããããã¡ãªã¿ã«èµ·åãªãã·ã§ã³ã§æ¸¡ãã¦ãç¹ã«ã¨ã©ã¼ã¯åºããµã¤ã¬ã³ãã«ç¡è¦ããããã¾ãããã¯ããã
ãããã® 2 ã¤ã®ããããã£ã¼ã¯ãã»ãã¥ãªãã£ã¼ããªã·ã¼ã®ä¸é¨ã§ããããã-D ãªãã·ã§ã³ã System.setProperty() API ã§ã¯è¨å®ããã¾ããããã®ä»£ããããããã®ããããã£ã¼ã¯ JRE ã®ã»ãã¥ãªãã£ã¼ããªã·ã¼ãã¡ã¤ã« lib/security/java.security ã§è¨å®ããã¾ãã
https://docs.oracle.com/javase/jp/7/api/java/net/doc-files/net-properties.html
ææ³ã®æ¯è¼
ä¸ã®ã»ã¯ã·ã§ã³ã§ãæ¸ããã®ã ããã©ããã®æåã®å¶å¾¡ã«ããã¦é£ããã®ã¯ããã¨ã30ç§ã® DNS ãã£ãã·ã¥ãæå¹ã«ãªã£ã¦ãã¦ããå®å¸¸æã®æåããã¯ããã確èªãã¥ããã¨ããã¨ããã«ããããã®ãã¨ãè¸ã¾ããã¨ãå°æ¥çãªæ¹ä¿®æã«å£ãã«ããé¸æè¢ãåãã®ãéè¦ã§ããã¨æãã
ãã®è¦³ç¹ããèããã¨ã jvm èµ·åãªãã·ã§ã³ã« deprecated ãªãªãã·ã§ã³ã渡ãã®ã¯æ¥µåé¿ãããé¸æè¢ã«è¦ãããããã¯æããã«å°æ¥ã® JDK ãã¼ã¸ã§ã³ã¢ããæã®ãªã¹ã¯ã¨ãªããå°æ¥ã® JDK ããã®ãã©ã¡ã¼ã¿è¨å®ã«å¯¾ãã¦ã¨ã©ã¼ãè¿ãã¦ããããªãã¾ã ããããµã¤ã¬ã³ãã«ç¡è¦ãããããªå¤æ´ã«ãªã£ãå ´åã«å¶å¾¡ã§ããªããªã£ã¦ãããã¨ã«æ°ä»ããªãå¯è½æ§ãé«ãã
ã¾ããã¢ããªã±ã¼ã·ã§ã³ã³ã¼ãå
ã®è¨å®ã«ã¤ãã¦ã¯ä¸ã®ã»ã¯ã·ã§ã³ã§ç´¹ä»ããæç¹ã§æ³¨æç¹ã«ã¤ãã¦æ¸ãããã¯ã©ã¹ã®ãã¼ãé åºã«å·¦å³ãããç©ã§ããããå人çã«ã¯ãã¾ãæ¡ç¨ãããã¨æã£ã¦ããªãããã»ãã¥ãªãã£ããªã·ã¼ãã¡ã¤ã«ãæä½ãã¥ããç°å¢ã§ããã°ãã¡ããé¸æè¢ã«ãªãã®ãããããªãã
ã¨ãããã¨ã§ããæç°å¼æ°´çãªçå±ã®å±éã§ããããã©ãå人çã«ã¯ã»ãã¥ãªãã£ããªã·ã¼ãã¡ã¤ã«ãæ¸ãæããã®ãæã¾ããããã«æããã¢ããªã±ã¼ã·ã§ã³ã³ã¼ãã§ã¯ãªãã¦ãµã¼ãå´ã®æ§æ管çã§æ ä¿ãã話é¡ã«ãªãããã©ãç¾ä»£ã§ããã° Chef ãªã ansible ãªãã§ãµã¼ãããããã¸ã§ãã³ã°ãã¦ããã ãããããã®æé ã®ä¸ã«å«ãã¦ããã°åååç¾å¯è½ã§ãããã¨æãããããã¯ã³ã³ããã®ä¸ã§ jvm ãåããã®ãªã Dockerfile ã§ãã¡ãã¨æ ä¿ã§ããã
çµè«
çµè«ã¨ããã»ã©ã§ããªãããã©ãæ¬ä»¶ã«é¢ããã¼ãå人ã®è¦è§£ã®ã¾ã¨ãã¯ä»¥ä¸ã®éã:
- JVM ã® DNS ãã£ãã·ã¥æ©æ§ã® TTL ã¯ã¯ã©ã¦ãæ代㮠DNS ãã¼ã¹ã®ä»çµã¿ã¨ã¯ææ©ããããããã«ã¹ã¿ãã¤ãºããã¨ãã
- ã¢ããªã±ã¼ã·ã§ã³ã³ã¼ãå é¨ã§ã®ã«ã¹ã¿ãã¤ãºã¯ãããããããã¾ã java èµ·åãã©ã¡ã¼ã¿ã¯ç¾ä»£ã§ã¯æ¨å¥¨ãããªã
- ãã£ã¦ãã»ãã¥ãªãã£ããªã·ã¼ãã¡ã¤ã«ãï¼æ§æ管çããä¸ã§ï¼æ¸ãæããã®ãå®å ¨ãªããã«æã
ãªã³ã¯é
DNS ãã£ãã·ã¥ä»¥å¤ãå«ãããã©ã¡ã¼ã¿ãã¥ã¼ãã³ã°ã®è©±é¡ãç®ãéãã¦ããã¨ããããã
moznion.hatenadiary.com
ä½è«: æåã®èª¿æ»
ã¨ããã§ããããã®æåã®èª¿æ»ã«é¢ãã¦ã¯ã対象㮠java ããã»ã¹ã®åå¨ãããµã¼ãä¸ã« DNS ãã£ãã·ã¥ãµã¼ã (unbound) ãç«ã¦ããã£ãã·ã¥ãµã¼ãã¸ã® DNS ã¯ã¨ãªæ°ã Mackerel ã§ã¢ãã¿ãªã³ã°ããªããè¡ã£ããä»ä»äºã§è§¦ã£ã¦ããããã¸ã§ã¯ãã§ã¯å¥ä»¶ã®äºæ ã§ã¢ããªã±ã¼ã·ã§ã³ãµã¼ãå é¨ã«å ã DNS ãã£ãã·ã¥ãµã¼ããåå± ãã¦ããã®ã§æéãæããã«ãããã®ãã©ã¡ã¼ã¿æ¤è¨¼ãã§ããããã©ãããããåãçµã¿ã®ãªãå ´å㯠tcpdump ããããã±ãããã£ããã£ãã¦æ§åãè¦ããã¨ã«ãªãã§ããããææ £ãã¦ã人ã¯ããã§ããããã ããããã©ãå人çã«ã¯ unbound ãåå± ãã¦ãã¦å©ãã£ãã¨ããæ°æã¡ã«ãªã£ã¦ããã