|NO.Z.00009|——————————|^^^^ 部署 ^^^^|——|OpenStack&元件.V02|--------------------------|openstack-glance|controller節點下部署glance映象服務|
阿新 • • 發佈:2022-03-27
[CloudVirtualiZation:OpenStack&元件.V02] [Applications.CloudVirtualiZation] [|OpenStack|OpenStack.glance|controller節點下部署glance映象服務|] [相關說明/元件工作流|實驗構建|驗證映象是否可用狀態]
一、構建實驗openstack-ImageServeice(glance):在controller節點安裝並配置OpenStack映象服務
### --- 配置先決條件 ### --- 建立資料庫 ~~~ 以資料庫管理員root的身份登入資料庫 [root@controller ~]# mysql -u root -p Enter password: 123456
~~~ 建立glance資料庫 MariaDB [(none)]> CREATE DATABASE glance; Query OK, 1 row affected (0.01 sec) ~~~ 建立資料庫使用者glance,並授予其對glance資料庫的管理許可權 ~~~ 退出資料庫 MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'GLANCE_DBPASS'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'GLANCE_DBPASS'; Query OK, 0 rows affected (0.00 sec)
### --- 啟動admin環境指令碼;啟動管理員指令碼
[root@controller ~]# source admin-openrc.sh
### --- 建立認證服務憑證,完成下列步驟; ~~~ 建立glance使用者 [root@controller ~]# keystone user-create --name glance --pass GLANCE_PASS +----------+----------------------------------+ | Property | Value | +----------+----------------------------------+ | email | | | enabled | True | | id | 8cdc5b5c70094cb79a819b26d8c94e40 | | name | glance | | username | glance | +----------+----------------------------------+
~~~ 將glance使用者連線到service租戶和admin角色
[root@controller ~]# keystone user-role-add --user glance --tenant service --role admin
~~~ 建立glance服務
[root@controller ~]# keystone service-create --name glance --type image --description "OpenStack Image Service"
+-------------+----------------------------------+
| Property | Value |
+-------------+----------------------------------+
| description | OpenStack Image Service |
| enabled | True |
| id | 659d6a3b0f0d441caa5c43de962434a7 |
| name | glance |
| type | image |
+-------------+----------------------------------+
### --- 為openstack映象服務建立認證服務端點
[root@controller ~]# keystone endpoint-create \
> --service-id $(keystone service-list | awk '/ image / {print$2}') \
> --publicurl http://controller.nice.com:9292 \
> --internalurl http://controller.nice.com:9292 \
> --adminurl http://controller.nice.com:9292 \
> --region regionOne
+-------------+----------------------------------+
| Property | Value |
+-------------+----------------------------------+
| adminurl | http://controller.nice.com:9292 |
| id | 492b4495a59142399824f86be0001e52 |
| internalurl | http://controller.nice.com:9292 |
| publicurl | http://controller.nice.com:9292 |
| region | regionOne |
| service_id | 659d6a3b0f0d441caa5c43de962434a7 |
+-------------+----------------------------------+
二、安裝並配置映象服務元件### --- 安裝軟體包
[root@controller ~]# yum install openstack-glance python-glaceclient
Installed:
openstack-glance.noarch 0:2014.2-1.el7.centos
Dependency Installed:
crudini.noarch 0:0.4-1.el7 openstack-utils.noarch 0:2014.1-3.el7.centos.1 pysendfile.x86_64 0:2.0.0-5.el7
python-boto.noarch 0:2.32.1-1.el7 python-cinderclient.noarch 0:1.1.1-1.el7.centos python-futures.noarch 0:2.1.6-1.el7
python-glance.noarch 0:2014.2-1.el7.centos python-glance-store.noarch 0:0.1.8-1.el7.centos python-glanceclient.noarch 1:0.14.1-1.el7.centos
python-httplib2.noarch 0:0.7.7-3.el7 python-ipaddr.noarch 0:2.1.9-5.el7 python-jsonpatch.noarch 0:1.2-3.el7.centos
python-jsonpointer.noarch 0:1.0-2.el7.centos python-oslo-vmware.noarch 0:0.6.0-1.el7.centos python-osprofiler.noarch 0:0.3.0-1.el7.centos
python-retrying.noarch 0:1.2.3-4.el7.centos python-simplegeneric.noarch 0:0.8-7.el7 python-simplejson.x86_64 0:3.3.3-1.el7
python-suds.noarch 0:0.4.1-5.el7 python-swiftclient.noarch 0:2.3.1-2.el7.centos python-warlock.noarch 0:1.0.1-1.el7
python-wsme.noarch 0:0.6-2.el7
Complete!
### --- 編輯/etc/glance/glance-api.conf檔案,並完成下列操作
[root@controller ~]# vim /etc/glance/glance-api.conf
# 修改[database]小節,配置資料庫連線:
[database]
......
connection=mysql://glance:[email protected]/glance
# 修改[keystone_authtoken]和[paste_deploy]小節,配置認證服務訪問:
[keystone_authtoken]
.....
auth_uri=http://controller.nice.com:5000/v2.0
identity_uri=http://controller.nice.com:35357
admin_tenant_name=service
admin_user=glance
admin_password=GLANCE_PASS
[paste_deploy]
......
flavor=keystone # 設定認證型別為keystone
# (可選)在[DEFAULT]小節中配置詳細日誌輸出,方便排錯
[DEFAULT]
......
verbose=True # 開啟日誌介面
### --- 編輯/etc/glance/glance-registry.con檔案,並完成下列配置:和資料庫交流的配置檔案
[root@controller ~]# vim /etc/glance/glance-registry.conf
# 在[database]
......
connection=mysql://glance:[email protected]/glance
# 在[keystone_authtoken]和[paste_deploy]小節中配置認證服務訪問
[keystone_authtoken]
......
auth_uri=http://controller.nice.com:5000/v2.0
identity_uri=http://controller.nice.com:35357
admin_tenant_name=service
admin_user=glance
admin_password=GLANCE_PASS
[paste_deploy]
......
flavor=keystone
# 在[glance_store]小節中配置本地檔案系統儲存和映象檔案的存放路徑
[glance_store] # 這個儲存預設是沒有的,我們自己去建立,
default_store=file
filesystem_store_datadir=/var/lib/glance/images/ # 這個目錄不需要手動建立,glance服務會幫我們建立
# (可選)在[DEFAULT]小節中配置詳細日誌輸出,方便排錯
[DEFAULT]
......
verbose=True # 開啟日誌
### --- 初始化映象服務的資料庫
[root@controller ~]# su -s /bin/sh -c "glance-manage db_sync" glance
### --- 登入到資料庫中;檢視是否建立成功
[root@controller ~]# mysql -uroot -p
Enter password: 123456
MariaDB [(none)]> use glance
MariaDB [glance]> show tables;
+----------------------------------+
| Tables_in_glance |
+----------------------------------+
| image_locations |
| image_members |
| image_properties |
| image_tags |
| images |
| metadef_namespace_resource_types |
| metadef_namespaces |
| metadef_objects |
| metadef_properties |
| metadef_resource_types |
| migrate_version |
| task_info |
| tasks |
+----------------------------------+
三、安裝完成### --- 啟動映象服務並設定開機自動啟動:
[root@controller ~]# systemctl enable openstack-glance-api.service openstack-glance-registry.service
[root@controller ~]# systemctl start openstack-glance-api.service openstack-glance-registry.service
四、驗證安裝
### --- 本節演示如何使用CirrOS驗證映象服務是否安裝成功,CirrOS是一個小linux映象,
~~~ 可以幫你驗證映象服務
[root@controller ~]# yum install -y lrzsz
### --- 建立一個臨時目錄
[root@controller ~]# mkdir /tmp/images // 此步不執行也可
[root@controller ~]# cd /tmp/images // 此步不執行也可
### --- 下載CirrOS映象檔案到臨時目錄
~~~ 將測試映象上傳到controller:cirros-0.3.3-x86_64-disk.img
[root@controller ~]# wget http://cdn.download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img(真實環境)
[root@controller ~]# wget ftp://ftp伺服器ip/cirros-0.3.3-x86_64-disk.img(實驗室環境) // 或者直接通過rz命令上傳
### --- 執行admin環境指令碼,以便執行管理命令
[root@controller ~]# source admin-openrc.sh
### --- 上傳映象檔案到映象伺服器
~~~ glance image-create相關選項含義:
--name<NAME> // 映象名稱:
--file<FILE> // 要上傳檔案及路徑
--disk-format<DISK_FORMAT> // 映象的磁碟格式。可以支援:ami/ari/aki/bhd/vmdk/raw/qcow2/vdi/is格式
--container-format<CONTAINER_FORMAT> // 映象容器格式,可以支援ami/ari/aki/bare/ovf格式。
--is-public{True,False} // 映象是否可以被公共訪問
--progress: // 顯示上傳進度
[root@controller ~]# glance image-create --name "cirros-0.3.3-x86_64" --file cirros-0.3.3-x86_64-disk.img --disk-format qcow2 --container-format bare --is-public True --progress
[=============================>] 100%
+------------------+--------------------------------------+
| Property | Value |
+------------------+--------------------------------------+
| checksum | 133eae9fb1c98f45894a4e60d8736619 |
| container_format | bare |
| created_at | 2021-01-10T02:51:21 |
| deleted | False |
| deleted_at | None |
| disk_format | qcow2 |
| id | 9254729e-15b4-4315-b396-3f3e2e5b339f |
| is_public | True |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros-0.3.3-x86_64 |
| owner | 7bce6e7e6d724ad188e4f70ad9d51e17 |
| protected | False |
| size | 13200896 |
| status | active |
| updated_at | 2021-01-10T02:51:22 |
| virtual_size | None |
+------------------+--------------------------------------+
### --- 確認映象檔案上傳並驗證屬性
~~~ status狀態為active狀態,說明上傳成功了;代表已經可用。
[root@controller ~]# glance image-list
+--------------------------------------+---------------------+-------------+------------------+----------+--------+
| ID | Name | Disk Format | Container Format | Size | Status |
+--------------------------------------+---------------------+-------------+------------------+----------+--------+
| 9254729e-15b4-4315-b396-3f3e2e5b339f | cirros-0.3.3-x86_64 | qcow2 | bare | 13200896 | active |
+--------------------------------------+---------------------+-------------+------------------+----------+--------+
### --- 刪除臨時目錄
[root@controller ~]# rm -rf cirros-0.3.3-x86_64-disk.img
附錄一:故障處理:
### --- 報錯現象:
[root@controller ~]# glance image-create --name "cirros-0.3.3-x86_64" --file cirros-0.3.3-x86_64-disk.img --disk-format qcow2 --container-format bare --is-public True --progress
You must provide a username via either --os-username or env[OS_USERNAME]
### --- 解決方案:
~~~ 執行admin環境指令碼,以便執行管理命令
[root@controller ~]# source admin-openrc.sh // 執行環境變數指令碼
===============================END===============================
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart ——W.S.Landor
來自為知筆記(Wiz)