CentOS 6.5でKVMを使う

MacBook AirのVMware Fusion環境に動作しているCentOS 6.5仮想マシンでKVMを使います。KVMの仮想マシンとしてDebianを動かします。


LinkIconCentOS 6.5をVMware Fusionにインストールする

LinkIconKVMをインストールする
LinkIconブリッジインターフェースを作成する
LinkIconKVMでDebianを動かす

milk_btn_pagetop.png

 

KVMをインストールする

KVMをインストールします。

仮想化支援機能有無の確認

KVMをインストールする前に、KVM を動作させるのに必要な仮想化支援機能をCPUが持っているかどうかを調べます。


[ono@localhost ~]$ cat /proc/cpuinfo | grep vmx
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc up arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi ept vpid fsgsbase smep
[ono@localhost ~]$

「vmx」の文字列が含まれており、仮想化支援機能を備えたCPUであることがわかります。

KVMのインストールと起動

KVMコンポーネントをインストールします。
# yum -y install qemu-kvm libvirt python-virtinst bridge-utils

ibvirtdを起動します。
# /etc/init.d/libvirtd start

仮想マシンマネージャのインストール

仮想マシンマネージャをインストールします。
# yum -y install virt-manager

仮想マシンマネージャを起動します。
# virt-manager

変更 2014.04.03
2014.02.21
milk_btn_pagetop.png


 

ブリッジインターフェースを作成する

ブリッジインターフェースを作成します。

Network Managerの終了

Network Managerを終了させます。

# service NetworkManager stop
# chkconfig NetworkManager off
# chkconfig NetworkManager --list
NetworkManager 	0:off	1:off	2:off	3:off	4:off   5:off   6:off


networkの開始

networkを開始させます。

# service network start
# chkconfig network on
# chkconfig network --list
network        	0:off	1:off	2:on	3:on	4:on   5:on   6:off


ifcfg-eth0の設定

/etc/sysconfig/network-scripts/ifcfg-eth0 を設定します。

# nano /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
ONBOOT=yes
BRIDGE=br0
TYPE=Ethernet
NAME="System eth0"

ifcfg-br0の設定

/etc/sysconfig/network-scripts/ifcfg-br0 を設定します。


# nano /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE=br0
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=static
BROADCAST=192.168.11.255
IPADDR=192.168.11.230
NETMASK=255.255.255.0
NETWORK=192.168.11.0
ONBOOT=yes
STP=on
DELAY=0

networkサービスの再起動

networkサービスを再起動します。

# service network restart

ネットワークインターフェースの確認

ネットワークインターフェースの情報を確認します。

# ifconfig
br0       Link encap:Ethernet  HWaddr 00:0C:29:3E:1B:30  
          inet addr:192.168.11.230  Bcast:192.168.11.255  Mask:255.255.255.0
          inet6 addr: 2001:c90:8480:c44c:20c:29ff:fe3e:1b30/64 Scope:Global
          inet6 addr: fe80::20c:29ff:fe3e:1b30/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:24 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1997 (1.9 KiB)  TX bytes:574 (574.0 b)

eth0      Link encap:Ethernet  HWaddr 00:0C:29:3E:1B:30  
          inet6 addr: fe80::20c:29ff:fe3e:1b30/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2712 errors:0 dropped:0 overruns:0 frame:0
          TX packets:966 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:672078 (656.3 KiB)  TX bytes:50918 (49.7 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:620 errors:0 dropped:0 overruns:0 frame:0
          TX packets:620 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:53444 (52.1 KiB)  TX bytes:53444 (52.1 KiB)

virbr0    Link encap:Ethernet  HWaddr 52:54:00:D8:52:93  
          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: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)


ブリッジインターフェイスの確認

ブリッジインターフェイスの情報を確認します。

#  brctl show
bridge name	bridge id		STP enabled	interfaces
br0		8000.000c293e1b30	yes		eth0
pan0		8000.000000000000	no		
virbr0		8000.525400d85293	yes		virbr0-nic


ファイアウォールの無効化

ホストマシンとゲストマシンがブリッジインターフェースを介して通信できるように、ファイアウォールの設定を無効にしておきます。

# system-config-firewall-tui

Firewall Configuration で
Firewall: [ ] Enabled
のチェックを外します。

システムの再起動を行います。
# reboot

リゾルバの設定

リゾルバを設定します。

# nano /etc/resolv.conf

nameserver 192.168.11.1

networkサービスを再起動します。
# service network restart

2014.04.02
milk_btn_pagetop.png

 

KVMでDebianを動かす

KVMでDebianを動かします。

Debianのダウンロード

Debian "wheezy" インストールCD/DVD用イメージ
http://cdimage.debian.or.jp/

PC/サーバー用 netinstイメージ 64 bit(amd64)
http://cdimage.debian.or.jp/7.4.0/amd64/iso-cd/debian-7.4.0-amd64-netinst.iso

Debian wheezy用仮想マシンの作成

Debian wheezy用仮想マシンを作成します。

・仮想マシンマネージャを起動します。
 # virt-manager

[Step 1 of 5]
・Create a new virtual machine をクリックします。
・Name に仮想マシンの名前を入力します。 (Debian)
・インストール方法として、Local install media を選択します。
・Forwardボタンをクリックします。

[Step 2 of 5]
・Use ISO image で debian-7.4.0-amd64-netinst.iso を指定します。
・OS type で Linux を選択します。
・Version で Debian Wheezy を選択します。
・Forwardボタンをクリックします。

[Step 3 of 5]
・Memory (RAM) で 1024MB を指定します。
・CPUs で 1 を指定します。
・Forwardボタンをクリックします。

[Step 4 of 5]
・Enable storage for this virtual machine にチェックを入れます。
・Create a disk image on the computer's hard drive で
 20GB を指定します。
・Allocate entire disk now のチェックを外します。
・Forwardボタンをクリックします。

[Step 4 of 5]
設定の確認画面が表示されます。

・設定内容の確認後、Finishボタンをクリックします。

〜 仮想マシンが起動し、仮想マシン用の画面が表示されます 〜

Debian wheezyのインストール操作

Debian wheezy (netinst版)をインストールします。

・インストーラの起動
ブート画面で「Graphical install」を選択し[Enter]キーを押します。
(グラフィカル環境でインストール作業を行います。)

・言語の選択
利用する言語に、「Japanese - 日本語」を選択して「Continue」をクリックします。

・場所の選択
 「日本」を選択します。

・利用するキーマップ
 「日本語」を選択します。

・ホスト名、ドメイン名の設定
ホスト名とドメイン名を入力します。
ホスト名は「debian」のままとします。
ドメイン名は「localdomain」とします。

・管理者のパスワードの設定
管理者(root)のパスワードを入力します。

・ユーザパスワードの設定
ユーザアカウントを作成します。
本名、アカウント名、パスワードを入力します。 (Ono Mitsuo ono <パスワード>)

・パーティショニングの方法
「ガイド - ディスク全体を使う」を選択します。

・パーティショニングするディスクの選択
 仮想ディスク 1 (vda) 21.5 GB virtio Block Device

・ディスクのパーティショニング
Debianをインストールするハードディスクを選択します。

・パーティションの構成
 「すべてのファイルを1つのパーティションに(初心者ユーザには推奨)」を選択します。
(ルートパーティションとスワップパーティションの2つが用意されます。)
パーティション構成を確認し、
 「パーティショニングの終了とディスクへの変更の書き込み」を選択します。

・パーティション変更の確認
警告画面で、「はい」を選択します。


・パッケージマネージャの設定
パッケージをダウンロードするサーバとして、「日本」を選択します。
一覧されたサーバのアドレスから 「ftp.riken.jp」を選択します。

・popularity-contestの設定
「いいえ」を選択します。

・ソフトウェア選択
システムにインストールしたいパッケージとして、
  Debian デスクトップ環境
  標準システムユーティリティ
 を選択します。

・ブートローダのインストール
ブートローダ「GNU GRUB」をインストール問い合わせで「はい」を選択します。

・インストールの完了
インストール完了で、「続ける」ボタンをクリックします。

・再起動
システムが再起動され、ログインプロンプトが表示されます。

仮想マシンDebianの起動

・Applicationメニュー → System Tools → Virtual Machine Manager をクリックします。
・Authenticate画面で、root のパスワードを入力します。
・Authenticateボタン をクリックします。

・Virtual Machine Manager画面で、Debianを選択します。
・Poweer on virtual machineアイコン をクリックして、Debianを起動します。
・Openアイコン をクリックして、Debianのコンソールを表示させます。

2014.02.21
milk_btn_pagetop.png

2014.02.21