如何在OpenStack上运行CentOS 8实例

时间:2020-02-23 14:31:25  来源:igfitidea点击:

如何将CentOS 8云/KVM镜像添加到OpenStack ?,如何在OpenStack上运行CentOS 8实例/VM? Openstack Glance服务使用户可以发现,注册和检索虚拟机镜像。这些图像的默认存储位置是/var/lib/glance/images /,其后端是文件。在本教程中,我们将CentOS 8 KVM云镜像上传到Openstack Glance服务。

CentOS 8的Vagrant和Cloud镜像在CentOS Linux 8(1911)向公众开放时发布。该版本源自Red Hat Enterprise Linux 8.1源代码。 CentOS 8和CentOS 8 Stream都可以从cloud.centos.org获得Cloud镜像。

OpenStack Glance支持以下图像格式:原始(非结构化格式)qcow2(Qemu/KVM,支持写时复制)iso(光盘的存档格式)vhd(Hyper-V,虚拟机通用来自VMware,Xen,Microsoft,VirtualBox等的监视器)vdi(Qemu/VirtualBox)vmdk(VMware)裸机(不包含元数据)aki/ami/ari(Amazon内核,ramdisk或者机器镜像)等

将CentOS 8 Cloud Image上载到OpenStack Glance

安装wget以下载云镜像:

--- Debian/Ubuntu --
$sudo apt install -y wget

--- CentOS/Fedora --
$sudo yum -y install wget
$sudo dnf -y install wget

从cloud.centos.org下载最新的Cloud镜像。

--- CentOS 8 Linux x86_64 --
wget https://cloud.centos.org/centos/8/x86_64/images/CentOS-8-GenericCloud-8.1.1911-20170113.3.x86_64.qcow2

--- CentOS 8 Stream Linux x86_64 --
wget https://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-20170113.0.x86_64.qcow2

在上传之前,我们可以使用我们的教程作为参考来进一步自定义qcow2图像。

如何使用virt-customize自定义Qcow2/Raw Linux OS磁盘镜像

然后打开openstack环境。

source ~/.keystonerc

并将CentOS 8 Cloud Images上传到OpenStack Glance。

--- CentOS 8 Linux x86_64 --
$openstack image create \
    --container-format bare \
    --disk-format qcow2 \
    --file CentOS-8-GenericCloud-8.1.1911-20170113.3.x86_64.qcow2 \
    CentOS-8

--- CentOS 8 Stream Linux x86_64 --
$openstack image create \
    --container-format bare \
    --disk-format qcow2 \
    --file CentOS-Stream-GenericCloud-8-20170113.0.x86_64.qcow2\
    CentOS-8-Stream

如果我们没有OpenStack CLI,请检查:如何在Linux上安装和配置OpenStack Client

确认图像是否在Glance中可用:

$openstack image list | grep CentOS-8
| adb61f0c-665e-481a-b689-e32414338415 | CentOS-8        | active |
| 031231af-97e4-4801-b171-fc1b6fc3245d | CentOS-8-Stream | active |

我们还可以使用Horizon Web界面上载图像导航到"项目">"计算">"图像">"创建图像"

提供图像名称,描述,浏览并从源中选择图像,选择图像可见性,然后单击"创建图像"按钮。

上载图像后,"图像"部分下将提供详细信息。

现在,我们可以从上传的图像启动实例。请参见以下示例:

$openstack server create \
 --image CentOS-8 \
 --key-name jmutai \
 --flavor m1.small \
 --security-group  7fffea2a-b756-473a-a13a-249dd0f1923a  \
 --network private  \
 mycentos8

确认服务器创建:

$openstack server list 
+--------------------------------------+-------------------+---------+-----------------------------------+-----------+----------+
| ID                                   | Name              | Status  | Networks                          | Image     | Flavor   |
+--------------------------------------+-------------------+---------+-----------------------------------+-----------+----------+
| 9e1e1b14-db2c-405e-9361-6b3b08c507b8 | mycentos8         | ACTIVE  | private=10.10.1.138               | CentOS-8  | m1.small |
+--------------------------------------+-------------------+---------+-----------------------------------+-----------+----------+

让我们测试一下是否可以ssh到创建的服务器。

$ssh theitroad@localhost
Warning: Permanently added '10.10.1.138' (ECDSA) to the list of known hosts.
Enter passphrase for key '/home/jmutai/.ssh/id_rsa': 
Activate the web console with: systemctl enable --now cockpit.socket

[theitroad@localhost ~]$cat /etc/os-release 
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

[theitroad@localhost ~]$exit
logout
Connection to 10.10.1.138 closed.

我们可以通过检查/etc/os-release内容来确认已登录到CentOS 8实例。