1、首先source环境变量 每次登陆节点需要操作openstack命令时,都需要source一次环境变量,这样才可以正确的访问相应的用户信息。 [root@cloud ~]#source openrc.sh 2、生成密钥对 [root@cloud ~]#openstack keypair create --public-key ~/.ssh/id_rsa.pub default +-------------+-------------------------------------------------+ | Field | Value | +-------------+-------------------------------------------------+ | fingerprint |72:5f:11:c0:6d:0e:1a:d3:b5:58:b6:9e:77:0d:1e:0a | | name | default | | user_id | 057a81efc7914639ba8e84672dffd4fd | +-------------+-------------------------------------------------+ 3、创建安全组规则 (1)添加允许进方向icmp报文规则 [root@cloud ~]#openstack security group rule create --ingress --ethertype IPv4 --protocol icmp c739ddd6-afda-4a35-b9d4-c2ee2edf6229 +-------------------+--------------------------------------+ | Field | Value | +-------------------+--------------------------------------+ | created_at | 2017-06-13T05:42:41Z | | description | | | direction | ingress | | ether_type | IPv4 | | id |98b627a2-6c16-44ec-bdfc-d56b57f28c3a | | name | None | | port_range_max | None | | port_range_min | None | | project_id | 4e79773819ff4f779802bceb4e7bf58a | | protocol | icmp | | remote_group_id | None | | remote_ip_prefix | 0.0.0.0/0 | | revision_number | 1 | | security_group_id |c739ddd6-afda-4a35-b9d4-c2ee2edf6229 | | updated_at | 2017-06-13T05:42:41Z | +-------------------+--------------------------------------+ (2)添加允许出方向icmp报文规则 [root@cloud ~]#openstack security grouprule create --ingress --ethertype IPv4 --protocol icmp c739ddd6-afda-4a35-b9d4-c2ee2edf6229 (3)添加允许所有tcp报文规则 [root@cloud ~]#openstack security group rulecreate --ingress --ethertype IPv4 --protocol tcp --dst-port 1:65535 --remote-ip 0.0.0.0/0 c739ddd6-afda-4a35-b9d4-c2ee2edf6229 4、创建实例 [root@cloud ~]#openstack server create --image cirros --flavor m1.tiny --key-name default--nic net-id=51ec6ecc-896f-495b-bb97-e103d3d49a01 demo1 +-------------------------------------+----------------------------------------+ | 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 | B46TZFkwsJ7w | | config_drive | | | created | 2017-06-13T03:48:13Z | | flavor | m1.tiny (1) | | hostId | | | id |eabed65d-d2a7-4e6b-b5b5-fab7f3f0dcc8 | | image | cirros (301cd776-a178-40ee-805c- | | | 7b3998f33869) | | key_name | default | | name | demo1 | | progress | 0 | | project_id | 4e79773819ff4f779802bceb4e7bf58a | | properties | | | security_groups | name='default' | | status | BUILD | | updated | 2017-06-13T03:48:13Z | | user_id | 057a81efc7914639ba8e84672dffd4fd | | volumes_attached | | +-------------------------------------+----------------------------------------+ 5、查看web界面,如下: 至此,利用命令行创建vm完毕。 (责任编辑:IT) |