Kvm installation and deployment connect to KVM through ssh, and deploy nginx in KVM, and can successfully access
Environmental preparation
The release version memory is preferably 3g or more
- 7.4 above are supported (including 7.4)
[root@localhost tmp]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
Turn off firewall
systemctl stop firewalld
Close selinux
setenforce 0
kvm introduction
Continue to the previous article: What is a kvm virtual machine
Install kvm virtual machine
1. Modify virtual machine settings before turning on VMware
Focus
2. Turn on the virtual machine and check whether the system supports virtualization.
If vmx and svm appear, they support
> [root@localhost ~]# cat /proc/cpuinfo | egrep 'vmx|svm'
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat
pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt pdpe1gb
rdtscp lm constant_tsc art rep_good nopl tsc_reliable nonstop_tsc
extd_apicid eagerfpu pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic
movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm svm extapic
cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw perfctr_core
retpoline_amd ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed
adx smap clflushopt clwb sha_ni xsaveopt xsavec clzero arat npt
svm_lock nrip_save vmcb_clean flushbyasid decodeassists overflow_recov
succor
3. Install and start KVM
yum install -y qemu-kvm libvirt virt-install
systemctl start libvirtd
systemctl enable libvirtd
4. Create a storage file
qemu-img create -f raw /opt/CentOS-7-x86_64.raw 10G
5. Upload system files to /tmp/
6. Install the virtual machine
> virt-install --virt-type kvm --name CentOS-7-x86_64 --ram 1536
> --cdrom=/tmp/CentOS-7-x86_64-Minimal-2003.iso --disk path=/opt/CentOS-7-x86_64.raw --network bridge=br0 --graphics
> vnc,listen=0.0.0.0 --noautoconsole
note! !
If the same error occurs, the bridge is not configured
Solution
First: create directly ! Execution failed, execute the next one!
[root@localhost ~]# virsh iface-bridge ens33 br0
Second: manual configuration
Configure physical network card
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=ens33
DEVICE=ens33
ONBOOT=yes
BRIDGE="br0"
Configure bridged network card
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-br0
TYPE=Bridge
PROXY_METHOD=none
BROSWER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=br0
DEVICE=br0
ONBOOT=yes
Restart network
systemctl restart network
Get IP to
create virtual machine
> virt-install --virt-type kvm --name CentOS-7-x86_64 --ram 1536
> --cdrom=/tmp/CentOS-7-x86_64-Minimal-2003.iso --disk path=/opt/CentOS-7-x86_64.raw --network bridge=br0 --graphics
> vnc,listen=0.0.0.0 --noautoconsole
7. Open VNC and use the above IP connection
8. Start the kvm virtual machine
9. Connect to view again through VNC
Now the bridge method is adopted, there is no ip, you need to get ip
10. Restart the network
systemctl restart network
Check ip again
ip addr
12. Connect to this ip through ssh
13. Close the firewall
systemctl stop firewalld
Install nginx on kvm and
upload nginx.repo to /etc/yum.repos.d/
to connect: nginx yum source nginx.repo
yum makecache fast
yum -y install nginx
nginx -t
nginx
yum -y install net-tools
netstat -lptnu