kvm创建openstack镜像文件
virsh常用维护命令:https://www.cnblogs.com/cyleon/p/9816989.html
openstack使用2——制作centos7镜像:https://blog.csdn.net/kwame211/article/details/79759931
kvm虚拟化环境安装:https://blog.51cto.com/koumm/1288795
centos创建kvm虚拟机:https://www.cnblogs.com/jottings/p/11831413.html
KVM虚拟化:https://www.cnblogs.com/xueheng36/p/10990521.html
kvm创建虚拟机报错:https://blog.csdn.net/weixin_30879169/article/details/95735499
无桌面搭建kvm虚拟化:https://www.jianshu.com/p/80f759885d3a/
二、创建qcow2镜像
上传centos7官方镜像:CentOS-7-x86_64-DVD-1511.iso
1、宿主机虚拟化环境配置
1.首先要开启宿主机的虚拟化:
执行 grep -E "(vmx|svm)" /proc/cpuinfo
,可以看CPU有没有开启虚拟化
vmware虚拟机的话,在虚拟机设置里,点击“处理器”,勾选 "虚拟化 intel VT-x/EPT 或 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
随后需要关闭防火墙和selinux、配置yum环境,步骤略。
2.安装kvm软件包
yum -y install kvm python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer virt-v2v --skip-broken
# 补充安装kvm虚拟化的一些管理包
yum -y install libguestfs-tools
yum install virt-install.noarch -y
3.检查虚拟化环境
# 检查libvirtd服务
[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.
# 检查kvm模块支持
[root@controller ~]# lsmod | grep kvm
kvm_intel 162153 0
kvm 525259 1 kvm_intel
# 检查虚拟工具版本
[root@controller ~]# virsh --version
1.2.17
[root@controller network-scripts]# virt-install --version
1.2.1
2、kvm虚拟机创建
1.宿主机创建系统盘:
[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
- 虚拟网络创建
# 首先判断是否有默认虚拟网络
[root@controller network-scripts]# virsh net-list --all
Name State Autostart Persistent
----------------------------------------------------------
# 在没有默认虚拟网情况下需要启动
# 首先判断/usr/share/libvirt/networks/default.xml是否存在,不存在如下操作:
[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文件内容:(根据openstack内网信息编写)
[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>
# 重新加载网络并激活xml配置
[root@controller networks]# virsh net-define /usr/share/libvirt/networks/default.xml
Network default defined from /usr/share/libvirt/networks/default.xml
# 激活网络
[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
# 检查宿主机网卡
[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
如上所示,多了一个virbr0网卡
3、手动完成虚拟网卡配置
# 创建一个新网卡
[root@controller networks]# cd /etc/sysconfig/network-scripts/
# 修改virbr0网卡内容
[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.创建kvm虚拟机
[root@controller opt]# pwd
/opt
[root@controller opt]# ls
CentOS-7-x86_64-DVD-1511.iso centos7.qcow2
# 执行创建kvm操作
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 连接虚拟机
# 首先下载vnc view软件
# 查看qemu-kvm端口
[root@controller opt]# netstat -ntpl | grep qemu-kvm
tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN 9102/qemu-kvm
# 访问192.168.16.10:5900,完成虚拟机安装,注意勾选上development-tools(gcc)
# 安装重启后,虚拟机往往是关机状态
# 执行如下命令查看状态
[root@controller ~]# virsh list --all
# 执行如下命令启动kvm虚拟机
[root@controller ~]# virsh start centos7
# 启动后查看端口
[root@controller opt]# netstat -ntpl | grep qemu-kvm
tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN 9102/qemu-kvm
# 即可再次用vnc访问kvm虚拟机
[root@controller ~]# systemctl restart sshd
[root@controller ~]# systemctl enable sshd
三、上传openstack使用
1、镜像上传glance
# 在控制节点,通过glance命令,将qcow2镜像上传到平台
[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 |
+------------------+--------------------------------------+
基于镜像创建新的云主机。
注意flavor类型:硬盘要大于19G。
注意检查dashboard上:系统——系统信息里面所有服务是否启动。
# 在compute节点上执行的服务恢复命令——如下参考
systemctl restart openstack-cinder-volume
systemctl restart openstack-nova-compute
service neutron-metadata-agent restart
service neutron-openvswitch-agent restart
2、控制台配置云主机
从 http://192.168.16.10/dashboard 登录openstack的dashboard。
项目——计算——云主机,进入云主机管理页面,点击 云主机名称 ,点击 控制台,点击只显示控制台进入控制台管理。
1.修改网卡信息
# 将网卡信息修改为平台上显示的ip地址
vi /etc/sysconfig/network-scripts/ifcfg-eth0
# 主要修改和增加如下内容
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.10.1.124
NETMASK=255.255.255.0
GATEWAY=10.10.1.2
DNS=8.8.8.8
# 重启网络
systemctl restart network
2.网络配置
# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
# 关闭网络管理
systemctl disable NetworkManager
# 关闭selinux,修改文件为disabled
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# 修改dns配置文件
vi /etc/resolv.conf
# 其他注释,添加如下内容:
nameserver 8.8.8.8
# 修改生效
setenforce 0
# 网络测试
ping www.baidu.com
3.yum源更新
# 将官方的yum源备份到一个新目录:
mkdir /etc/yum.repos.d/repo.bak/
mv /etc/yum.repos.d/*.repo repo.bak/
# 更新下载阿里源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 清理yum
yum clean all
yum makecache
# 更新yum信息
yum update -y