一、 创建flat网络的实例
#运行admin环境变量,创建网络类型为flat
. admin-openrc
openstack network create --share \
--provider-physical-network provider \
--provider-network-type flat provider
#创建subnet
openstack subnet create \
--network provider \
--subnet-range 172.16.0.0/16 provider \
--allocation-pool start=172.16.2.100,end=172.16.2.200 \
--gateway 172.16.0.1 \
--dns-nameserver 172.16.0.1 \
--dns-nameserver 8.8.8.8
#验证IP网络
. admin-openrc
ip netns
#创建模板(flvor)
openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
openstack flavor create --id 1 --vcpus 1 --ram 1024 --disk 10 chen.nano
#创建钥匙对
. demo-openrc
ssh-keygen -q -N ""
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
openstack keypair list
#安全组策略设置
openstack security group rule create --proto icmp default
openstack security group rule create --proto tcp --dst-port 22 default
#查看相关信息
. demo-openrc
openstack flavor list
openstack image list
openstack network list
openstack security group list
#创建provider-instance实例(以cirros镜像为例)
openstack server create \
--flavor m1.nano \
--image cirros \
--security-group default \
--key-name mykey \
provider-instance
openstack server list
openstack console url show provider-instance
ping -c 4 openstack.org
ssh cirros@172.16.2.100
#创建存储块并加载到实例
. demo-openrc
openstack volume create --size 1 volume1
openstack volume list
openstack server add volume provider-instance volume1
openstack volume list
二、 创建route网络
#运行环境变量,创建网络类型为flat(外网)
. admin-openrc
openstack network create --share \
--provider-physical-network provider \
--provider-network-type flat provider
openstack subnet create \
--network provider \
--subnet-range 172.0.0/16 provider \
--allocation-pool start=172.16.2.100,end=172.16.2.200 \
--gateway 172.16.0.1 \
--dns-nameserver172.16.0.1 \
--dns-nameserver 8.8.8.8
#创建selfservice网络(内网)
. demo-openrc
openstack network create selfservice
openstack subnet create \
--network selfservice \
--dns-nameserver 8.8.8.8 \
--gateway 192.168.11.1 \
--subnet-range 192.168.11.0/24 selfservice
#更新外部路由
. admin-openrc
neutron net-update provider --router:external
#创建路由
. demo-openrc
openstack router create router
neutron router-interface-add router selfservice
neutron router-gateway-set router provider
#验证
. admin-openrc
ip netns
neutron router-port-list router
#创建模板flvor
openstack flavor create --id 0 --vcpus 1 --ram 1024 --disk 10 chen.nano
#创建钥匙对
. demo-openrc
ssh-keygen -q -N ""
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
openstack keypair list
#安全组策略
openstack security group rule create --proto icmp default
openstack security group rule create --proto tcp --dst-port 22 default
#查看相关信息
. demo-openrc
openstack flavor list
openstack image list
openstack network list
openstack security group list
#创建selfservice-instance实例( openstack network list查看selfservice的id)
openstack server create \
--flavor chen1.nano \
--image chen-test \
--nic net-id=8ff69e7c-0762-4243-bfe3-1925752f0e96 \
--security-group default \
--key-name mykey \
selfservice-instance
openstack server list
openstack console url show selfservice-instance
ping -c 4 www.baidu.com
#创建浮点IP,用于通过外部网络访问虚拟机,相当于给虚拟机映射一个外网IP
openstack floating ip create provider
openstack server add floating ip selfservice-instance 172.16.2.150(上一步创建的ip)
openstack server list
ping -c 4 192.168.11.2
ssh cirros@172.16.2.150
#创建存储块
. demo-openrc
openstack volume create --size 10 volume2
openstack volume list
openstack server add volume provider-instance volume2
openstack volume list