本节全部在Controller节点完成
1.Provider Network
1)生效admin用户环境变量,创建flat网络
# . admin-openrc
# neutron net-create --shared --provider:physical_network provider --provider:network_type flat provider
注:
–shared选项:允许所有项目使用虚拟网络
–provider:physical_network选项和–provider:network_type选项:使虚拟网络和物理网络连接
2)创建子网
# neutron subnet-create --name provider --allocation-pool start=192.168.200.100,end=192.168.200.200 \
--dns-nameserver 8.8.4.4 --gateway 192.168.200.1 provider 192.168.200.0/24
注:
–allocation-pool选项:IP地址池
–dns-nameserver选项:DNS服务
–gateway选项:网关
192.168.200.0/24 表示网络号
2.Self-service Network
1)生效demo用户环境变量,创建网络
注:创建Self-service Network之前必须创建Provider Network
# . demo-openrc
# neutron net-create selfservice
3)创建路由
生效admin用户环境变量,设置provider网络为外部网络
# . admin-openrc
# neutron net-update provider --router:external
Updated network: provider
生效demo用户环境变量,创建并设置路由器
# . demo-openrc
# neutron router-create router
# neutron router-interface-add router selfservice
# neutron router-gateway-set router provider
# . admin-openrc
# ip netns
# neutron router-port-list router
1.设置密匙对
# . demo-openrc
# ssh-keygen -q -N "" (此处直接回车)
# openstack keypair create --public-key /root/.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
1) 查看可用云主机类型
# . demo-openrc
# openstack flavor list
2) 查看可以镜像
# openstack image list
3) 查看可用网络列表
# openstack network list
4) 查看可用安全组
# openstack security group list
# openstack server create --flavor m1.small --image centos7 --nic net-id=8f5fe950-f7a2-4ba9-96e0-fe74a7f3de51 \
--security-group default --key-name mykey selfservice-instance
注:–nic net-id 选项 :id为openstack network list列表中的selfservice网络的id。
创建的云主机的id为随机生成且唯一。
6) 查看云主机
# openstack server list
# openstack ip floating create provider
# openstack ip floating add 192.168.200.102 selfservice-instance
# openstack server list
# ping -c 4 192.168.200.102
# ssh [email protected]
注:由于虚拟机性能不足,所以需删除上一个centos7云主机(ID为openstack server list所对应的centos7云主机ID)
# openstack server delete ID
# . admin-openrc
# cd /opt/mitaka/image/
# openstack image create "cirros" --file cirros-0.3.4-x86_64-disk.img \
--disk-format qcow2 --container-format bare --public
# openstack server create --flavor m1.tiny --image cirros --nic net-id=8f5fe950-f7a2-4ba9-96e0-fe74a7f3de51 \
--security-group default --key-name mykey selfservice-instance
注:–flavor选项 根据镜像大小选择不同的云主机类型,(cirros只有12MB,我们选择m1.tiny)
–nic net-id 选项 :id为openstack network list列表中的selfservice网络的id。
# openstack ip floating create provider
# openstack ip floating add 192.168.200.103 selfservice-instance
# openstack server list
# ping -c 4 192.168.200.103
# ssh cirros@192.168.200.103
注:远程登录账户为:cirros 密码 为:cubswin:)