[root@localhost ~]# free
total used free shared buff/cache available
Mem: 995684 129056 757828 7776 108800 736956
Swap: 2097148 0 2097148
[root@localhost ~]# grep -Ei 'vmx|svm' /proc/cpuinfo
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 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 invpcid_single ssbd ibrs ibpb stibp tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec arat md_clear spec_ctrl intel_stibp flush_l1d arch_capabilities
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 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
[root@localhost ~]# mkfs.ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
无论如何也要继续? (y,n) y
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3276800 inodes, 13107200 blocks
655360 blocks (5.00%) reserved for the super user
第一个数据块=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: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@localhost ~]# blkid /dev/sdb
/dev/sdb: UUID="700d9e0c-de3e-4d57-8458-549356388fd7" TYPE="ext4"
[root@localhost ~]# mkdir /kvm_data
[root@localhost ~]# mount /dev/sdb /kvm_data/
[root@localhost ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Aug 10 23:37:47 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=12ba9b17-8596-439c-bd06-cca6d607513b /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sdb /kvm_data ext4 defaults 0 0
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# vi /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 values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@localhost ~]#reboot
[root@localhost ~]# getenforce
Disabled
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.4G 16G 9% /
/dev/sdb 50G 53M 47G 1% /kvm_data
/dev/sda1 1014M 137M 878M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
#安装KVM
[root@localhost network-scripts]# yum install -y virt-* libvirt bridge-utils qemu-img
启动
配置网卡
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-ens33 ifdown-ipv6 ifdown-Team ifup-eth ifup-post ifup-tunnel
ifcfg-lo ifdown-isdn ifdown-TeamPort ifup-ippp ifup-ppp ifup-wireless
ifdown ifdown-post ifdown-tunnel ifup-ipv6 ifup-routes init.ipv6-global
ifdown-bnep ifdown-ppp ifup ifup-isdn ifup-sit network-functions
ifdown-eth ifdown-routes ifup-aliases ifup-plip ifup-Team network-functions-ipv6
ifdown-ippp ifdown-sit ifup-bnep ifup-plusb ifup-TeamPort
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-br0
[root@localhost network-scripts]# vi ifcfg-br0
TYPE=Bridge
BOOTPROTO=none
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.100.10
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
DNS1=114.114.114.114
DNS2=8.8.8.8
[root@localhost network-scripts]# vi ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=none
NAME=ens33
DEVICE=ens33
NBOOT=yes
BRIDGE=br0
[root@localhost ~]# service network restart
Restarting network (via systemctl): [ 确定 ]
[root@localhost ~]# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.10 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::20c:29ff:fe7e:88fc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:7e:88:fc txqueuelen 1000 (Ethernet)
RX packets 12 bytes 830 (830.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 21 bytes 1805 (1.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:7e:88:fc txqueuelen 1000 (Ethernet)
RX packets 619 bytes 55545 (54.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 535 bytes 76301 (74.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 131 bytes 12126 (11.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 131 bytes 12126 (11.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
启动libvirtd服务
[root@localhost ~]# lsmod|grep kvm
kvm_intel 188688 0
kvm 636969 1 kvm_intel
irqbypass 13503 1 kvm
[root@localhost network-scripts]# systemctl start libvirtd
[root@localhost network-scripts]# ps -ef |grep libvirt
root 2794 1 0 15:31 ? 00:00:00 /usr/sbin/libvirtd
nobody 2908 1 0 15:31 ? 00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root 2910 2908 0 15:31 ? 00:00:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root 2961 1220 0 15:32 pts/0 00:00:00 grep --color=auto libvirt
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c297e88fc no ens33
virbr0 8000.525400cae3c3 yes virbr0-nic
上传CentOS 7镜像到/tmp/下
[root@localhost tmp]# virt-install --name=test --memory=512,maxmemory=1024 --vcpus=1,maxvcpus=2 --os-type=linux --os-variant=rhel7 --location=/tmp/CentOS-7-x86_64-DVD-2003.iso --disk path=/kvm_data/test.img,size=10 --bridge=br0 --graphics=none --console=pty,target_type=serial --extra-args="console=tty0 console=ttyS0"
================================================================================
================================================================================
Installation
1) [x] Language settings 2) [!] Time settings
(English (United States)) (Timezone is not set.)
3) [x] Installation source 4) [x] Software selection
(Local media) (Minimal Install)
5) [!] Installation Destination 6) [x] Kdump
(No disks selected) (Kdump is enabled)
7) [ ] Network configuration 8) [!] Root password
(Not connected) (Password is not set.)
9) [!] User creation
(No user will be created)
Please make your choice from above ['q' to quit | 'b' to begin installation |
'r' to refresh]: 2
#按1
================================================================================
Timezone settings
Available regions
1) Europe 6) Pacific 10) Arctic
2) Asia 7) Australia 11) US
3) America 8) Atlantic 12) Etc
4) Africa 9) Indian
5) Antarctica
Please select the timezone.
Use numbers or type names directly [b to region list, q to quit]: 2
================================================================================
================================================================================
Timezone settings
Available timezones in region Asia
1) Aden 29) Hong_Kong 56) Pontianak
2) Almaty 30) Hovd 57) Pyongyang
3) Amman 31) Irkutsk 58) Qatar
4) Anadyr 32) Jakarta 59) Qostanay
5) Aqtau 33) Jayapura 60) Qyzylorda
6) Aqtobe 34) Jerusalem 61) Riyadh
7) Ashgabat 35) Kabul 62) Sakhalin
8) Atyrau 36) Kamchatka 63) Samarkand
9) Baghdad 37) Karachi 64) Seoul
10) Bahrain 38) Kathmandu 65) Shanghai
11) Baku 39) Khandyga 66) Singapore
12) Bangkok 40) Kolkata 67) Srednekolymsk
13) Barnaul 41) Krasnoyarsk 68) Taipei
14) Beirut 42) Kuala_Lumpur 69) Tashkent
15) Bishkek 43) Kuching 70) Tbilisi
16) Brunei 44) Kuwait 71) Tehran
17) Chita 45) Macau 72) Thimphu
18) Choibalsan 46) Magadan 73) Tokyo
19) Colombo 47) Makassar 74) Tomsk
20) Damascus 48) Manila 75) Ulaanbaatar
21) Dhaka 49) Muscat 76) Urumqi
22) Dili 50) Nicosia 77) Ust-Nera
Press ENTER to continue65
23) Dubai 51) Novokuznetsk 78) Vientiane
24) Dushanbe 52) Novosibirsk 79) Vladivostok
25) Famagusta 53) Omsk 80) Yakutsk
26) Gaza 54) Oral 81) Yangon
27) Hebron 55) Phnom_Penh 82) Yekaterinburg
28) Ho_Chi_Minh 83) Yerevan
Please select the timezone.
Use numbers or type names directly [b to region list, q to quit]: 65
================================================================================
================================================================================
Installation
1) [x] Language settings 2) [x] Time settings
(English (United States)) (Asia/Shanghai timezone)
3) [x] Installation source 4) [x] Software selection
(Local media) (Minimal Install)
5) [!] Installation Destination 6) [x] Kdump
(No disks selected) (Kdump is enabled)
7) [ ] Network configuration 8) [!] Root password
(Not connected) (Password is not set.)
9) [!] User creation
(No user will be created)
Please make your choice from above ['q' to quit | 'b' to begin installation |
'r' to refresh]: 5
================================================================================
Installation
1) [x] Language settings 2) [x] Time settings
(English (United States)) (Asia/Shanghai timezone)
3) [x] Installation source 4) [x] Software selection
(Local media) (Minimal Install)
5) [!] Installation Destination 6) [x] Kdump
(No disks selected) (Kdump is enabled)
7) [ ] Network configuration 8) [!] Root password
(Not connected) (Password is not set.)
9) [!] User creation
(No user will be created)
Please make your choice from above ['q' to quit | 'b' to begin installation |
'r' to refresh]: 5
================================================================================
================================================================================
Probing storage...
Installation Destination
[x] 1) : 10 GiB (vda)
1 disk selected; 10 GiB capacity; 10 GiB free ...
Please make your choice from above ['q' to quit | 'c' to continue |
'r' to refresh]: c
================================================================================
================================================================================
Autopartitioning Options
[ ] 1) Replace Existing Linux system(s)
[x] 2) Use All Space
[ ] 3) Use Free Space
Installation requires partitioning of your hard drive. Select what space to use
for the install target.
Please make your choice from above ['q' to quit | 'c' to continue |
'r' to refresh]: c
================================================================================
================================================================================
Partition Scheme Options
[ ] 1) Standard Partition
[ ] 2) Btrfs
[x] 3) LVM
[ ] 4) LVM Thin Provisioning
Select a partition scheme configuration.
Please make your choice from above ['q' to quit | 'c' to continue |
'r' to refresh]: c
Generating updated storage configuration
Checking storage configuration...
================================================================================
================================================================================
Installation
1) [x] Language settings 2) [x] Time settings
(English (United States)) (Asia/Shanghai timezone)
3) [x] Installation source 4) [x] Software selection
(Local media) (Minimal Install)
5) [x] Installation Destination 6) [x] Kdump
(Automatic partitioning (Kdump is enabled)
selected) 8) [!] Root password
7) [ ] Network configuration (Password is not set.)
(Not connected)
9) [!] User creation
(No user will be created)
Please make your choice from above ['q' to quit | 'b' to begin installation |
'r' to refresh]: 8
================================================================================
================================================================================
Please select new root password. You will have to type it twice.
Password:
Password (confirm):
================================================================================
================================================================================
Question
The password you have provided is weak: The password fails the dictionary check
- it is too simplistic/systematic.
Would you like to use it anyway?
Please respond 'yes' or 'no': yes
================================================================================
================================================================================
Installation
1) [x] Language settings 2) [x] Time settings
(English (United States)) (Asia/Shanghai timezone)
3) [x] Installation source 4) [x] Software selection
(Local media) (Minimal Install)
5) [x] Installation Destination 6) [x] Kdump
(Automatic partitioning (Kdump is enabled)
selected) 8) [x] Root password
7) [ ] Network configuration (Password is set.)
(Not connected)
9) [ ] User creation
(No user will be created)
Please make your choice from above ['q' to quit | 'b' to begin installation |
'r' to refresh]: b
================================================================================
CentOS Linux 7 (Core)
Kernel 3.10.0-1127.el7.x86_64 on an x86_64
localhost login: root
Password:
//按“Ctrl+]”键,退出终端,回到宿主机。
[root@localhost tmp]# virsh list
Id 名称 状态
----------------------------------------------------
2 test running
[root@localhost tmp]# virsh console test
连接到域 test
换码符为 ^]
[root@localhost ~]#