1. 程式人生 > >openstack之網路分析2

openstack之網路分析2

neutron如何讓tap和虛擬機器建立聯絡?

這幾天的收穫是,看日誌不僅要分析控制節點的日誌,還要分析物理節點的日誌。而且物理節點和虛擬機器的相關性更大一點。從物理節點的neutron日誌分析中可以得到更多答案。

這些是刪除虛擬機器時日誌中出現的部分命令

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'iptables-save', '-c']

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'iptables-restore', '-c']

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ip6tables-save', '-c']

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ip6tables-restore', '-c']

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'conntrack', '-D', '-f', 'ipv4', '-d', '172.16.15.31', '-w', '11', '-s', '172.16.15.35']

conntrack -D -f ipv4 -d 172.16.15.31 -w 11 -s 172.16.15.35 (no filter matched)

Removing device (tap1965e495-8a) filter remove_port_filter /usr/lib/python2.7/site-packages/neutron/agent/linux/iptables_firewall.py:184

注意這個py檔案

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'iptables-save', '-c']

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'iptables-restore', '-c'] 

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ip6tables-save', '-c']

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ip6tables-restore', '-c']

瞭解這些命令iptables-save -c,iptables-restore -c,ip6tables-save -c和ip6tables-restore -c

iptables-save  and  ip6tables-save are used to dump the contents of IP or IPv6 Table in easily parseable format to STDOUT. Use I/O-redirection provided by your shell to write to a file.

 iptables-restore and ip6tables-restore are used to restore IP and IPv6 Tables from data specified on STDIN. Use I/O redirection provided by your shell to read from a file

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ebtables', '-L']

 ['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ebtables', '-D', 'FORWARD', '-i', 'tap1965e495-8a', '-j', 'neutronARP-tap1965e495-8a', '-p', 'ARP']

 ['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ebtables', '-X', 'neutronARP-tap1965e495-8a']

 Agent loop found changes! {'current': set([]), 'removed': set(['tap9ab7d96e-55']), 'added': set([]), 'updated': set([])} daemon_loop /usr/lib/python2.7/site-packages/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py:1104

接著分析新增虛擬機器時的日誌記錄:

Agent loop found changes! {'current': set(['tapddb826cd-f2']), 'removed': set([]), 'added': set(['tapddb826cd-f2']), 'updated': set([])} daemon_loop /usr/lib/python2.7/site-packages/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py:1104

【新裝置應該就是從這開始創立的】

 Preparing filters for devices set(['tapddb826cd-f2'])

 Get security group information for devices via rpc ['tapddb826cd-f2'] security_group_info_for_devices /usr/lib/python2.7/site-packages/neutron/api/rpc/handlers/securitygroups_rpc.py:53

MSG_ID is 871c9377eaf346aa8aba1a22b72ecf35 _send /usr/lib/python2.7/site-packages/oslo_messaging/_drivers/amqpdriver.py:392

Preparing device (tapddb826cd-f2) filter prepare_port_filter /usr/lib/python2.7/site-packages/neutron/agent/linux/iptables_firewall.py:164

 Update security group information for ports [u'ddb826cd-f28b-4fc7-b548-9fcd19a6b782'] prepare_devices_filter /usr/lib/python2.7/site-packages/neutron/agent/securitygroups_rpc.py:165

 Update rules of security group (3e07d4ff-0fdd-4fe0-988f-016c42edb10d) update_security_group_rules /usr/lib/python2.7/site-packages/neutron/agent/linux/iptables_firewall.py:141

Update members of security group (3e07d4ff-0fdd-4fe0-988f-016c42edb10d) update_security_group_members /usr/lib/python2.7/site-packages/neutron/agent/linux/iptables_firewall.py:145

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ipset', 'create', '-exist', 'NIPv43e07d4ff-0fdd-4fe0-988f-', 'hash:net', 'family', 'inet']

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ipset', 'swap', 'NIPv43e07d4ff-0fdd-4fe0-988f--n', 'NIPv43e07d4ff-0fdd-4fe0-988f-']

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ipset', 'destroy', 'NIPv43e07d4ff-0fdd-4fe0-988f--n']

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ipset', 'restore', '-exist']

['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ipset', 'swap', 'NIPv63e07d4ff-0fdd-4fe0-988f--n', 'NIPv63e07d4ff-0fdd-4fe0-988f-']

IPTablesManager.apply completed with success _apply_synchronized 

Releasing semaphore "iptables" 

MSG_ID is eb6d37801b08476385f697728fcd4df1

Port tapddb826cd-f2 added treat_devices_added_updated

Port tapddb826cd-f2 updated. Details: {u'profile': {}, u'network_qos_policy_id': None, u'qos_policy_id': None, u'allowed_address_pairs': [], u'admin_state_up': True, u'network_id': u'0a807a08-337e-4e61-bf42-c9cd7b4df1e4', u'segmentation_id': None, u'device_owner': u'compute:OA', u'physical_network': u'oa', u'mac_address': u'fa:16:3e:82:42:c9', u'device': u'tapddb826cd-f2', u'port_security_enabled': True, u'port_id': u'ddb826cd-f28b-4fc7-b548-9fcd19a6b782', u'fixed_ips': [{u'subnet_id': u'2445dd26-5275-492f-8d14-e13ecf876667', u'ip_address': u'172.16.15.21'}], u'network_type': u'flat', u'security_groups': [u'3e07d4ff-0fdd-4fe0-988f-016c42edb10d']}

Command: ['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ebtables', '-L']

ebtables  is an application program used to set up and maintain the tables of rules (inside the Linux kernel) that inspect Ethernet frames.  It is analogous to the iptables appli-cation, but less complicated, due to the fact that the Ethernet protocol is much simpler than the IP protocol.

ebtables -L 列出所有規則

Command: ['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ebtables', '-N', 'neutronARP-tapddb826cd-f2', '-P', 'DROP']

ebtables -N 建立一條新鏈,預設策略是丟包

Command: ['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ebtables', '-F', 'neutronARP-tapddb826cd-f2']

重新整理這個鏈

Command: ['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ebtables', '-A', 'neutronARP-tapddb826cd-f2', '-p', 'ARP', '--arp-ip-src', '172.16.15.21', '-j', 'ACCEPT']

新增一條規則到這條鏈上 -p ARP  是指ARP協議  .這裡是指原地址規則,估計是設定ip地址。

The (R)ARP IP source address specification

Command: ['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ebtables', '-A', 'FORWARD', '-i', 'tapddb826cd-f2', '-j', 'neutronARP-tapddb826cd-f2', '-p', 'ARP']

轉發鏈新增新建的過濾規則

Command: ['ip', '-o', 'link', 'show', 'tapddb826cd-f2']

【有沒有這個o的區別就是會不會提前換行,如果有,意味著輸出單線圖,會把裝置所有的資訊在一行上輸出,一行不夠時自動跳到下一行。如果沒有-o,可能沒到行尾,就自動換行了】

Command: ['ip', 'addr', 'show', 'bond1', 'scope', 'global']

顯示bond1的ip地址(去掉scope global)

Command: ['ip', 'route', 'list', 'dev', 'bond1', 'scope', 'global']

Command: ['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ip', 'link', 'set', 'brq0a807a08-33', 'up']

Command: ['ip', '-o', 'link', 'show', 'bond1']

Command: ['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ip', 'link', 'set', 'tapddb826cd-f2', 'mtu', '1500']

Command: ['ip', '-o', 'link', 'show', 'brq0a807a08-33']

MTUMaximum Transmission Unit的縮寫。意思是網路上傳送的最大資料包。MTU的單位位元組。 大部分網路裝置的MTU1500

1byte=8bit 

日誌看到這裡,瞭解到系統對新建的虛擬裝置增加了對應的過濾規則,但是沒有看到對於虛擬裝置和虛擬機器是如何連線的介紹。

openstack是如何讓物理節點和虛擬節點接力網路聯絡的?

當我在谷歌上搜索這個問題時,突然想起來我一直裝虛擬機器的經過。平時我在oa或者測試環境安裝suse的虛擬機器時,也需要配置網路。首先是虛擬機器的安裝,這是直接依賴於圖形化介面安裝好的,中間可以裝置虛擬網絡卡的數量。之後安裝系統時,就可以根據虛擬網絡卡配置ip地址。

我想我提出這個問題的原因是之前給docker容器配置網路就是用pipework,由此想到openstack是不是也是通過網路設定的。思維轉過彎之後,我現在意思到,openstack給虛擬機器分配網路應該和我手動建立虛擬機器然後設定網路是一樣的,只不過openstack完全實現了自動化。

現在再想想openstack是如何將tap和虛擬機器建立聯絡的,顯示是生成虛擬裝置後,openstack需要做的只有兩件事,一件是分配ip,另一件是就是制定iptables過濾規則(或者叫ebtables)。

還有前面我提到的vnet和vxlan,我想他們也不是openstack建立的,而是我們手工在這臺物理機上建立虛擬機器時建立的。這兩個名字開頭的虛擬網路裝置和openstack壓根沒有半點關係。(不對,看了3號物理機和11號控制節點,即便vnet可能沒有關係,但是vxlan一定是有關係的。)

【有一點可以確定了:vnet和openstack沒有半點關係,他是我在手動建立虛擬機器時生成的虛擬網絡卡裝置,當我把這兩個虛擬機器停掉後,就看到vnet。】

現在可以想象一下openstack是如何給虛擬機器分配網路的了:首先是建立虛擬機器,然後某臺物理節點檢測到多了個虛擬網絡卡,這個虛擬網絡卡的名字已經生成,叫tap******之類,然後物理機給這臺tap設定ebtables過濾規則。虛擬機器的ip和路由應當是在虛擬機器內部設定的。因此我在物理節點上看不到經過。

【預設安全組,oa環境無法建立虛擬機器】

原因是protect安全組的入口規則有問題,修改之後就正常了。

【將dashboard上所有虛擬機器終止後,為什麼在物理機上還是能看到例項?難道openstack不止一個?】

新的疑問,tap虛擬裝置和vxlan的關係是什麼?vxlan是如何建立的和tap建立過程相同嗎?或者和vlan建立過程相同嗎?

補充:

1、初步確定vxlan和虛擬區域網有關,就是如果建立的虛擬機器屬於內網,那麼就關聯到vxlan。

2、在dashboard上大量新建區域網虛擬機發現,虛擬機器並非只會建在含有vxlan裝置的物理節點上。但是在含非vxlan物理節點上建立的虛擬機器卻沒有啟動成功。

3、可以確定只要虛擬機器private環境,而且建在04沒有vxlan的節點上,虛擬機器就一定不能啟動成功

【這說明,vxlan是和本地區域網有關的,也就是在內網才會有vxlan。那麼為什麼2,3,5,6都有vxlan鏈,但是4號節點卻沒有vxlan,這應該是和控制節點剛剛和物理節點建立聯絡時說起。同時表示,vxlan是在最開始物理機和控制節點建立聯絡時建立的,現在需要問的就是如何將控制節點和物理機關聯起來,或者修改之間的關係】