vmvare 17 gpu 虚拟化 vmware workstation gpu虚拟化
https://blog.51cto.com/u_12959/6296111?articleABtest=0
虚拟化(KVM)
虚拟化介绍:
VMware Workstation就是虚拟化
虚拟化简单讲,就是把一台物理计算机虚拟成多台逻辑计算机,每个逻辑计算机里面可以运行不同的操作系统,相互不受影响,这样就可以充分利用硬件资源
关键词Hypervisor(VMM) 虚拟机管理器
虚拟化技术分为全虚拟化和半虚拟化
早期的CPU硬件不支持虚拟化,虚拟机上的操作系统(guestos)要想使用cpu资源,需要通过VMM来翻译指令,这个过程比较耗费资源,这种虚拟化技术叫做全虚拟化(VMware Workstation)
半虚拟化技术通过修改guestos内核,让guestos可以直接使用CPU资源,而不需要翻译指令了,从而节省了资源,但修改内核比较鸡肋(XEN)
后续cpu厂商直接支持虚拟化,不需要通过VMM翻译指令了,无所谓半虚拟化和全虚拟化
Centos7上安装KVM
前提是CPU支持虚拟化
虚拟机设置要求:
虚拟机设置内存2G,增加一个50G的虚拟磁盘,处理器2核,虚拟化引擎两个虚拟化相关的选项打上对勾
注意虚拟化引擎的地方要打上勾
查看内存是否更改成功
[root@kvm ~]# free
total used free shared buff/cache available
Mem: 1868684 104824 1600708 8752 163152 1603176
Swap: 2097148 0 2097148
1.
2.
3.
4.
5.
检查cpu参数是否支持虚拟化
检查CPU是否开启虚拟化支持
[root@kvm ~]# cat /proc/cpuinfo |grep vmx
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch arat tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f rdseed adx smap clflushopt avx512cd xsaveopt xsavec xgetbv1 xsaves
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch arat tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f rdseed adx smap clflushopt avx512cd xsaveopt xsavec xgetbv1 xsaves
[root@kvm ~]# cat /proc/cpuinfo |grep svm
//vmx为英特尔的cpu;svm为AMD的cpu。
1.
2.
3.
4.
5.
6.
7.
在格式化新磁盘前先看是否添加磁盘成功
注意:添加完磁盘后要重启
查看磁盘情况
使用lsblk命令,检查虚拟机是否新增一块50 GB的磁盘
[root@kvm ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─centos-root 253:0 0 17.5G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 50G 0 disk
sr0 11:0 1 1024M 0 rom
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
由此可知,sdb这块新磁盘已添加
格式化新磁盘
格式化这块磁盘,格式化成ext4格式
[root@kvm ~]# mkfs.ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3276800 inodes, 13107200 blocks
655360 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2162163712
400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
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.
[root@kvm ~]# blkid
/dev/sdb: UUID="100ccced-54e3-4d45-8061-e8769c22294f" TYPE="ext4"
/dev/sda1: UUID="b8a1c1b7-954b-408b-b6e4-24c330b0ca73" TYPE="xfs"
/dev/sda2: UUID="Cu8T2o-9lgu-hX2v-M2vp-Hwbf-N64t-d3LFYH" TYPE="LVM2_member"
/dev/mapper/centos-root: UUID="9c16a4ed-bb0b-4042-811b-1256636d7c72" TYPE="xfs"
/dev/mapper/centos-swap: UUID="1a91125f-a432-4c62-b44f-e6af58b2ea56" TYPE="swap"
1.
2.
3.
4.
5.
6.
blkid+磁盘:查看磁盘信息
[root@kvm ~]# blkid /dev/sdb
/dev/sdb: UUID="100ccced-54e3-4d45-8061-e8769c22294f" TYPE="ext4"
1.
2.
3.
挂载
格式化完成后,我们挂载磁盘,先创建挂载目录/kvm_data,然后进行挂载
[root@kvm ~]# mkdir /kvm_data
[root@kvm ~]# mount /dev/sdb /kvm_data
//这种方式挂载,重启虚拟机后,需要再次重新挂载,我们为了方便开机后可以自动挂载,编写/etc/fstab文件,添加文件最末一行
[root@kvm ~]# vi /etc/fstab //永久挂载
/dev/sdb /kvm_data ext4 defaults 0 0
1.
2.
3.
4.
5.
关闭一系列的防火墙,并设置开机不自启
[root@kvm ~]# systemctl stop firewalld
[root@kvm ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
关闭SELinux,编辑/etc/selinux/config,将enforcing修改为disabled,命令如下:
[root@kvm ~]# vi /etc/selinux/config
[root@kvm ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
//修改这一位置的内容
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
修改完成后,重启虚拟机,使其生效,使用getenforce查看
[root@kvm ~]# iptables -nvL
Chain INPUT (policy ACCEPT 1330 packets, 97508 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 865 packets, 97027 bytes)
pkts bytes target prot opt in out source destination
[root@kvm ~]# setenforce 0
[root@kvm ~]# getenforce
Disabled
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.
安装kvm
[root@kvm ~]# yum install -y virt-* libvirt bridge-utils qemu-img
1.
配置网卡
配置网卡,增加桥接网卡
[root@kvm ~]# cd /etc/sysconfig/net
netconsole network network-scripts/
[root@kvm ~]# cd /etc/sysconfig/network-scripts/
[root@kvm network-scripts]# ls
ifcfg-eno16777736 ifdown-Team ifup-post
ifcfg-lo ifdown-TeamPort ifup-ppp
ifdown ifdown-tunnel ifup-routes
ifdown-bnep ifup ifup-sit
ifdown-eth ifup-aliases ifup-Team
ifdown-ib ifup-bnep ifup-TeamPort
ifdown-ippp ifup-eth ifup-tunnel
ifdown-ipv6 ifup-ib ifup-wireless
ifdown-isdn ifup-ippp init.ipv6-global
ifdown-post ifup-ipv6 network-functions
ifdown-ppp ifup-isdn network-functions-ipv6
ifdown-routes ifup-plip
ifdown-sit ifup-plusb
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
设置一个br0网卡,TYPE为Bridge,IP地址设置为eno16777736的ip
eno16777736配置文件里把IP地址去掉,增加BRIDGE=br0
**增加桥接网卡br0**
[root@kvm network-scripts]# cp ifcfg-eno16777736 ifcfg-br0
[root@kvm network-scripts]# vi ifcfg-br0
TYPE=Bridge
BOOTPROTO=none
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.153.20
GATEWAY=192.168.153.2
NETMASK=255.255.255.0
DNS1=114.114.114.114
DNS2=8.8.8.8
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
[root@kvm network-scripts]# vi ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=static
NAME=eno16777736
DEVICE=eno16777736
ONBOOT=yes
BRIDGE=br0
[root@kvm network-scripts]# service network restart
Restarting network (via systemctl): [OK ]
修改完成网卡内容后,重新启动网卡服务并查看网卡信息
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
[root@kvm network-scripts]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00: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: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP qlen 1000
link/ether 00:0c:29:69:61:1c brd ff:ff:ff:ff:ff:ff
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 00:0c:29:69:61:1c brd ff:ff:ff:ff:ff:ff
inet 192.168.153.20/24 brd 192.168.153.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::7cf3:2ff:fe70:e5db/64 scope link
valid_lft forever preferred_lft forever
可以清楚的看到br0网卡出现并且带有IP,而以前的eno16777736网卡则没有IP。网卡配置完成
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
启动libvirtd服务
检查KVM模块是否加载
[root@kvm network-scripts]# lsmod|grep kvm
kvm_intel 162153 0
kvm 525259 1 kvm_intel
[root@kvm network-scripts]# systemctl start libvirtd
[root@kvm network-scripts]# ps -ef |grep libvirtd //查看libvirtd进程
root 22738 1 0 19:47 ? 00:00:00 /usr/sbin/libvirtd
root 22896 2774 0 19:57 pts/0 00:00:00 grep --color=auto libvirtd
查看网卡详细信息
启动成功后,使用brctl命令可以看到两个网卡
[root@kvm network-scripts]# brctl show // brctl show可以看到两个网卡br0和virbr0
bridge name bridge id STP enabled interfaces
br0 8000.000c2969611c no eno16777736
virbr0 8000.000000000000 yes
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
到此网卡配置完成
-----------------------------------
vmvare 17 gpu 虚拟化 vmware workstation gpu虚拟化
https://blog.51cto.com/u_16099274/7242861