LoginSignup
2
3

More than 5 years have passed since last update.

InetAddress.getLocalHost().getHostAddress() が 127.0.0.1 になるのが嫌な場合 (Linux)

Posted at

前提

EhCache (使ってる人そんなにいないのかな)でキャッシュのレプリケーション設定する時の話

例えば、設定で

<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost, port=40001,
socketTimeoutMillis=2000"/>

Ehcache | Documentation | RMI Replicated Caching - http://goo.gl/MurBem

こんな風にするという例があって、 'hostname=localhost' は良くないから、指定しないで

<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="port=40001,
socketTimeoutMillis=2000"/>

のようにした場合、削除した hostname 部分は、内部的に 'InetAddress.getLocalHost().getHostAddress()' が使用されるというのが EhCache の仕様

ところが、OSによってはこの値が '127.0.0.1' になることがあるらしく(CentOS 6.7 のデフォルトではそう)、それだとよろしくない

解決方法

例えば、 '192.168.1.5' にしたい場合

hosts ファイルを変更

hostname の設定を確認

$ hostname
amaterasu

/etc/hosts ファイルを編集して以下を追加

192.168.1.5    amaterasu
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3