在创建HDFS集群的时候,深感/etc/hosts中添加配置的不方便,容易不一致导致错误,工作量也大。
还是在局域网内创建dhcp服务器来的方便。官方文档:https://help.ubuntu.com/community/isc-dhcp-server
先创建一台KVM虚拟机,OS为Ubuntu 12.04.
然后安装dhcp3 server
编辑文件/etc/default/isc-dhcp-serverapt-get install isc-dhcp-server
填入eth0
INTERFACES="eth0"
编辑文件:/etc/dhcp/dhcpd.conf
修改原来的example.org的设置为:# option definitions common to all supported networks... option domain-name "hadoop.cn"; option domain-name-servers dhcp.hadoop.cn, namenode1.hadoop.cn, namenode2.hadoop.cn, datanode1.hadoop.cn, datanode2.hadoop.cn, datanode3.hadoop.cn, datanode4.had\ oop.cn, datanode5.hadoop.cn, datanode6.hadoop.cn;
default-lease-time 6000; max-lease-time 72000;
option routers 192.168.1.1; subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.10 192.168.1.100; option domain-name-servers 192.168.1.1; option broadcast-address 192.168.1.255; }
服务命令:
service isc-dhcp-server start
注意,dhcp使用的地址必须是和eth0在一个网段。否则启动会失败。
因为我实际上希望能够在另一个网段用DHCP分配地址,所以在/etc/network/interfaces文件中创建新的虚拟IP地址:
不用eth0:1 这种方式。
# The primary network interface auto eth0 iface eth0 inet static address 192.168.1.111 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 # dns-* options are implemented by the resolvconf package, if installed dns-nameservers 8.8.8.8 dns-search defaultdomain iface eth0 inet static address 192.168.4.1 netmask 255.255.255.0
INTERFACES="eth0"