解決C3P0在Linux下Failed to get local InetAddress for VMID問題

昨天部署兩臺機器,同時連接的數據庫是第三臺機器,其中一臺生產機運行是發生異常:
報錯代碼:
Failed to get local InetAddress for VMID. This is unlikely to matter. At all. We'll add some extra randomness
java.net.UnknownHostException: p2p-8-41: p2p-8-41
 
源碼大概是這段:
public final class C3P0ImplUtils {
try{
      dos.write( InetAddress.getLocalHost().getAddress() );
    }catch (Exception  e)
      {
       if (logger.isLoggable(MLevel.INFO))
             logger.log(MLevel.INFO, "Failed to get local InetAddress for VMID. This is unlikely to matter. At all. We'll add some extra randomness", e);
           dos.write( srand.nextInt() );
}
 
}
....
 
那麼:p2p-8-41是怎麼得來的呢?
 
[root@p2p-8-41 ~]#     cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=p2p-8-41
 
很明確了吧!
 
解決辦法:
搜索谷歌和百度,整合一些資料:
主要是因爲系統沒有找到主機名p2p-8-41對應的IP,修改Linux的hosts文件即可。具體操作步驟如下:
vi /etc/hosts
在行127.0.0.1  localhost localhost.localdomain 後加上 p2p-8-41保存即可。
Linux查找域名時通常指先查找文件/etc/hosts,找不到時再向DNS服務器請求。
 
127.0.0.1               localhost.localdomain localhost p2p-8-41
 
原因分析:
Linux於host相關的幾個文件如下:
/etc/host.conf
功能:指定主機名查找方法,通常指先查找文件/etc/hosts,找不到時再向DNS服務器請求。
對於大多數用戶不用改動此文件內容。
Linux: /etc/host.conf文件內容
order hosts, bind
multi on
/etc/resolv.conf
文件功能:DNS客戶機配置文件,設置DNS服務器的IP地址及DNS域名
相關文件:/etc/host.conf
文件格式:
domainname 域名
search 域名
nameserver Primary_DNS_Server_IP_address
nameserver Second_DNS_Server_IP_address
其中domainname和search可同時存在,也可只有一個;nameserver可指定多個
/etc/hosts
#/etc/hosts
#文件格式: IPaddress hostname aliases
#文件功能: 提供主機名到IP地址的對應關係,建議將自己經常使用的主機
# 加入此文件中,也可將沒有DNS記錄的機器加入到此文件中,
# 這樣會方便網絡應用
127.0.0.1 localhost localhost.localdomain
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章