當前位置:網站首頁>G020-OP-INS-RHEL-02 RedHat OpenStack 發放雲主機(命令行)

G020-OP-INS-RHEL-02 RedHat OpenStack 發放雲主機(命令行)

2022-05-13 18:18:2351CTO

1 您需要了解

  • 本篇采用 OpenStack 命令行進行操作
  • 模擬彈性公網 EIP 地址段規劃 :采用和控制節點、計算節點及 NTP 節點同一網段即可,如:192.168.45.0/24
  • 模擬雲主機私網 IP 地址段規劃 :自定義網段,如:192.168.100.0/24
  • RedHatOpenStack 環境可參考下方 G019 博文進行搭建
  • 文章中所提到的 公網外網彈性IP 均為模擬網段,本環境特指 192.168.45.0/24
  • 發放雲主機所使用的測試鏡像 cirros-0.5.2-x86_64-disk.img 點擊這裏 進行下載

2 環境配置

2.1 創建 BR-EX 虛擬交換機

創建 br-ex(OVS類型)虛擬交換機,目的是為了使用三方工具(外部)通過彈性IP連接到雲主機(內部),也是未來雲主機訪問外部網絡的必經之路。

  • 創建 br-ex 網卡並修改如下
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-eno16777736 ifcfg-br-ex
[[email protected] network-scripts]# vim ifcfg-br-ex 
[[email protected] network-scripts]# cat ifcfg-br-ex 
TYPE=OVSBridge
BOOTPROTO=none
DEFROUTE=yes
NAME=br-ex
UUID=c4fd661f-6ce8-4532-ad57-4653077fefa2
DEVICE=br-ex
DEVICETYPE=ovs
ONBOOT=yes
DNS1=192.168.45.1
IPADDR=192.168.45.150
PREFIX=24
GATEWAY=192.168.45.1

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 原網卡內容修改如下
[[email protected] network-scripts]# vim ifcfg-eno16777736 
[[email protected] network-scripts]# cat ifcfg-eno16777736 
TYPE=OVSPort
BOOTPROTO=none
DEFROUTE=yes
NAME=eno16777736
UUID=c4fd661f-6ce8-4532-ad57-4653077fefa2
DEVICE=eno16777736
DEVICETYPE=ovs
OVS_BRIDGE=br-ex
ONBOOT=yes

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 重啟網絡服務並查看 ovs
[[email protected] network-scripts]# service network restart 
Restarting network (via systemctl):                        [  OK  ]
[[email protected] network-scripts]# ovs-vsctl show

     
  • 1.
  • 2.
  • 3.

2.2 創建用戶環境變量文件

RedHat OpenStack 環境搭建好之後,會在控制節點 root 家目錄下生成 keystonerc_admin 文件,該文件指定了管理員 admin 用戶的環境變量。複制該文件並進行編輯,將它作為普通用戶(如 cloudcs)的環境變量文件。

[[email protected] ~]# cp keystonerc_admin keystonerc_cloudcs
[[email protected] ~]# vim keystonerc_cloudcs 
[[email protected] ~]# cat keystonerc_cloudcs 
export OS_USERNAME=cloudcs
export OS_TENANT_NAME=cloud
export OS_PASSWORD=redhat
export OS_AUTH_URL=http://192.168.45.150:5000/v2.0/
export OS_REGION_NAME=WuHan
export PS1='[\[email protected]\h \W(keystone_cloudcs)]\$ '

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

3 發放操作

3.1 創建租戶(Keystone)

注意 :租戶名與環境變量文件 keystonerc_cloudcs 中的 OS_TENANT_NAME 保持一致

  • 創建
[[email protected] ~]# source keystonerc_admin 
[[email protected] ~(keystone_admin)]# keystone tenant-create --name cloud --description cloud.tenant
+-------------+----------------------------------+
|   Property  |              Value               |
+-------------+----------------------------------+
| description |           cloud.tenant           |
|   enabled   |               True               |
|      id     | a530945733cb4bf4b48291516b4f0871 |
|     name    |              cloud               |
+-------------+----------------------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 查看
[[email protected] ~(keystone_admin)]# keystone tenant-list 
+----------------------------------+----------+---------+
|                id                |   name   | enabled |
+----------------------------------+----------+---------+
| 4f82f5364afd4b43bd617d9db95004ce |  admin   |   True  |
| a530945733cb4bf4b48291516b4f0871 |  cloud   |   True  |
| 56efa6dbc50a4fdab535867f5cf4af4c | services |   True  |
+----------------------------------+----------+---------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

3.2 創建用戶(Keystone)

注意 :用戶名與環境變量文件 keystonerc_cloudcs 中的 OS_USERNAME 保持一致

  • 創建
[[email protected] ~(keystone_admin)]# keystone user-create --name cloudcs --pass redhat --tenant cloud
+----------+----------------------------------+
| Property |              Value               |
+----------+----------------------------------+
|  email   |                                  |
| enabled  |               True               |
|    id    | f95c9cbf86c14468bd1527b8b9bd6a9f |
|   name   |             cloudcs              |
| tenantId | a530945733cb4bf4b48291516b4f0871 |
| username |             cloudcs              |
+----------+----------------------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 查看
[[email protected] ~(keystone_admin)]# keystone user-list 
+----------------------------------+------------+---------+----------------------+
|                id                |    name    | enabled |        email         |
+----------------------------------+------------+---------+----------------------+
| 6ab83537adee422ab19b80285f3dc650 |   admin    |   True  |    [email protected]    |
| b9836d0742bf4846adbfa45a36b1326b | ceilometer |   True  | [email protected] |
| 299fb3d55cdb411f9e6567ba9d90c7b9 |   cinder   |   True  |   [email protected]   |
| f95c9cbf86c14468bd1527b8b9bd6a9f |  cloudcs   |   True  |                      |
| f8aeae7e02074fc193dbf73867df1f9b |   glance   |   True  |   [email protected]   |
| 8006f7c5099b468385ed8b6c3280f0ff |  neutron   |   True  |  [email protected]   |
| 9c2e14eea3f04de5be6ad35f4af9c389 |    nova    |   True  |    [email protected]    |
| 467ead4a5bd94b97bef80fc0a0e93540 |   swift    |   True  |   [email protected]calhost    |
+----------------------------------+------------+---------+----------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

3.3 創建鏡像(Glance)

注意 :創建的鏡像需提前下載並上傳至控制節點

  • 創建
[[email protected] ~(keystone_admin)]# ls /soft/
cirros-0.5.2-x86_64-disk.img 
[[email protected] ~(keystone_admin)]# glance image-create \
> --name cirros \
> --disk-format qcow2 \
> --container-format bare \
> --file=/soft/cirros-0.5.2-x86_64-disk.img \
> --is-public true --progress
[=============================>] 100%
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | b874c39491a2377b8490f5f1e89761a4     |
| container_format | bare                                 |
| created_at       | 2022-05-13T01:13:54                  |
| deleted          | False                                |
| deleted_at       | None                                 |
| disk_format      | qcow2                                |
| id               | 6a8eeae6-fae9-4665-ab32-684fda6a334f |
| is_public        | True                                 |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | cirros                               |
| owner            | 4f82f5364afd4b43bd617d9db95004ce     |
| protected        | False                                |
| size             | 16300544                             |
| status           | active                               |
| updated_at       | 2022-05-13T01:13:54                  |
| virtual_size     | None                                 |
+------------------+--------------------------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 查看
[[email protected] ~(keystone_admin)]# glance image-list
+--------------------------------------+--------+-------------+------------------+----------+--------+
| ID                                   | Name   | Disk Format | Container Format | Size     | Status |
+--------------------------------------+--------+-------------+------------------+----------+--------+
| 6a8eeae6-fae9-4665-ab32-684fda6a334f | cirros | qcow2       | bare             | 16300544 | active |
+--------------------------------------+--------+-------------+------------------+----------+--------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

3.4 創建規格(Nova)

注意 :創建的鏡像需提前下載並上傳至控制節點

  • 創建
[[email protected] ~(keystone_admin)]# nova flavor-create m2.tiny auto 2048 5 1
+--------------------------------------+---------+-----------+------+-----------+------+-------+-------------+-----------+
| ID                                   | Name    | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+--------------------------------------+---------+-----------+------+-----------+------+-------+-------------+-----------+
| 5b8a69da-76a8-494d-b605-7413689204de | m2.tiny | 2048      | 5    | 0         |      | 1     | 1.0         | True      |
+--------------------------------------+---------+-----------+------+-----------+------+-------+-------------+-----------+


     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 查看
[[email protected] ~(keystone_admin)]# nova flavor-list 
+--------------------------------------+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| ID                                   | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+--------------------------------------+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| 1                                    | m1.tiny   | 512       | 1    | 0         |      | 1     | 1.0         | True      |
| 2                                    | m1.small  | 2048      | 20   | 0         |      | 1     | 1.0         | True      |
| 3                                    | m1.medium | 4096      | 40   | 0         |      | 2     | 1.0         | True      |
| 4                                    | m1.large  | 8192      | 80   | 0         |      | 4     | 1.0         | True      |
| 5                                    | m1.xlarge | 16384     | 160  | 0         |      | 8     | 1.0         | True      |
| 5b8a69da-76a8-494d-b605-7413689204de | m2.tiny   | 2048      | 5    | 0         |      | 1     | 1.0         | True      |
+--------------------------------------+-----------+-----------+------+-----------+------+-------+-------------+-----------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

3.5 創建網絡(Neutron)

3.5.1 創建公網

  • 創建公網
[[email protected] ~(keystone_admin)]# source keystonerc_cloudcs 
[[email protected] ~(keystone_cloudcs)]# neutron net-create public
Created a new network:
+-----------------+--------------------------------------+
| Field           | Value                                |
+-----------------+--------------------------------------+
| admin_state_up  | True                                 |
| id              | fc27b34c-1505-43a7-a454-f254d65aa024 |
| name            | public                               |
| router:external | False                                |
| shared          | False                                |
| status          | ACTIVE                               |
| subnets         |                                      |
| tenant_id       | a530945733cb4bf4b48291516b4f0871     |
+-----------------+--------------------------------------+

[[email protected] ~(keystone_cloudcs)]# neutron net-list
+--------------------------------------+--------+------------------------------------------------------+
| id                                   | name   | subnets                                              |
+--------------------------------------+--------+------------------------------------------------------+
| fc27b34c-1505-43a7-a454-f254d65aa024 | public | 41b0163e-fe41-4392-ae21-88b63064da12 192.168.45.0/24 |
+--------------------------------------+--------+------------------------------------------------------+


     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 創建公網子網
[[email protected] ~(keystone_cloudcs)]# neutron subnet-create \
> --name public_sub \
> --allocation-pool start=192.168.45.230,end=192.168.45.240 \
> --disable-dhcp \
> --gateway 192.168.45.254 public 192.168.45.0/24
Created a new subnet:
+-------------------+------------------------------------------------------+
| Field             | Value                                                |
+-------------------+------------------------------------------------------+
| allocation_pools  | {"start": "192.168.45.230", "end": "192.168.45.240"} |
| cidr              | 192.168.45.0/24                                      |
| dns_nameservers   |                                                      |
| enable_dhcp       | False                                                |
| gateway_ip        | 192.168.45.254                                       |
| host_routes       |                                                      |
| id                | 41b0163e-fe41-4392-ae21-88b63064da12                 |
| ip_version        | 4                                                    |
| ipv6_address_mode |                                                      |
| ipv6_ra_mode      |                                                      |
| name              | public_sub                                           |
| network_id        | fc27b34c-1505-43a7-a454-f254d65aa024                 |
| tenant_id         | a530945733cb4bf4b48291516b4f0871                     |
+-------------------+------------------------------------------------------+

[[email protected] ~(keystone_cloudcs)]# neutron subnet-list 
+--------------------------------------+------------+-----------------+------------------------------------------------------+
| id                                   | name       | cidr            | allocation_pools                                     |
+--------------------------------------+------------+-----------------+------------------------------------------------------+
| 41b0163e-fe41-4392-ae21-88b63064da12 | public_sub | 192.168.45.0/24 | {"start": "192.168.45.230", "end": "192.168.45.240"} |
+--------------------------------------+------------+-----------------+------------------------------------------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 將網絡更新為共享的和外部的
[[email protected] ~(keystone_cloudcs)]# source keystonerc_admin
[[email protected] ~(keystone_admin)]# neutron net-update --shared=true --router:external=true public
Updated network: public

[[email protected] ~(keystone_admin)]# neutron net-show public
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| id                        | fc27b34c-1505-43a7-a454-f254d65aa024 |
| name                      | public                               |
| provider:network_type     | vxlan                                |
| provider:physical_network |                                      |
| provider:segmentation_id  | 10                                   |
| router:external           | True                                 |
| shared                    | True                                 |
| status                    | ACTIVE                               |
| subnets                   | 41b0163e-fe41-4392-ae21-88b63064da12 |
| tenant_id                 | a530945733cb4bf4b48291516b4f0871     |
+---------------------------+--------------------------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.

3.5.2 創建私網

  • 創建私網
[[email protected] ~(keystone_admin)]# source keystonerc_cloudcs 
[[email protected] ~(keystone_cloudcs)]# neutron net-create private
Created a new network:
+-----------------+--------------------------------------+
| Field           | Value                                |
+-----------------+--------------------------------------+
| admin_state_up  | True                                 |
| id              | e2986914-856f-4360-a292-da845804073d |
| name            | private                              |
| router:external | False                                |
| shared          | False                                |
| status          | ACTIVE                               |
| subnets         |                                      |
| tenant_id       | a530945733cb4bf4b48291516b4f0871     |
+-----------------+--------------------------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 創建私網子網
[[email protected] ~(keystone_cloudcs)]# neutron subnet-create --name private_sub --enable-dhcp private 192.168.100.0/24
Created a new subnet:
+-------------------+------------------------------------------------------+
| Field             | Value                                                |
+-------------------+------------------------------------------------------+
| allocation_pools  | {"start": "192.168.100.2", "end": "192.168.100.254"} |
| cidr              | 192.168.100.0/24                                     |
| dns_nameservers   |                                                      |
| enable_dhcp       | True                                                 |
| gateway_ip        | 192.168.100.1                                        |
| host_routes       |                                                      |
| id                | 82a5961c-4cda-43e1-b464-445079d14c42                 |
| ip_version        | 4                                                    |
| ipv6_address_mode |                                                      |
| ipv6_ra_mode      |                                                      |
| name              | private_sub                                          |
| network_id        | e2986914-856f-4360-a292-da845804073d                 |
| tenant_id         | a530945733cb4bf4b48291516b4f0871                     |
+-------------------+------------------------------------------------------+

[[email protected] ~(keystone_cloudcs)]# neutron net-list
+--------------------------------------+---------+-------------------------------------------------------+
| id                                   | name    | subnets                                               |
+--------------------------------------+---------+-------------------------------------------------------+
| fc27b34c-1505-43a7-a454-f254d65aa024 | public  | 41b0163e-fe41-4392-ae21-88b63064da12 192.168.45.0/24  |
| e2986914-856f-4360-a292-da845804073d | private | 82a5961c-4cda-43e1-b464-445079d14c42 192.168.100.0/24 |
+--------------------------------------+---------+-------------------------------------------------------+
[[email protected] ~(keystone_cloudcs)]# neutron subnet-list
+--------------------------------------+-------------+------------------+------------------------------------------------------+
| id                                   | name        | cidr             | allocation_pools                                     |
+--------------------------------------+-------------+------------------+------------------------------------------------------+
| 41b0163e-fe41-4392-ae21-88b63064da12 | public_sub  | 192.168.45.0/24  | {"start": "192.168.45.230", "end": "192.168.45.240"} |
| 82a5961c-4cda-43e1-b464-445079d14c42 | private_sub | 192.168.100.0/24 | {"start": "192.168.100.2", "end": "192.168.100.254"} |
+--------------------------------------+-------------+------------------+------------------------------------------------------+


     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.

3.5.3 創建路由

  • 創建路由
[[email protected] ~(keystone_cloudcs)]# neutron router-create router01
Created a new router:
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| admin_state_up        | True                                 |
| external_gateway_info |                                      |
| id                    | 3dd25c07-7b77-48e0-ae24-9b3a162b3df7 |
| name                  | router01                             |
| routes                |                                      |
| status                | ACTIVE                               |
| tenant_id             | a530945733cb4bf4b48291516b4f0871     |
+-----------------------+--------------------------------------+

[[email protected] ~(keystone_cloudcs)]# neutron router-list
+--------------------------------------+----------+-----------------------+
| id                                   | name     | external_gateway_info |
+--------------------------------------+----------+-----------------------+
| 3dd25c07-7b77-48e0-ae24-9b3a162b3df7 | router01 | null                  |
+--------------------------------------+----------+-----------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 設置網關
[[email protected] ~(keystone_cloudcs)]# neutron router-gateway-set router01 public
Set gateway for router router01

     
  • 1.
  • 2.
  • 設置路由接口
[[email protected] ~(keystone_cloudcs)]# neutron router-interface-add router01 private_sub
Added interface 05534215-7af5-4248-8903-f3e038cdefbd to router router01.

     
  • 1.
  • 2.

3.6 創建安全組(Neutron)

  • 創建安全組
[[email protected] ~(keystone_cloudcs)]# neutron security-group-create sec01
[[email protected] ~(keystone_cloudcs)]# neutron security-group-list 
+--------------------------------------+---------+-------------+
| id                                   | name    | description |
+--------------------------------------+---------+-------------+
| 90fc7f5d-8458-49b6-8cd3-489ea8a6d3e7 | sec01   |             |
| 93737ddb-4750-469f-9946-8af3fb6e2f81 | default | default     |
+--------------------------------------+---------+-------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 設置安全組規則,添加入方向 icmp(ping) 及 22(ssh) 端口
[[email protected] ~(keystone_cloudcs)]# neutron security-group-rule-create --direction ingress --protocol icmp sec01
Created a new security_group_rule:
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| direction         | ingress                              |
| ethertype         | IPv4                                 |
| id                | 4c5d001a-93fa-4a13-bd53-dd4df135eb92 |
| port_range_max    |                                      |
| port_range_min    |                                      |
| protocol          | icmp                                 |
| remote_group_id   |                                      |
| remote_ip_prefix  |                                      |
| security_group_id | 90fc7f5d-8458-49b6-8cd3-489ea8a6d3e7 |
| tenant_id         | a530945733cb4bf4b48291516b4f0871     |
+-------------------+--------------------------------------+

[[email protected] ~(keystone_cloudcs)]# neutron security-group-rule-create --direction ingress --protocol tcp --port-range-min 22 --port-range-max 22 sec01
Created a new security_group_rule:
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| direction         | ingress                              |
| ethertype         | IPv4                                 |
| id                | 6da3efb0-9190-4506-a475-264489dd7453 |
| port_range_max    | 22                                   |
| port_range_min    | 22                                   |
| protocol          | tcp                                  |
| remote_group_id   |                                      |
| remote_ip_prefix  |                                      |
| security_group_id | 90fc7f5d-8458-49b6-8cd3-489ea8a6d3e7 |
| tenant_id         | a530945733cb4bf4b48291516b4f0871     |
+-------------------+--------------------------------------+

[[email protected] ~(keystone_cloudcs)]# neutron security-group-rule-list 
+--------------------------------------+----------------+-----------+----------+------------------+--------------+
| id                                   | security_group | direction | protocol | remote_ip_prefix | remote_group |
+--------------------------------------+----------------+-----------+----------+------------------+--------------+
| 2e75fd97-cd8b-48fd-b82a-5b563a32dc4e | sec01          | egress    |          |                  |              |
| 46a11379-afe2-4873-8768-e43ca55887e3 | default        | ingress   |          |                  | default      |
| 4c5d001a-93fa-4a13-bd53-dd4df135eb92 | sec01          | ingress   | icmp     |                  |              |
| 620144c0-5d45-4605-8855-562e7c8c6a89 | default        | ingress   |          |                  | default      |
| 6da3efb0-9190-4506-a475-264489dd7453 | sec01          | ingress   | tcp      |                  |              |
| 8b9fb51a-e8ed-4963-b8d5-3545e4b133f9 | default        | egress    |          |                  |              |
| cd3c2347-915f-4545-af4b-7f30da58cfb5 | default        | egress    |          |                  |              |
| d4f1cefd-f604-43e7-8124-ea93661a810c | sec01          | egress    |          |                  |              |
+--------------------------------------+----------------+-----------+----------+------------------+--------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.

3.7 創建密鑰(Nova)

[[email protected] ~(keystone_cloudcs)]# nova keypair-add key01 > key01.pem
[[email protected] ~(keystone_cloudcs)]# ls
anaconda-ks.cfg  Desktop    Downloads             key01.pem         keystonerc_cloudcs  Music     Public     Videos
cloudcs.txt      Documents  initial-setup-ks.cfg  keystonerc_admin  keystonerc_user     Pictures  Templates

     
  • 1.
  • 2.
  • 3.
  • 4.

3.8 創建雲主機(Nova)

3.8.1 獲取所需信息

  • 獲取規格
[[email protected] ~(keystone_cloudcs)]# nova flavor-list 
+--------------------------------------+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| ID                                   | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+--------------------------------------+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| 1                                    | m1.tiny   | 512       | 1    | 0         |      | 1     | 1.0         | True      |
| 2                                    | m1.small  | 2048      | 20   | 0         |      | 1     | 1.0         | True      |
| 3                                    | m1.medium | 4096      | 40   | 0         |      | 2     | 1.0         | True      |
| 4                                    | m1.large  | 8192      | 80   | 0         |      | 4     | 1.0         | True      |
| 5                                    | m1.xlarge | 16384     | 160  | 0         |      | 8     | 1.0         | True      |
| 5b8a69da-76a8-494d-b605-7413689204de | m2.tiny   | 2048      | 5    | 0         |      | 1     | 1.0         | True      |
+--------------------------------------+-----------+-----------+------+-----------+------+-------+-------------+-----------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 獲取鏡像
[[email protected] ~(keystone_cloudcs)]# glance image-list
+--------------------------------------+--------+-------------+------------------+----------+--------+
| ID                                   | Name   | Disk Format | Container Format | Size     | Status |
+--------------------------------------+--------+-------------+------------------+----------+--------+
| 6a8eeae6-fae9-4665-ab32-684fda6a334f | cirros | qcow2       | bare             | 16300544 | active |
+--------------------------------------+--------+-------------+------------------+----------+--------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 獲取密鑰
[[email protected] ~(keystone_cloudcs)]# nova keypair-list 
+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| key01 | 69:d5:8c:63:b1:f6:fe:3f:f6:60:fe:11:7c:9a:87:dd |
+-------+-------------------------------------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 獲取安全組
[[email protected] ~(keystone_cloudcs)]# neutron security-group-list 
+--------------------------------------+---------+-------------+
| id                                   | name    | description |
+--------------------------------------+---------+-------------+
| 90fc7f5d-8458-49b6-8cd3-489ea8a6d3e7 | sec01   |             |
| 93737ddb-4750-469f-9946-8af3fb6e2f81 | default | default     |
+--------------------------------------+---------+-------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 獲取私網 net-id
[[email protected] ~(keystone_cloudcs)]# neutron net-list
+--------------------------------------+---------+-------------------------------------------------------+
| id                                   | name    | subnets                                               |
+--------------------------------------+---------+-------------------------------------------------------+
| fc27b34c-1505-43a7-a454-f254d65aa024 | public  | 41b0163e-fe41-4392-ae21-88b63064da12 192.168.45.0/24  |
| e2986914-856f-4360-a292-da845804073d | private | 82a5961c-4cda-43e1-b464-445079d14c42 192.168.100.0/24 |
+--------------------------------------+---------+-------------------------------------------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

3.8.2 創建雲主機

[[email protected] ~(keystone_cloudcs)]# nova boot \
> --flavor m2.tiny \
> --image cirros \
> --min-count 1 \
> --key-name key01 \
> --security-groups sec01 \
> --nic net-id=e2986914-856f-4360-a292-da845804073d ecs01
+--------------------------------------+------------------------------------------------+
| Property                             | Value                                          |
+--------------------------------------+------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                         |
| OS-EXT-AZ:availability_zone          | nova                                           |
| OS-EXT-STS:power_state               | 0                                              |
| OS-EXT-STS:task_state                | scheduling                                     |
| OS-EXT-STS:vm_state                  | building                                       |
| OS-SRV-USG:launched_at               | -                                              |
| OS-SRV-USG:terminated_at             | -                                              |
| accessIPv4                           |                                                |
| accessIPv6                           |                                                |
| adminPass                            | gL6QDnAcTedj                                   |
| config_drive                         |                                                |
| created                              | 2022-05-13T02:29:08Z                           |
| flavor                               | m2.tiny (5b8a69da-76a8-494d-b605-7413689204de) |
| hostId                               |                                                |
| id                                   | 342631e7-e540-45e0-b79b-e487f811a01e           |
| image                                | cirros (6a8eeae6-fae9-4665-ab32-684fda6a334f)  |
| key_name                             | key01                                          |
| metadata                             | {}                                             |
| name                                 | ecs01                                          |
| os-extended-volumes:volumes_attached | []                                             |
| progress                             | 0                                              |
| security_groups                      | sec01                                          |
| status                               | BUILD                                          |
| tenant_id                            | a530945733cb4bf4b48291516b4f0871               |
| updated                              | 2022-05-13T02:29:08Z                           |
| user_id                              | f95c9cbf86c14468bd1527b8b9bd6a9f               |
+--------------------------------------+------------------------------------------------+

[[email protected] ~(keystone_cloudcs)]# nova list
+--------------------------------------+-------+--------+------------+-------------+-----------------------+
| ID                                   | Name  | Status | Task State | Power State | Networks              |
+--------------------------------------+-------+--------+------------+-------------+-----------------------+
| 342631e7-e540-45e0-b79b-e487f811a01e | ecs01 | ACTIVE | -          | Running     | private=192.168.100.2 |
+--------------------------------------+-------+--------+------------+-------------+-----------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.

3.9 綁定浮動IP

3.9.1 申請浮動 IP(Neutron)

[[email protected] ~(keystone_cloudcs)]# neutron floatingip-create public
Created a new floatingip:
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| fixed_ip_address    |                                      |
| floating_ip_address | 192.168.45.231                       |
| floating_network_id | fc27b34c-1505-43a7-a454-f254d65aa024 |
| id                  | e13cdca7-1314-4f88-a080-acc98d6b57a2 |
| port_id             |                                      |
| router_id           |                                      |
| status              | DOWN                                 |
| tenant_id           | a530945733cb4bf4b48291516b4f0871     |
+---------------------+--------------------------------------+

[[email protected] ~(keystone_cloudcs)]# neutron floatingip-list 
+--------------------------------------+------------------+---------------------+---------+
| id                                   | fixed_ip_address | floating_ip_address | port_id |
+--------------------------------------+------------------+---------------------+---------+
| e13cdca7-1314-4f88-a080-acc98d6b57a2 |                  | 192.168.45.231      |         |
+--------------------------------------+------------------+---------------------+---------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.

3.9.2 綁定浮動 IP(Nova)

[[email protected] ~(keystone_cloudcs)]# nova floating-ip-associate ecs01 192.168.45.231
[[email protected] ~(keystone_cloudcs)]# nova list
+--------------------------------------+-------+--------+------------+-------------+---------------------------------------+
| ID                                   | Name  | Status | Task State | Power State | Networks                              |
+--------------------------------------+-------+--------+------------+-------------+---------------------------------------+
| 342631e7-e540-45e0-b79b-e487f811a01e | ecs01 | ACTIVE | -          | Running     | private=192.168.100.2, 192.168.45.231 |
+--------------------------------------+-------+--------+------------+-------------+---------------------------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 宿主機嘗試 ping
C:\Users\cloudcs>ping 192.168.45.231

正在 Ping 192.168.45.231 具有 32 字節的數據:
來自 192.168.45.231 的回複: 字節=32 時間=3ms TTL=63
來自 192.168.45.231 的回複: 字節=32 時間=1ms TTL=63
來自 192.168.45.231 的回複: 字節=32 時間=2ms TTL=63
來自 192.168.45.231 的回複: 字節=32 時間=4ms TTL=63

192.168.45.231 的 Ping 統計信息:
    數據包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
往返行程的估計時間(以毫秒為單比特):
    最短 = 1ms,最長 = 4ms,平均 = 2ms

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.

3.10 綁定雲硬盤

3.10.1 申請雲硬盤(Cinder)

[[email protected] ~(keystone_cloudcs)]# cinder create --display-name evs01 2
+---------------------+--------------------------------------+
|       Property      |                Value                 |
+---------------------+--------------------------------------+
|     attachments     |                  []                  |
|  availability_zone  |                 nova                 |
|       bootable      |                false                 |
|      created_at     |      2022-05-13T02:41:44.744620      |
| display_description |                 None                 |
|     display_name    |                evs01                 |
|      encrypted      |                False                 |
|          id         | 47c82317-5477-495a-a357-bac3c22c05a6 |
|       metadata      |                  {}                  |
|         size        |                  2                   |
|     snapshot_id     |                 None                 |
|     source_volid    |                 None                 |
|        status       |               creating               |
|     volume_type     |                 None                 |
+---------------------+--------------------------------------+

[[email protected] ~(keystone_cloudcs)]# cinder list
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
|                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
| 47c82317-5477-495a-a357-bac3c22c05a6 | available |    evs01     |  2   |     None    |  false   |             |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.

3.10.2 附加雲硬盤(Nova)

[[email protected] ~(keystone_cloudcs)]# nova volume-attach ecs01 47c82317-5477-495a-a357-bac3c22c05a6
+----------+--------------------------------------+
| Property | Value                                |
+----------+--------------------------------------+
| device   | /dev/vdb                             |
| id       | 47c82317-5477-495a-a357-bac3c22c05a6 |
| serverId | 342631e7-e540-45e0-b79b-e487f811a01e |
| volumeId | 47c82317-5477-495a-a357-bac3c22c05a6 |
+----------+--------------------------------------+

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

4 登錄操作

4.1 登錄雲主機

通過彈性IP使用密鑰進行登錄

[[email protected] ~(keystone_cloudcs)]# ssh -i key01.pem [email protected]

The authenticity of host '192.168.45.231 (192.168.45.231)' can't be established. ECDSA key fingerprint is f4:01:49:1e:4b:99:77:b1:80:45:53:6f:b9:c1:ae:9e. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.45.231' (ECDSA) to the list of known hosts.

$ sudo -i
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc pfifo_fast qlen 1000
    link/ether fa:16:3e:c8:25:c0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.2/24 brd 192.168.100.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fec8:25c0/64 scope link 
       valid_lft forever preferred_lft forever

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.

4.2 使用雲硬盤

4.2.1 格式化雲硬盤

  • 查看
# fdisk -l
Disk /dev/vda: 5 GiB, 5368709120 bytes, 10485760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 92674365-8FD5-41C2-B173-9F3F1E3BA5A1

Device     Start      End  Sectors Size Type
/dev/vda1  18432 10485726 10467295   5G Linux filesystem
/dev/vda15  2048    18431    16384   8M EFI System

Partition table entries are not in disk order.


Disk /dev/vdb: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 創建分區
# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.33).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x0a2fc205.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-4194303, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-4194303, default 4194303): 

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 格式化
# mkfs.ext3 /dev/vdb1
mke2fs 1.44.5 (15-Dec-2018)
Creating filesystem with 524032 4k blocks and 131072 inodes
Filesystem UUID: 0626ceb7-4e89-476a-b2f8-391455bc1e77
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

4.2.2 創建文件系統

# mkdir /data
# mount /dev/vdb1 /data/
# df -Th
Filesystem           Type            Size      Used Available Use% Mounted on
/dev                 devtmpfs      986.7M         0    986.7M   0% /dev
/dev/vda1            ext3            4.9G     31.5M      4.7G   1% /
tmpfs                tmpfs         993.8M         0    993.8M   0% /dev/shm
tmpfs                tmpfs         993.8M     84.0K    993.7M   0% /run
/dev/vdb1            ext3            1.9G      3.0M      1.8G   0% /data

     
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

  • END

版權聲明
本文為[51CTO]所創,轉載請帶上原文鏈接,感謝
https://cht.chowdera.com/2022/133/202205131657442930.html

隨機推薦