Openstack Train配置手册-Glance配置

snow chuai汇总、整理、撰写---2020/3/2


1. 添加及配置Glance用户及设定endpint信息
# 添加glance账户,并定义其隶属于service租户,密码为servicepassword
[root@node1 ~(keystone)]# openstack user create --domain default --project service --password servicepassword glance
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| default_project_id  | 7972f61f4a1c4f2592d2bb6dc7711e81 |
| domain_id           | default                          |
| enabled             | True                             |
| id                  | b1316db84c0348958e0aed7b106fd711 |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
# 授权glance账户为admin角色 [root@node1 ~(keystone)]# openstack role add --project service --user glance admin
# 创建glance服务 [root@node1 ~(keystone)]# openstack service create --name glance --description "OpenStack Image service" image +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | OpenStack Image service | | enabled | True | | id | 36af687fea80426eb8c167b57aa84aa7 | | name | glance | | type | image | +-------------+----------------------------------+
# 创建glance endpoint的public、internal、admin信息 [root@node1 ~(keystone)]# openstack endpoint create --region RegionOne image public http://192.168.10.11:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 998585d6078142a58dfe347466efeb19 | | interface | public | | region | RegionOne | | region_id | RegionOne | | service_id | 36af687fea80426eb8c167b57aa84aa7 | | service_name | glance | | service_type | image | | url | http://192.168.10.11:9292 | +--------------+----------------------------------+
[root@node1 ~(keystone)]# openstack endpoint create --region RegionOne image internal http://192.168.10.11:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 252278de39df4bdfb6e61615993ace68 | | interface | internal | | region | RegionOne | | region_id | RegionOne | | service_id | 36af687fea80426eb8c167b57aa84aa7 | | service_name | glance | | service_type | image | | url | http://192.168.10.11:9292 | +--------------+----------------------------------+
[root@node1 ~(keystone)]# openstack endpoint create --region RegionOne image admin http://192.168.10.11:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 44ec4e78fbb64691b79f5d5bc41b4668 | | interface | admin | | region | RegionOne | | region_id | RegionOne | | service_id | 36af687fea80426eb8c167b57aa84aa7 | | service_name | glance | | service_type | image | | url | http://192.168.10.11:9292 | +--------------+----------------------------------+
2. 设定Glance数据库
[root@node1 ~(keystone)]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.1.20-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database glance; Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on glance.* to glance@'localhost' identified by 'password'; Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on glance.* to glance@'%' identified by 'password'; Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit Bye
3. 安装及配置Glance
1) 安装Glance
[root@node1 ~(keystone)]# yum --enablerepo=centos-openstack-train,epel install openstack-glance -y
2) 配置Glance API [root@node1 ~(keystone)]# mv /etc/glance/glance-api.conf /etc/glance/glance-api.conf.bak [root@node1 ~(keystone)]# vim /etc/glance/glance-api.conf [DEFAULT] bind_host = 0.0.0.0
[glance_store] stores = file,http default_store = file filesystem_store_datadir = /var/lib/glance/images/
[database] connection = mysql+pymysql://glance:password@192.168.10.11/glance
# 定义连接keystone的信息 [keystone_authtoken] www_authenticate_uri = http://192.168.10.11:5000 auth_url = http://192.168.10.11:5000 memcached_servers = 192.168.10.11:11211 auth_type = password project_domain_name = default user_domain_name = default project_name = service username = glance password = servicepassword
[paste_deploy] flavor = keystone

[root@node1 ~(keystone)]# chmod 640 /etc/glance/glance-api.conf [root@node1 ~(keystone)]# chown root:glance /etc/glance/glance-api.conf
[root@node1 ~(keystone)]# su -s /bin/bash glance -c "glance-manage db_sync" ...... ...... Database is synced successfully.
[root@node1 ~(keystone)]# systemctl enable --now openstack-glance-api
3) SELinxu及防火墙设定 [root@node1 ~(keystone)]# setsebool -P glance_api_can_network on
[root@node1 ~(keystone)]# firewall-cmd --add-port=9292/tcp --permanent success [root@node1 ~(keystone)]# firewall-cmd --reload success
4. 创建实例并将实例,并将镜像注册至Glance中
1) 安装KVM并设置桥接
[root@node1 ~(keystone)]# yum install qemu-kvm libvirt virt-install bridge-utils -y
[root@node1 ~(keystone)]# lsmod | grep kvm
kvm_intel             188644  0 
kvm                   621480  1 kvm_intel
irqbypass              13503  1 kvm
[root@node1 ~(keystone)]# systemctl enable --now libvirtd
2) 安装实例 [root@node1 ~(keystone)]# qemu-img create -f qcow2 /var/lib/libvirt/images/c7.img 5G
[root@node1 ~(keystone)]# virt-install \ --name c77 \ --ram 2048 \ --disk path=/var/lib/libvirt/images/c7.img,format=qcow2 \ --vcpus 2 \ --os-type linux \ --os-variant rhel7 \ --graphics none \ --console pty,target_type=serial \ --location 'ftp://csrv.1000cc.net/pub/CentOS/7/os/x86_64' \ --extra-args 'console=ttyS0,115200n8 serial'
3) 配置实例 (1) 删除实例中网卡配置文件中的HWADDRUUID字段信息,并将BOOTPROTO改为dhcp [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
(2) 安装cloud init并启动这个服务,这个服务在启动之后将会自动添加一个centos的普通账户
[root@localhost ~]# yum install cloud-init -y
# 不要启动cloud-init [root@localhost ~]# systemctl enable cloud-init
[root@localhost ~]# poweroff
5. 将实例镜像添加至Glance
[root@node1 ~(keystone)]# openstack image create "c77" \
--file /var/lib/libvirt/images/c7.img \
--disk-format qcow2 \
--container-format bare \
--public
+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | 8294e7bdabfeac2ebe0edec3e2c8855a                     |
| container_format | bare                                                 |
| created_at       | 2020-03-02T14:05:21Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/d848c42d-801b-437b-a8ab-4b86a67eb584/file |
| id               | d848c42d-801b-437b-a8ab-4b86a67eb584                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | c77                                                  |
| owner            | 558ed85c8f84439a876cfd35150d0fe1                     |
| protected        | os_hash_algo='sha512', os_hash_value='b426b........  |
| schema           | /v2/schemas/image                                    |
| size             | 1663303680                                           |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2020-03-02T14:05:53Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+
[root@node1 ~(keystone)]# openstack image list +--------------------------------------+------+--------+ | ID | Name | Status | +--------------------------------------+------+--------+ | d848c42d-801b-437b-a8ab-4b86a67eb584 | c77 | active | +--------------------------------------+------+--------+

 

如对您有帮助,请随缘打个赏。^-^

gold