OpenStack的网络及简单操作

     OpenStack的网络主要有两类,内部网络和外部网络;再细分内部网络包括管理网络和虚拟机之间的数据网络,外部网络包括互联internet网络和API管控网络。其中:管理网络主要是来管理OpenStack中各个组件的,在安装部署时,很多配置文件项相关的网络IP就属于管理网络范畴;数据网络主要用于虚拟机之间的通信,虚拟网络划分,Network as a Service等,它由OpenStack的网络组件(G版本是quantum)管理和操作;外部网络就是指可以访问互联网和被cloud之外主机访问或接入的通道;API网络是对cloud之外提供的可以管理的通道,一般不与外部网络区分开来。以上只是个人见解和体会,可能都是错的,请参考官方说法:

http://docs.openstack.org/grizzly/basic-install/apt/content/basic-install_architecture.html

  • Management network. Used for internal communication between OpenStack components. The IP addresses on this network should be reachable only within the data center. 
  • Data network. Used for VM data communication within the cloud deployment. The IP addressing requirements of this network depend on the OpenStack Networking plugin in use. 
  • External network. Provides VMs with Internet access in some deployment scenarios. The IP addresses on this network should be reachable by anyone on the Internet. 
  • API network. Exposes all OpenStack APIs, including the OpenStack Networking API, to tenants. The IP addresses on this network should be reachable by anyone on the Internet. This may be the same network as the external network, as it is possible to create a quantum subnet for the external network that uses IP allocation ranges to use only less than the full range of IP addresses in an IP block.

  

     就Data Network而言,在概念上主要有网络<net>,子网<subnet>,端口<port>和路由<router>。最简单也是最一般的layout情况是:用户可以通过quantum(为租户)创建多个网络;每一个网络至少要有一个子网(也可以有多个子网);每一个网络至少有一个路由,这个路由的网关要关联这个网络;网络中的每个子网要添加到这个网络的路由[生成qrouter namespace],才能通过这个网络通信,通信的路径由路由表设定;子网内有多个端口(一般会有MAC地址和IP地址),在GRE模式中子网中一般会有qdhcp端口、qrouter端口和为虚拟机实例分配的端口,它们的IP地址属于这个子网。



创建网络: 

 

   # quantum net-create network1 
 
 
 

   为网络network1创建子网 
 
 
 

    # quantum subnet-create network1 192.168.1.0/24

然而外部网络会特殊一些,详解如下:

1 创建外部网络:

可以用这个网络分配floating ip,绑到虚拟机上,外部就可以访问虚拟机了。在创建外部网络之前要注意网络节点上要有br-ex网桥,并且br-ex要绑定到物理网卡上,这个被绑定的物理网卡(比如eth1,eth2,ethx等)是可以访问internet的。只有这样的外部网络的子网才能分配到有效的floating IP,其它网络的子网内的虚拟机分配到floating IP才能被外网访问。

=================================================================================================
 
 

    # The loopback network interface 
  
 
  

    auto lo 
  
 
  

    iface lo inet loopback 
  
 
  
 
   
 
  

     # Internal Network 
   
 
   

     auto eth0 
   
 
   

     iface eth0 inet static 
   
 
   

     address 192.168.0.25 
   
 
   

     netmask 255.255.255.0 
   
 
   
 
    
 
   

     # External Network 
   
 
   

     auto eth1 
   
 
   

     iface eth1 inet static 
   
 
   
10.10.10.25 
   
 
   

     netmask 255.255.255.0 
   
 
   
10.10.10.254 
   
 
   

     dns-nameservers 192.168.1.3 
   
 
 

   ================================================================================================= 
 
 
 
ovs-vsctl add-port br-ex eth1
 
 
=================================================================================================
 
 

    # The loopback network interface 
  
 
  

    auto lo 
  
 
  

    iface lo inet loopback 
  
 
  
 
   
 
  

     # Internal Network 
   
 
   

     auto eth0 
   
 
   

     iface eth0 inet static 
   
 
   

     address 192.168.0.25 
   
 
   

     netmask 255.255.255.0 
   
 
   
 
     
 
    

      auto br-ex 
    
 
    

      iface br-ex inet static 
    
 
    
10.10.10.25 
    
 
    

      netmask 255.255.255.0 
    
 
    
10.10.10.254 
    
 
    

      dns-nameservers 192.168.1.3 
    
 
    
 
     
 
    

      auto eth1 
    
 
    

      iface eth1 inet manual 
    
 
    

      up ifconfig $IFACE 0.0.0.0 up 
    
 
    

      up ip link set $IFACE promisc on 
    
 
    

      down ip link set $IFACE promisc off 
    
 
    

      down ifconfig $IFACE down 
    
 
 
=================================================================================================
 
 

   # quantum net-create ext_net --router:external=True 
 
 
 
 
  
 
 
ext_subnet1: 
 
 
 
10.10.10.2到 
  10.10.10.100,在参数中指定--allocation-pool start=10.10.10.2,end=10.10.10.100,  
  对于创建外部网络而言dhcp是需要关闭的。 
 
 
 
10.10.10.2  
  ,end= 
  10.10.10.100  
    
  --gateway  
  10.10.10.1 ext_net  
    
  10.10.10.0/24 --enable_dhcp=False 
 
 
 
 
  
 
 
ext_router: 
 
 
 

   # quantum router-create ext_router

4 设置路由ext_router和网络ext_net相关:

# quantum router-gateway-set $ext_router_id $ext_net_id

5 设置子网ext_subnet1和路由ext_router相关:

ext_router  ,由于这个 ext_router  的网关已经被设置为外部网络,所以这个子网就能上网了。

# quantum router-interface-add $ext_router_id $ext_subnet1_id

接下来即可创建floating IP,为虚拟机绑定floating IP,来验证是否成功。

# Obtain the VM's fixed IP
nova --os-tenant-name TenantA --os-username UserA --os-password password  --os-auth-url=http://localhost:5000/v2.0 list
# You can find its fixed IP in the "Networks" section: TenantA-Net={fixed IP}.
# Obtain the virtual port ID from the fixed IP quantum --os-tenant-name TenantA --os-usernameUserA --os-password password  --os-auth-url=http://localhost:5000/v2.0 port-list | grep "{fixed IP}"
# The first column shows the virtual port ID.   # Create a floating IP
quantum --os-tenant-name TenantA --os-username UserA --os-password password  --os-auth-url=http://localhost:5000/v2.0 floatingip-create Ext-Net
# Associate the created floating IP to the VM's virtual port
quantum --os-tenant-name TenantA --os-username UserA --os-password password  --os-auth-url=http://localhost:5000/v2.0 floatingip-associate {floating IP ID} {virtual port ID}
# Check your VM status
nova --os-tenant-name TenantA --os-username UserA --os-password password  --os-auth-url=http://localhost:5000/v2.0 list
# SSH to your VM when your VM is ACTIVE # The password is cubswin:)
ssh xxx@{floating_ip}