制作openstack的centos7镜像

创建镜像目录,创建镜像文件,安装系统

1
2
3
4
5
mkdir /home/vms/centos7-image1

qemu-img create -f qcow2 /home/vms/centos7/centos7.qcow2 10G

virt-install --virt-type kvm --name centos7 --ram 2048 --disk /home/vms/centos7/centos7.qcow2,format=qcow2 --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --os-type=linux --os-variant=centos7.0 --location=/home/iso/CentOS-7-x86_64-Minimal-1810.iso

安装系统:
只要一个根分区,存储驱动选择Virtio Block Device,设置时区,关闭kdump,网络开启dhcp

优化:
安装epel源

1
2
3
4
yum install epel-release
yum update
yum groupinstall -y 'Development Tools'
yum install vim wget ntp

关闭防火墙和selinux,配置ntp时间同步

1
2
3
4
5
systemctl stop firewalld
systemctl disable firewalld
systemctl start ntpd
systemctl enable ntpd
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

安装电源管理服务

1
2
3
yum install acpid
systemctl start acpid.service
systemctl enable acpid.service

配置启动日志显示

1
2
3
vim /etc/default/grub
删除 rhgb quiet 增加 console=tty0 console=ttyS0,115200n8
grub2-mkconfig -o /boot/grub2/grub.cfg

Disable the zeroconf route 禁用zeroconf 路由

1
echo "NOZEROCONF=yes" >> /etc/sysconfig/network

安装配置qemu-guest-agent

1
2
3
4
yum install -y qemu-guest-agent
vim /etc/sysconfig/qemu-ga
#增加下面的配置
BLACKLIST_RPC=guest-file-open,guest-file-close,guest-file-read,guest-file-write,guest-file-seek,guest-file-flush,guest-exec,guest-exec-status

安装配置cloud 软件包

1
2
3
4
5
6
yum install cloud-init cloud-utils cloud-utils-growpart
useradd -u 1000 centos -s /sbin/nologin
vim /etc/cloud/cloud.cfg
system_info:
default_user:
name: centos

弹出cdrom

1
virsh attach-disk --type cdrom --mode readonly centos7 "" hda

封装镜像

1
2
3
yum install libguestfs-tools
virt-sysprep -d centos7
virsh undefine centos7

压缩镜像

1
virt-sparsify --compress centos7.qcow2 CentOS-7-x86_64.qcow2

上传镜像

1
openstack image create --file CentOS-7-2019.04.08.qcow2 --container-format bare --disk-format qcow2 --public Centos-7

坚持原创技术分享,您的支持将鼓励我继续创作!