為了在VirtualBox上安裝oracle 11g rac,使VirtualBox虛擬機(jī)與主機(jī)互通,,并且虛擬機(jī)又能上網(wǎng)配置,找了很多網(wǎng)上文章但都沒有都對(duì)最終設(shè)置方式進(jìn)行詳細(xì)的說明,
現(xiàn)在自己總結(jié)如下:
一,、VirtualBox的提供了四種網(wǎng)絡(luò)接入模式,它們分別是:
1,、NAT 網(wǎng)絡(luò)地址轉(zhuǎn)換模式(NAT,Network Address Translation)
2,、Bridged Adapter 橋接模式
3、Internal 內(nèi)部網(wǎng)絡(luò)模式
4,、Host-only Adapter 主機(jī)模式
VMWare中有三種,,其實(shí)他跟VMWare 的網(wǎng)絡(luò)連接方式都是一樣概念,只是比VMWare多了Internal方式,。要讓自己(或別人)理解深刻,,方法就是做比較和打比方,比較之間的不同和相同,,拿熟知的事物打比方,。先來一張圖,通過這張圖就很容易看出這4種方式的區(qū)別:
更詳細(xì)的介紹可以自行百度,。
二,、我的環(huán)境
Linux rac1虛擬機(jī)
網(wǎng)卡1 (網(wǎng)卡1的目的是用上虛擬機(jī)與主機(jī)之間通訊,并且可以上外網(wǎng))
由于VirtualBox 的 NAT方式,,只允許虛擬機(jī)與主機(jī)之間單向通訊(因?yàn)閂irtualBox只虛擬了一個(gè)網(wǎng)卡,,所以主機(jī)是ping不通虛擬機(jī)的,而vmware有虛擬兩個(gè)網(wǎng)卡,, VMnet1是host網(wǎng)卡,,用于host方式連接網(wǎng)絡(luò)的。VMnet8是NAT網(wǎng)卡,,用于NAT方式連接網(wǎng)絡(luò),。
所以vmware Nat方式可以主機(jī)與虛擬機(jī)互通。但可以設(shè)置端口轉(zhuǎn)發(fā),,這樣主機(jī)就可以ssh到虛擬機(jī),。
通過以下端口轉(zhuǎn)發(fā)的設(shè)置,可以讓主機(jī)連上虛擬機(jī)(點(diǎn)上網(wǎng)的"端口轉(zhuǎn)發(fā)“)
虛擬機(jī)CentOS的對(duì)應(yīng)的eth0網(wǎng)絡(luò)設(shè)置是:
eth0 必須是dhcp 通過虛擬機(jī)NAT模式獲取的默認(rèn)IP地址是 10.0.2.15,好像改不了,,改靜態(tài)就不行了,。
如果用命令行始終配置不好,就用system-network-config啟動(dòng)圖行界面來配置,,保證配置結(jié)果沒有錯(cuò)誤
以上NAT設(shè)置可以適合單臺(tái)虛擬機(jī)服務(wù)的設(shè)置,,即虛擬是NAT地址轉(zhuǎn)換方式,虛擬是默認(rèn)地址,,這樣虛擬就可以與主機(jī)通訊,,并且可以上網(wǎng)
但rac環(huán)境要求public兩個(gè)網(wǎng)卡可以互通,pritiave網(wǎng)卡也可以互相,,但如果rac2的網(wǎng)卡1 eth0也是NAT,,那么這兩個(gè)將不互通。
(原因:NAT方式只是虛擬與主機(jī)的單向通訊,,所以rac2如果也是NAT方式,,只說明它也可以也主機(jī)單向通訊,并不能與另外的虛擬機(jī)互通)
所以,,要想達(dá)到主機(jī)與兩臺(tái)虛擬機(jī)之間都可以互通,,虛擬機(jī)之間又可以互通,必須修改網(wǎng)卡1的連接方式為host-only,,網(wǎng)卡2改成是內(nèi)部網(wǎng)址,,用與私網(wǎng)通訊
如果要讓兩臺(tái)虛擬機(jī)都可以上網(wǎng),那么就需要配置win7上網(wǎng)的網(wǎng)絡(luò)連接為共享,,共享給VirtualBox生成的host-only網(wǎng)卡,,這樣兩臺(tái)虛擬機(jī)就可以通過host-only的網(wǎng)上,再由經(jīng)過上網(wǎng)的網(wǎng)卡上網(wǎng)了,。
第1步:
先做共享操作最后確定后,,此時(shí)Host-only會(huì)被置為192.168.137.1(本人的機(jī)器,機(jī)器不同可能不同,,這個(gè)網(wǎng)址也就是兩臺(tái)虛擬機(jī)public的網(wǎng)段,,改網(wǎng)段就是不行)
可以修改(但修改了之后,即使虛擬機(jī)也設(shè)置但一網(wǎng)段了,,只可以主機(jī)與虛擬機(jī)之間通訊,,就是不能上網(wǎng),所以虛擬機(jī)必須設(shè)置成同一個(gè)網(wǎng)段的IP才可以上網(wǎng))
以下是通過system-config-network配置圖
另外:Virtual軟件全局設(shè)置(可以選擇開啟dhcp,,也可以設(shè)置靜態(tài)IP)
這里為關(guān)閉DHCP服務(wù),,進(jìn)行手動(dòng)設(shè)置IP,手動(dòng)不手動(dòng)似乎沒什么不一樣,,最終eth0還是要dhcp的
最終VirtualBox軟件虛擬機(jī)的網(wǎng)絡(luò)設(shè)置如下:(rac1和rac2一樣)
最終rac的是eth0和eth1分別如下:
rac1的eth0 和eth1如下:
[root@rac1 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:FB:4E:66
inet addr:192.168.137.141 Bcast:192.168.137.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fefb:4e66/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:481 errors:0 dropped:0 overruns:0 frame:0
TX packets:350 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:95721 (93.4 KiB) TX bytes:43273 (42.2 KiB)
eth1 Link encap:Ethernet HWaddr 08:00:27:A3:0F:55
inet addr:10.10.10.10 Bcast:10.10.10.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fea3:f55/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:262 errors:0 dropped:0 overruns:0 frame:0
TX packets:165 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:30822 (30.0 KiB) TX bytes:14466 (14.1 KiB)
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:18 errors:0 dropped:0 overruns:0 frame:0
TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1325 (1.2 KiB) TX bytes:1325 (1.2 KiB)
[root@rac1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:fb:4e:66
TYPE=Ethernet
UUID=ada6c5d8-382e-4218-8582-2757ccb9d3c5
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
#IPADDR=192.168.137.10
#NETMASK=255.255.255.0
#GETWAY=192.168.137.1
IPV6INIT=no
USERCTL=no
DNS1=192.168.1.1
PEERDNS=yes
[root@rac1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
DEVICE=eth1
BOOTPROTO=static
NETMASK=255.255.255.0
TYPE=Ethernet
HWADDR=08:00:27:a3:0f:55
IPADDR=10.10.10.10
IPV6INIT=no
ONBOOT=yes
USERCTL=no
[root@rac1 ~]#
rac2 的eth0 和eth1如下:
[root@rac2 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:B2:21:03
inet addr:192.168.137.166 Bcast:192.168.137.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:feb2:2103/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:214 errors:0 dropped:0 overruns:0 frame:0
TX packets:141 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:33589 (32.8 KiB) TX bytes:15498 (15.1 KiB)
eth1 Link encap:Ethernet HWaddr 08:00:27:AE:AB:08
inet addr:10.10.10.11 Bcast:10.10.10.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:feae:ab08/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6 errors:0 dropped:0 overruns:0 frame:0
TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:512 (512.0 b) TX bytes:1292 (1.2 KiB)
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:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:720 (720.0 b) TX bytes:720 (720.0 b)
[root@rac2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:b2:21:03
TYPE=Ethernet
UUID=ada6c5d8-382e-4218-8582-2757ccb9d3c5
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
#IPADDR=10.10.10.2
#NETMASK=255.255.255.0
#GETWAY=10.10.10.1
USERCTL=no
PEERDNS=yes
IPV6INIT=no
[root@rac2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
DEVICE=eth1
BOOTPROTO=none
NETMASK=255.255.255.0
TYPE=Ethernet
IPADDR=10.10.10.11
HWADDR=08:00:27:ae:ab:08
IPV6INIT=no
ONBOOT=yes
USERCTL=no
[root@rac2 ~]#
驗(yàn)證網(wǎng)絡(luò)連通:
rac1:
[root@rac1 ~]# ping www.qq.com
PING www.qq.com (117.135.169.41) 56(84) bytes of data.
64 bytes from . (117.135.169.41): icmp_seq=1 ttl=53 time=8.54 ms
64 bytes from . (117.135.169.41): icmp_seq=2 ttl=53 time=8.75 ms
64 bytes from . (117.135.169.41): icmp_seq=3 ttl=53 time=96.1 ms
64 bytes from . (117.135.169.41): icmp_seq=4 ttl=53 time=8.88 ms
64 bytes from . (117.135.169.41): icmp_seq=5 ttl=53 time=10.0 ms
64 bytes from . (117.135.169.41): icmp_seq=6 ttl=53 time=10.6 ms
64 bytes from . (117.135.169.41): icmp_seq=7 ttl=53 time=10.3 ms
64 bytes from . (117.135.169.41): icmp_seq=8 ttl=53 time=8.79 ms
64 bytes from . (117.135.169.41): icmp_seq=9 ttl=53 time=9.11 ms
^C
--- www.qq.com ping statistics ---
9 packets transmitted, 9 received, 0% packet loss, time 8280ms
rtt min/avg/max/mdev = 8.540/19.021/96.128/27.270 ms
[root@rac1 ~]# ping 10.10.10.11
PING 10.10.10.11 (10.10.10.11) 56(84) bytes of data.
64 bytes from 10.10.10.11: icmp_seq=1 ttl=64 time=2.25 ms
64 bytes from 10.10.10.11: icmp_seq=2 ttl=64 time=0.592 ms
64 bytes from 10.10.10.11: icmp_seq=3 ttl=64 time=0.364 ms
64 bytes from 10.10.10.11: icmp_seq=4 ttl=64 time=0.312 ms
64 bytes from 10.10.10.11: icmp_seq=5 ttl=64 time=0.310 ms
64 bytes from 10.10.10.11: icmp_seq=6 ttl=64 time=0.301 ms
64 bytes from 10.10.10.11: icmp_seq=7 ttl=64 time=0.313 ms
^C
--- 10.10.10.11 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6685ms
rtt min/avg/max/mdev = 0.301/0.634/2.250/0.666 ms
[root@rac1 ~]#
rac2:
[root@rac2 ~]# ping www.qq.com
PING www.qq.com (117.135.169.41) 56(84) bytes of data.
64 bytes from . (117.135.169.41): icmp_seq=1 ttl=53 time=10.5 ms
64 bytes from . (117.135.169.41): icmp_seq=2 ttl=53 time=10.2 ms
64 bytes from . (117.135.169.41): icmp_seq=3 ttl=53 time=9.93 ms
64 bytes from . (117.135.169.41): icmp_seq=4 ttl=53 time=9.47 ms
64 bytes from . (117.135.169.41): icmp_seq=5 ttl=53 time=61.6 ms
64 bytes from . (117.135.169.41): icmp_seq=6 ttl=53 time=10.3 ms
^C
--- www.qq.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5485ms
rtt min/avg/max/mdev = 9.476/18.714/61.632/19.196 ms
[root@rac2 ~]# ping 10.10.10.10
PING 10.10.10.10 (10.10.10.10) 56(84) bytes of data.
64 bytes from 10.10.10.10: icmp_seq=1 ttl=64 time=0.551 ms
64 bytes from 10.10.10.10: icmp_seq=2 ttl=64 time=0.448 ms
64 bytes from 10.10.10.10: icmp_seq=3 ttl=64 time=0.319 ms
64 bytes from 10.10.10.10: icmp_seq=4 ttl=64 time=0.471 ms
64 bytes from 10.10.10.10: icmp_seq=5 ttl=64 time=0.566 ms
^C
--- 10.10.10.10 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4365ms
rtt min/avg/max/mdev = 0.319/0.471/0.566/0.088 ms
[root@rac2 ~]#
如果內(nèi)部不通的,,需要關(guān)閉iptables就可以
在這里成這樣是因?yàn)閺?fù)制系統(tǒng)的過程中復(fù)制的文件已經(jīng)有一個(gè)網(wǎng)卡在/etc/udev/rules.d/70-persistent-net.rules被識(shí)別成了eth0,,而虛擬機(jī)中的識(shí)別成了eth1。
解決方法:
1.編輯/etc/udev/rules.d/70-persistent-net.rules,找到與ifconfig -a得出的MAC相同的一行(NAME='eth1'這一行),,把它改為"NAME=eth0 ",,然后把上面一行(NAME='eth0')刪除掉。
vim /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:bb:41:2b", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
2.編輯/etc/sysconfig/network-script/ifcfg-eth0,把MAC改為正確的,,把UUID刪掉,。
3.編輯/etc/sysconf/network,把hostname也改一下,。
4.重啟生效,!
|