G020-OP-INS-RHEL-02 RedHat OpenStack 发放云主机(命令行)

Posted CloudCS

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了G020-OP-INS-RHEL-02 RedHat OpenStack 发放云主机(命令行)相关的知识,希望对你有一定的参考价值。

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 网卡并修改如下
[root@controller ~]# cd /etc/sysconfig/network-scripts/
[root@controller network-scripts]# cp ifcfg-eno16777736 ifcfg-br-ex
[root@controller network-scripts]# vim ifcfg-br-ex 
[root@controller 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
  • 原网卡内容修改如下
[root@controller network-scripts]# vim ifcfg-eno16777736 
[root@controller 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
  • 重启网络服务并查看 ovs
[root@controller network-scripts]# service network restart 
Restarting network (via systemctl):                        [  OK  ]
[root@controller network-scripts]# ovs-vsctl show

2.2 创建用户环境变量文件

[root@controller ~]# cp keystonerc_admin keystonerc_cloudcs
[root@controller ~]# vim keystonerc_cloudcs 
[root@controller ~]# 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=[\\u@\\h \\W(keystone_cloudcs)]\\$ 

3 发放操作

3.1 创建租户(Keystone)

  • 创建
[root@controller ~]# source keystonerc_admin         
[root@controller ~(keystone_admin)]# keystone tenant-create --name cloud --description cloud.tenant
+-------------+----------------------------------+
|   Property  |              Value               |
+-------------+----------------------------------+
| description |           cloud.tenant           |
|   enabled   |               True               |
|      id     | a530945733cb4bf4b48291516b4f0871 |
|     name    |              cloud               |
+-------------+----------------------------------+
  • 查看
[root@controller ~(keystone_admin)]# keystone tenant-list 
+----------------------------------+----------+---------+
|                id                |   name   | enabled |
+----------------------------------+----------+---------+
| 4f82f5364afd4b43bd617d9db95004ce |  admin   |   True  |
| a530945733cb4bf4b48291516b4f0871 |  cloud   |   True  |
| 56efa6dbc50a4fdab535867f5cf4af4c | services |   True  |
+----------------------------------+----------+---------+

3.2 创建用户(Keystone)

  • 创建
[root@controller ~(keystone_admin)]# keystone user-create --name cloudcs --pass redhat --tenant cloud
+----------+----------------------------------+
| Property |              Value               |
+----------+----------------------------------+
|  email   |                                  |
| enabled  |               True               |
|    id    | f95c9cbf86c14468bd1527b8b9bd6a9f |
|   name   |             cloudcs              |
| tenantId | a530945733cb4bf4b48291516b4f0871 |
| username |             cloudcs              |
+----------+----------------------------------+
  • 查看
[root@controller ~(keystone_admin)]# keystone user-list 
+----------------------------------+------------+---------+----------------------+
|                id                |    name    | enabled |        email         |
+----------------------------------+------------+---------+----------------------+
| 6ab83537adee422ab19b80285f3dc650 |   admin    |   True  |    root@localhost    |
| b9836d0742bf4846adbfa45a36b1326b | ceilometer |   True  | ceilometer@localhost |
| 299fb3d55cdb411f9e6567ba9d90c7b9 |   cinder   |   True  |   cinder@localhost   |
| f95c9cbf86c14468bd1527b8b9bd6a9f |  cloudcs   |   True  |                      |
| f8aeae7e02074fc193dbf73867df1f9b |   glance   |   True  |   glance@localhost   |
| 8006f7c5099b468385ed8b6c3280f0ff |  neutron   |   True  |  neutron@localhost   |
| 9c2e14eea3f04de5be6ad35f4af9c389 |    nova    |   True  |    nova@localhost    |
| 467ead4a5bd94b97bef80fc0a0e93540 |   swift    |   True  |   swift@localhost    |
+----------------------------------+------------+---------+----------------------+

3.3 创建镜像(Glance)

  • 创建
[root@controller ~(keystone_admin)]# ls /soft/
cirros-0.5.2-x86_64-disk.img 
[root@controller ~(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                                 |
+------------------+--------------------------------------+
  • 查看
[root@controller ~(keystone_admin)]# glance image-list
+--------------------------------------+--------+-------------+------------------+----------+--------+
| ID                                   | Name   | Disk Format | Container Format | Size     | Status |
+--------------------------------------+--------+-------------+------------------+----------+--------+
| 6a8eeae6-fae9-4665-ab32-684fda6a334f | cirros | qcow2       | bare             | 16300544 | active |
+--------------------------------------+--------+-------------+------------------+----------+--------+

3.4 创建规格(Nova)

  • 创建
[root@controller ~(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      |
+--------------------------------------+---------+-----------+------+-----------+------+-------+-------------+-----------+
  • 查看
[root@controller ~(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      |
+--------------------------------------+-----------+-----------+------+-----------+------+-------+-------------+-----------+

3.5 创建网络(Neutron)

3.5.1 创建公网

  • 创建公网
[root@controller ~(keystone_admin)]# source keystonerc_cloudcs 
[root@controller ~(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     |
+-----------------+--------------------------------------+

[root@controller ~(keystone_cloudcs)]# neutron net-list
+--------------------------------------+--------+------------------------------------------------------+
| id                                   | name   | subnets                                              |
+--------------------------------------+--------+------------------------------------------------------+
| fc27b34c-1505-43a7-a454-f254d65aa024 | public | 41b0163e-fe41-4392-ae21-88b63064da12 192.168.45.0/24 |
+--------------------------------------+--------+------------------------------------------------------+
  • 创建公网子网
[root@controller ~(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                     |
+-------------------+------------------------------------------------------+

[root@controller ~(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" |
+--------------------------------------+------------+-----------------+------------------------------------------------------+
  • 将网络更新为共享的和外部的
[root@controller ~(keystone_cloudcs)]# source keystonerc_admin
[root@controller ~(keystone_admin)]# neutron net-update --shared=true --router:external=true public
Updated network: public

[root@controller ~(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     |
+---------------------------+--------------------------------------+

3.5.2 创建私网

  • 创建私网
[root@controller ~(keystone_admin)]# source keystonerc_cloudcs 
[root@controller ~(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     |
+-----------------+--------------------------------------+
  • 创建私网子网
[root@controller ~(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                     |
+-------------------+------------------------------------------------------+

[root@controller ~(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 |
+--------------------------------------+---------+-------------------------------------------------------+
[root@controller ~(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" |
+--------------------------------------+-------------+------------------+------------------------------------------------------+

3.5.3 创建路由

  • 创建路由
[root@controller ~(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     |
+-----------------------+--------------------------------------+

[root@controller ~(keystone_cloudcs)]# neutron router-list
+--------------------------------------+----------+-----------------------+
| id                                   | name     | external_gateway_info |
+--------------------------------------+----------+-----------------------+
| 3dd25c07-7b77-48e0-ae24-9b3a162b3df7 | router01 | null                  |
+--------------------------------------+----------+-----------------------+
  • 设置网关
[root@controller ~(keystone_cloudcs)]# neutron router-gateway-set router01 public
Set gateway for router router01
  • 设置路由接口
[root@controller ~(keystone_cloudcs)]# neutron router-interface-add router01 private_sub
Added interface 05534215-7af5-4248-8903-f3e038cdefbd to router router01.

3.6 创建安全组(Neutron)

  • 创建安全组
[root@controller ~(keystone_cloudcs)]# neutron security-group-create sec01
[root@controller ~(keystone_cloudcs)]# neutron security-group-list 
+--------------------------------------+---------+-------------+
| id                                   | name    | description |
+--------------------------------------+---------+-------------+
| 90fc7f5d-8458-49b6-8cd3-489ea8a6d3e7 | sec01   |             |
| 93737ddb-4750-469f-9946-8af3fb6e2f81 | default | default     |
+--------------------------------------+---------+-------------+
  • 设置安全组规则,添加入方向 icmp(ping) 及 22(ssh) 端口
[root@controller ~(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     |
+-------------------+--------------------------------------+

[root@controller ~(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     |
+-------------------+--------------------------------------+

[root@controller ~(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    |          |                  |              |
+--------------------------------------+----------------+-----------+----------+------------------+--------------+

3.7 创建密钥(Nova)

[root@controller ~(keystone_cloudcs)]# nova keypair-add key01 > key01.pem
[root@controller ~(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

3.8 创建云主机(Nova)

3.8.1 获取所需信息

  • 获取规格
[root@controller ~(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      |
+--------------------------------------+-----------+-----------+------+-----------+------+-------+-------------+-----------+
  • 获取镜像
[root@controller ~(keystone_cloudcs)]# glance image-list
+--------------------------------------+--------+-------------+------------------+----------+--------+
| ID                                   | Name   | Disk Format | Container Format | Size     | Status |
+--------------------------------------+--------+-------------+------------------+----------+--------+
| 6a8eeae6-fae9-4665-ab32-684fda6a334f | cirros | qcow2       | bare             | 16300544 | active |
+--------------------------------------+--------+-------------+------------------+----------+--------+
  • 获取密钥
[root@controller ~(keystone_cloudcs)]# nova keypair-list 
+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| key01 | 69:d5:8c:63:b1:f6:fe:3f:f6:60:fe:11:7c:9a:87:dd |
+-------+-------------------------------------------------+
  • 获取安全组
[root@controller ~(keystone_cloudcs)]# neutron security-group-list 
+--------------------------------------+---------+-------------+
| id                                   | name    | description |
+--------------------------------------+---------+-------------+
| 90fc7f5d-8458-49b6-8cd3-489ea8a6d3e7 | sec01   |             |
| 93737ddb-4750-469f-9946-8af3fb6e2f81 | default | default     |
+--------------------------------------+---------+-------------+
  • 获取私网 net-id
[root@controller ~(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 |
+--------------------------------------+---------+-------------------------------------------------------+

3.8.2 创建云主机

[root@controller ~(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               |
+--------------------------------------+------------------------------------------------+

[root@controller ~(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 |
+--------------------------------------+-------+--------+------------+-------------+-----------------------+

3.9 绑定浮动IP

3.9.1 申请浮动 IP(Neutron)

[root@controller ~(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     |
+---------------------+--------------------------------------+

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

3.9.2 绑定浮动 IP(Nova)

[root@controller ~(keystone_cloudcs)]# nova floating-ip-associate ecs01 192.168.45.231
[root@controller ~(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 |
+--------------------------------------+-------+--------+------------+-------------+---------------------------------------+
  • 宿主机尝试 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


## 3.10 绑定云硬盘

### 3.10.1 申请云硬盘(Cinder)

```shell
[root@controller ~(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                 |
+---------------------+--------------------------------------+

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

3.10.2 附加云硬盘(Nova)

[root@controller ~(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 |
+----------+--------------------------------------+

4 登录操作

4.1 登录云主机

[root@controller ~(keystone_cloudcs)]# ssh -i key01.pem cirros@192.168.45.231

The authenticity of host 192.168.45.231 (192.168.45.231) cant 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

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
  • 创建分区
# 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 +/-sizeK,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.
  • 格式化
# 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

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

  • END

以上是关于G020-OP-INS-RHEL-02 RedHat OpenStack 发放云主机(命令行)的主要内容,如果未能解决你的问题,请参考以下文章

redha7 链路聚合

redha 精简开机,优化系统

redha7.2配置静态网卡(三步搞定)

安装saltstack

CentOS还好吗?

nginx升级