Kvm basic Command 2
1) View the port corresponding to the virtual machine
[root@localhost ~]# virsh vncdisplay test01:0:0====5900:1====5901
2) Suspend virtual machine
[root@localhost ~]# virsh suspend test01//suspend
[root@localhost ~]# virsh resume test01//resume
3) Start the machine automatically
[root@localhost ~]# virsh dominfo test01//See details
[root@localhost ~]# virsh autostart test01//boot
[root@localhost ~]# virsh dominfo test01//See details
test
[root@localhost ~]# reboot
//restart
[root@localhost ~]# virsh list
[root@localhost autostart]# cd /etc/libvirt/qemu/autostart[root@localhost autostart]# ll
4) Cancel startup and self-start
[root@localhost autostart]# virsh autostart --disable test01//cancel boot
[root@localhost autostart]# cd /etc/libvirt/qemu/autostart[root@localhost autostart]# ll
5) console login (xshell)
//Add to KVM domain
[root@localhost ~]# grubby --update-kernel=ALL --args="console=ttyS0"
Test it in xshell
[root@localhost autostart]# virsh console test01//Log in to the virtual machine. If you cannot log in, you can restart the kvm virtual machine.
If it doesn't, restart libvirtd.
[root@localhost ~]# systemctl restart libvirtd//Restart disk management on the host
RAW:(Naked Format) Default
It takes up a large space and has good performance, but it does not support snapshot function.
QCOW2:(copy on write)
Small footprint, support snapshot, performance is slightly worse than RAW.
Test Create Disk
Create disk: (default bare format)
[root@localhost ~]# mkdir /xgp #Create Test Directory [root@localhost ~]# cd /xgp/ #Enter Test Directory [root@localhost xgp]# qemu-img create 123.raw 5g #Create Disk
To view disk information:
[root@localhost xgp]# qemu-img info 123.raw
To create a disk in the specified format:
[root@localhost xgp]# qemu-img create -f qcow2 bdqn.qcow2 5g
Convert disk format:
[root@localhost xgp]# cd /kvm-vm/ #Enter disk file [root@localhost kvm-vm]# virsh destroy test01 #Shut down virtual machine [root@localhost kvm-vm]# qemu-img convert -f raw -O qcow2 centos.raw centos.qcow2//Convert disk format to qcow2
Take a snapshot:
[root@localhost kvm-vm]# virsh edit test01
[root@localhost kvm-vm]# virsh snapshot-create test01 Domain snapshot generated 1575255005 View snapshot information: [root@localhost kvm-vm]# virsh snapshot-list test01 Name generation time Status----------------------------------------------------- 1575255005 2019-12-02 10:50:05 +0800 shutoff timestamp: 1970: C language born, linux system born Kvm make some mistakes rm -rf /*xshell restore system according to snapshot: [root@localhost kvm-vm]# virsh snapshot-list test01 name generation time Status----------------------------------------------------- 1575255005 2019-12-02 10:50:05 +0800 shutoff 1575255330 2019-12-02 10:55:30 +0800 shutoff[root@localhost kvm-vm]# virsh snapshot-revert test01 1575255330 Delete snapshot: [root@localhost kvm-vm]# virsh snapshot-delete test01 1575255330
1)Enter the test1 virtual machine domain, set it to ping the periphery, and then deploy an httpd service, and change its default access interface content to: test+ own name.
Set it to ping the perimeter
Modify the network configuration of the kvm virtual machine
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# systemctl restart network
//Restart the network
Testing for connectivity
[root@localhost ~]# ping baidu.com
Deploy an httpd service and change its default access interface content to: test+ own name
Find epel on Ali mirror site https://developer.aliyun.com/mirror and copy one inside.
yum source for epel(RHEL 7) wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
Yum source performing replication on host
[root@localhost kvm-vm]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
Kvm virtual machine installation httpd
[root@localhost ~]# yum -y install httpd[root@localhost ~]# vi /var/www/html/index.html
//Create a test page
[root@localhost ~]# systemctl start httpd
//Open httpd service
2) Take a snapshot of the VM domain test1, although the disk type needs to be reformatted.
Convert disk format:
[root@localhost xgp]# cd /kvm-vm/ #Enter disk file [root@localhost kvm-vm]# virsh destroy test01 #Shut down virtual machine [root@localhost kvm-vm]# qemu-img convert -f raw -O qcow2 centos.raw centos.qcow2//Convert disk format to qcow2
[root@localhost kvm-vm]# virsh snapshot-create test01//take snapshot
3) What should I do if I want to be able to access HTTP services in the KVM domain?
The host does nginx reverse proxy
29 rz 30 tar zxf nginx-1.14.0.tar.gz 31 cd nginx-1.14.0/ 33 yum -y install gcc gcc-c++ autoconf automake make 35 yum -y install openssl-devel pcre-devel zlib-devel 36 ./ configure --prefix=/usr/local/nginx1.14 && make && make install 37 ln -s /usr/local/nginx1.14/sbin/nginx /usr/local/sbin/ 38 nginx 40 netstat -anpt | grep nginx
//host install nginx and turn on
[root@localhost ]# vim /usr/local/nginx1.14/conf/nginx.conf //point to http server [root@localhost nginx]# vim /etc/nginx/nginx.conf Add upstream backend {server 192.168.122.243:80 weight=1 max_failures =2 fail_timeout=10s;} Add Location module location / { #root html; #index index.html index.htm;proxy_pass http://backend; # nginx -s reload//Restart nginx
browser accesses
Experiment complete.