Ubuntu Server 仮想マシン 構築【kvm – qemu – vnc 】

<概要>
今回管理者が構築したH/W環境は下記です。
HostとGuestは同じ「Ubuntu Server 11.10 64bits」を使用しました。
Server:HP ProLiant MicroServer
CPU:AMD Turion(tm) II Neo N40L Dual-Core Processor
RAM:8 Gbytes
OS:Ubuntu 11.10 Server 64bit

1. Host OS Install
2. kvm-pxe”導入
3. Virtual Disk 作成
4. Guest OS Install
5. ゲストOSの基本起動
6. ホストネットワーク設定(再起動時設定が残る)
7. ホストネットワーク設定(一時的起動の場合)
8. bridgeに接続する起動方法
9. ゲストIP設定
10.ゲストOS自動起動化

1. Host OS Install
<<Host OS Install>>
-OS:”ubuntu-11.10-server-amd64.iso”
-初期インストール最低限環境で「kvm、qemu-kvm、ssh」を設定

2. kvm-pxe導入
-kvmコマンド(vncを動かすツール)を実行時”kvm-pxe”が要求されたため”kvm-pxe”も導入
$ sudo apt-get install kvm-pxe

3. Virtual Disk 作成
-Virtual Disk 作成
$ qemu-img create -f qcow2 ubuntuServ.qcow2 10G

4. Guest OS Install
<<Guest OS Install>>
-OS:”ubuntu-11.10-server-amd64.iso”
-kvmでiso読み込み、vnc起動
$ sudo kvm -m 1024 -cdrom ubuntu-11.10-server-amd64.iso -hda ubuntuServ.qcow2 -boot d -vnc :0

5. ゲストOSの基本起動
<<仮想ハードディスクからゲストOSの基本起動>>
-vnc出力
$ sudo kvm -hda ubuntuServ.qcow2 -boot c -m 1024 -vnc :0
-local console出力
$ sudo kvm -hda ubuntuServ.qcow2 -boot c -m 1024 -curses

6. ホストネットワーク設定(再起動時設定が残る)
<<ホスト側のネットワークの設定>>
<IP設定+bridge作成> 固定Up on system start!
———————————–
$ cat interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
#auto eth0
#iface eth0 inet dhcp
# Build bridge for kvm gest OS
# Also can be done with shell script (bridge.sh)
auto br0
iface br0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
pre-up ifconfig eth0 down
pre-up ifconfig eth0 0.0.0.0 promisc up
pre-up brctl addbr br0
pre-up brctl addif br0 eth0
pre-up ifconfig eth0 up
post-down ifconfig eth0 down
post-down brctl delif br0 eth0
———————————–

7. ホストネットワーク設定(一時的起動の場合)
<IP設定+bridge作成> 一時的起動シェール
$ cat bridge.sh
#!/bin/sh
IP=172.18.21.80 # ホストのIPアドレス
GATEWAY=172.18.21.1 # ルータのLAN側IPアドレス
echo “change IP address : $IP”
ifconfig eth0 0.0.0.0 promisc up # プロミスキャスモードに設定
brctl addbr br0 # ブリッジの作成
brctl addif br0 eth0 # ブリッジにeth0を接続
ifconfig br0 up # ブリッジを起動
ifconfig br0 $IP netmask 255.255.255.0 # ブリッジにIP設定
route add default gw $GATEWAY # ゲートウェイ設定
———————————–

8. bridgeに接続する起動方法
<<bridgeに接続する起動方法>>
-tap0がhost OSに浮かぶ
-eth0がguest OSに浮かぶ
$ sudo kvm -hda ubuntuServ.qcow2 -boot c -m 1024 -net nic -net tap,ifname=tap0,script=/etc/qemu-ifup -vnc :0
●二つ目のゲストOSを起動する場合:
$ sudo kvm -hda Virtual_Hardisk_File -boot c -m 1024 -net nic -net tap,ifname=tap0,script=/etc/qemu-ifup -vnc :1

9. ゲストIP設定
<<Guest IP Setting>>
$ cat /etc/network/interfaces
———————————–
auto eth0
iface eth0 inet static
address 192.168.0.101
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
———————————–

10.ゲストOS自動起動化
<<kvm Guest OS自動起動>>
上記起動コマンドを下記ファイルに記載
/etc/rc.local

Share Button

コメントを残す


6 + 3 =

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>