欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 明星 > openstack下如何生成centos9 centos10 和Ubuntu24 镜像

openstack下如何生成centos9 centos10 和Ubuntu24 镜像

2025/6/8 5:07:10 来源:https://blog.csdn.net/wzlsunice88/article/details/145059920  浏览:    关键词:openstack下如何生成centos9 centos10 和Ubuntu24 镜像

如何生成一个centos 10和centos 9 的镜像
1. 下载  对应的版本
wget https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-x86_64-10-latest.x86_64.qcow2
 wget https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-20241216.0.x86_64.qcow2
2 生成镜像
   glance image-create --name centos10 --disk-format=qcow2 --container-format=bare  --file=/root/CentOS-Stream-GenericCloud-10-latest.x86_64.qcow2
   glance image-create --name centos9 --disk-format=qcow2 --container-format=bare  --file=/root/CentOS-Stream-GenericCloud-9-20241216.0.x86_64.qcow2
  由于镜像的root密码不知道,通过下面的命令不能改变密码。
  systemctl start libvirtd
  export LIBGUESTFS_BACKEND=direct
  virt-customize -a CentOS-Stream-GenericCloud-10-latest.x86_64.qcow2 --root-password password:xxxxx
但是通过此命令改变ubuntu镜像的root密码
   virt-customize -a noble-server-cloudimg.img --root-password password:XXX
3 生成虚拟机
 nova boot  --image centos10  --flavor 4cpu8G-disk50G   --security-groups default --availability-zone nova:controller02 --nic net-name=provider,v4-fixed-ip=10.0.41.13 k8s-master03
4  修改root密码(10和9版本一样)
重启虚拟机,
在 grub 界面按字母e
找到 linux 一行,这一行中加入 init=/bin/bash, 并删掉 console=tty0 console=ttyS0,115200, 把 ro 改为 rw
按 ctrl + x 继续启动
这时就可以直接登录到系统里面,
mount -o remount,rw /
passwd root  修改密码
touch /.autorelabel(一定要使用这个命令,不然不能生效)
exec /sbin/init
硬重启操作系统 nova reboot --hard
5 修改网络
   由于默认是dhcp获取网络地址,需要指定网络地址,所以需要做如下的修改
   去掉 cloud-init服务
    rpm -qa | grep cloud-init 查看 是否有此服务
   yum remove cloud-init    
10版本
   vi  /etc/NetworkManager/system-connections/ens3.nmconnection  内容如下:
[ipv4]
#method=auto
method=manual
address1=10.0.41.13/26
dns=10.2.10.1,10.2.10.2
gateway=10.0.41.1
必修修改同一个目录下cloud-init-ens3.nmconnection,修改文件名也没有作用,修改内容如下:
[ipv4]
method=manual
may-fail=true
把auto 修改为上面的manual ,不然会生效 dhcp获得地址。
9 版本
  修改/etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=static
IPADDR=10.0.41.14
NETMASK=255.255.255.192
GATEWAY=10.0.41.1
一定要去掉mac地址这行不然设置静态地址不成功

6   修改ssh,可以使用密码登陆
   vi /etc/ssh/sshd_config
PermitRootLogin yes
PasswordAuthentication yes
还需要修改/etc/ssh/sshd_config.d/50-cloud-init.conf,不然也无法登陆
PasswordAuthentication yes    # no 修改为yes
systemctl  restart sshd
7 如果可以用用户名密码登陆,可以生产虚拟机,虚拟机可以快照,快照可以生产镜像。
可以拿快照或者镜像生产虚拟机

glance image-create --name "CentOS10-2025-1-6" --file  /var/lib/glance/images/12fa35d2-6507-4baa-ac68-2e828d702e92 --disk-format qcow2 --container-format bare --visibility public --progres
------------------------------------------------
如何生产一个ubuntu 24

1. 下载对应的版本
wget https://cloud-images.ubuntu.com/daily/server/server/noble/current/noble-server-cloudimg-amd64.img
2 设置root密码
      由于镜像的root密码不知道,通过下面的命令改变密码。
  systemctl start libvirtd
  export LIBGUESTFS_BACKEND=direct
   virt-customize -a noble-server-cloudimg.img --root-password password:XXX
3  配置网络
vi  /etc/netplan/50-cloud-init.yaml
network:
  version: 2
  ethernets:
    ens3:
      match:
        macaddress: "fa:16:3e:ec:35:23"
      dhcp4: no
      dhcp6: no
      addresses: [10.0.41.12/24]
      gateway4: 10.0.41.1
      nameservers:
        addresses: [10.2.10.1, 10.2.10.2]
      set-name: "ens3"
命令
netplan apply
4 修改ssh,允许用户名密码登陆
用户名和密码登陆修改如下的配置文件
/etc/ssh/sshd_config.d/60-cloudimg-settings.conf
还需要修改/etc/ssh/sshd_config, 修改见上面

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词