Linux 运维手册之 OpenStack 从入门到放弃(Part 2)
后知后觉 暂无评论

OpenStack 是一个开源的云计算管理平台,由几个主要的组件组合起来完成具体工作。OpenStack 支持几乎所有类型的云环境,项目目标是提供实施简单、可大规模扩展、丰富、标准统一的云计算管理平台。OpenStack通过各种互补的服务提供了基础设施即服务(IaaS)的解决方案,每个服务提供API以进行集成。

环境

消息队列

OpenStack 使用消息队列来协调服务之间的操作和状态信息,消息队列服务通常运行在控制节点上,也可以单独部署于其他服务器或消息队列集群。 OpenStack 支持多种消息队列服务,包括 RabbitMQQpidZeroMQ 。大多数支持 OpenStack 的发行版都有指定的消息队列产品,本文与官方文档一致使用 RabbitMQ 若使用其他消息队列产品请查询相关使用文档。

Message queue for SUSE

安装服务

sudo zypper install rabbitmq-server

启动服务并自启动

sudo systemctl enable rabbitmq-server.service
sudo systemctl start rabbitmq-server.service

添加 OpenStack 用户

sudo rabbitmqctl add_user openstack RABBIT_PASS
Creating user "openstack" ...
小贴士:自行替换字符串 RABBIT_PASS 为合适的密码。

为 OpenStack 用户授权

sudo rabbitmqctl set_permissions openstack ".*" ".*" ".*"

Setting permissions for user "openstack" in vhost "/" ...

Message queue for RHEL and CentOS

安装服务

sudo yum install rabbitmq-server

启动服务并自启动

sudo systemctl enable rabbitmq-server.service
sudo systemctl start rabbitmq-server.service

添加 OpenStack 用户

sudo rabbitmqctl add_user openstack RABBIT_PASS
Creating user "openstack" ...
小贴士:自行替换字符串 RABBIT_PASS 为合适的密码。

为 OpenStack 用户授权

sudo rabbitmqctl set_permissions openstack ".*" ".*" ".*"

Setting permissions for user "openstack" in vhost "/" ...

Message queue for Ubuntu

安装服务

sudo apt install rabbitmq-server

启动服务并自启动

sudo systemctl enable rabbitmq-server.service
sudo systemctl start rabbitmq-server.service

添加 OpenStack 用户

sudo rabbitmqctl add_user openstack RABBIT_PASS
Creating user "openstack" ...
小贴士:自行替换字符串 RABBIT_PASS 为合适的密码。

为 OpenStack 用户授权

sudo rabbitmqctl set_permissions openstack ".*" ".*" ".*"

Setting permissions for user "openstack" in vhost "/" ...

Memcached

OpenStack 的服务身份验证机制需要 Memcached 缓存 Token (令牌),此服务通常部署在控制节点上。对于生产环境来说,建议部署防火墙、身份验证等策略对其进行保护。

Memcached for SUSE

安装服务

sudo zypper install memcached python-python-memcached

修改配置文件

sudo vim /etc/sysconfig/memcached

修改以下字段

MEMCACHED_PARAMS="-l 10.0.0.11"
小贴士:搜索 MEMCACHED_PARAMS 字段即可。

启动服务并自启动

sudo systemctl enable memcached.service
sudo systemctl start memcached.service

Memcached for RHEL and CentOS

安装服务

sudo yum install memcached python-memcached

修改配置文件

sudo vim /etc/sysconfig/memcached 

修改以下字段

OPTIONS="-l 127.0.0.1,::1,controller"
小贴士:搜索 OPTIONS 字段即可。

启动服务并自启动

sudo systemctl enable memcached.service
sudo systemctl start memcached.service

Memcached for Ubuntu

安装服务

sudo apt install memcached python-memcache

修改配置文件

sudo vim /etc/memcached.conf 

修改以下字段

-l 10.0.0.11
小贴士:搜索 OPTIONS 字段即可。

重启服务即可

sudo systemctl restart memcached.service

Etcd

Etcd,一种分布式可靠的键值存储,用于分布式密钥锁定,存储配置,跟踪服务生存和其他场景。

Etcd for SUSE

创建用户

sudo groupadd --system etcd
# useradd --home-dir "/var/lib/etcd" \
      --system \
      --shell /bin/false \
      -g etcd \
      etcd

创建必要的文件夹

sudo mkdir -p /etc/etcd
sudo chown etcd:etcd /etc/etcd
sudo mkdir -p /var/lib/etcd
sudo chown etcd:etcd /var/lib/etcd

确认系统架构(一般皆为 x86_64)

uname -m

下载安装相应架构

# ETCD_VER=v3.2.7
# rm -rf /tmp/etcd && mkdir -p /tmp/etcd
# curl -L \
      https://github.com/coreos/etcd/releases/download/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz \
      -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
# tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz \
      -C /tmp/etcd --strip-components=1
# cp /tmp/etcd/etcd /usr/bin/etcd
# cp /tmp/etcd/etcdctl /usr/bin/etcdctl
# ETCD_VER=v3.2.7
# rm -rf /tmp/etcd && mkdir -p /tmp/etcd
# curl -L \
      https://github.com/coreos/etcd/releases/download/${ETCD_VER}/etcd-${ETCD_VER}-linux-arm64.tar.gz \
      -o /tmp/etcd-${ETCD_VER}-linux-arm64.tar.gz
# tar xzvf /tmp/etcd-${ETCD_VER}-linux-arm64.tar.gz \
      -C /tmp/etcd --strip-components=1
# cp /tmp/etcd/etcd /usr/bin/etcd
# cp /tmp/etcd/etcdctl /usr/bin/etcdctl

创建配置文件

sudo vim /etc/etcd/etcd.conf.yml
name: controller
data-dir: /var/lib/etcd
initial-cluster-state: 'new'
initial-cluster-token: 'etcd-cluster-01'
initial-cluster: controller=http://10.0.0.11:2380
initial-advertise-peer-urls: http://10.0.0.11:2380
advertise-client-urls: http://10.0.0.11:2379
listen-peer-urls: http://0.0.0.0:2380
listen-client-urls: http://10.0.0.11:2379
注意:将 initial-cluster, initial-advertise-peer-urls, advertise-client-urls, listen-client-urls 值设置为控制节点的 IP 地址。

创建 SystemD 守护单元

sudo vim /usr/lib/systemd/system/etcd.service
[Unit]
After=network.target
Description=etcd - highly-available key value store

[Service]
# Uncomment this on ARM64.
# Environment="ETCD_UNSUPPORTED_ARCH=arm64"
LimitNOFILE=65536
Restart=on-failure
Type=notify
ExecStart=/usr/bin/etcd --config-file /etc/etcd/etcd.conf.yml
User=etcd

[Install]
WantedBy=multi-user.target

重载守护单元

sudo systemctl daemon-reload

启动服务并设置自启动

sudo systemctl enable etcd
# systemctl start etcd

Etcd for RHEL and CentOS

安装服务

sudo yum install etcd

修改配置文件

sudo vim /etc/etcd/etcd.conf

写入配置

#[Member]
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://10.0.0.11:2380"
ETCD_LISTEN_CLIENT_URLS="http://10.0.0.11:2379"
ETCD_NAME="controller"
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.0.0.11:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://10.0.0.11:2379"
ETCD_INITIAL_CLUSTER="controller=http://10.0.0.11:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
ETCD_INITIAL_CLUSTER_STATE="new"
注意:将 initial-cluster, initial-advertise-peer-urls, advertise-client-urls, listen-client-urls 值设置为控制节点的 IP 地址。

启动服务并设置自启动

sudo systemctl enable etcd
sudo systemctl start etcd

Etcd for Ubuntu

安装服务

sudo apt install etcd

修改配置文件

sudo vim /etc/default/etcd 

写入配置

ETCD_NAME="controller"
ETCD_DATA_DIR="/var/lib/etcd"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
ETCD_INITIAL_CLUSTER="controller=http://10.0.0.11:2380"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.0.0.11:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://10.0.0.11:2379"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="http://10.0.0.11:2379"
注意:将 initial-cluster, initial-advertise-peer-urls, advertise-client-urls, listen-client-urls 值设置为控制节点的 IP 地址。

启动服务并设置自启动

sudo systemctl enable etcd
sudo systemctl start etcd

安装 OpenStack 服务

因篇幅有限,本文以 CentOS 最小化部署 OpenStack Stein 为例。

验证服务 KeyStone

Keystone(OpenStack Identity Service)是 OpenStack 框架中负责管理身份验证、服务规则和服务令牌功能的模块。用户访问资源需要验证用户的身份与权限,服务执行操作也需要进行权限检测,这些都需要通过 Keystone 来处理。Keystone 类似一个服务总线, 或者说是整个 OpenStack 框架的注册表, 其他服务通过 keystone 来注册其服务的 Endpoint(服务访问的URL),任何服务之间相互的调用, 需要经过 Keystone 的身份验证, 来获得目标服务的 Endpoint 来找到目标服务。

数据库操作

连接数据库

mysql -u root -p

建立验证服务数据库

MariaDB [(none)]> CREATE DATABASE keystone;

建立用户并授权

MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' \
IDENTIFIED BY 'KEYSTONE_DBPASS';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' \
IDENTIFIED BY 'KEYSTONE_DBPASS';
小贴士:注意替换 KEYSTONE_DBPASS 为合适的密码。

安装与配置

sudo yum install openstack-keystone httpd mod_wsgi

修改配置文件

sudo vim /etc/keystone/keystone.conf

修改 [database] 标签下的数据库密码 KEYSTONE_DBPASS

[database]
# ...
connection = mysql+pymysql://keystone:KEYSTONE_DBPASS@controller/keystone
注意:此处使用主机名进行通讯,必须进行 host 解析后才能使用。

修改 [token] 标签下的内容

[token]
# ...
provider = fernet

写入数据库数据

sudo su -s /bin/sh -c "keystone-manage db_sync" keystone

初始化 Fernet 密钥仓库

sudo keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
sudo keystone-manage credential_setup --keystone-user keystone --keystone-group keystone

重新引导服务

小贴士:在 OpenStack Queens 版本后,keystone 必须需要多个端口运行 v2 API 通过移除 v2 API keystone 服务可以运行在一个端口中。
sudo keystone-manage bootstrap --bootstrap-password ADMIN_PASS \
  --bootstrap-admin-url http://controller:5000/v3/ \
  --bootstrap-internal-url http://controller:5000/v3/ \
  --bootstrap-public-url http://controller:5000/v3/ \
  --bootstrap-region-id RegionOne
小贴士:替换 ADMIN_PASS 为合适的密码。

配置 Apache HTTP 服务

sudo vim /etc/httpd/conf/httpd.conf

添加以下一行

ServerName controller

创建软链接

sudo ln -s /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/
小贴士:可以为了提高安全级别而添加 SSL 证书。

启动 Apache HTTP 服务

sudo systemctl enable httpd.service
sudo systemctl start httpd.service

配置管理员账户

$ export OS_USERNAME=admin
$ export OS_PASSWORD=ADMIN_PASS
$ export OS_PROJECT_NAME=admin
$ export OS_USER_DOMAIN_NAME=Default
$ export OS_PROJECT_DOMAIN_NAME=Default
$ export OS_AUTH_URL=http://controller:5000/v3
$ export OS_IDENTITY_API_VERSION=3
小贴士:替换 ADMIN_PASS 为正确的密码。

创建域、项目、用户和角色

$ openstack domain create --description "An Example Domain" example

+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | An Example Domain                |
| enabled     | True                             |
| id          | 2f4f80574fd84fe6ba9067228ae0a50c |
| name        | example                          |
| tags        | []                               |
+-------------+----------------------------------+
$ openstack project create --domain default \
  --description "Service Project" service

+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | Service Project                  |
| domain_id   | default                          |
| enabled     | True                             |
| id          | 24ac7f19cd944f4cba1d77469b2a73ed |
| is_domain   | False                            |
| name        | service                          |
| parent_id   | default                          |
| tags        | []                               |
+-------------+----------------------------------+
$ openstack project create --domain default \
  --description "Demo Project" myproject

+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | Demo Project                     |
| domain_id   | default                          |
| enabled     | True                             |
| id          | 231ad6e7ebba47d6a1e57e1cc07ae446 |
| is_domain   | False                            |
| name        | myproject                        |
| parent_id   | default                          |
| tags        | []                               |
+-------------+----------------------------------+
$ openstack user create --domain default \
  --password-prompt myuser

User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | aeda23aa78f44e859900e22c24817832 |
| name                | myuser                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
$ openstack role create myrole

+-----------+----------------------------------+
| Field     | Value                            |
+-----------+----------------------------------+
| domain_id | None                             |
| id        | 997ce8d05fc143ac97d83fdfb5998552 |
| name      | myrole                           |
+-----------+----------------------------------+

添加角色到项目中和用户中

openstack role add --project myproject --user myuser myrole

验证操作

临时取消环境变量

unset OS_AUTH_URL OS_PASSWORD

以 admin 用户身份请求验证令牌

$ openstack --os-auth-url http://controller:5000/v3 \
  --os-project-domain-name Default --os-user-domain-name Default \
  --os-project-name admin --os-username admin token issue

Password:
+------------+-----------------------------------------------------------------+
| Field      | Value                                                           |
+------------+-----------------------------------------------------------------+
| expires    | 2016-02-12T20:14:07.056119Z                                     |
| id         | gAAAAABWvi7_B8kKQD9wdXac8MoZiQldmjEO643d-e_j-XXq9AmIegIbA7UHGPv |
|            | atnN21qtOMjCFWX7BReJEQnVOAj3nclRQgAYRsfSU_MrsuWb4EDtnjU7HEpoBb4 |
|            | o6ozsA_NmFWEpLeKy0uNn_WeKbAhYygrsmQGA49dclHVnz-OMVLiyM9ws       |
| project_id | 343d245e850143a096806dfaefa9afdc                                |
| user_id    | ac3377633149401296f6c0d92d79dc16                                |
+------------+-----------------------------------------------------------------+

以 myuser 用户身份请求验证令牌

$ openstack --os-auth-url http://controller:5000/v3 \
  --os-project-domain-name Default --os-user-domain-name Default \
  --os-project-name myproject --os-username myuser token issue

Password:
+------------+-----------------------------------------------------------------+
| Field      | Value                                                           |
+------------+-----------------------------------------------------------------+
| expires    | 2016-02-12T20:15:39.014479Z                                     |
| id         | gAAAAABWvi9bsh7vkiby5BpCCnc-JkbGhm9wH3fabS_cY7uabOubesi-Me6IGWW |
|            | yQqNegDDZ5jw7grI26vvgy1J5nCVwZ_zFRqPiz_qhbq29mgbQLglbkq6FQvzBRQ |
|            | JcOzq3uwhzNxszJWmzGC7rJE_H0A_a3UFhqv8M4zMRYSbS2YF0MyFmp_U       |
| project_id | ed0b60bf607743088218b0a533d5943f                                |
| user_id    | 58126687cbcc4888bfa9ab73a2256f27                                |
+------------+-----------------------------------------------------------------+

创建客户端环境脚本

为了提高操作效率,可以创建包含用户身份信息的脚本进行验证,也称 OpenRC 文件。

小贴士:此类脚本无固定存放地点,但为了防止其他用户滥用,推荐放置于 /root 目录下。

创建 admin-openrc 文件并添加以下内容

export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=ADMIN_PASS
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
小贴士:需要替换用户密码 ADMIN_PASS 为用户设置的密码。

创建 demo-openrc 文件并添加以下内容

export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=myproject
export OS_USERNAME=myuser
export OS_PASSWORD=MYUSER_PASS
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
小贴士:注意替换 DEMO_PASS 用配置的 demo 用户密码。

使用脚本

. admin-openrc

验证请求令牌

$ openstack token issue

+------------+-----------------------------------------------------------------+
| Field      | Value                                                           |
+------------+-----------------------------------------------------------------+
| expires    | 2016-02-12T20:44:35.659723Z                                     |
| id         | gAAAAABWvjYj-Zjfg8WXFaQnUd1DMYTBVrKw4h3fIagi5NoEmh21U72SrRv2trl |
|            | JWFYhLi2_uPR31Igf6A8mH2Rw9kv_bxNo1jbLNPLGzW_u5FC7InFqx0yYtTwa1e |
|            | eq2b0f6-18KZyQhs7F3teAta143kJEWuNEYET-y7u29y0be1_64KYkM7E       |
| project_id | 343d245e850143a096806dfaefa9afdc                                |
| user_id    | ac3377633149401296f6c0d92d79dc16                                |
+------------+-----------------------------------------------------------------+

镜像服务 Glance

Glance(OpenStack Image Service) 是 OpenStack 框架中负责为用户发现、注册、抓取虚拟机镜像的服务。

注意:本文以文件存储为后端支撑情况下,默认镜像存放路径 /var/lib/glance/images/

数据库操作

登陆数据库

mysql -u root -p

创建 Glance 数据库

MariaDB [(none)]> CREATE DATABASE glance;

创建用户并授权

MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
  IDENTIFIED BY 'GLANCE_DBPASS';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
  IDENTIFIED BY 'GLANCE_DBPASS';
小贴士:替换 GLANCE_DBPASS 为适宜的密码。

建立用户表

获取 admin 用户凭据,使用管理员 CLI 命令

. admin-openrc

创建 glance 服务用户

$ openstack user create --domain default --password-prompt glance

User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 3f4e777c4062483ab8d9edd7dff829df |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

添加 admin 角色添加到 glance 用户和 service 项目中

openstack role add --project service --user glance admin

创建 glance 服务实例

$ openstack service create --name glance \
  --description "OpenStack Image" image

+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+

创建镜像服务 API 终端

$ openstack endpoint create --region RegionOne \
  image public http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 340be3625e9b4239a6415d034e98aace |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

$ openstack endpoint create --region RegionOne \
  image internal http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | a6e4b153c2ae4c919eccfdbb7dceb5d2 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

$ openstack endpoint create --region RegionOne \
  image admin http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 0c37ed58103f4300a84ff125a539032d |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

安装与配置

安装软件包

sudo yum install openstack-glance

修改配置 /etc/glance/glance-api.conf 完成以下操作。

sudo vim /etc/glance/glance-api.conf

修改 [database] 标签下的访问信息

[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
小贴士:把 GLANCE_DBPASS 替换为合适的密码。

修改 [keystone_authtoken] 和 [paste_deploy] 标签下的内容

[keystone_authtoken]
# ...
www_authenticate_uri  = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = GLANCE_PASS

[paste_deploy]
# ...
flavor = keystone
小贴士:把 GLANCE_PASS 替换为合适的密码。注意变量名,_DBPASS 是数据库密码,_PASS 为服务本身的密码。
注意:要注释掉 [keystone_authtoken] 标签下的其他项。

在 [glance_store] 标签下,配置全局系统镜像存储位置。

[glance_store]
# ...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

修改配置 /etc/glance/glance-registry.conf 完成以下操作。

sudo vim /etc/glance/glance-registry.conf 

在 [database] 标签下修改数据库访问权限

[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
小贴士:把 GLANCE_DBPASS 替换为正确密码。

在 [keystone_authtoken] 和 [paste_deploy] 标签下,修改认证服务权限

[keystone_authtoken]
# ...
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = GLANCE_PASS

[paste_deploy]
# ...
flavor = keystone
小贴士:把 GLANCE_PASS 替换为 glance 用户的密码。

填充镜像服务数据库

sudo su -s /bin/sh -c "glance-manage db_sync" glance

启动服务并配置自启动

sudo systemctl enable openstack-glance-api.service \
  openstack-glance-registry.service
sudo systemctl start openstack-glance-api.service \
  openstack-glance-registry.service

验证操作

获取 admin 令牌使用管理员专用 CLI 命令

. admin-openrc

下载 CirrOS 镜像

wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img

上传镜像到 Glance 服务使用 QCOW2 磁盘格式,并开放给全部项目拉取权限。

$ openstack image create "cirros" \
  --file cirros-0.4.0-x86_64-disk.img \
  --disk-format qcow2 --container-format bare \
  --public

+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | 133eae9fb1c98f45894a4e60d8736619                     |
| container_format | bare                                                 |
| created_at       | 2015-03-26T16:52:10Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/cc5c6982-4910-471e-b864-1098015901b5/file |
| id               | cc5c6982-4910-471e-b864-1098015901b5                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | cirros                                               |
| owner            | ae7a98326b9c455588edd2656d723b9d                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 13200896                                             |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2015-03-26T16:52:10Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+

检查现有镜像

$ openstack image list

+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 38047887-61a7-41ea-9b49-27987d5e8bb9 | cirros | active |
+--------------------------------------+--------+--------+

附录

相关链接

参考链接

本文撰写于一年前,如出现图片失效或有任何问题,请在下方留言。博主看到后将及时修正,谢谢!
禁用 / 当前已拒绝评论,仅可查看「历史评论」。