宿主机为Centos6.3 64位,三台虚拟机为为Centos6.3 64位。虚拟机的网络连接方式为默认的NAT方式。虚拟机默认为DHCP方式动态获取IP。为了在三台虚拟机上搭建hadoop,需要将这三台虚拟机构建成可以相互访问的局域网,所以将三台虚拟机都设置成静态IP。具体设置方法如下:
1、在宿主机上执行:ifconfig -a
显示:
eth0 Link encap:Ethernet HWaddr 00:0B:2F:XX:XX:XX
inet addr:XXX.XXX.XXX.XXX Bcast:XXX.XXX.XXX.255 Mask:255.255.255.128
inet6 addr: XXXXXXXXXXXXXXXXXX/64 Scope:Global
inet6 addr: XXXXXXXXXX/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:335991 errors:0 dropped:0 overruns:0 frame:0
TX packets:19935 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:54399176 (51.8 MiB) TX bytes:2590997 (2.4 MiB)
eth1 Link encap:Ethernet HWaddr 3F:3F:3F:3F:3F:3F
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:41128 errors:0 dropped:0 overruns:0 frame:0
TX packets:41128 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:138218445 (131.8 MiB) TX bytes:138218445 (131.8 MiB)
virbr0 Link encap:Ethernet HWaddr 52:54:00:75:98:B4
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1319 errors:0 dropped:0 overruns:0 frame:0
TX packets:539 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:99958 (97.6 KiB) TX bytes:453583 (442.9 KiB)
virbr0-nic Link encap:Ethernet HWaddr 52:54:00:75:98:B4
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
vnet0 Link encap:Ethernet HWaddr FE:54:00:17:67:42
inet6 addr: fe80::fc54:ff:fe17:6742/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:904 errors:0 dropped:0 overruns:0 frame:0
TX packets:4557 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:76846 (75.0 KiB) TX bytes:472213 (461.1 KiB)
vnet1 Link encap:Ethernet HWaddr FE:54:00:4B:93:57
inet6 addr: fe80::fc54:ff:fe4b:9357/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1443 errors:0 dropped:0 overruns:0 frame:0
TX packets:5320 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:132821 (129.7 KiB) TX bytes:547440 (534.6 KiB)
vnet2 Link encap:Ethernet HWaddr FE:54:00:05:B1:D6
inet6 addr: fe80::fc54:ff:fe05:b1d6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1120 errors:0 dropped:0 overruns:0 frame:0
TX packets:5152 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:115229 (112.5 KiB) TX bytes:327311 (319.6 KiB)
2、先在各虚拟机的终端命令窗口中执行:ifconfig -a
显示结果中会有eth0, eth1, 或eth2之类,以及HWaddr
3、执行:vim /etc/sysconfig/network-scripts/ifcfg-eth0(或ifcfg-eth1,ifcfg-eth2取决于第二步骤看到的结果)
编辑内容如下:
DEVICE=“eth1” #(或eth0,eth2取决于第二步骤看到的结果)
HWADDR="52:54:00:75:98:B4"#即第二步骤所得到的HWaddr值
ONBOOT="yes"
BOOTPROTO="static"
IPADDR=“192.168.122.10”#
NETMASK=“255.255.255.0”
GATEWAY=“192.168.122.1”#(取决于第1步中得到的virbr0 inet addr:192.168.122.1 )
TYPE=“Ethernet”
至此,三台虚拟机之间以及与宿主机之间已经可以相互访问了,可以使用ping+IP来测试一下。
4、让各虚拟机可以上网。