OpenStack实践(九):Open vSwitch方式实现floating IP
架构图:
环境:
openstack版本 | pike |
控制节点主机 | openstack-controller(ubuntu 16.04.5) 172.27.34.37/137 esn160、ens192、ens224 |
计算节点主机 | openstack-computer(ubuntu 16.04.5) 172.27.34.38/138 esn160、ens192 |
vxlan100 | centos01(172.27.100.5, floating ip172.27.34.11) |
vxlan101 | centos02(172.27.101.22,floating ip172.27.34.12) |
ubuntu安装详见:Ubuntu16.04.5以lvm方式安装全记录
openstack安装详见:OpenStack实践(一):Ubuntu16.04下DevStack方式搭建p版OpenStack
本文测试内容有:
实例centos01和centos02之间能互通;
实例centos01和centos02可访问外网;
floating ip配置,为instance分配浮动ip,外网可直接访问实例;
内网配置
内网采用vxlan,配置如下:
stack@openstack-controller:~$ source devstack/openrc admin adminstack@openstack-controller:~$ view /etc/neutron/plugins/ml2/ml2_conf.ini[ml2]tenant_network_types = vxlanextension_drivers = port_securitymechanism_drivers = openvswitch,l2populationtype_drivers = local,flat,vlan,gre,vxlan,geneve[agent]tunnel_types = vxlanl2_population = True[ovs]datapath_type = systembridge_mappings =tunnel_bridge = br-tunlocal_ip = 172.27.34.137
计算节点local_ip=172.27.34.138,其它相同。
重启后生效
stack@openstack-controller:~$ sudo systemctl restart devstack@q*
VXLAN创建
创建vxlan100和vxlan101
图形化方式
创建vlan100
网络名称为vxlan100,段id为100
子网为172.27.100.0/24
激活DHCP
创建完成
命令方式
创建网络vxlan101
stack@openstack-controller:~$ openstack network create --provider-network-type vxlan --provider-segment 101 --project admin vxlan101
创建子网subnet172.27.101.0
stack@openstack-controller:~$ openstack subnet create --network vxlan101 --subnet-range 172.27.101.0/24 --gateway 172.27.101.1 subnet172.27.101.0
外网配置
外网采用flat,配置如下
在控制节点执行
stack@openstack-controller:~$ view /etc/neutron/plugins/ml2/ml2_conf.ini[ml2_type_flat]flat_networks = externaltt[ovs]bridge_mappings = externaltt:br-ens224
创建网桥br-ens224并将物理网卡ens224桥接在br-ens224上
stack@openstack-controller:~$ sudo ovs-vsctl add-br br-ens224stack@openstack-controller:~$ sudo ovs-vsctl add-port br-ens224 ens224
重启网络服务
stack@openstack-controller:~$ sudo systemctl restart devstack@q*
创建外网ext_net_flat
stack@openstack-controller:~$ openstack network create --provider-network-type flat --provider-physical-network externaltt --project admin --external ext_net_flat
创建子网subnet172.27.34.0
stack@openstack-controller:~$ openstack subnet create --network ext_net_flat --subnet-range 172.27.34.0/24 --gateway 172.27.34.1 --no-dhcp subnet172.27.34.0
查看创建的网络
stack@openstack-controller:~$ openstack network list
创建路由
创建路由router_100_101
stack@openstack-controller:~$ openstack router create --project admin router_100_101
将路由器连接到外部网络
stack@openstack-controller:~$ openstack router set router_100_101 --external-gateway ext_net_flat
将路由器连接到子网
stack@openstack-controller:~$ openstack router add subnet router_100_101 subnet172.27.101.0stack@openstack-controller:~$ openstack router add subnet router_100_101 subnet172.27.100.0
查看路由信息
stack@openstack-controller:~$ openstack router list
创建实例
制作镜像
上传介质CentOS-7-x86_64-GenericCloud-1809.qcow2c至/tmp目录,下载地址:http://cloud.centos.org/centos/7/images/
生成镜像centos7
stack@openstack-controller:/tmp$ openstack image create centos7 --file CentOS-7-x86_64-GenericCloud-1809.qcow2c --disk-format qcow2 --container-format bare --public
新建密钥对
新建密钥对centos7
stack@openstack-controller:~$ mkdir keysstack@openstack-controller:~$ cd keysstack@openstack-controller:~/keys$ openstack keypair create centos7 > centos7.pemstack@openstack-controller:~/keys$ chmod 600 centos7.pem stack@openstack-controller:~/keys$ lltotal 12drwxrwxr-x 2 stack stack 4096 Jan 24 10:53 ./drwxr-xr-x 27 stack stack 4096 Jan 24 10:52 ../-rw------- 1 stack stack 1680 Jan 24 10:53 centos7.pem
查看密钥对
stack@openstack-controller:~$ nova keypair-list
创建安全组
创建安全组centos7
stack@openstack-controller:~$ openstack security group create centos7
新增规则允许ping和ssh
stack@openstack-controller:~$ openstack security group rule create --protocol icmp centos7stack@openstack-controller:~$ openstack security group rule create --protocol TCP --dst-port 22 centos7
查看安全组和规则
stack@openstack-controller:~$ openstack security group liststack@openstack-controller:~$ openstack security group rule list centos7
创建实例
创建实例centos01
stack@openstack-controller:~$ nova boot --flavor m1.small --image centos7 --availability-zone nova:openstack-controller --nic net-name=vxlan100 --key-name centos7 --security-groups centos7 centos01
flavor选择m1.small,计算节点选择openstack-controller,网络选择vxlan100。
创建实例centos02
stack@openstack-controller:~$ nova boot --flavor m1.small --image centos7 --availability-zone nova:openstack-controller --nic net-name=vxlan101 --key-name centos7 --security-groups centos7 centos02
flavor选择m1.small,计算节点选择openstack-controller,网络选择vxlan101。
查看创建的实例
stack@openstack-controller:~$ nova list
创建浮动ip
创建floating IP
创建floating IP 172.27.34.11/12
stack@openstack-controller:~$ openstack floating ip create --project admin --floating-ip-address 172.27.34.11 ext_net_flatstack@openstack-controller:~$ openstack floating ip create --project admin --floating-ip-address 172.27.34.12 ext_net_flatstack@openstack-controller:~$ openstack floating ip list
浮动ip关联实例
关联的命令执行方式为
stack@openstack-controller:~$ nova floating-ip-associate centos01 172.27.34.11 stack@openstack-controller:~$ nova floating-ip-associate centos02 172.27.34.12
查看实例浮动ip
stack@openstack-controller:~$ nova list
测试
登陆实例
登陆实例centos01
stack@openstack-controller:~/keys$ ssh -i centos7.pem centos@172.27.34.11
ping外网
[centos@centos01 ~]$ ping www.baidu.com
ping centos02
[centos@centos01 ~]$ ping 172.27.101.22
架构图分析
端口查看
vxlan100
vxlan101
查看网桥
root@openstack-controller:~# ovs-vsctl show
root@openstack-controller:~# brctl show
patch port查看
br-int与br-tun的patch port
br-int与br-tun通过patch port"patch-tun"和"br-tun"连接
br-int与br-ens224的patch port
br-int与br-ens224这两个网桥通过int-br-ens224和phy-br-ens224连接在一起了。
Linux Bridge方式详见:OpenStack实践(四):Linux Bridge方式实现floating IP
参考文章:
https://docs.openstack.org/zh_CN/user-guide/index.html