在Ubuntu上安装KVM并搭建虚拟环境(2)

~ sudo vi /etc/network/interfaces
 auto lo
 iface lo inet loopback
 auto eth0
 iface eth0 inet manual
 auto br0
 iface br0 inet static
 address 192.168.1.10
 netmask 255.255.255.0
 gateway 192.168.1.1
 bridge_ports eth0

保存,重起网卡设置

~ sudo /etc/init.d/networking restart

再查看网卡的设置

~ ifconfig
 br0 Link encap:Ethernet HWaddr 00:1c:25:a1:99:fc
 inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
 inet6 addr: fe80::21c:25ff:fea1:99fc/64 Scope:Link
 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
 RX packets:91 errors:0 dropped:0 overruns:0 frame:0
 TX packets:100 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:0
 RX bytes:6260 (6.2 KB) TX bytes:15470 (15.4 KB)

eth0 Link encap:Ethernet HWaddr 00:1c:25:a1:99:fc
 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
 RX packets:605 errors:0 dropped:0 overruns:0 frame:0
 TX packets:425 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:1000
 RX bytes:112441 (112.4 KB) TX bytes:61529 (61.5 KB)
 Interrupt:20 Memory:fc200000-fc220000

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:36 errors:0 dropped:0 overruns:0 frame:0
 TX packets:36 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:0
 RX bytes:2100 (2.1 KB) TX bytes:2100 (2.1 KB)

virbr0 Link encap:Ethernet HWaddr 2a:b8:36:cf:cc:c6
 inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
 UP 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:0
 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

这个时候eth0,已经没有具体的IP地址。IP地址出在了br0的虚拟网上面。

我们ping一下公网ip,看看是不是通的。

~ ping 8.8.8.8
 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
 64 bytes from 8.8.8.8: icmp_req=1 ttl=46 time=51.7 ms
 64 bytes from 8.8.8.8: icmp_req=2 ttl=46 time=50.8 ms

4. 创建虚拟机

通过virt虚拟机管理软件,创建虚拟机(Guest)。

上传2个安装镜像到Server: u1204.iso, xp.iso

放在/home/conan/os目录下面。

1)创建Guest1, Ubuntu 64位LTS 12.04版本(命令行,无可视化界面)

把u1204.iso文件mount一个目录

~ sudo mount -o loop /home/conan/os/u1204.iso /home/conan/os/ubuntu
~ ls /home/conan/os/ubuntu
 boot dists EFI isolinux pics preseed ubuntu
 cdromupgrade doc install md5sum.txt pool README.diskdefines

创建虚拟机

~ sudo virt-install --connect=qemu:///system \
 --name g1 \
 --ram 2048 \
 --vcpus=2 \
 --os-type=linux \
 --os-variant=ubuntuprecise \
 --accelerate \
 --hvm \
 --disk path=/home/conan/os/g1.img,size=6,bus=virtio \
 --location /home/conan/os/ubuntu \
 --extra-args='console=tty0 console=ttyS0' \
 --network bridge=br0,model=virtio \
 --graphics none

进入安装界面

lqqqqqqqqqqqqqqqqqqqqqqqu [!!] Select a language tqqqqqqqqqqqqqqqqqqqqqqqqk
 x x
 x Choose the language to be used for the installation process. The x
 x selected language will also be the default language for the installed x
 x system. x
 x x
 x Language: x
 x x
 x C x
 x English x
 x x
 x <Go Back> x
 x x
 mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
 <Tab> moves; <Space> selects; <Enter> activates buttons

安装系统

lqqqqqqqqqqqqqqqqqqqqqu [!] Configure the network tqqqqqqqqqqqqqqqqqqqqqk
 x x
 x Please enter the hostname for this system. x
 x x
 x The hostname is a single word that identifies your system to the x
 x network. If you don't know what your hostname should be, consult your x
 x network administrator. If you are setting up your own home network, x
 x you can make something up here. x
 x x
 x Hostname: x
 x x
 x localhost____________________________________________________________ x
 x x
 x <Go Back> <Continue> x
 x x
 mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
 <Tab> moves; <Space> selects; <Enter> activates buttons

安装完成

2). 创建Guest2, Ubuntu 64位LTS 12.04版本(通过VNC,有可视化界面)

在server端,我要打开vnc_listen的端口支持

~ vi /etc/libvirt/qemu.conf
 #打开注释
vnc_listen="0.0.0.0"

重启virt软件

~ sudo /etc/init.d/libvirt-bin restart
 ~ netstat -nlt|grep 5900
 tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN


我们需要使用到Xming和putty配合,可以让putty远程传输的VNC信号通过Xming显示出来。

在putty里面,我们要修改一下配置。

putty1

putty2

启动Xming软件

执行命令

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/15879.html