Openstack Liberty Lab第8部分:添加VM映像

在本系列的这一部分中,您将完成添加用于在Openstack Cloud platorm中插入虚拟机的映像的完整过程。 演示如何使用virt-install工具从ISO映像安装和导出OS。我认为您已经涵盖了该系列的所有其他部分。它们包括:

Openstack Liberty Lab第1部分:网络设置和所有先决条件

Openstack Liberty Lab第2部分:安装Openstack软件包

Openstack Liberty Lab第3部分:配置Keystone ID服务

Openstack Liberty Lab第4部分:配置Glance映像服务

Openstack Liberty Lab第5部分:配置Nova计算服务

Openstack Liberty Lab第6部分:配置Neutron网络服务

Openstack Liberty Lab第7部分:配置Horizo​​n仪表板服务

让我们仔细看看创建和上传虚拟机映像的过程。 使用virt-install命令执行所有安装。 要使用virt-install命令,您需要在系列的第1部分和第2部分中安装所有KVM软件包。如果您没有这样做,则可以在这里进行:对于Ubuntu / Debian系统:

[[email protected] ~]# apt-get -y install virtinst qemu-kvm bridge-utils libvirt-bin

对于RHEL / CentOS 7:

对于Arch Linux,请阅读以下内容。

在Arch Linux和Manjaro上完全安装KVM,QEMU和VirtManager

现在,您可以创建一个虚拟机映像,您可以一眼看到。 描述Ubuntu 14.04和CentOS 7.2服务器的映像文件的安装。

CentOS的

首先,将CentOS 7iso映像复制到/ var / lib / libvirt / images /。 您可以从CentOS的官方页面下载它。

下载CentOS

[[email protected] ~]# cp /home/josepy/Kvm images/CentOS-7-x86_64-Minimal-1503-01.iso /var/lib/libvirt/images/
  1. 创建一个qcow2映像磁盘。
[[email protected] ~]# qemu-img create -f qcow2 /var/lib/libvirt/images/centos-server.qcow2 10G
  1. 使用virt-install命令安装CentOS 7。
virt-install 
--name centos-server 
--ram 1024 
--disk path=/var/lib/libvirt/images/centos-server.qcow2 
--vcpus 1 
--os-type linux 
--os-variant rhel7 
--graphics none 
--console pty,target_type=serial 
--location /var/lib/libvirt/images/CentOS-7-x86_64-Minimal-1503-01.iso 
--extra-args 'console=ttyS0,115200n8 serial'

样本输出:

Starting install...
Retrieving file .treeinfo... | 1.1 kB 00:00:00 
Retrieving file vmlinuz... | 4.8 MB 00:00:00 
Retrieving file initrd.img... | 34 MB 00:00:00 
Creating domain... | 0 B 00:00:05 
Connected to domain centos-server
Escape character is ^]
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 3.10.0-229.el7.x86_64 ([email protected]) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #1 SMP Fri Mar 6 11:36:42 UTC 2015
[ 0.000000] Command line: console=ttyS0,115200n8 serial
[ 0.000000] e820: BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000003ffd8fff] usable
[ 0.000000] BIOS-e820: [mem 0x000000003ffd9000-0x000000003fffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
[ 0.000000] NX (Execute Disable) protection: active
[ 0.000000] SMBIOS 2.8 present.
[ 0.000000] Hypervisor detected: KVM
[ 0.000000] No AGP bridge found
[ 0.000000] e820: last_pfn = 0x3ffd9 max_arch_pfn = 0x400000000
[ 0.000000] x86 PAT enabled: cpu 0, old 0x7040600070406, new 0x7010600070106
[ 0.000000] found SMP MP-table at [mem 0x000f6b40-0x000f6b4f] mapped at [ffff8800000f6b40]
[ 0.000000] init_memory_mapping: [mem 0x00000000-0x000fffff]
[ 0.000000] init_memory_mapping: [mem 0x3da00000-0x3dbfffff]
[ 0.000000] init_memory_mapping: [mem 0x3c000000-0x3d9fffff]
[ 0.000000] init_memory_mapping: [mem 0x00100000-0x3bffffff]
[ 0.000000] init_memory_mapping: [mem 0x3dc00000-0x3ffd8fff]
[ 0.000000] RAMDISK: [mem 0x3ddb9000-0x3ffcffff]
[ 0.000000] ACPI: RSDP 00000000000f6960 00014 (v00 BOCHS )
[ 0.000000] ACPI: RSDT 000000003ffe1647 00030 (v01 BOCHS BXPCRSDT 00000001 BXPC 00000001)
[ 0.000000] ACPI: FACP 000000003ffe0bda 00074 (v01 BOCHS BXPCFACP 00000001 BXPC 00000001)
[ 0.000000] ACPI: DSDT 000000003ffe0040 00B9A (v01 BOCHS BXPCDSDT 00000001 BXPC 00000001)
[ 0.000000] ACPI: FACS 000000003ffe0000 00040
[ 0.000000] ACPI: SSDT 000000003ffe0c4e 00981 (v01 BOCHS BXPCSSDT 00000001 BXPC 00000001)
[ 0.000000] ACPI: APIC 000000003ffe15cf 00078 (v01 BOCHS BXPCAPIC 00000001 BXPC 00000001)
[ 0.000000] No NUMA configuration found
[ 0.000000] Faking a node at [mem 0x0000000000000000-0x000000003ffd8fff]
[ 0.000000] Initmem setup node 0 [mem 0x00000000-0x3ffd8fff]
[ 0.000000] NODE_DATA [mem 0x3dd92000-0x3ddb8fff]
[ 0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00
Start installation by changing settings to your liking. They are numbered 1-9
Starting installer, one moment...
anaconda 19.31.123-1 for CentOS 7 started.
* installation log files are stored in /tmp during the installation
* shell is available on TTY2
* when reporting a bug add logs from /tmp as separate text/plain attachments
16:54:56 Not asking for VNC because we don't have a network
================================================================================
================================================================================
Installation 1) [x] Language settings 2) [!] Timezone settings


(English (United States)) (Timezone is not set.)
3) [!] Software selection 4) [!] Installation source

(Processing...) (Processing...)
5) [x] Network settings 6) [!] Install Destination

(Not connected) (No disks selected)
7) [x] Kdump 8) [!] Create user

(Kdump is enabled) (No user will be created)
9) [!] Set root password

(Password is not set.)
Please make your choice from above ['q' to quit | 'b' to begin installation |
'r' to refresh]:

您可以使用在安装过程中在线获得的ISO映像。 只需将–location选项指向该URL。

  1. 使用virt-install命令安装Ubuntu / Debian。

[[email protected] ~]# qemu-img create -f qcow2 /var/lib/libvirt/images/ubuntu-server.qcow2 10G
Formatting '/var/lib/libvirt/images/ubuntu-server.qcow2', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
  • 开始安装过程。
virt-install 
--name ubuntu-server 
--ram 1024 
--disk path=/var/lib/libvirt/images/ubuntu-server.qcow2 
--vcpus 1 
--os-type linux 
--os-variant ubuntu14.04 
--graphics spice 
--hvm 
--console pty,target_type=serial 
--cdrom=/var/lib/libvirt/images/ubuntu-14.04.3-server-amd64.iso
  • 您可以使用以下方法检查操作系统版本:
[[email protected] ~]# osinfo-query os

可以如下指定网络选项:

--network=bridge:br100
--network=network:default

下一步是将创建的图像添加到其中。步骤如下:

  1. 允许您导出VM。
  • 引导来宾计算机,然后:

对于CentOS

[[email protected] ~]# vi /etc/rc.d/rc.local

添加:

if [ ! -d /root/.ssh ]; then
mkdir -p /root/.ssh
chmod 700 /root/.ssh
fi # Fetch public key using HTTP
ATTEMPTS=30
FAILED=0
while [ ! -f /root/.ssh/authorized_keys ]; do
curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key 


> /tmp/metadata-key 2>/dev/null
if [ $? -eq 0 ]; then

cat /tmp/metadata-key >> /root/.ssh/authorized_keys
chmod 0600 /root/.ssh/authorized_keys
restorecon /root/.ssh/authorized_keys
rm -f /tmp/metadata-key
echo "Successfully retrieved public key from instance metadata"
echo "*****************"
echo "AUTHORIZED KEYS"
echo "*****************"
cat /root/.ssh/authorized_keys
echo "*****************"
fi
done

必须禁用默认的Zeroconf根,实例才能访问元数据服务。

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

对于Ubuntu:安装cloud-init

# apt-get install cloud-init

# dpkg-reconfigure cloud-init

  • 关闭实例,然后清除MAC地址详细信息。
[[email protected] ~]# virt-sysprep -d centos-server
[[email protected] ~] # virt-sysprep -d ubuntu-server

现在,您可以将虚拟机映像上载到映像服务。

  1. 确保在虚拟机上将网络启动协议设置为DHCP。
  2. 取消注释或取消注释网络配置文件中设置的UUID。

添加CentOS服务器映像。

[[email protected] ~]# glance image-create --name "Centos-server" --file /var/lib/libvirt/images/centos-server.qcow2 --disk-format qcow2 --container-format bare --visibility public
+------------------+--------------------------------------+
| Property | Value |
+------------------+--------------------------------------+
| checksum | 3198fc821f3202425dc8254469eacad4 |
| container_format | bare |
| created_at | 2016-03-29T20:29:08Z |
| disk_form t | qcow2 |
| id | 0742131d-ac17-48ba-abf5-160a435085ba |
| min_disk | 0 |
| min_ram | 0 |
| name | Centos-server |
| owner | abc5d2a310ad46fba0b2a311a187088b |
| protected | False |
| size | 4071686144 |
| status | active |
| tags | [] |
| updated_at | 2016-03-29T20:31:40Z |
| virtual_size | None |
| visibility | public |
+------------------+--------------------------------------+

添加Ubuntu服务器映像。

[[email protected] ~]# glance image-create --name "Ubuntu-server" --file /var/lib/libvirt/images/ubuntu-server.qcow2 --disk-format qcow2 --container-format bare --visibility public
+------------------+--------------------------------------+
| Property | Value |
+------------------+--------------------------------------+
| checksum | 3198fc821f3202425dc8254469eacad4 |
| container_format | bare |
| created_at | 2016-03-29T20:29:08Z |
| disk_form t | qcow2 |
| id | 0742131d-ac17-48ba-abf5-160a435085ba |
| min_disk | 0 |
| min_ram | 0 |
| name | Ubuntu-server |
| owner | abc5d2a310ad46fba0b2a311a187088b |
| protected | False |
| size | 4071686144 |
| status | active |
| tags | [] |
| updated_at | 2016-03-29T20:31:40Z |
| virtual_size | None |
| visibility | public |
+------------------+--------------------------------------+
  • 添加图像的清单:
[[email protected] images]# glance image-list 
+---------------------------------------------+--------------------+
| ID | Name |
+----------------------------------------------+-------------------+
| 4dd5dfac-da3b-49bf-80bd-989642421eb0 | Ubuntu-server |
| 0742131d-ac17-48ba-abf5-160a435085ba | Centos-server |
+--------------------------------------+----------------------------+ 

您可以从添加的映像启动虚拟机。它将在本系列的下一部分开始。您可以使用glanceimage-delete命令删除Glance图像,如下所示。

 [[email protected] ~]# glance image-list
+-----------------------------------------------------------------+------------------------+
| ID                                                               | Name               |
+-----------------------------------------------------------------+-------------------------+
| 4dd5dfac-da3b-49bf-80bd-989642421eb0 | Centos-server |
| 0742131d-ac17-48ba-abf5-160a435085ba| Ubuntu-server |
+------------------------------------------------------------------+--------------------------+

您可以使用glanceimage-delete命令删除当前图像。

[[email protected] ~]# glance image-delete 4dd5dfac-da3b-49bf-80bd-989642421eb0 
[[email protected] ~]# glance image-delete 0742131d-ac17-48ba-abf5-160a435085ba

再检查一遍:

[[email protected] ~]# glance image-list
+----+------+
| ID | Name |
+----+------+
+----+------+
[[email protected] ~]#

上一篇文章:

Openstack Liberty Lab第7部分:配置Horizo​​n仪表板服务

下一篇文章:

Sidebar