본문 바로가기
  • AI (Artificial Intelligence)
Legacy Skills/OpenStack

Problems with hostname -f and domain name resolution on CentOS VMs

by 로샤스 2014. 8. 8.
0

In VMs I created earlier, the host name was the local IP address, with dashes instead of dots, something like 10-0-0-6.openstacklocal.

Since today (1/14/2014), when I create a new CentOS 6.3 VM, it has the name I specify as the instance name, but I'm having trouble with this new name, for example when I try to start Hadoop.

On the old VM, I get the following:

hostname -f
10-0-0-6.openstacklocal

On the new VM, created today, I get this:

[demouser@demovm13 ~]$ hostname
demovm13
[demouser@demovm13 ~]$ hostname -f
hostname: Unknown host
[demouser@demovm13 ~]$ 

The real error I get from Hadoop is the following, but I assume it's related to the issue above:

java.net.UnknownHostException: demovm13: demovm13
    at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
    at org.apache.hadoop.security.SecurityUtil.getLocalHostName(SecurityUtil.java:223)
    at org.apache.hadoop.security.SecurityUtil.login(SecurityUtil.java:243)
    at org.apache.hadoop.hdfs.server.datanode.DataNode.instantiateDataNode(DataNode.java:1692)
    at org.apache.hadoop.hdfs.server.datanode.DataNode.createDataNode(DataNode.java:1717)
    at org.apache.hadoop.hdfs.server.datanode.DataNode.secureMain(DataNode.java:1870)
    at org.apache.hadoop.hdfs.server.datanode.DataNode.main(DataNode.java:1891)
Caused by: java.net.UnknownHostException: demovm13
    at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
    at java.net.InetAddress.getLocalHost(InetAddress.java:1469)
    ... 6 more

Thanks,

Hans

Here is an update. We were able to solve this problem by doing two things:

1. add the following line to /etc/sysconfig/network:

HOSTNAME=<hostname>

2. Add the following line to /etc/hosts:

<internal IP address> <hostname>.openstacklocal <hostname>

To avoid having to do this every time we launched a new VM image, we added the following to /etc/rc.d/rc.local

grep `hostname` /etc/hosts >/dev/null
if [ $? -eq 1 ]; then
ipaddr=$(ip addr show to 0.0.0.0/0 scope global | awk '/[[:space:]]inet / { print gensub("/.*","","g",$2) }')
hostnm=`hostname`
echo "Adding an entry for IP address $ipaddr and host $hostnm to /etc/hosts"
echo "$ipaddr ${hostnm}.openstacklocal $hostnm" >>/etc/hosts
fi
grep "HOSTNAME=$(hostname)" /etc/sysconfig/network >/dev/null
if [ $? -eq 1 ]; then
echo "HOSTNAME=$(hostname)" >>/etc/sysconfig/network
fi














출처 : https://community.hpcloud.com/question/2383/problems-hostname-f-and-domain-name-resolution-centos-vms











댓글