1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
PRE-INSTALL
kvm相关安装包及其作用
qemu-kvm 主要的KVM程序包
python-virtinst 创建虚拟机所需要的命令行工具和程序库
virt-manager GUI虚拟机管理工具
virt-
top
虚拟机统计命令
virt-viewer GUI连接程序,连接到已配置好的虚拟机
libvirt C语言工具包,提供libvirt服务
libvirt-client 为虚拟客户机提供的C语言工具包
virt-
install
基于libvirt服务的虚拟机创建命令
bridge-utils 创建和管理桥接设备的工具
INSTALL
[root@master~]
# yum install bridge-utils tunctl virt-manager virt-viewer kvm kmod-kvm qemu libvirt python-virtinst acpid -y
#查看是否加载kvm模块
[root@master~]
# lsmod|grep kvm
kvm_intel 138567 0
kvm 441119 1 kvm_intel
#如果没有这两条,可以用"modprobe kvm"加载;
#相关命令"insmod;rmmod;modinfo"
#启动libvirtd
[root@master~]
# systemctl start libvirtd;systemctl enable libvirtd
[root@master~]
# systemctl list-unit-files|grep libvirtd
libvirtd.service enabled
NETWORK CONFIGURATION
#修改网卡文件ens33
[root@master~]
# cd /etc/sysconfig/network-scripts/
[root@master network-scripts]
# echo "BRIDGE=br0" >>ifcfg-ens33 #在ifcfg-e**原网卡文件中增加"BRIDGE=br0"
#新建网桥文件ifcfg-br0(网桥名称),增加内容如下
[root@master network-scripts]
# vi ifcfg-br0
*************************************************
DEVICE=br0
TYPE=
"Bridge"
#大小写敏感,所以必须是Bridge
BOOTPROTO=
"dhcp"
ONBOOT=
"yes"
DELAY=
"0"
STP=
"yes"
#这一行是来启动STP,和brctl命令行出来的结果有关
*************************************************
#重启NetworkManager及network服务:
[root@masternetwork-scripts]
# systemctl restart NetworkManager
#当你手动修改了网卡文件后,需要重启NetworkManager服务来重新接管网络配置
#网卡配置文件和NetworkManager配置冲突时,解决方案:{1、重启NetworkManager;2、关闭NetworkManager}
[root@masternetwork-scripts]
# systemctl restart network
[root@master network-scripts]
# ip a #ip命令用来查看和管理ip信息
1: lo:<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link
/loopback
00:00:00:00:00:00 brd00:00:00:00:00:00
inet 127.0.0.1
/8
scope host lo
valid_lft forever preferred_lft forever
inet6 ::1
/128
scope host
valid_lft forever preferred_lft forever
2:ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fastmaster br0 state UP qlen 1000
link
/ether
00:0c:29:61:5c:1d brdff:ff:ff:ff:ff:ff
3:virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue stateDOWN
link
/ether
52:54:00:b6:45:5b brdff:ff:ff:ff:ff:ff
inet 192.168.122.1
/24
brd 192.168.122.255scope global virbr0
valid_lft forever preferred_lft forever
4:virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0state DOWN qlen 500
link
/ether
52:54:00:b6:45:5b brdff:ff:ff:ff:ff:ff
6: br0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link
/ether
00:0c:29:61:5c:1d brdff:ff:ff:ff:ff:ff
inet 192.168.0.170
/24
brd 192.168.0.255scope global dynamic br0
valid_lft 11979sec preferred_lft11979sec
inet6 fe80::20c:29ff:fe61:5c1d
/64
scopelink
valid_lft forever preferred_lft forever
7: vnet0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0state UNKNOWN qlen 500
link
/ether
fe:54:00:cb:63:b2 brdff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fecb:63b2
/64
scope link
valid_lft forever preferred_lft forever
#查看网桥连接
[root@master network-scripts]
# brctl show #brctl是一个网桥连接管理命令
bridge name bridge
id
STP enabled interfaces
#如果上面不设置STP=yes,这里就会显示no
br0 8000.000c29615c1d
yes
ens33
vnet0
virbr0 8000.525400b6455b
yes
virbr0-nic
CLOSE SELINUX
[root@masternetwork-scripts]
# setenforce 0
[root@masternetwork-scripts]
# getenforce
Permissive
[root@masternetwork-scripts]
#vi /etc/selinux/config
******************************************
SELINUX=permissive
#修改配置文件使其永久生效
******************************************
CREATE A VM
[root@master~]
# mkdir -p /data/kvm
[root@master~]
# virt-install --network bridge=br0 --name centos73 --ram 2048 --vcpus 1 --disk path=/data/kvm/centos73.img,size=16 --graphics none --location 'http://mirrors.163.com/centos/7.3.1611/os/x86_64/' --extra-args="console=tty0 console=ttyS0,115200"
#详细每个参数的意义可以查看扩展资料
#安装过程会让你选择textmode 还是vnc,选择textmode继续安装吧
#如果网络会有问题的话,尽量选择用--cdrom /path/to/centos7.iso
#virt-install --network bridge=br0 --name centos73 --ram 2048 --vcpus 1 --disk path=/data/kvm/centos73.img,size=16 --graphics none --location 'http://mirrors.163.com/centos/7.3.1611/os/x86_64/' --extra-args="console=tty0 console=ttyS0,115200"
|
本文转自 喵来个鱼 51CTO博客,原文链接:http://blog.51cto.com/m51cto/1958520,如需转载请自行联系原作者