由于官方的Openstack文档Neutron网络一般以VxLan或者Gre模式为例,反而简单的Vlan模式却一直没成功过,花了点时间,利用packstack装了一个,算是普及了一下网络的基本知识吧
一.环境构成
事先准备两台虚拟机(RHEL7系),每台机器两张网卡,其中一张网卡通外网。
Vlan双节点Openstack环境示意图
二.事前准备
1.打开控制节点上两张网卡
# cd /etc/sysconfig/network-scripts
# vim ifcfg-ens3 -->连接内网网卡
ONBOOT=no --> ONBOOT=yes
# vim ifcfg-ens7 -->连接外网网卡
ONBOOT=no --> ONBOOT=yes
# service network restart
# ifconfig
ens3: flags=4163 mtu 1500
inet 192.168.102.53 netmask 255.255.255.0 broadcast 192.168.102.255
ens7: flags=4163 mtu 1500
inet 193.168.140.135 netmask 255.255.0.0 broadcast 193.168.255.255
三.相关配置
1.修改packstack配置文件
①确认写入ip均为ens3的ip,组件必选keystone、nova、neutron、glance、horizon
②密码修改
CONFIG_DEFAULT_PASSWORD=remyxu
CONFIG_KEYSTONE_ADMIN_PW=remyxu
③compute节点ip设置
CONFIG_COMPUTE_HOSTS=192.168.102.154
注:此处ip选择compute节点上ens3的ip,与之前不同
④neutron配置修改
CONFIG_NEUTRON_ML2_TYPE_DRIVERS=vlan
CONFIG_NEUTRON_ML2_TENANT_NETWORK_TYPES=vlan
CONFIG_NEUTRON_ML2_VLAN_RANGES=physnet1:10:20
CONFIG_NEUTRON_OVS_BRIDGE_MAPPINGS=physnet1:br-ens3
CONFIG_NEUTRON_OVS_BRIDGE_IFACES=br-ens3:ens3
注:br-ens3名字自拟,ens3为控制节点绑定网卡名称
⑤关闭DEMO创建
CONFIG_PROVISION_DEMO=n
2.开始安装
# packstack --answer-file=/home/answer.conf
成功后显示
**** Installation completed successfully *****
3.控制节点br-ex制成
修改br-ex配置文件
# vim /etc/sysconfig/network-scripts/ifcfg-br-ex
DEVICE=br-ex
ONBOOT=yes
DEVICETYPE=ovs
TYPE=OVSBridge
BOOTPROTO=static
IPADDR=193.168.140.135
NETMASK=255.255.0.0
GATEWAY=193.168.1.1
修改网卡ens7配置文件
# vim /etc/sysconfig/network-scripts/ifcfg-ens7
DEVICE=ens7
ONBOOT=yes
HWADDR=52:54:00:71:a7:2c
将网卡ens7绑定是网桥br-ex
# ovs-vsctl add-port br-ex ens7; service network restart
# ovs-vsctl show
Bridge br-ex
Port "qg-f0902a63-df"
Interface "qg-f0902a63-df"
type: internal
Port br-ex
Interface br-ex
type: internal
Port "ens7"
Interface "ens7"
Bridge "br-ens3"
Port "br-ens3"
Interface "br-ens3"
type: internal
Port "phy-br-ens3"
Interface "phy-br-ens3"
type: patch
options: {peer="int-br-ens3"}
Port "ens3"
Interface "ens3"
Bridge br-int
fail_mode: secure
Port br-int
Interface br-int
type: internal
Port "int-br-ens3"
Interface "int-br-ens3"
type: patch
options: {peer="phy-br-ens3"}
5.查看计算节点ovs网络
# ovs-vsctl show
Bridge "br-ens3"
Port "br-ens3"
Interface "br-ens3"
type: internal
Port "ens3"
Interface "ens3"
Port "phy-br-ens3"
Interface "phy-br-ens3"
type: patch
options: {peer="int-br-ens3"}
Bridge br-int
fail_mode: secure
Port "int-br-ens3"
Interface "int-br-ens3"
type: patch
options: {peer="phy-br-ens3"}
Port br-int
Interface br-int
type: internal
四.环境确认
1.创建Vlan网络及路由
①创建外部网络及子网
# neutron net-create ext-net --shared --router:external
# neutron subnet-create ext-net --name ext-subnet --allocation-pool start=193.168.3.11,end=193.168.3.50 --gateway 193.168.1.1 193.168.0.0/16
②创建内部网络及子网
# neutron net-create demo-net
# neutron subnet-create demo-net --name demo-subnet --gateway 192.168.102.1 192.168.102.0/24
③创建路由
# neutron router-create demo-router
# neutron router-interface-add demo-router demo-subnet
# neutron router-gateway-set demo-router ext-net
# neutron net-show ext-net
+---------------------------+--------------------------------------+
| Field | Value |
+---------------------------+--------------------------------------+
| admin_state_up | True |
| id | 6a51bf0a-b1f5-45f7-b3c6-3a97202ba5f7 |
| mtu | 0 |
| name | ext-net |
| provider:network_type | vlan |
| provider:physical_network | physnet1 |
| provider:segmentation_id | 10 |
| router:external | True |
| shared | True |
| status | ACTIVE |
| subnets | 0ba89c96-f716-44f0-a340-ea8e3b4605b0 |
| tenant_id | 5bb67e639cf34454b5cd669f5e6f6a55 |
+---------------------------+--------------------------------------+
# neutron net-show demo-net
+---------------------------+--------------------------------------+
| Field | Value |
+---------------------------+--------------------------------------+
| admin_state_up | True |
| id | f2bb2afc-0ab6-46c9-8703-8be4084cd4ca |
| mtu | 0 |
| name | demo-net |
| provider:network_type | vlan |
| provider:physical_network | physnet1 |
| provider:segmentation_id | 11 |
| router:external | False |
| shared | False |
| status | ACTIVE |
| subnets | 35720b75-b48a-4f2f-aba1-6683b3de518a |
| tenant_id | 5bb67e639cf34454b5cd669f5e6f6a55 |
+---------------------------+--------------------------------------+
!可以看见type都是vlan的
2.上传Image及创建instance
# glance image-create --name demo --disk-format qcow2 --container-format bare --file /home/cirros-0.3.3-x86_64-disk.img --is-public True
# nova boot --flavor m1.tiny --image demo --nic net-id=f2bb2afc-0ab6-46c9-8703-8be4084cd4ca test
3.创建添加floating ip
# nova floating-ip-create 6a51bf0a-b1f5-45f7-b3c6-3a97202ba5f7
# nova floating-ip-associate e4da3438-25d4-4c6c-ac84-9718a47d4116 193.168.3.11
注:193.168.3.11为分配的的ip
# nova list
+--------------------------------------+------+--------+------------+-------------+-----------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+------+--------+------------+-------------+-----------------------------------+
| e4da3438-25d4-4c6c-ac84-9718a47d4116 | test | ACTIVE | - | Running | net=192.168.102.3, 193.168.3.11 |
+--------------------------------------+------+--------+------------+-------------+-----------------------------------+
# nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
# nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
# ssh [email protected]
[email protected]'s password:
$ ifconfig
eth0 Link encap:Ethernet HWaddr FA:16:3E:D4:19:CD
inet addr:192.168.102.3 Bcast:192.168.102.255 Mask:255.255.255.0
inet6 addr: fe80::f816:3eff:fed4:19cd/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:301 errors:0 dropped:0 overruns:0 frame:0
TX packets:304 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:40692 (39.7 KiB) TX bytes:33952 (33.1 KiB)
大功告成!packstack的功能还是很强大的嘛,当然装3节点也是可以的,有待进一步发掘。