2.7创建虚拟机
2.7.1创建提供者虚拟网络
a在控制节点上,加载 admin 凭证来获取管理员能执行的命令访问权限
sourceadmin-openstack
b创建网络
openstack network create --share \
--provider-physical-network public \
--provider-network-type flat public
验证
[[email protected]~]# neutron net-list
+--------------------------------------+--------+---------+
| id | name |subnets |
+--------------------------------------+--------+---------+
| 98f8acb1-6ee4-43c4-b28b-d2a71b76a870| public | |
+--------------------------------------+--------+---------+
c在网络上创建一个子网
openstack subnet create --network public \
--allocation-pool start=192.168.56.100,end=192.168.56.200 \
--dns-nameserver 192.168.56.2 --gateway 192.168.56.2 \
--subnet-range 192.168.56.0/24 public-subnet
验证
[[email protected]~]# neutron subnet-list
+-------------------------------------+---------------+-----------------+-------------------------------------+
| id | name | cidr| allocation_pools |
+-------------------------------------+---------------+-----------------+-------------------------------------+
|5f912ae8-fa19-426d-91ca- | public-subnet | 192.168.56.0/24 |{"start": "192.168.56.100", "end": |
| 043e2e2d9664 | || "192.168.56.200"} |
+-------------------------------------+---------------+-----------------+-------------------------------------+
[[email protected]~]# neutron net-list
+--------------------------------------+--------+------------------------------------------------------+
| id | name |subnets |
+--------------------------------------+--------+------------------------------------------------------+
|98f8acb1-6ee4-43c4-b28b-d2a71b76a870 | public |5f912ae8-fa19-426d-91ca-043e2e2d9664 192.168.56.0/24 |
+--------------------------------------+--------+------------------------------------------------------+
2.7.2创建m1.nano类型
默认的最小规格的主机需要512 MB内存。对于环境中计算节点内存不足4 GB的,我们推荐创建只需要64 MB的``m1.nano``规格的主机。若单纯为了测试的目的,请使用``m1.nano``规格的主机来加载CirrOS镜像
openstack flavorcreate --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
a生成一个键值对
导入demo项目凭证
sourcedemo-openstack
b生成和添加秘钥对
ssh-keygen -q -N""
openstack keypaircreate --public-key ~/.ssh/id_rsa.pub mykey
+-------------+-------------------------------------------------+
| Field | Value |
+-------------+-------------------------------------------------+
| fingerprint |ee:3d:2e:97:d4:e2:6a:54:6d:0d:ce:43:39:2c:ba:4d |
| name | mykey |
| user_id |58126687cbcc4888bfa9ab73a2256f27 |
+-------------+-------------------------------------------------+
c验证公钥的添加
$ openstack keypairlist
+-------+-------------------------------------------------+
| Name |Fingerprint |
+-------+-------------------------------------------------+
| mykey |ee:3d:2e:97:d4:e2:6a:54:6d:0d:ce:43:39:2c:ba:4d |
+-------+-------------------------------------------------+
2.7.3.增加安全组
a添加规则到default安全组
openstack securitygroup rule create --proto icmp default
b允许安全 shell (SSH) 的访问
openstack securitygroup rule create --proto tcp --dst-port 22 default
2.7.4公网创建实例
在控制节点上,获得 admin 凭证来获取只有管理员能执行的命令的访问权限:
sourcedemo-openstack
一个实例指定了虚拟机资源的大致分配,包括处理器、内存和存储。
[[email protected]~]# openstack flavor list
+----+---------+-----+------+-----------+-------+-----------+
| ID | Name | RAM |Disk | Ephemeral | VCPUs | Is Public |
+----+---------+-----+------+-----------+-------+-----------+
| 0 | m1.nano | 64| 1 | 0 | 1 | True |
+----+---------+-----+------+-----------+-------+-----------+
a列出可用镜像
[[email protected]~]# openstack image list
+--------------------------------------+--------+--------+
| ID | Name |Status |
+--------------------------------------+--------+--------+
|01d13e57-6ae1-4bf8-98e2-0d83f3c7dd75 | cirros | active |
+--------------------------------------+--------+--------+
b列出可用安全组
[[email protected]~]# openstack security group list
+--------------------------------------+---------+------------------------+----------------------------------+
| ID | Name |Description | Project |
+--------------------------------------+---------+------------------------+----------------------------------+
|14f5bf0e-58ba-4be9-9967-89b59331ff74 | default | Default security group |a6c20f56f252445b85b247501b995e50 |
+--------------------------------------+---------+------------------------+----------------------------------+
c列出可用网络
[[email protected]~]# openstack network list
+--------------------------------------+--------+--------------------------------------+
| ID | Name |Subnets |
+--------------------------------------+--------+--------------------------------------+
|98f8acb1-6ee4-43c4-b28b-d2a71b76a870 | public | 5f912ae8-fa19-426d-91ca-043e2e2d9664|
+--------------------------------------+--------+--------------------------------------+
d启动虚拟机
openstack servercreate --flavor m1.nano --image cirros \
--nicnet-id=98f8acb1-6ee4-43c4-b28b-d2a71b76a870 --security-group default \
--key-name mykeydemo-instance
e检查实例的状态
[[email protected]~]# openstack server list
+--------------------------------------+---------------+--------+-----------------------+------------+
| ID | Name |Status | Networks | Image Name |
+--------------------------------------+---------------+--------+-----------------------+------------+
| c50d1093-1059-4a2c-9b88-89feab212f3b| demo-instance | ACTIVE | public=192.168.56.101 | cirros |
+--------------------------------------+---------------+--------+-----------------------+------------+
f使用虚拟控制台访问实例
openstack consoleurl show provider-instance
获取你势力的 Virtual Network Computing(VNC) 会话URL并从web浏览器访问它:
[[email protected]~]# openstack console url show demo-instance
+-------+------------------------------------------------------------------------------------+
| Field | Value |
+-------+------------------------------------------------------------------------------------+
| type | novnc |
| url |http://192.168.56.11:6080/vnc_auto.html?token=d7ec4e02-e485-47c1-b276-ae517779af26|
+-------+------------------------------------------------------------------------------------+
+-------+------------------------------------------------------------------------------------+
CirrOS 镜像包含传统的用户名/密码认证方式并需在登录提示中提供这些这些认证。登录到 CirrOS 后,即可连接上虚拟机并登陆。