簡單的DHCP server
在建立HDFS叢集的時候,深感/etc/hosts中添加配置的不友善,容易不一緻導緻錯誤,工作量也大。
還是在區域網路内建立dhcp伺服器來的友善。官方文檔:https://help.ubuntu.com/community/isc-dhcp-server
先建立一台KVM虛拟機,OS為Ubuntu 12.04.
然後安裝dhcp3 server
apt-get install isc-dhcp-server
編輯檔案/etc/default/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;
}
包括router位址, IP位址範圍,DNS server IP, 廣播IP位址等。
服務指令:
service isc-dhcp-server start
注意,dhcp使用的位址必須是和eth0在一個網段。否則啟動會失敗。
基于Virutal IP建立
因為我實際上希望能夠在另一個網段用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
然後在/etc/default/isc-dhcp-server裡面
INTERFACES="eth0"
然後将上面dhcpd.conf中的所有192.168.1.X都換成192.168.4.X即可。重新啟動,成功!