运行实例 - 创建公网网络【控制节点】
执行初始化脚本
source admin-openrc.sh
创建网络
neutron net-create public --shared --provider:physical_network public \
--provider:network_type flat
[root@controller ~]# source admin-openrc.sh [root@controller ~]# neutron net-create public --shared --provider:physical_network public \ > --provider:network_type flat Created a new network: +---------------------------+--------------------------------------+ | Field | Value | +---------------------------+--------------------------------------+ | admin_state_up | True | | id | 4981837b-46f6-41b3-8c27-0175d4a60069 | | mtu | 0 | | name | public | | port_security_enabled | True | | provider:network_type | flat | | provider:physical_network | public | | provider:segmentation_id | | | router:external | False | | shared | True | | status | ACTIVE | | subnets | | | tenant_id | 5c007739446b44eebab043e2573021b1 | +---------------------------+--------------------------------------+ [root@controller ~]#
创建子网
neutron subnet-create public 192.168.100.0/24 --name public \
--allocation-pool start=192.168.100.100,end=192.168.100.200 \
--dns-nameserver 8.8.8.8 --gateway 192.168.100.1
[root@controller ~]# neutron subnet-create public 192.168.100.0/24 --name public \ > --allocation-pool start=192.168.100.100,end=192.168.100.200 \ > --dns-nameserver 8.8.8.8 --gateway 192.168.100.1 Created a new subnet: +-------------------+--------------------------------------------------------+ | Field | Value | +-------------------+--------------------------------------------------------+ | allocation_pools | {"start": "192.168.100.100", "end": "192.168.100.200"} | | cidr | 192.168.100.0/24 | | dns_nameservers | 8.8.8.8 | | enable_dhcp | True | | gateway_ip | 192.168.100.1 | | host_routes | | | id | 9c621051-7d2b-441f-a7e6-c1de6a68abdb | | ip_version | 4 | | ipv6_address_mode | | | ipv6_ra_mode | | | name | public | | network_id | 4981837b-46f6-41b3-8c27-0175d4a60069 | | subnetpool_id | | | tenant_id | 5c007739446b44eebab043e2573021b1 | +-------------------+--------------------------------------------------------+ [root@controller ~]#
说明:这里的公网,实际上是虚拟机用的那个网段,我们暂时把它作为公网,在这里因为涉及到dhcp服务,会和局域网内的路由器上的dhcp服务产生冲突,所以需要先把路由器上的dhcp服务关掉。
运行实例 - 创建key 【控制节点】
执行初始化脚本
source demo-openrc.sh
生成密钥
ssh-keygen -q -N ""
nova keypair-add --pub-key ~/.ssh/id_rsa.pub mykey
[root@controller ~]# ssh-keygen -q -N "" Enter file in which to save the key (/root/.ssh/id_rsa): [root@controller ~]# nova keypair-add --pub-key ~/.ssh/id_rsa.pub mykey [root@controller ~]#
验证密钥
nova keypair-list
增加安全组规则
nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
允许ssh 访问
nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
[root@controller ~]# nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0 +-------------+-----------+---------+-----------+--------------+ | IP Protocol | From Port | To Port | IP Range | Source Group | +-------------+-----------+---------+-----------+--------------+ | icmp | -1 | -1 | 0.0.0.0/0 | | +-------------+-----------+---------+-----------+--------------+ [root@controller ~]# nova secgroup-add-rule default tcp 22 22 0.0.0.0/0 +-------------+-----------+---------+-----------+--------------+ | IP Protocol | From Port | To Port | IP Range | Source Group | +-------------+-----------+---------+-----------+--------------+ | tcp | 22 | 22 | 0.0.0.0/0 | | +-------------+-----------+---------+-----------+--------------+ [root@controller ~]#
运行实例 - 配置实例选项【控制节点】
执行初始化脚本
source demo-openrc.sh
列出实例类型
nova flavor-list
[root@controller ~]# source demo-openrc.sh [root@controller ~]# 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 | +----+-----------+-----------+------+-----------+------+-------+-------------+-----------+ [root@controller ~]#
列出所有镜像
nova p_w_picpath-list
[root@controller ~]# nova p_w_picpath-list +--------------------------------------+--------+--------+--------+ | ID | Name | Status | Server | +--------------------------------------+--------+--------+--------+ | 6b44feb1-141c-4177-ba54-22bb927db70f | cirros | ACTIVE | | +--------------------------------------+--------+--------+--------+ [root@controller ~]#
列出可用网络
neutron net-list
[root@controller ~]# neutron net-list +--------------------------------------+--------+-------------------------------------------------------+ | id | name | subnets | +--------------------------------------+--------+-------------------------------------------------------+ | 4981837b-46f6-41b3-8c27-0175d4a60069 | public | 9c621051-7d2b-441f-a7e6-c1de6a68abdb 192.168.100.0/24 | +--------------------------------------+--------+-------------------------------------------------------+ [root@controller ~]#
列出安全组
nova secgroup-list
[root@controller ~]# nova secgroup-list +--------------------------------------+---------+------------------------+ | Id | Name | Description | +--------------------------------------+---------+------------------------+ | d34628ae-49e0-48bd-ac2a-70dc5bfd788a | default | Default security group | +--------------------------------------+---------+------------------------+ [root@controller ~]#
运行实例
nova boot --flavor m1.tiny --p_w_picpath cirros --nic net-id=PUBLIC_NET_ID\
--security-group default --key-name mykey public-instance
说明:这里的PUBLIC_NET_ID需要替换为可用网络里面public网络的id;public-instance可以自定义名字
[root@controller ~]# nova boot --flavor m1.tiny --p_w_picpath cirros --nic net-id=4981837b-46f6-41b3-8c27-0175d4a60069 --security-group default --key-name mykey vps_test +--------------------------------------+-----------------------------------------------+ | Property | Value | +--------------------------------------+-----------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | | | 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 | WV5FSdjVk2QM | | config_drive | | | created | 2016-09-24T15:53:30Z | | flavor | m1.tiny (1) | | hostId | | | id | f5c2d431-2b7a-4e7a-96e1-b97b936e9226 | | p_w_picpath | cirros (6b44feb1-141c-4177-ba54-22bb927db70f) | | key_name | mykey | | metadata | {} | | name | vps_test | | os-extended-volumes:volumes_attached | [] | | progress | 0 | | security_groups | default | | status | BUILD | | tenant_id | ab6fd0b354444bf58db83cb998fd96dd | | updated | 2016-09-24T15:53:31Z | | user_id | 7b33d224785141a3a0539f0c89e02be9 | +--------------------------------------+-----------------------------------------------+ [root@controller ~]#
检测实例状态
nova list
[root@controller ~]# nova list +--------------------------------------+----------+--------+------------+-------------+------------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+----------+--------+------------+-------------+------------------------+ | f5c2d431-2b7a-4e7a-96e1-b97b936e9226 | vps_test | ACTIVE | - | Running | public=192.168.100.101 | +--------------------------------------+----------+--------+------------+-------------+------------------------+ [root@controller ~]#
实例ip地址为192.168.100.101
运行实例 - 连接实例【控制节点】
使用vnc连接(使用下面命令可以列出vnc的连接)
nova get-vnc-console vps_test novnc
[root@controller ~]# nova get-vnc-console vps_test novnc +-------+---------------------------------------------------------------------------------+ | Type | Url | +-------+---------------------------------------------------------------------------------+ | novnc | http://controller:6080/vnc_auto.html?token=065054df-021a-4cd1-940f-c23ecb51d7bc | +-------+---------------------------------------------------------------------------------+ [root@controller ~]# 复制链接地址到浏览器中打开,未做主机解析的主机名换位ip地址
验证网络(在实例里面)
ping -c 2 192.168.100.1
ping -c2 www.baidu.com测试网络连通性
远程连接实例
首先用nova list 查看实例的ip(为192.168.100.101)
验证ip
ping -c4 192.168.100.101
远程ssh登录 ssh [email protected] 密码:cubswin:)
[root@controller ~]# ssh [email protected] The authenticity of host '192.168.100.101 (192.168.100.101)' can't be established. RSA key fingerprint is fd:ca:cf:e7:7f:f5:93:da:16:e8:ac:94:a9:2e:61:68. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.100.101' (RSA) to the list of known hosts. [email protected]'s password: $ ifconfig eth0 Link encap:Ethernet HWaddr FA:16:3E:F8:87:59 inet addr:192.168.100.101 Bcast:192.168.100.255 Mask:255.255.255.0 inet6 addr: fe80::f816:3eff:fef8:8759/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:132 errors:0 dropped:0 overruns:0 frame:0 TX packets:154 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:16853 (16.4 KiB) TX bytes:16169 (15.7 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) $