1 檢查CPU虛擬化支持
egrep 'svm|vmx' /proc/cpuinfo
有輸出說明cpu支持虛擬化,在BIOS中打開inter-VT
2 宿主機(jī)網(wǎng)橋設(shè)置
bridge不支持NetworkManager,所有在下面的操作前確保NetworkManager處于關(guān)閉狀態(tài)
cat /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq
[ifupdown]
managed=false
配置managed=false
systemctl stop NetworkManager.service
配置網(wǎng)橋
安裝bridge-utils
sudo apt-get install bridge-utils
創(chuàng)建網(wǎng)橋
brctl addbr br0
brctl addif br0 eno1
ifconfig eno1 0.0.0.0
ifconfig br0 192.168.100.20/24
添加默認(rèn)網(wǎng)關(guān)
route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.100.1
若要永久生效狡相,則如下配置
cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto br0
iface br0 inet static
bridge_ports eno1
address 192.168.100.20
netmask 255.255.255.0
gateway 192.168.100.1
bridge_stp off
bridge_fd 0
dns-nameservers 8.8.8.8
重啟網(wǎng)絡(luò)后梯轻,查看網(wǎng)絡(luò)
ifconfig
br0 Link encap:Ethernet HWaddr 1c:b7:2c:aa:3d:89
inet addr:192.168.100.20 Bcast:192.168.100.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2007114 errors:0 dropped:3179 overruns:0 frame:0
TX packets:2547163 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14447174274 (14.4 GB) TX bytes:11544824281 (11.5 GB)
eno1 Link encap:Ethernet HWaddr 1c:b7:2c:aa:3d:89
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11663933 errors:0 dropped:8384 overruns:0 frame:0
TX packets:2472983 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:16484732144 (16.4 GB) TX bytes:237579422 (237.5 MB)
Interrupt:20 Memory:f7f00000-f7f20000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:5895380 errors:0 dropped:0 overruns:0 frame:0
TX packets:5895380 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9039764297 (9.0 GB) TX bytes:9039764297 (9.0 GB)
virbr0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
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:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
以上說明網(wǎng)橋設(shè)置ok
2 安裝軟件包
apt install kvm qemu qemu-kvm
通過kvm-ok檢測kvm是否安裝好了
kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
這樣說明已經(jīng)安裝好了
apt install virtinst libvirt-bin python-libvirt virt-viewer virt-manager (管理工具)
apt install bridge-utils (網(wǎng)橋管理)
3 創(chuàng)建虛擬磁盤
qemu-img create -f qcow2 /vm/kvm/instance-1.img 20G
創(chuàng)建一個20G大小,名稱為instance-001,格式為qcow2的虛擬磁盤
4 安裝GuestOS
本文采用的是非交互文本方式進(jìn)行安裝尽棕,所以做一下操作
4.1 掛載iso鏡像
sudo mount /home/wangpei/iso/CentOS-7-x86_64-DVD-1708.iso /mnt/os -o loop
4.2 搭建ftp,允許匿名登錄喳挑,匿名用戶家目錄指向/mnt
apt instal vsftp
vsftpd配置如下:
anonymous_enable=YES
anon_root=/mnt
4.3 在/mnt下建ks.cfg文件內(nèi)容如下:
bootloader --location=mbr --driveorder=vda --append="console=ttyS0 crashkernel=auto"
clearpart --all --initlabel
install
url --url=ftp://192.168.100.20/os
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto static --ip 192.168.100.115 --netmask 255.255.255.0 --gateway 192.168.100.1 --ipv6 auto --nameserver 8.8.8.8
rootpw --iscrypted $6$1Y6QA0TPid69iYMp$ygY0OFrw06w1oHuOC8D666fO5E9NNUMvCZuL7Uewcq8/Kz5RikrwJ9yOdouSQbTbeEIpzugqllTlSpIBVboQk0
#firewall --service=ssh
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc Asia/Shanghai
#zerombr
autopart
repo --name="CentOS" --baseurl=ftp://192.168.100.20/os --cost=100
%packages
@core
net-tools
vim
%end
reboot
5 創(chuàng)建虛擬機(jī)
sudo virt-install
--connect qemu:///system
--virt-type kvm
--name instance-1
--metadata description="192.168.100.115"
--ram 2048
--vcpus 2
--disk "/vm/kvm/instance-1.img"
--location ftp://192.168.100.20/os
--extra-arg="ks=ftp://192.168.100.20/ks.cfg"
--nographic
-x console=ttyS0
--force
等到出現(xiàn)localhost login: 說明安裝好了
用virsh list --all查看虛機(jī)實例
virsh list --all
Id Name State
57 centos7 running
71 instance-1 running
78 instance-2 running
80 instance-3 running
84 instance-4 running
87 ubuntu16.04 running
97 instance-5 running
99 instance-6 running