背景:业务方需求须要ubuntu 18.4版本的系统linux
下载ubuntu 18.4wget http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/current/images/netboot/mini.iso
web
经过镜像建立kvm虚拟机(kvm的环境安装不做介绍了,几个yum的事情,前提要在biso开启cpu虚拟化)virt-install --virt-type kvm --name ubuntu --ram 1024 --cdrom=/vm/iso/ubuntu-mini.iso --disk /vm/vm/ubuntu/os.img,bus=virtio,size=4,format=qcow2 --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --os-type=linux --os-variant=ubuntu18.04
ubuntu
经过控制台配置安装vim
设置ip
配置主机名
添加用户ubuntucentos
选在openssh server便可网络
系统安装完成ssh
添加管理keyionic
root@ubuntu:/home/ubuntu/.ssh# find / -name authorized_keys /root/.ssh/authorized_keys /home/ubuntu/.ssh/authorized_keys
关闭用户登陆,开启key登陆
vim /etc/sshd/sshd_config
找到PubkeyAuthentication 改成yes //开启密钥登录
找到PasswordAuthentication 改成no //关闭密码登录ide
关闭防火墙和selinux测试
root@ubuntu:~# ufw disable Firewall stopped and disabled on system startup root@ubuntu:~# root@ubuntu:~# getenforce Disabled
安装cloud-init包apt install cloud-init -y
设置镜像使用的元数据源,运行 dpkg-reconfigure命令cloud-init。出现提示时,选择EC2数据源:dpkg-reconfigure cloud-init
网络设置dhcp获取 /etc/netplan/01-netcfg.yaml
network: versiom: 2 renderer: networkd ethernets: ens3: dhcp4:yes
编辑/etc/default/grub文件并配置 GRUB_CMDLINE_LINUX选项。让openstack能获取日志GRUB_CMDLINE_LINUX=" console=ttyS0,115200n8"
更新grub文件
update-grub
关机,清理mac等信息
virt-sysprep -d bionic
查看磁盘格式。咱们不用qcow2的格式,使用raw格式,2种的区别能够去google下。
转换磁盘格式
[root@tbj*** ubuntu-18.4]# qemu-img info os.img image: os.img file format: qcow2 virtual size: 4.0G (4294967296 bytes) disk size: 2.2G cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: true refcount bits: 16 corrupt: false [root@tbj*** ubuntu-18.4]# qemu-img convert -f qcow2 -O raw os.img ubuntu-18.4.raw [root@tbj*** ubuntu-18.4]# qemu-img info ubuntu-18.4.raw image: ubuntu-18.4.raw file format: raw virtual size: 4.0G (4294967296 bytes) disk size: 2.1G [root@tbj*** ubuntu-18.4]#
将作好的raw文件上传到openstack控制节点生成镜像。openstack image create "ubuntu-18.04" --file /root/ubuntu-18.4.raw --disk-format raw
web界面已经能够看到这个镜像了
添加完成
[root@wuhan31-ceph01 ~]# openstack image list +--------------------------------------+--------------------------------+--------+ | ID | Name | Status | +--------------------------------------+--------------------------------+--------+ | 0e548332-80a5-4d57-85a5-d4dee50b52fa | centos-7-x86_64-antiy-20190508 | active | | 2dd5b64b-0b9d-433a-8b64-e1553d704c2c | online | active | | 099824a6-2081-48a5-b871-740adff8b297 | ubuntu-18.04 | active | +--------------------------------------+--------------------------------+--------+ [root@wuhan31-ceph01 ~]#
测试:
使用这个镜像建立虚拟机
日志正常
启动正常