Create an OpenStack cloud host

create process

  1. Create a virtual network
  2. Create a host of m1.nano specification (equivalent to defining the hardware configuration of the virtual machine)
  3. Generate a key pair (the principle of openstack is not to use a password to connect, but to use a key pair to connect)
  4. Add security group rules (security group made with iptables)
  5. Start an instance (there are three types of startup virtual machines: 1. Command CLI 2.api 3.Dashboard) In fact, Dashboard also operates through api
  6. The virtual network is divided into a provider network and a private network. The provider network is in the same network as the host, and the private network customizes the router, etc., and is not in the same network as the host.

 

1.) Create the network

1.1. Node operation, create network

[root@controller ~]# source admin-openrc

[root@controller ~]# neutron net-create --shared --provider:physical_network provider --provider:network_type flat public-net
Created a new network:
+---------------------------+--------------------------------------+
| Field | Value |
+---------------------------+--------------------------------------+
| admin_state_up | True |
| availability_zone_hints | |
| availability_zones | |
| created_at | 2018-04-13T12:03:41Z |
| description | |
| id | c7e2a252-775d-48e1-a748-11089994f455 |
| ipv4_address_scope | |
| ipv6_address_scope | |
| man | 1500 |
| name | public-net |
| port_security_enabled | True |
| project_id | 24a37179b1844e8897e77a0c44cc8d25 |
| provider:network_type | flat |
| provider:physical_network | provider |
| provider:segmentation_id | |
| revision_number | 3 |
| router:external | False |
| shared | True |
| status | ACTIVE |
| subnets | |
| tags | |
| tenant_id | 24a37179b1844e8897e77a0c44cc8d25 |
| updated_at | 2018-04-13T12:03:41Z |
+---------------------------+--------------------------------------+

In the above figure, tenant_id is equal to project_id. View the project list as shown below

[root@controller ~]# openstack project list

+----------------------------------+---------+
| ID | Name |
+----------------------------------+---------+
| 24a37179b1844e8897e77a0c44cc8d25 | admin |
| a1c365af1dcb4811a96d10381d3b5606 | service |
| dece6a569ea74a43a50119d04edec8c8 | demo |
+----------------------------------+---------

1.2 Check if the creation is successful

[root@controller ~]# neutron net-list
+--------------------------------------+------------+---------+
| id | name | subnets |
+--------------------------------------+------------+---------+
| c7e2a252-775d-48e1-a748-11089994f455 | public-net | |
+--------------------------------------+------------+---------+

  

1.3 Create a subnet

[root@controller ~]# neutron subnet-create --name public-subnet \
> --allocation-pool start=10.0.0.100,end=10.0.0.200 \
> --dns-nameserver 233.5.5.5 --gateway 10.0.0.2 \
> public-net 10.0.0.0/24
Created a new subnet:
+-------------------+----------------------------------------------+
| Field             | Value                                        |
+-------------------+----------------------------------------------+
| allocation_pools  | {"start": "10.0.0.100", "end": "10.0.0.200"} |
| cidr | 10.0.0.0/24 |
| created_at        | 2018-04-13T12:08:37Z                         |
| description       |                                              |
| dns_nameservers   | 233.5.5.5                                    |
| enable_dhcp       | True                                         |
| gateway_ip        | 10.0.0.2                                     |
| host_routes       |                                              |
| id                | 4c5d0667-f711-4eb1-a750-0ae4143976b9         |
| ip_version        | 4                                            |
| ipv6_address_mode |                                              |
| ipv6_ra_mode      |                                              |
| name              | public-subnet                                |
| network_id        | c7e2a252-775d-48e1-a748-11089994f455         |
| project_id        | 24a37179b1844e8897e77a0c44cc8d25             |
| revision_number   | 2                                            |
| service_types     |                                              |
| subnetpool_id     |                                              |
| tenant_id         | 24a37179b1844e8897e77a0c44cc8d25             |
| updated_at        | 2018-04-13T12:08:37Z                         |
+-------------------+----------------------------------------------+

 Parameter Description

neutron subnet- create subnet creation
 -- name (name)
 -- allocation-pool allocation address pool
start = start IP address
end = end IP address
dns -nameserver DNS address, 233.5.5.5 is Ali's public DNS address
 -- gateway gateway
public -net provider's network name (corresponds to the name of the network created above)

 

1.4 Check whether the association is successful

[root@controller ~]# neutron net-list

+--------------------------------------+------------+--------------------------------------------------+
| id | name | subnets |
+--------------------------------------+------------+--------------------------------------------------+
| c7e2a252-775d-48e1-a748-11089994f455 | public-net | 4c5d0667-f711-4eb1-a750-0ae4143976b9 10.0.0.0/24 |
+--------------------------------------+------------+--------------------------------------------------+
[root@controller ~]#
[root@controller ~]# neutron subnet-list
+--------------------------------------+---------------+-------------+----------------------------------------------+
| id | name | cidr | allocation_pools |
+--------------------------------------+---------------+-------------+----------------------------------------------+
| 4c5d0667-f711-4eb1-a750-0ae4143976b9 | public-subnet | 10.0.0.0/24 | {"start": "10.0.0.100", "end": "10.0.0.200"} |
+--------------------------------------+---------------+-------------+----------------------------------------------+

  

1.5 Create a host with m1.nano specification (custom cloud host specification)

The default minimum specification of the host requires 512 MB of memory. We recommend creating a host that requires only 64 MB of m1.nano specification. For testing purposes only, use a host with m1.nano specification to load the CirrOS image.

[root@controller ~]# openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
+----------------------------+---------+
| Field | Value |
+----------------------------+---------+
| OS-FLV-DISABLED:disabled | False |
| OS-FLV-EXT-DATA:ephemeral | 0 |
| disk | 1 |
| id | 0 |
| name | m1.nano |
| os-flavor-access:is_public | True |
| properties | |
| ram | 64 |
| rxtx_factor | 1.0 |
| swap | |
| vcpus | 1 |
+----------------------------+---------+

 

Parameter Description:
openstack flavor create create host
--id host ID
--vcpus number of cpus
--ram 64 (default is MB, can be written as G)
--disk disk (default unit is G)

  

1.6 View the creation result

[root@controller ~]# openstack flavor list
+----+---------+-----+------+-----------+-------+-----------+
| ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+---------+-----+------+-----------+-------+-----------+
| 0 | m1.nano | 64 | 1 | 0 | 1 | True |
+----+---------+-----+------+-----------+-------+-----------+

1.7 Generate secret key

Most cloud images support public key authentication instead of traditional password authentication. Before launching an instance, a public key must be added to the compute service.

[root@controller ~]# source admin-openrc
[root@controller ~]# ssh-keygen -q -N ""
Enter file in which to save the key (/root/.ssh/id_rsa):

1.8 Put the key on openstack

[root@controller ~]# openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
+-------------+-------------------------------------------------+
| Field | Value |
+-------------+-------------------------------------------------+
| fingerprint | e7:bb:a1:e5:a1:ef:1a:e7:ea:59:b2:67:cb:4c:5f:85 |
| name | mykey |
| user_id | ff64ec1a3fa7461d890b9757401d475d |
+-------------+-------------------------------------------------+

1.9 Verify the addition of the public key

[root@controller ~]# openstack keypair list
+-------+-------------------------------------------------+
| Name | Fingerprint |
+-------+-------------------------------------------------+
| mykey | e7:bb:a1:e5:a1:ef:1a:e7:ea:59:b2:67:cb:4c:5f:85 |
+-------+-------------------------------------------------+

1.10 Add security group rules
to allow ICMP (ping)

By default, the default security group applies to all instances and includes firewall rules that deny remote access to instances. For Linux images such as CirrOS, we recommend at least allowing ICMP (ping) and secure shell (SSH) rules.

[root@controller ~]# openstack security group rule create --proto icmp default
+-------------------+--------------------------------------+
| Field | Value |
+-------------------+--------------------------------------+
| created_at | 2018-04-13T12:16:28Z |
| description | |
| direction | ingress |
| ethertype | IPv4 |
| headers | |
| id | f45624e2-bd78-4131-82c6-c09ccdfbe317 |
| port_range_max | None |
| port_range_min | None |
| project_id | 24a37179b1844e8897e77a0c44cc8d25 |
| project_id | 24a37179b1844e8897e77a0c44cc8d25 |
| protocol | icmp |
| remote_group_id | None |
| remote_ip_prefix | 0.0.0.0/0 |
| revision_number | 1 |
| security_group_id | b40c315f-9625-4877-a9f4-3b52b1f750d1 |
| updated_at | 2018-04-13T12:16:28Z |
+-------------------+--------------------------------------+

 Allow secure shell (SSH) access

openstack security group rule create --proto tcp --dst-port 22 default

1.11 View the ID of the network

[root@controller ~]# openstack network list
+--------------------------------------+------------+--------------------------------------+
| ID | Name | Subnets |
+--------------------------------------+------------+--------------------------------------+
| c7e2a252-775d-48e1-a748-11089994f455 | public-net | 4c5d0667-f711-4eb1-a750-0ae4143976b9 |
+--------------------------------------+------------+--------------------------------------+

1.12 Create an instance

[root@controller ~]# openstack server create --flavor m1.nano --image cirros \
> --nic net-id=c7e2a252-775d-48e1-a748-11089994f455 --security-group default \
> --key-name mykey xuli-instance

+--------------------------------------+-----------------------------------------------+
| Field | Value |
+--------------------------------------+-----------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | |
| OS-EXT-SRV-ATTR:host | None |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None |
| OS-EXT-SRV-ATTR:instance_name | |
| OS-EXT-STS:power_state | NOSTATE |
| OS-EXT-STS:task_state | scheduling |
| OS-EXT-STS:vm_state | building |
| OS-SRV-USG:launched_at | None |
| OS-SRV-USG:terminated_at | None |
| accessIPv4 | |
| accessIPv6 | |
| addresses | |
| adminPass | rYP39r4N8th6 |
| config_drive | |
| created | 2018-04-13T12:19:11Z |
| flavor | m1.nano (0) |
| hostId | |
| id | d403e69a-adfc-41b6-937d-75156c080ce0 |
| image | cirros (c952e002-680e-45e1-9337-08d2c3a9abe6) |
| key_name | mykey |
| name | xuli-instance |
| os-extended-volumes:volumes_attached | [] |
| progress | 0 |
| project_id | 24a37179b1844e8897e77a0c44cc8d25 |
| properties | |
| security_groups | [{u'name': u'default'}] |
| status | BUILD |
| updated | 2018-04-13T12:19:12Z |
| user_id | ff64ec1a3fa7461d890b9757401d475d |
+--------------------------------------+-----------------------------------------------+

1.14 Viewing virtual machines 

[root@controller ~]# openstack server list

+--------------------------------------+------+---------+-----------------------+------------+
| ID | Name | Status | Networks | Image Name |
+--------------------------------------+------+---------+-----------------------+------------+
| b47c5250-20d7-4a05-a555-e59714a08959 | GGG | SHUTOFF | public-net=10.0.0.111 | |
| 1df453d3-c393-4277-8221-f73a1dc69709 | RRR | SHUTOFF | public-net=10.0.0.107 | |
| 3da5bba5-beae-435c-a9b6-cc774951e678 | QQQ | SHUTOFF | public-net=10.0.0.110 | |
+--------------------------------------+------+---------+-----------------------+------------+

1.15 View the URL address of the virtual machine

[root@controller ~]# openstack console url show GGG
+-------+---------------------------------------------------------------------------------+
| Field | Value |
+-------+---------------------------------------------------------------------------------+
| type | novnc |
| url | http://10.0.0.101:6080/vnc_auto.html?token=433f2e28-b480-4d35-96b2-5ac068f699e3 |
+-------+---------------------------------------------------------------------------------+

You can copy the above URL address and visit it in the browser

1.16 Troubleshooting

If the virtual machine cannot be created, we need to view the logs of all services of the control node and the computing node, as well as iptables, selinux, time synchronization, etc.

grip 'ERROR' / var / log / nova / *
grip 'ERROR' / var / log / neutron / *
grip 'ERROR' / var / log / glance / *
grip 'ERROR' / var / log / keystone / *

an examination

source admin-openstack.sh
nova service-list
neutron agent-list
nova image-list

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324535860&siteId=291194637