搭建多OpenStack多节点私有云平台(三)(镜像服务)

1.镜像服务

1.完成下面的步骤以创建数据库:

  • 用数据库连接客户端以 root 用户连接到数据库服务器:

    $ mysql -u root -p
    
  • 创建 glance 数据库:

    CREATE DATABASE glance;
    
  • glance数据库授予恰当的权限:

    GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
      IDENTIFIED BY 'GLANCE_DBPASS';
    GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
      IDENTIFIED BY 'GLANCE_DBPASS';
    

    用一个合适的密码替换 GLANCE_DBPASS

  • 退出数据库客户端。

2.获得 admin 凭证来获取只有管理员能执行的命令的访问权限:

$ . admin-openrc

3.要创建服务证书,完成这些步骤:

  • 创建 glance 用户:

    $ openstack user create --domain default --password GLANCE_PASS glance
    +-----------+----------------------------------+
    | Field     | Value                            |
    +-----------+----------------------------------+
    | domain_id | e0353a670a9e496da891347c589539e9 |
    | enabled   | True                             |
    | id        | e38230eeff474607805b596c91fa15d9 |
    | name      | glance                           |
    +-----------+----------------------------------+
    
  • 添加 admin 角色到 glance 用户和 service 项目上。

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

    查看有没有添加

    openstack role assignment list
    
    $ mysql keystone -e "show tables;"|grep role
    application_credential_role
    implied_role
    role
    trust_role
    
  • 创建glance服务实体:

    $ openstack service create --name glance \
      --description "OpenStack Image" image
    +-------------+----------------------------------+
    | Field       | Value                            |
    +-------------+----------------------------------+
    | description | OpenStack Image                  |
    | enabled     | True                             |
    | id          | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
    | name        | glance                           |
    | type        | image                            |
    +-------------+----------------------------------+
    

4.创建镜像服务的 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           |
+--------------+----------------------------------+

安全并配置组件

1.安装软件包:

# yum install openstack-glance -y

2.编辑文件 /etc/glance/glance-api.conf 并完成如下动作:

  • [database] 部分,配置数据库访问:

    [database]
    ...
    connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
    

    GLANCE_DBPASS 替换为你为镜像服务选择的密码。

  • [keystone_authtoken][paste_deploy] 部分,配置认证服务访问:

    [keystone_authtoken]
    ...
    auth_uri = http://controller:5000
    auth_url = http://controller:35357
    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 用户选择的密码。

  • [glance_store] 部分,配置本地文件系统存储和镜像文件位置:

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

3.编辑文件 “/etc/glance/glance-registry.conf``并完成如下动作:

  • [database] 部分,配置数据库访问:

    [database]
    ...
    connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
    

    GLANCE_DBPASS 替换为你为镜像服务选择的密码。

  • [keystone_authtoken][paste_deploy] 部分,配置认证服务访问:

    [keystone_authtoken]
    ...
    auth_uri = http://controller:5000
    auth_url = http://controller:35357
    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 用户选择的密码。

4.写入镜像服务数据库:

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

5.验证同步的数据库有没有同步出来

mysql glance -e "show tables;"

6.完成安装

  • 启动镜像服务、配置他们随机启动:

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

6.查看端口有9191和9292

netstat -nltup

验证操作

1.下载rz

yum -y install lrzsz

把cirros镜像上传到/root文件夹

或者下载源镜像:

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

2.使用 QCOW2 磁盘格式, bare 容器格式上传镜像到镜像服务并设置公共可见,这样所有的项目都可以访问它:

openstack image create "cirros" --file cirros-0.3.4-x86_64-disk.img --disk-format qcow2 --container-format bare --public
+------------------+------------------------------------------------------+
| Property         | 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                                               |
+------------------+------------------------------------------------------+

3.确认镜像的上传并验证属性:

$ openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 38047887-61a7-41ea-9b49-27987d5e8bb9 | cirros | active |
+--------------------------------------+--------+--------+
posted @ 2020-11-02 08:05  龙吟九枭  阅读(565)  评论(0)    收藏  举报