用外部物理路由器時與外部dhcp服務時怎樣使用metadata服務(by quqi99)

來源:互聯網
上載者:User

標籤:ips   eve   netns   i18n   inet6   turn   tac   流量   ifconfig   

張華  發表於:2015-12-31
著作權聲明:能夠隨意轉載,轉載時請務必以超連結形式標明文章原始出處和作者資訊及本著作權聲明( http://blog.csdn.net/quqi99 )

用外部物理路由器意味著不使用neutron-l3-agent, 故定義網路時需指定--router:external=True

neutron net-create phy_net -- --router:external=True --provider:network_type flat --provider:physical_network physnet1

上例使用了flat網路。故要求配置bridge_mappings = physnet1:br-phy (bridge_mapping僅針對flat與vlan有效)。

不配置bridge_mappings屬性建立虛機會失敗(報bind_failed錯誤)。報bind_failed錯誤可能還會有一個原因就是neutron.conf裡的agent_down_time設定得過小,導致心跳覺得它dead從而在bind裡找不到agent所致。

/etc/neutron/plugins/ml2/ml2_conf.ini:
[ml2]
tenant_network_types = flat,vlan,gre,vxlan
type_drivers = local,flat,vlan,gre,vxlan
mechanism_drivers = openvswitch
[ovs]
bridge_mappings = physnet1:br-phy

使用devstack安裝時的配置參數是:

Q_ML2_TENANT_NETWORK_TYPE=flat,vlan,gre,vxlan
OVS_BRIDGE_MAPPINGS=physnet1:br-phy


眼下唯獨l3-agent與dhcp-agent提供了metadata服務。

metadata namespace proxy識別不同tenant下來的中繼資料流量,通過unix socket與metadata agent相連。 metadata agent向nova-metadata-api傳遞一些須要的HTTP Headers代理訪問nova-metadata-api服務。假設我們不使用l3-agent與dhcp-agent提供的metadata服務的話。我們自己寫的程式要必須做識別namespace與傳遞HTTP headers兩件事情。

所以我們要想使用metadata服務還是應該使用l3-agent與dhcp-agent提供的metadata服務

使用dhcp-agent提供的metadata服務的配置例如以下:

[email protected]:~$ grep -r ‘^enable_‘ /etc/neutron/dhcp_agent.ini enable_isolated_metadata = Trueenable_metadata_network = True[email protected]:~$ grep -r ‘^enable_‘ /etc/neutron/l3_agent.ini enable_metadata_proxy = False
另外,上述的enable_isolated_metadata = True 意味著必須是真正的隔離網路,所以非隔離網路是指有一個port指向subnet。且這個port的gateway ip是subnet的gateway ip。所以有下列三種方式處理:

  • 使用--no-gateway建立真正的隔離網路:subnet-create net1 172.17.17.0/24 --no-gateway --name=sub1
  • 或者不建立neutron router。通過--router:external=True使用外部路由:neutron net-create phy_net -- --router:external=True --provider:network_type flat --provider:physical_network physnet1
  • 配置強制使用metadata服務。 force_metadata=True


使用l3-agent提供的metadata服務的配置例如以下, 不使用dhcp-agent能夠停掉dhcp-agent進程也就不須要配置以下和dhcp-agent的配置了。但須要設定dhcp_agent_notification=False避免依賴):

[email protected]:~$ grep -r ‘^enable_‘ /etc/neutron/dhcp_agent.ini enable_isolated_metadata = Trueenable_metadata_network = False[email protected]:~$ grep -r ‘^enable_‘ /etc/neutron/l3_agent.ini enable_metadata_proxy = True


如今使用外部dhcpserver, 所以我們能夠使用l3-agent來只提供metadata服務,但正常的l3流量仍然走外部路由器。

neutron subnet-create --allocation-pool start=172.16.1.102,end=172.16.1.126 --gateway 172.16.1.2 phy_net 172.16.1.101/24 --enable_dhcp=False --name=phy_subnet_without_dhcp

那麼虛機必須配置靜態路由:metadata流量走neutron-l3-agent(如neuton提供的gateway: 172.16.1.2),正常的l3流量走外部路由器(如外部網關的IP: 172.16.1.1)。有兩種方式能夠做到:

1, 做鏡像時就將靜態路由寫死在鏡像裡。

2, 使用外部dhcpserver提供的靜態路由功能。比如使用dnamsq的話。配置應該例如以下:

# 不清楚為什麼以下對openstack的虛機一定要使用qbr59bbcb56-86,我使用br-phy沒有成功。但用它成功了。
sudo ifconfig qbr59bbcb56-86 172.16.1.99/24
sudo dnsmasq --strict-order --bind-interfaces  -i qbr59bbcb56-86 --dhcp-range=set:tag0,172.16.1.100,172.16.1.109,2h --dhcp-optsfile=/home/demo/opts -d
[email protected]:~/devstack$ route -n |grep qbr172.16.1.0      0.0.0.0         255.255.255.0   U     0      0        0 qbr59bbcb56-86[email protected]:~$ cat /home/demo/opts tag:tag0,option:classless-static-route,169.254.169.254/32,172.16.1.2,0.0.0.0/0,172.16.1.1tag:tag0,249,169.254.169.254/32,172.16.1.2,0.0.0.0/0,172.16.1.1tag:tag0,option:router,172.16.1.1

確保虛機同意來自172.16.1.0/24網段的dhcp響應:

-A neutron-openvswi-i59bbcb56-8 -s 172.16.1.0/24 -p udp -m udp --sport 67 --dport 68 -j RETURN

-A neutron-openvswi-o59bbcb56-8 -p udp -m udp --sport 68 --dport 67 -m comment --comment "Allow DHCP client traffic." -j RETURN


$ sudo udhcpc eth0
udhcpc (v1.20.1) started
WARN: ‘/usr/share/udhcpc/default.script‘ should not be used in cirros. Replaced by cirros-dhcpc.
Sending discover...
Sending select for 172.16.1.100...
Lease of 172.16.1.100 obtained, lease time 7200
WARN: ‘/usr/share/udhcpc/default.script‘ should not be used in cirros. Replaced by cirros-dhcpc.
$

[email protected]:~$ sudo dnsmasq --strict-order --bind-interfaces  -i qbr59bbcb56-86 --dhcp-range=set:tag0,172.16.1.100,172.16.1.109,2h --dhcp-optsfile=/home/demo/opts -d
dnsmasq: started, version 2.68 cachesize 150
dnsmasq: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth
dnsmasq-dhcp: DHCP, IP range 172.16.1.100 -- 172.16.1.109, lease time 2h
dnsmasq-dhcp: DHCP, sockets bound exclusively to interface qbr59bbcb56-86
dnsmasq: reading /etc/resolv.conf
dnsmasq: using nameserver 192.168.100.1#53
dnsmasq: read /etc/hosts - 5 addresses
dnsmasq-dhcp: read /home/demo/opts
dnsmasq-dhcp: DHCPDISCOVER(qbr59bbcb56-86) fa:16:3e:79:1e:2c
dnsmasq-dhcp: DHCPOFFER(qbr59bbcb56-86) 172.16.1.100 fa:16:3e:79:1e:2c
dnsmasq-dhcp: DHCPREQUEST(qbr59bbcb56-86) 172.16.1.100 fa:16:3e:79:1e:2c
dnsmasq-dhcp: DHCPACK(qbr59bbcb56-86) 172.16.1.100 fa:16:3e:79:1e:2c


改用sudo cirros-dhcpc up eth0成功。

$ sudo cirros-dhcpc up eth0
udhcpc (v1.20.1) started


[email protected]:~/devstack$ ping -c 1 172.16.1.100
PING 172.16.1.100 (172.16.1.100) 56(84) bytes of data.
64 bytes from 172.16.1.100: icmp_seq=1 ttl=64 time=0.400 ms
--- 172.16.1.100 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.400/0.400/0.400/0.000 ms


[email protected]:~$ ssh [email protected]
The authenticity of host ‘172.16.1.100 (172.16.1.100)‘ can‘t be established.
RSA key fingerprint is fe:f2:85:fd:81:96:3c:94:78:a4:be:b0:41:59:ca:37.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘172.16.1.100‘ (RSA) to the list of known hosts.
[email protected]‘s password:
$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.1.1      0.0.0.0         UG    0      0        0 eth0
169.254.169.254 172.16.1.2      255.255.255.255 UGH   0      0        0 eth0
172.16.1.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0
$ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether fa:16:3e:79:1e:2c brd ff:ff:ff:ff:ff:ff
    inet 172.16.1.100/24 brd 172.16.1.255 scope global eth0
    inet6 fe80::f816:3eff:fe79:1e2c/64 scope link
       valid_lft forever preferred_lft forever


虛機的虛資料流量通過上面的靜態路由走到l3-agent節點上之後。以下的iptables rule會將metadata流量導到9697連接埠的neutron-ns-metadata-proxy進程上。(若是dhcp-agent提供的metadata server,連接埠是80,所以也就不須要這個規則了)。

至此。流程已通。


[email protected]:~$ sudo ip netns exec qrouter-05591292-1191-4f50-9503-215b6962aaec iptables-save |grep 9697
-A neutron-vpn-agen-PREROUTING -d 169.254.169.254/32 -i qr-+ -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 9697
-A neutron-vpn-agen-INPUT -p tcp -m tcp --dport 9697 -j DROP

[email protected]:~$ ps -ef|grep metadata
demo      9648  9615  1 09:54 pts/15   00:01:28 python /usr/local/bin/neutron-metadata-agent --config-file /etc/neutron/neutron.conf --config-file=/etc/neutron/metadata_agent.ini
demo     10057     1  0 09:54 ?

        00:00:00 /usr/bin/python /usr/local/bin/neutron-ns-metadata-proxy --pid_file=/opt/stack/data/neutron/external/pids/05591292-1191-4f50-9503-215b6962aaec.pid --metadata_proxy_socket=/opt/stack/data/neutron/metadata_proxy --router_id=05591292-1191-4f50-9503-215b6962aaec --state_path=/opt/stack/data/neutron --metadata_port=9697 --metadata_proxy_user=1000 --metadata_proxy_group=1000 --verbose



用外部物理路由器時與外部dhcp服務時怎樣使用metadata服務(by quqi99)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.