Official: http: //www.linux-kvm.org
About a KVM
KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko.
Using KVM, one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.
KVM is open source software. The kernel component of KVM is included in mainline Linux, as of 2.6.20. The userspace component of KVM is included in mainline QEMU, as of 1.3.
Two KVM installation
See if cpu virtualization support
# Grep -E 'VMX | svm' / proc / cpuinfo
Vmx which is intel, svm to amd
installation
# yum install qemu-kvm qemu-kvm-tools qemu-img virt-manager libvirt libvirt-python libvirt-client bridge-utils virt-viewer virt-install
start up
# Lsmod | grep sqm
# systemctl start libvirtd
Three modify user
# vi /etc/libvirt/qemu.conf
#user = "root"
#group = "root"
More than two lines uncommented
# systemctl restart libvirtd
Four download centos
http://isoredirect.centos.org/centos/7/isos/x86_64/
Recommended Mirror: http: //mirrors.cqu.edu.cn/CentOS/7.7.1908/isos/x86_64/
Centos install five
1 nat way
# virt-install --name=$myname --memory=61440,maxmemory=61440 --vcpus=16,maxvcpus=16 --os-type=linux --os-variant=rhel7 --location=/root/CentOS-7-x86_64-Minimal-1908.iso --disk path=/kvm/$myname/root.img,size=150 --disk path=/data1/$myname/data1.img,size=300 --bridge=virbr0 --graphics=none --console=pty,target_type=serial --extra-args="console=tty0 console=ttyS0"
Note:
. 1) - = virbr0 bridge, the bridge is automatically installed using kvm virbr0;
2) may be configured as required plurality --disk, size units of G, in the simplest case only needs to be configured to install a disk system;
2 bridge mode
1 Configure bridge
# cat /etc/sysconfig/network-scripts/ifcfg-br0 DEVICE=br0 ONBOOT=yes TYPE=Bridge BOOTPROTO=static IPADDR=192.168.1.100 GATEWAY=192.168.1.1 DNS1=192.168.1.1 DEFROUTE=yes
2 Modify eth0
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Finally, additional
BRIDGE = br0
3 Restart network
# systemctl restart network
4 View bridge
# brctl show
5 install centos
# virt-install --name=$myname --memory=61440,maxmemory=61440 --vcpus=16,maxvcpus=16 --os-type=linux --os-variant=rhel7 --location=/root/CentOS-7-x86_64-Minimal-1908.iso --disk path=/kvm/$myname/root.img,size=150 --disk path=/data1/$myname/data1.img,size=300 --bridge=br0 --graphics=none --console=pty,target_type=serial --extra-args="console=tty0 console=ttyS0"
Note: - bridge = br0, using the br0 just created;
PS: If the first nat way to install centos, you want to modify the bridge, you can modify
1) via the command
# virsh edit $myname <interface type='bridge'> <mac address='52:54:00:e7:32:0d'/> <source bridge='br0'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
Modify type as bridge, modify the bridge to br0
2) to directly modify file
# We /etc/libvirt/qemu/$myname.xml
After the modification restart
# sytemctl restart libvirtd
Six text interface to install centos
1 initial interface
================================================================================ ================================================================================ Installation 1) [x] Language settings 2) [!] Time settings (English (United States)) (Timezone is not set.) 3) [!] Installation source 4) [!] Software selection (Processing...) (Processing...) 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]: [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1
Note: is optional, you can complete the configuration changes in numerical and tips; [!]
2 partitions on the way
Wherein 5) [!] Installation Destination need to select the partition mode, text mode can not customize the size of each partition, automatic partitioning logic / directory 50G, other points to / home directory, if you want to install adjust the default partition size, to where select LVM
================================================================================ ================================================================================ 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...
3 Preparing to Install
================================================================================ ================================================================================ 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 [anaconda] 1:main* 2:shell 3:log 4:storage-lo> Switch tab: Alt+Tab | Help: F1
Until the installation is complete;
Seven adjust the default disk partition size
The default partition size is / directory 50G, are distributed to the other / home directory, if you want to adjust, operation is as follows
# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 30G 0 30G 0% /dev tmpfs 30G 0 30G 0% /dev/shm tmpfs 30G 8.6M 30G 1% /run tmpfs 30G 0 30G 0% /sys/fs/cgroup /dev/mapper/centos-root 50G 1.3G 49G 2% / /dev/vda1 1014M 149M 866M 15% /boot /dev/mapper/centos-home 84G 33M 84G 1% /home tmpfs 5.9G 0 5.9G 0% /run/user/0 # umount /home # lvremote /dev/mapper/centos-home # lvextend -L +50G /dev/mapper/centos-home # xfs_growfs /dev/mapper/centos-root # lvcreate -L 34G -n home centos # mkfs.xfs /dev/centos/home # mount /dev/mapper/centos-home # df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 30G 0 30G 0% /dev tmpfs 30G 0 30G 0% /dev/shm tmpfs 30G 8.6M 30G 1% /run tmpfs 30G 0 30G 0% /sys/fs/cgroup /dev/mapper/centos-root 100G 1.3G 99G 2% / /dev/vda1 1014M 149M 866M 15% /boot /dev/mapper/centos-home 34G 33M 34G 1% /home tmpfs 5.9G 0 5.9G 0% /run/user/0
Eight network
1 nat way
carried out
# dhclient eth0
To the Internet
[root@test ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 52:54:00:aa:f7:c1 brd ff:ff:ff:ff:ff:ff [root@test ~]# dhclient eth0 [root@test ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 52:54:00:aa:f7:c1 brd ff:ff:ff:ff:ff:ff inet 192.168.122.13/24 brd 192.168.122.255 scope global dynamic eth0 valid_lft 3597sec preferred_lft 3597sec [root@test ~]# ping www.baidu.com PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data. 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=53 time=23.9 ms
2 bridge mode
1) Set a static ip
# cat /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE=Ethernet BOOTPROTO=static DEFROUTE=yes NAME=eth0 UUID=0a67f932-b328-49ce-8166-af12fb0b482f DEVICE=eth0 ONBOOT=yes IPADDR=192.168.1.101 GATEWAY=192.168.1.1 DNS1=192.168.1.1 DEFROUTE=yes
2) Restart Network
# systemctl restart network
3 connectivity between) the test host (192.168.1.100) and virtual machine (192.168.1.101)
Nine commonly used commands
Set automatic restart kvm
# systemctl enable libvirtd
virsh related
# virsh list --all # virsh console $myname # virsh start $myname # virsh shutdown $myname # virsh destroy $myname # virsh undefine $myname
After entering the virtual machine you can install some commonly used commands, such as ifconfig
# yum install net-tools
Finally virsh may be connected by a host virtual machine, or remotely connected via 192.168.1.101 virtual machine;
Reference:
http://www.linux-kvm.org/page/Main_Page