kvm creates openstack image file

Common virsh maintenance commands: https://www.cnblogs.com/cyleon/p/9816989.html

openstack uses 2 – making centos7 image: https://blog.csdn.net/kwame211/article/details/79759931

kvm virtualization environment installation: https://blog.51cto.com/koumm/1288795

Centos creates kvm virtual machine: https://www.cnblogs.com/jottings/p/11831413.html

KVM virtualization: https://www.cnblogs.com/xueheng36/p/10990521.html

kvm creates virtual machine error: https://blog.csdn.net/weixin_30879169/article/details/95735499

Build kvm virtualization without desktop: https://www.jianshu.com/p/80f759885d3a/

2. Create qcow2 mirror

Upload centos7 official image: CentOS-7-x86_64-DVD-1511.iso

1. Host virtualization environment configuration

1. First enable virtualization on the host:
Execute grep -E "(vmx|svm)" /proc/cpuinfo to see whether the CPU has virtualization enabled.
For vmware virtual machines, in the virtual machine settings, click “Processor” and check “Virtualize intel VT-x/EPT or AMD-V/RVI(V)”

[root@controller ~]# grep -E "(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 ht 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 arat tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec 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 ht 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 arat tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xsaves

Then you need to turn off the firewall and selinux, and configure the yum environment. The steps are omitted.

2.Install kvm package

yum -y install kvm python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer virt-v2v --skip-broken
# Supplementary installation of some management packages for kvm virtualization
yum -y install libguestfs-tools
yum install virt-install.noarch -y

3. Check the virtualization environment

# Check libvirtd service
[root@controller ~]# systemctl start libvirtd
[root@controller ~]# systemctl status libvirtd
● libvirtd.service - Virtualization daemon
   Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2021-11-18 10:34:54 EST; 1s ago
     Docs: man:libvirtd(8)
           http://libvirt.org
 Main PID: 3935 (libvirtd)
   CGroup: /system.slice/libvirtd.service
           └─3935 /usr/sbin/libvirtd

Nov 18 10:34:54 controller systemd[1]: Starting Virtualization daemon...
Nov 18 10:34:54 controller libvirtd[3935]: libvirt version: 1.2.17, package: 13.el7_2.5 (CentOS BuildSystem <http://bugs.cento...os.org)
Nov 18 10:34:54 controller libvirtd[3935]: Module /usr/lib64/libvirt/connection-driver/libvirt_driver_lxc.so not accessible
Nov 18 10:34:54 controller systemd[1]: Started Virtualization daemon.
Hint: Some lines were ellipsized, use -l to show in full.

# Check kvm module support
[root@controller ~]# lsmod | grep kvm
kvm_intel 162153 0
kvm 525259 1 kvm_intel

# Check virtual tool version
[root@controller ~]# virsh --version
1.2.17
[root@controller network-scripts]# virt-install --version
1.2.1

2. kvm virtual machine creation

1. The host creates a system disk:

[root@controller ~]# qemu-img create -f qcow2 centos7.qcow2 16G
Formatting 'centos7.qcow2', fmt=qcow2 size=17179869184 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
[root@controller ~]# du -sh *
4.0K anaconda-ks.cfg
196K centos7.qcow2
  1. Virtual network creation
# First determine whether there is a default virtual network
[root@controller network-scripts]# virsh net-list --all
 Name State Autostart Persistent
-------------------------------------------------- --------

# Need to start if there is no default virtual network
# First determine whether /usr/share/libvirt/networks/default.xml exists. If it does not exist, do the following:
[root@controller libvirt]# mkdir -p /usr/share/libvirt/networks
[root@controller libvirt]# cd /usr/share/libvirt/networks/
[root@controller networks]# touch default.xml

# default.xml file content: (written based on openstack intranet information)
[root@controller networks]# vi default.xml
<network>
  <name>default</name>
  <bridge name="virbr0" />
  <forward/>
  <ip address="10.10.1.0" netmask="255.255.255.0">
    <dhcp>
      <range start="10.10.1.101" end="10.10.1.240" />
    </dhcp>
  </ip>
</network>

# Reload the network and activate the xml configuration
[root@controller networks]# virsh net-define /usr/share/libvirt/networks/default.xml
Network default defined from /usr/share/libvirt/networks/default.xml

# Activate network
[root@controller networks]# virsh net-autostart default
Network default marked as autostarted

[root@controller networks]# virsh net-start default
Network default started

[root@controller networks]# virsh net-list --all
 Name State Autostart Persistent
-------------------------------------------------- --------
 default active yes yes

# Check the host network card
[root@controller networks]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
eno3554960: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
        inet 10.10.1.0 netmask 255.255.255.0 broadcast 10.10.1.255
        ether 52:54:00:68:28:4c txqueuelen 0 (Ethernet)
        RX packets 0 bytes 0 (0.0 B)
        RX errors 0 dropped 0 overruns 0 frame 0
        TX packets 0 bytes 0 (0.0 B)
        TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
As shown above, there is an additional virbr0 network card

3. Manually complete the virtual network card configuration

# Create a new network card
[root@controller networks]# cd /etc/sysconfig/network-scripts/

# Modify virbr0 network card content
[root@controller network-scripts]# vi ifcfg-virbr0
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
NAME=virbr0
DEVICE=virbr0
ONBOOT=yes
NETMASK=255.255.255.0
UUID=c3295183-7dca-41a8-a60d-abf1ab7be8ed

4. Create kvm virtual machine

[root@controller opt]# pwd
/opt
[root@controller opt]# ls
CentOS-7-x86_64-DVD-1511.iso centos7.qcow2

# Execute the creation kvm operation
virt-install --virt-type kvm \
--name centos7 --ram 1024 \
--cdrom=/opt/CentOS-7-x86_64-DVD-1511.iso \
--disk path=/opt/centos7.qcow2 \
--network network=default \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole

5.vnc view connects to the virtual machine

# First download the vnc view software

# Check the qemu-kvm port
[root@controller opt]# netstat -ntpl | grep qemu-kvm
tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN 9102/qemu-kvm

# Visit 192.168.16.10:5900 to complete the virtual machine installation. Make sure to check development-tools (gcc)

# After installation and restart, the virtual machine is often shut down.
# Execute the following command to check the status
[root@controller ~]# virsh list --all

# Execute the following command to start the kvm virtual machine
[root@controller ~]# virsh start centos7

# Check the port after startup
[root@controller opt]# netstat -ntpl | grep qemu-kvm
tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN 9102/qemu-kvm

# You can use vnc to access the kvm virtual machine again
[root@controller ~]# systemctl restart sshd
[root@controller ~]# systemctl enable sshd

Three, upload openstack and use

1. Mirror upload glance

# On the control node, upload the qcow2 image to the platform through the glance command
[root@controller images]# source /etc/keystone/admin-openrc.sh
[root@controller images]# glance image-create --name "centos7" --disk-format qcow2 --container-format bare --progress < /opt/centos7.qcow2
[==============================>] 100%
 + ------------------ + ---------------------------------- -------- +
| Property | Value |
 + ------------------ + ---------------------------------- -------- +
| checksum | 8fedcc705e0f107be3376ebf57f304cd |
| container_format | bare |
| created_at | 2021-12-06T22:06:30Z |
| disk_format | qcow2 |
| id | 3023637e-045b-4833-b953-476d72f2f21b |
| min_disk | 0 |
| min_ram | 0 |
| name | centos7 |
| owner | 386dbfcf77e444c7872e4e23d5829fcc |
| protected | False |
| size | 1141178368 |
| status | active |
| tags | [] |
| updated_at | 2021-12-06T22:06:33Z |
| virtual_size | None |
| visibility | private |
 + ------------------ + ---------------------------------- -------- + 

Create a new cloud host based on the image.
Pay attention to the flavor type: the hard disk must be larger than 19G.
Pay attention to check whether all services in the dashboard: System – System Information are started.

# Service recovery command executed on the compute node - refer to the following
systemctl restart openstack-cinder-volume

systemctl restart openstack-nova-compute

service neutron-metadata-agent restart

service neutron-openvswitch-agent restart

2. Console configuration cloud host

Log in to the openstack dashboard from http://192.168.16.10/dashboard.
Project – Computing – Cloud Host, enter the cloud host management page, click the cloud host name, click Console, click Show Only Console to enter console management.

1. Modify network card information

# Modify the network card information to the ip address displayed on the platform
vi /etc/sysconfig/network-scripts/ifcfg-eth0

#Mainly modify and add the following content
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.10.1.124
NETMASK=255.255.255.0
GATEWAY=10.10.1.2
DNS=8.8.8.8

# Restart the network
systemctl restart network

2.Network configuration

# Turn off the firewall
systemctl stop firewalld
systemctl disable firewalld

# Close network management
systemctl disable NetworkManager

# Turn off selinux and modify the file to disabled
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# Modify dns configuration file
vi /etc/resolv.conf
# For other comments, add the following:
nameserver 8.8.8.8

# Modification takes effect
setenforce 0

#Network test
ping www.baidu.com

3.yum source update

# Back up the official yum source to a new directory:
mkdir /etc/yum.repos.d/repo.bak/
mv /etc/yum.repos.d/*.repo repo.bak/

# Update and download Ali source
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# Clean up yum
yum clean all
yum makecache

# Update yum information
yum update -y