本节开始用命令行方式启动虚拟机,仅在CT01进行操作
一、网络配置
1、新建虚拟网络(外网)
. admin-openrc openstack network create --share --external --provider-physical-network provider --provider-network-type flat provider
2、确认配置文件正确(外网)
/etc/neutron/plugins/ml2/ml2_conf.ini:
[ml2_type_flat] flat_networks = provider linuxbridge_agent.ini [linux_bridge] physical_interface_mappings = provider:enp0s8
3、创建子网(外网)
openstack subnet create --network provider --allocation-pool start=192.168.12.100,end=192.168.12.120 --dns-nameserver 8.8.8.8 --gateway 172.16.172.2 --subnet-range 192.168.12.0/24 provider
4、新建虚拟网络(内网)
openstack network create selfservice
5、确认配置文件正确(内网)
/etc/neutron/plugins/ml2/ml2_conf.ini:
[ml2] tenant_network_types = vxlan [ml2_type_vxlan] vni_ranges = 1:1000
6、创建子网(内网)
openstack subnet create --network selfservice --dns-nameserver 8.8.8.8 --gateway 172.16.172.2 --subnet-range 192.168.13.0/24 selfservice
7、创建路由,让内网可以通过外网访问外网
. admin-openrc openstack router create router neutron router-interface-add router selfservice neutron router-gateway-set router provider ip netns neutron router-port-list router ping -c 4 192.168.12.107
二、虚拟机flavor配置
openstack flavor list openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 2 flavor02
三、虚拟机keypair配置
ssh-keygen -q -N "" openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey openstack keypair list
四、虚拟机security group配置
openstack security group rule create --proto icmp default openstack security group rule create --proto tcp --dst-port 22 default
五、查看配置
openstack flavor list openstack image list openstack network list openstack security group list
六、创建虚拟机,并访问
1、外网虚拟机
openstack server create --flavor flavor02 --image cirros --nic net-id=PROVIDER_NET_ID --security-group default --key-name mykey provider-instance openstack server list openstack console url show provider-instance ping -c 4 192.168.12.1 ping -c 4 openstack.org ping -c 4 192.168.12.104 ssh cirros@192.168.12.104
2、内网虚拟机
openstack server create --flavor flavor02 --image cirros --nic net-id=SELFSERVICE_NET_ID --security-group default --key-name mykey selfservice-instance openstack server list openstack console url show selfservice-instance ping -c 4 192.168.13.1 ping -c 4 openstack.org openstack floating ip create provider openstack server add floating ip selfservice-instance 192.168.12.106 openstack server list ping -c 4 192.168.12.106 ssh cirros@192.168.12.106
七、创建挂载块存储
1、创建并挂载
. admin-openrc openstack volume create --size 2 volumeA openstack volume list openstack server add volume provider-instance volumeA
2、虚拟机中验证
sudo fdisk -l