OpenStack中部署glance的步骤(基于Ubuntu14.04系统)

author:headsen  chen   2017-10-13   08:34:35

个人原创,转载请注明作者,出处,否则依法追究法律责任

1,在数据库里创建glance的数据库和glance用户,并进行授权。

MariaDB [(none)]> create database glance;
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> grant all privileges on glance.* to 'glance'@'localhost' identified by 'openstack';
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> grant all privileges on glance.* to 'glance'@'%' identified by 'openstack';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye

OpenStack中部署glance的步骤-LMLPHP

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

root@controller:~# . admin-openrc

OpenStack中部署glance的步骤-LMLPHP

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

创建 glance 用户(密码也设置为openstack):

root@controller:~# openstack user create --domain default --password-prompt glance
User Password:
Repeat User Password:

OpenStack中部署glance的步骤-LMLPHP

添加 admin 角色到 glance 用户和 service 项目上(这个命令执行完成后无输出)

root@controller:~# openstack role add --project service --user glance admin

OpenStack中部署glance的步骤-LMLPHP

创建``glance``服务实体:

root@controller:~# openstack service create --name glance \
> --description "OpenStack Image" image

OpenStack中部署glance的步骤-LMLPHP

4,创建镜像服务的 API 端点:

root@controller:~# openstack endpoint create --region RegionOne \

> image public http://controller:9292

OpenStack中部署glance的步骤-LMLPHP

root@controller:~# openstack endpoint create --region RegionOne \
> image internal http://controller:9292

OpenStack中部署glance的步骤-LMLPHP

root@controller:~# openstack endpoint create --region RegionOne \
> image admin http://controller:9292

OpenStack中部署glance的步骤-LMLPHP

5,安装glance的软件包:

root@controller:~# apt-get install glance

OpenStack中部署glance的步骤-LMLPHP

6,修改配置文件:

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

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

    将``GLANCE_DBPASS`` 替换为你为镜像服务选择的密码(openstack)。

  • 在 [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 -----------替换为你为认证服务中你为 glance 用户选择的密码。 [paste_deploy]
    ...
    flavor = keystone
  • 在 [glance_store] 部分,配置本地文件系统存储和镜像文件位置:

    [glance_store]
    ...
    stores = file,http
    default_store = file
    filesystem_store_datadir = /var/lib/glance/images/ 7,编辑文件 ``/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 8,写入镜像服务数据库:
      # su -s /bin/sh -c "glance-manage db_sync" glance

      OpenStack中部署glance的步骤-LMLPHP

      9,完成安装

    • # service glance-registry restart
    • # service glance-api restart
    • OpenStack中部署glance的步骤-LMLPHP

      10,验证操作

        
      使用 `CirrOS <http://launchpad.net/cirros>`__对镜像服务进行验证,CirrOS是一个小型的Linux镜像可以用来帮助你进行 OpenStack部署测试。
      1. 使用 admin 凭证来获取只有管理员能执行的命令的访问权限:

        $ . admin-openrc
        
      2. 下载源镜像:

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

        如果您的发行版里没有包含wget,请安装它

      3. 使用 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 |
        +------------------+------------------------------------------------------+
      4. 确认镜像的上传并验证属性:

        $ openstack image list
        +--------------------------------------+--------+--------+
        | ID | Name | Status |
        +--------------------------------------+--------+--------+
        | 38047887-61a7-41ea-9b49-27987d5e8bb9 | cirros | active |
        +--------------------------------------+--------+--------+
      
      
05-07 15:46