前天把一台win服务器格了装ubuntu,原来的asp程序用virtualbox虚拟一个win2003运行
下载最新的ubuntu 12.0.4 安装时候可以用U盘或光盘安装,如果你的cpu支持kvm虚拟主机可以直接安装时候选择virtualhost。
因为我cpu是老至强,不支持vms也就是内核不支持虚拟化。所以我后期安装virtualbox。如果原来安装了kvm那要先删除
删除可以参照网上
删除kvm
如果没有装可以跳过
------------------------------------------------------
执行以下命令:
1. sudo aptitude remove kvm qemu
2. sudo modprobe -r kvm-intel 或 sudo modprobe -r kvm-amd
3. sudo modprobe -r kvm
第二步根据实际选择一个即可。
上述三步成功后,就可以安装virtualbox了
1.查看相关正在运行的mod
lsmod | grep kvm
2.停止模块运行
如果你的cpu是AMD:sudo rmmod kvm-amd
如果是Intel:sudo rmmod kvm
3.卸载模块
如果你的cpu是AMD:sudo modprobe -r kvm-amd
如果你的cpu是Intel:sudo modprobe -r kvm-intel
sudo modprobe -r kvm
4.完全卸载
sudo aptitude purge kvm qemu-kvm
sudo apt-get remove kvm qemu-kvm
------------------------------------------------------------------------------------
安装virtualbox
手动安装很麻烦的,还要重新编译内核
如果说要安装内核可以使用下面代码
apt-get install build-essentials
and install linux-kernel-headers
apt-get install linux-kernel-headers
or
apt-get install linux-kernel-*
出现下面错误时候,还是内核问题
VirtualBox kernel driver not installed. The vboxdrv kernel module was either not loaded or /dev/vboxdrv was not created for some reason. Re-setup the kernel module by executing '/etc/init.d/vboxdrv setup' as root.
运行
/etc/init.d/vboxdrv setup
然后他会说让你检查下 /var/log/vbox-install.log
去看下,然后看看提示缺什么内核,用apt-get install linux**这种方式安装下就可以了
还有两个依赖包
sudo apt-get install libxalan110 libqt3-mt
sudo apt-get install libxerces27 libxalan110 libqt3-mt
2 下载VirtualBox [手动下载最新的]
wget http://www.virtualbox.org/download/1.3. ... gy_x86.deb
3 安装VirtualBox:
sudo dpkg -i VirtualBox_1.3.2_Ubuntu_Edgy_x86.deb
简单安装virtualbox
1、首先添加一个源 vi /etc/apt/sources.list
deb http://download.virtualbox.org/virtualbox/debian lucid non-free
2、下载证书
sudo apt-key add sun_vbox.asc
3、注册证书
wget -q http://download.virtualbox.org/virtualbox/debian/sun_vbox.asc -O- | sudo apt-key add -
4、install VirtualBox
sudo apt-get update sudo apt-get install virtualbox-3.1这个就不用担心缺少这库那库的了
现在安装好了virtualbox 如果你只用命令行安装,不想最xwindow环境那应该在本地配好vdi
然后上传。
如果要虚拟主机跟主机并行在一个环境,也就是都用192.168.0.x这个网段。那ubuntu要装网桥。也就是使用网桥形式
不然只能用虚拟主机访问外部,外部无法访问内部的虚拟主机。
安装网桥包
sudo apt-get install uml-utilities
sudo apt-get install bridge-utils
添加br0网桥 一般网卡为eth0和eth1 目前我们只使用eth0
数据先过br0然后再到eth0,网桥可以和eth0同一个IP
br0是一个虚拟的网卡样子。数据可以全部转发到eth0
使用网桥程序添加网桥
配置网桥: 先创建一个网桥接口: SYSHUNTER-UBUNTU# brctl addbr br0 将两块已有的网卡添加到网桥: SYSHUNTER-UBUNTU# brctl addif br0 eth0 SYSHUNTER-UBUNTU# brctl addif br0 eth1 将两块网卡IP设置为0,它们已经不再需要了: SYSHUNTER-UBUNTU# ifconfig eth0 0.0.0.0 SYSHUNTER-UBUNTU# ifconfig eth1 0.0.0.0 给新网桥设置一个IP: SYSHUNTER-UBUNTU# ifconfig br0 192.168.1.10 netmask 255.255.255.0 注意要在终端上操作,因为把eth0 添加到 br0时候已经断网了。 也可以使用脚本形式,这样保证执行完整 把上面几行代码写成脚本为br.sh 远程执行下。 然后用ifconfig 检查下是不是有br0 br0 Link encap:Ethernet HWaddr 00:30:48:72:58:0e inet addr:218.112.19.141 Bcast:218.112.19.191 Mask:255.255.255.192 inet6 addr: fe80::230:48ff:fe72:580e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:395464 errors:0 dropped:1367 overruns:0 frame:0 TX packets:232003 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 如果有就可以编辑下 vim /etc/network/interface 整个内容如下,下面是我的interface -------------------------------------- auto lo br0 eth0 iface lo inet loopback iface eth0 inet manual iface br0 inet static address 218.112.19.141 netmask 255.255.255.192 broadcast 218.112.19.191 network 218.112.19.128 gateway 218.112.19.129 bridge_ports eth0 bridge_stp off bridge_fd 0 bridge_maxwait 0
------------------------------------------
我设置两个vm1 vm2两个虚拟网卡如下
记得把vm1和vm2加到 br0网桥里 qiye企业是linux用户用来转发数据包的。所以一定要让
brctl addif br0 vm1
设置/dev/net/tun的读写权限
chmod 0666 /dev/net/tun
---------------------------------------------------------------
auto lo vm1 vm2 br0 eth0 iface lo inet loopback iface eth0 inet manual iface vm1 inet manual up ifconfig $IFACE 218.112.19.143 up down ifconfig $IFACE down tunctl_user qiye iface vm2 inet manual up ifconfig $IFACE------------------------------------------------------------------------218.112.19.142 up down ifconfig $IFACE down tunctl_user qiye iface br0 inet static address 218.112.19.141 netmask 255.255.255.192 broadcast 218.112.19.191 network 218.112.19.128 gateway 218.112.19.129 bridge_ports eth0 vm1 vm2 bridge_stp off bridge_fd 0 bridge_maxwait 0
定义了br0和eth0 bridge_ports 都转到eth0这样eth0的ip跟一样,所以不用设置eth0的网卡地址
完成后可以重启下网络
sudo /etc/init.d/networking restart
如果有错可以按照提示
具体看
http://blog.csdn.net/dsjlzh/article/details/7359472
然后在virtualbox 网络里面设置网桥形式 然后选择br0 下面高级选项可以默认。
如果不装窗口环境,可以在本地配置好vdi然后上传
先用命令行
VBoxManage createvm –name “ win2003″ –register
用
VBoxManage list vms
列出虚拟主机
"win2003" {e82ec0c3-37cb-4703-a4c0-4922594f9406}
后面一串e82ec0c3-37cb-4703-a4c0-4922594f9406是唯一串号
上传本地win2003.vbox 文件到服务器
用服务器的串号e82ec0c3-37cb-4703-a4c0-4922594f9406换掉本地上传那个里面的主机串号f572531e-cea3-470c-93da-aa25fdcf5d5b 并把name改为win2003
<?xml version="1.0"?> <!-- ** DO NOT EDIT THIS FILE. ** If you make changes to this file while any VirtualBox related application ** is running, your changes will be overwritten later, without taking effect. ** Use VBoxManage or the VirtualBox Manager GUI to make changes. --> <VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.12-linux"> <Machine uuid="{f572531e-cea3-470c-93da-aa25fdcf5d5b}" name="win2003" OSType="Windows2003" snapshotFolder="Snapshots" lastStateChange="2013-01-19T18:13:47Z" aborted="true"> <MediaRegistry> <HardDisks> <HardDisk uuid="{556ed811-0d35-428a-babe-9de62d3c6332}" location="/site/vps/haowei.vdi" format="VDI" type="Normal"/> <HardDisk uuid="{7eb0970b-6045-43eb-806b-680fc65697fd}" location="/site/vps/haodata.vdi" format="VDI" type="Normal"/> </HardDisks> <DVDImages/> <FloppyImages/> </MediaRegistry> <ExtraData> <ExtraDataItem name="GUI/LastGuestSizeHint" value="720,400"/> <ExtraDataItem name="GUI/LastNormalWindowPosition" value="110,145,720,422"/> </ExtraData> <Hardware version="2"> <CPU count="1" hotplug="false"> <HardwareVirtEx enabled="true" exclusive="true"/> <HardwareVirtExNestedPaging enabled="true"/> <HardwareVirtExVPID enabled="true"/> <PAE enabled="false"/> <HardwareVirtExLargePages enabled="false"/> <HardwareVirtForce enabled="false"/> </CPU> <Memory RAMSize="512" PageFusion="false"/> <HID Pointing="USBTablet" Keyboard="PS2Keyboard"/> <HPET enabled="false"/> <Chipset type="PIIX3"/> <Boot> <Order position="1" device="Floppy"/> <Order position="2" device="DVD"/> <Order position="3" device="HardDisk"/> <Order position="4" device="None"/> </Boot> <Display VRAMSize="16" monitorCount="1" accelerate3D="false" accelerate2DVideo="false"/> <RemoteDisplay enabled="false" authType="Null"/> <BIOS> <ACPI enabled="true"/> <IOAPIC enabled="false"/> <Logo fadeIn="true" fadeOut="true" displayTime="0"/> <BootMenu mode="MessageAndMenu"/> <TimeOffset value="0"/> <PXEDebug enabled="false"/> </BIOS> <USBController enabled="true" enabledEhci="false"/> <Network> <Adapter slot="0" enabled="true" MACAddress="0800275F3EA2" cable="true" speed="0" type="Am79C973"> <DisabledModes> <NAT> <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/> <Alias logging="false" proxy-only="false" use-same-ports="false"/> </NAT> </DisabledModes> <BridgedInterface name="br0"/> </Adapter> <Adapter slot="1" enabled="false" MACAddress="080027EB257E" cable="true" speed="0" type="Am79C973"> <DisabledModes> <NAT> <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/> <Alias logging="false" proxy-only="false" use-same-ports="false"/> </NAT> </DisabledModes> </Adapter> <Adapter slot="2" enabled="false" MACAddress="080027BD2456" cable="true" speed="0" type="Am79C973"> <DisabledModes> <NAT> <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/> <Alias logging="false" proxy-only="false" use-same-ports="false"/> </NAT> </DisabledModes> </Adapter> <Adapter slot="3" enabled="false" MACAddress="0800277E3F3C" cable="true" speed="0" type="Am79C973"> <DisabledModes> <NAT> <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/> <Alias logging="false" proxy-only="false" use-same-ports="false"/> </NAT> </DisabledModes> </Adapter> <Adapter slot="4" enabled="false" MACAddress="080027378DDF" cable="true" speed="0" type="Am79C973"> <DisabledModes> <NAT> <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/> <Alias logging="false" proxy-only="false" use-same-ports="false"/> </NAT> </DisabledModes> </Adapter> <Adapter slot="5" enabled="false" MACAddress="08002700FF51" cable="true" speed="0" type="Am79C973"> <DisabledModes> <NAT> <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/> <Alias logging="false" proxy-only="false" use-same-ports="false"/> </NAT> </DisabledModes> </Adapter> <Adapter slot="6" enabled="false" MACAddress="0800270EFA2F" cable="true" speed="0" type="Am79C973"> <DisabledModes> <NAT> <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/> <Alias logging="false" proxy-only="false" use-same-ports="false"/> </NAT> </DisabledModes> </Adapter> <Adapter slot="7" enabled="false" MACAddress="080027DF7CF4" cable="true" speed="0" type="Am79C973"> <DisabledModes> <NAT> <DNS pass-domain="true" use-proxy="false" use-host-resolver="false"/> <Alias logging="false" proxy-only="false" use-same-ports="false"/> </NAT> </DisabledModes> </Adapter> </Network> <UART> <Port slot="0" enabled="false" IOBase="0x3f8" IRQ="4" hostMode="Disconnected"/> <Port slot="1" enabled="false" IOBase="0x2f8" IRQ="3" hostMode="Disconnected"/> </UART> <LPT> <Port slot="0" enabled="false" IOBase="0x378" IRQ="4"/> <Port slot="1" enabled="false" IOBase="0x378" IRQ="4"/> </LPT> <AudioAdapter controller="AC97" driver="Pulse" enabled="true"/> <RTC localOrUTC="local"/> <SharedFolders/> <Clipboard mode="Bidirectional"/> <IO> <IoCache enabled="true" size="5"/> <BandwidthGroups/> </IO> <HostPci> <Devices/> </HostPci> <Guest memoryBalloonSize="0"/> <GuestProperties/> </Hardware> <StorageControllers> <StorageController name="IDE Controller" type="PIIX4" PortCount="2" useHostIOCache="true" Bootable="true"> <AttachedDevice type="HardDisk" port="0" device="0"> <Image uuid="{556ed811-0d35-428a-babe-9de62d3c6332}"/> </AttachedDevice> <AttachedDevice type="HardDisk" port="0" device="1"> <Image uuid="{7eb0970b-6045-43eb-806b-680fc65697fd}"/> </AttachedDevice> <AttachedDevice passthrough="false" type="DVD" port="1" device="0"/> </StorageController> </StorageControllers> </Machine> </VirtualBox>
最后用命令行起来就可以了
VBoxManage startvm "win2003" --type headless