目錄
- 目錄
- 1、安裝環境說明
- 2、Network Service (Neutron) 概觀
- 3、設定 Controller Node
- 4、設定 Network Node
- 5、設定 Compute Node
- 6、初始化網路
- 7、參考資料
1、安裝環境說明
OS:Ubuntu 14.04 LTS
Controller
- IP:10.0.0.11 / 24
- Gateway:10.0.0.1
Network
- Management IP:10.0.0.21 / 24 (eth0)
- Gateway:10.0.0.1
- Instance Tunnel IP:10.0.1.21 / 24 (eth1)
- External Interface (eth2)
- IP:不指定 IP
- 設定方式如下:(修改 /etc/network/interfaces)
auto eth2
iface eth2 inet manual
up ip link set dev $IFACE up
down ip link set dev $IFACE down
Compute 1
- Management IP:10.0.0.31 / 24
- Gateway:10.0.0.1
- Instance Tunnel IP:10.0.1.31
修改每個 node 的 /etc/hosts 檔案,並加入以下內容:
10.0.0.11 controller
10.0.0.21 network
10.0.0.31 compute1
- 使用者身分:root
2、Network Service (Neutron) 概觀
Network Service (Neutron) 負責虛擬網路架構與外部實體網路架構(包含各廠商的設備)之間的整合 & 存取,用以提供 tenant 可自行建立像是防火牆、負載平衡、VPN … 等網路環境。
網路設定的概念其實跟我們之前所學的並沒有差太多,包含 DHCP、VLAN、Routing … 等等。
比較值得一提的是 Networking Service 支援了 security group 的概念:
- 管理者可以針對每個 security group 進行防火牆規則的設定
- 每個 VM 可以屬於一個或多個 security group
有了以上的機制,讓 Firewall-as-a-Service & Load-Balancing-as-a-Service 變的很容易實現。
3、設定 Controller Node
3.1 建立所需資料庫 & 設定權限
# 登入 MySQL server
controller# mysql -u root -p
Enter password:
# 建立 DB (neutron)
mysql> create database neutron;
Query OK, 1 row affected (0.00 sec)
# 設定權限
mysql> grant all privileges on neutron.* to 'neutron'@'localhost' identified by 'YOUR_DB_PASSWORD';
Query OK, 0 rows affected (0.00 sec)
# 設定權限
mysql> grant all privileges on neutron.* to 'neutron'@'%' identified by 'YOUR_DB_PASSWORD';
Query OK, 0 rows affected (0.00 sec)
3.2 向 Identity Service (Keystone) 註冊 Network Service
建立使用者 neutron
controller# keystone user-create --name neutron --pass YOUR_NEUTRON_PASSWORD --email manager@example.com
+----------+----------------------------------+
| Property | Value |
+----------+----------------------------------+
| email | manager@example.com |
| enabled | True |
| id | 7f3839ca2d774d0e81baf7dbba8574a8 |
| name | neutron |
| username | neutron |
+----------+----------------------------------+
將使用者(neutron)與 Role(admin) & Tenant(service) 綁定
controller# keystone user-role-add --user neutron --tenant service --role admin
將 Network Service(Neutron) 註冊到 Identity Service(Keystone) 中
controller# # keystone service-create --name neutron --type network --description "OpenStack Networking"
+-------------+----------------------------------+
| Property | Value |
+-------------+----------------------------------+
| description | OpenStack Networking |
| enabled | True |
| id | 577265111b73447e8a235946bd4b124c |
| name | neutron |
| type | network |
+-------------+----------------------------------+
建立 Network Service 服務端點資料
controller# keystone endpoint-create --service-id $(keystone service-list | awk '/ network / {print $2}') --publicurl http://controller:9696 --adminurl http://controller:9696 --internalurl http://controller:9696
+-------------+----------------------------------+
| Property | Value |
+-------------+----------------------------------+
| adminurl | http://controller:9696 |
| id | 974f0c66803f427488b60404f47e4931 |
| internalurl | http://controller:9696 |
| publicurl | http://controller:9696 |
| region | regionOne |
| service_id | 577265111b73447e8a235946bd4b124c |
+-------------+----------------------------------+
3.3 安裝相關套件
controller# apt-get -y install neutron-server neutron-plugin-ml2
3.4 設定 Networking Service 各元件
Networking Service 的設定包含了以下幾項:
- 資料庫
- 認證機制
- Message Broker
- Topology Change Notifier
- Modular Layer 2 Plug-in
3.4.1 資料庫
修改 /etc/neutron/neutron.conf,加入資料庫的設定:
[database]
connection = mysql://neutron:YOUR_DB_PASSWORD@controller/neutron
並刪除在 [database] 區段中 SQLite 的相關設定。
3.4.2 認證機制
修改 /etc/neutron/neutron.conf,加入認證機制的設定:
[DEFAULT]
auth_strategy = keystone
[keystone_authtoken]
auth_uri = http://controller:5000
auth_host = controller
auth_port = 35357
auth_protocol = http
admin_tenant_name = service
admin_user = neutron
admin_password = YOUR_NEUTRON_PASSWORD
3.4.3 Message Broker
修改 /etc/neutron/neutron.conf,加入 Message Broker 的設定:
[DEFAULT]
rpc_backend = neutron.openstack.common.rpc.impl_kombu
rabbit_host = controller
rabbit_password = RABBIT_PASS
3.4.4 Topology Change Notifier
首先取得 Tenant ID (service):
controller# source ~/OpenStack/admin-openrc.sh
controller:~# keystone tenant-get service
+-------------+----------------------------------+
| Property | Value |
+-------------+----------------------------------+
| description | Service Tenant |
| enabled | True |
| id | b43a362300c7478193fa26ce5bb0f5c7 |
| name | service |
+-------------+----------------------------------+
修改 /etc/neutron/neutron.conf,加入 Neutron & Nova 的互動設定:
[DEFAULT]
notify_nova_on_port_status_changes = True
notify_nova_on_port_data_changes = True
nova_url = http://controller:8774/v2
nova_admin_username = nova
# 上面的命令取得 b43a362300c7478193fa26ce5bb0f5c7
nova_admin_tenant_id = SERVICE_TENANT_ID
nova_admin_password = NOVA_PASS
nova_admin_auth_url = http://controller:35357/v2.0
3.4.5 Modular Layer 2 Plug-in
修改 /etc/neutron/neutron.conf,加入 ML2 Plug-in 相關設定:
[DEFAULT]
core_plugin = ml2
service_plugins = router
allow_overlapping_ips = True
3.5 設定 Modular Layer 2 (ML2) plug-in
ML2 plug-in 是透過 Opeb vSwitch 建立 VM instances 所使用的虛擬網路架構,以下進行 ML2 相關的設定。
修改 /etc/neutron/plugins/ml2/ml2_conf.ini,加入以下內容:
[ml2]
type_drivers = gre
tenant_network_types = gre
mechanism_drivers = openvswitch
[ml2_type_gre]
tunnel_id_ranges = 1:1000
[securitygroup]
firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
enable_security_group = True
3.6 修改 Compute 相關設定
大部分的預設情況下,Compute(Nova) 所使用的是 nova-network,因此這邊必須修改為使用 Neutron。
修改 /etc/nova/nova.conf,在 Nova 的設定中增加以下內容:
[DEFAULT]
network_api_class = nova.network.neutronv2.api.API
neutron_url = http://controller:9696
neutron_auth_strategy = keystone
neutron_admin_tenant_name = service
neutron_admin_username = neutron
neutron_admin_password = NEUTRON_PASS
neutron_admin_auth_url = http://controller:35357/v2.0
linuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver
firewall_driver = nova.virt.firewall.NoopFirewallDriver
security_group_api = neutron
預設 Compute(Nova) 使用內部的 firewall service,若 Network Service 中包含了 firewall service,就必須停用 Nova 上的 firewall service,改成使用 nova.virt.firewall.NoopFirewallDriver。
3.7 啟動服務
重新啟動 Compute service (Nova):
controller# service nova-api restart
controller# service nova-scheduler restart
controller# service nova-conductor restart
重新啟動 Network Service (Neutron):
controller# service neutron-server restart
4、設定 Network Node
4.1 調整 kernel 網路設定
在 Network node 上,要先將 kernel 的某些網路功能開啟(or 關閉),修改 /etc/sysctl.conf,加入以下設定:
net.ipv4.ip_forward=1
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
套用 kernel 設定:
network# sysctl -p
4.2 安裝 Networking Service 相關套件
network# apt-get -y install neutron-plugin-ml2 neutron-plugin-openvswitch-agent openvswitch-datapath-dkms neutron-l3-agent neutron-dhcp-agent
4.3 Networking 一般元件設定
Networking 一般元件設定包含了以下幾項:
- 認證機制
- Message Broker
- Modular Layer 2 Plug-in
4.3.1 認證機制
修改 /etc/neutron/neutron.conf,加入以下設定:
[DEFAULT]
auth_strategy = keystone
[keystone_authtoken]
auth_uri = http://controller:5000
auth_host = controller
auth_protocol = http
auth_port = 35357
admin_tenant_name = service
admin_user = neutron
admin_password = YOUR_NEUTRON_PASSWORD
4.3.2 Message Broker
修改 /etc/neutron/neutron.conf,加入以下設定:
[DEFAULT]
rpc_backend = neutron.openstack.common.rpc.impl_kombu
rabbit_host = controller
rabbit_password = YOUR_RABBITMQ_PASSWORD
4.3.3 Modular Layer 2 Plug-in
修改 /etc/neutron/neutron.conf,加入以下設定:
[DEFAULT]
core_plugin = ml2
service_plugins = router
allow_overlapping_ips = True
4.4 設定 Layer 3 agent
在 virtual network 中,Layer 3 agent 提供了 routing 的功能,修改 /etc/neutron/l3_agent.ini,加入 Layer 3 agent 相關設定:
[DEFAULT]
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
use_namespaces = True
4.5 設定 DHCP agent
修改 /etc/neutron/dhcp_agent.ini,加入 DHCP agent 相關設定:
[DEFAULT]
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
use_namespaces = True
dnsmasq_config_file = /etc/neutron/dnsmasq-neutron.conf
新增 /etc/neutron/dnsmasq-neutron.conf 並加入設定:
network# echo 'dhcp-option-force=26,1454' > /etc/neutron/dnsmasq-neutron.conf
刪除目前存在的 dnsmasq process:
network# killall dnsmasq
4.6 設定 metadata agent
metadata agent 的功能在提供存取遠端 VM instance 時的相關設定資訊。
修改 /etc/neutron/metadata_agent.ini,加入以下設定:
[DEFAULT]
auth_url = http://controller:5000/v2.0
auth_region = regionOne
admin_tenant_name = service
admin_user = neutron
admin_password = YOUR_NEUTRON_PASSWORD
nova_metadata_ip = controller
metadata_proxy_shared_secret = METADATA_SECRET
4.6.1 以下兩個步驟回到 controller node 進行設定
- 修改 /etc/nova/nova.conf,加入以下設定:
[DEFAULT]
service_neutron_metadata_proxy = true
neutron_metadata_proxy_shared_secret = METADATA_SECRET
- 重新啟動 compute API service:
controller# service nova-api restart
4.7 設定 Modular Layer 2 (ML2) plug-in
修改 /etc/neutron/plugins/ml2/ml2_conf.ini,加入以下設定:
[ml2]
type_drivers = gre
tenant_network_types = gre
mechanism_drivers = openvswitch
[ml2_type_gre]
tunnel_id_ranges = 1:1000
[ovs]
local_ip = 10.0.1.21
tunnel_type = gre
enable_tunneling = True
[securitygroup]
firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
enable_security_group = True
4.8 設定 Open vSwitch(OVS) Service
Open vSwitch Service 提供虛擬網路架構給 VM instance 使用,不僅處理 VM instance 之間的內部流量,也包含對外實體網路介面的對外流量。
執行以下命令設定 OVS:
# 重新啟動 Open vSwitch Service
network# service openvswitch-switch restart
# 增加處理內部流量用的 bridge interface (br-int)
network# ovs-vsctl add-br br-int
# 增加處理外部流量的 bridge interface (br-ex)
network# ovs-vsctl add-br br-ex
# 指定連結外部實體網路卡的 interface name (因內部測試先,這邊暫時先不做)
network# ovs-vsctl add-port br-ex INTERFACE_NAME
4.8.1 啟動 Networking Service
network# service neutron-plugin-openvswitch-agent restart
network# service neutron-l3-agent restart
network# service neutron-dhcp-agent restart
network# service neutron-metadata-agent restart
5、設定 Compute Node
5.1 調整 kernel 網路設定
在 Compute node 上,要先將 kernel 的某些網路功能開啟(or 關閉),修改 /etc/sysctl.conf,加入以下設定:
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
套用設定至 kernel:
sysctl -p
5.2 安裝 Networking 相關套件
執行以下命令:
compute1# apt-get -y install neutron-common neutron-plugin-ml2 neutron-plugin-openvswitch-agent openvswitch-datapath-dkms
5.3 Networking 一般元件設定
Networking 一般元件設定包含了以下幾項:
- 認證機制
- Message Broker
- Modular Layer 2 Plug-in
5.3.1 認證機制
修改 /etc/neutron/neutron.conf,加入以下設定:
[DEFAULT]
auth_strategy = keystone
[keystone_authtoken]
auth_uri = http://controller:5000
auth_host = controller
auth_protocol = http
auth_port = 35357
admin_tenant_name = service
admin_user = neutron
admin_password = YOUR_NEUTRON_PASSWORD
5.3.2 Message Broker
修改 /etc/neutron/neutron.conf,加入以下設定:
[DEFAULT]
rpc_backend = neutron.openstack.common.rpc.impl_kombu
rabbit_host = controller
rabbit_password = YOUR_RABBIT_PASS
5.3.3 Modular Layer 2 Plug-in
修改 /etc/neutron/neutron.conf,加入以下設定:
[DEFAULT]
core_plugin = ml2
service_plugins = router
allow_overlapping_ips = True
5.4 設定 Modular Layer 2 (ML2) plug-in
修改 /etc/neutron/plugins/ml2/ml2_conf.ini,加入以下設定:
[ml2]
type_drivers = gre
tenant_network_types = gre
mechanism_drivers = openvswitch
[ml2_type_gre]
tunnel_id_ranges = 1:1000
[ovs]
local_ip = 10.0.1.31
tunnel_type = gre
enable_tunneling = True
[securitygroup]
firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
enable_security_group = True
5.5 設定 Open vSwitch(OVS) Service
Open vSwitch Service 提供虛擬網路架構給 VM instance 使用,不僅處理 VM instance 之間的內部流量,也包含對外實體網路介面的對外流量。
執行以下命令設定 OVS:
# 啟動 Open vSwitch Service
compute1# service openvswitch-switch restart
# 增加處理內部流量用的 bridge interface (br-int)
compute1# ovs-vsctl add-br br-int
5.6 指定 Compute 使用 Neutron
大部分狀況下,Compute 所使用的是 nova-network,但因為這邊安裝的是 Neutron,因此要做一些設定上的調整,修改 /etc/nova/nova.conf,加入以下內容:
[DEFAULT]
network_api_class = nova.network.neutronv2.api.API
neutron_url = http://controller:9696
neutron_auth_strategy = keystone
neutron_admin_tenant_name = service
neutron_admin_username = neutron
neutron_admin_password = NEUTRON_PASS
neutron_admin_auth_url = http://controller:35357/v2.0
linuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver
firewall_driver = nova.virt.firewall.NoopFirewallDriver
security_group_api = neutron
因為 Compute 會預設使用畚箕的防火牆服務,但因為在 OpenStack 的環境中,防火牆服務是設定在 Network node 上面,因此要透過設定將防火牆的功能交給 Neutron 來做。
5.7 重新啟動相關服務
# 重新啟動 compute service
compute1# service nova-compute restart
# 重新啟動 Open vSwitch agent
compute1# service neutron-plugin-openvswitch-agent restart
6、初始化網路

6.1 External network
外部虛擬網路提供 VM instance 存取網際網路的能力,預設僅能讓 VM instance 透過 NAT 的方式連線到網際網路,若要讓外部可以存取 VM instance,則必須指定 IP & 設定 security group 規則來達成。
以下指令必須在 controller 上執行,並非 network node
6.1.1 建立外部虛擬網路 (ext-net)
controller# source ~/OpenStack/admin-openrc.sh
controller:~# neutron net-create ext-net --shared --router:external=True
Created a new network:
+---------------------------+--------------------------------------+
| Field | Value |
+---------------------------+--------------------------------------+
| admin_state_up | True |
| id | 629c575d-5d2e-4258-bb96-d2def517aa04 |
| name | ext-net |
| provider:network_type | gre |
| provider:physical_network | |
| provider:segmentation_id | 1 |
| router:external | True |
| shared | True |
| status | ACTIVE |
| subnets | |
| tenant_id | 27466ca061e34b469f84da1e57b5605e |
+---------------------------+--------------------------------------+
6.1.2 為外部虛擬網路(ext-net)設定網段資訊
虛擬網路也像實體網路一樣,需要指定網段(subnet)資訊。
而 Network node 對外連接的 interface 會與外部實體網路共用相同的 subnet & gateway 等資訊。
因此以下將外部實體網路的 subnet & gateway 等資訊設定到 Network node 的外部虛擬網路中:
以下以 192.168.20.0/24 作為外部網路範例
controller# neutron subnet-create ext-net --name ext-subnet --allocation-pool start=192.168.20.11,end=192.168.20.30 --disable-dhcp --gateway=192.168.20.254 192.168.20.0/24
Created a new subnet:
+------------------+----------------------------------------------------+
| Field | Value |
+------------------+----------------------------------------------------+
| allocation_pools | {"start": "192.168.20.11", "end": "192.168.20.30"} |
| cidr | 192.168.20.0/24 |
| dns_nameservers | |
| enable_dhcp | False |
| gateway_ip | 192.168.20.254 |
| host_routes | |
| id | 4af846a3-3e14-450d-b620-134cb1479e0d |
| ip_version | 4 |
| name | ext-subnet |
| network_id | 629c575d-5d2e-4258-bb96-d2def517aa04 |
| tenant_id | 27466ca061e34b469f84da1e57b5605e |
+------------------+----------------------------------------------------+
6.2 Tenant network
tenant network 提供存取 VM instance 的內部網路,這類型的網路會以 tenant 為單位進行隔離,因此不同 tenant 之間的 VM instance 是無法互相存取的。
6.2.1 建立 Tenant Virtual Network
以下指令必須在 controller 上執行,並非 network node
建立 demo credential 資訊 ~/OpenStack/demo-openrc.sh,並設定內容如下:
unset OS_USERNAME
unset OS_PASSWORD
unset OS_TENANT_NAME
unset OS_AUTH_URL
export OS_USERNAME=demo
export OS_PASSWORD=YOUR_DEMO_PASSWORD
export OS_TENANT_NAME=demo
export OS_AUTH_URL=http://controller:35357/v2.0
新增 tenant virtual network
# 以 demo 的身分執行
controller# source ~/OpenStack/demo-openrc.sh
# 建立名稱為 demo-net 的 tenant virtual network
controller:~# neutron net-create demo-net
Created a new network:
+----------------+--------------------------------------+
| Field | Value |
+----------------+--------------------------------------+
| admin_state_up | True |
| id | 65c99acc-6438-493e-bbde-b3c0def3f575 |
| name | demo-net |
| shared | False |
| status | ACTIVE |
| subnets | |
| tenant_id | 7539436331ca4f9783bf93163e2a2e0f |
+----------------+--------------------------------------+
6.2.2 在 tenant network(demo-net) 設定網段資訊
如同外部網路一樣,也必須要給定 tenant network 網段資訊,這邊以上圖為範例,設定 192.168.1.0/24 網段:
controller# neutron subnet-create demo-net --name demo-subnet --gateway 192.168.3.254 192.168.3.0/24 --dns_nameservers list=true 8.8.8.8 8.8.4.4
Created a new subnet:
+------------------+--------------------------------------------------+
| Field | Value |
+------------------+--------------------------------------------------+
| allocation_pools | {"start": "192.168.3.1", "end": "192.168.3.253"} |
| cidr | 192.168.3.0/24 |
| dns_nameservers | 8.8.4.4 |
| | 8.8.8.8 |
| enable_dhcp | True |
| gateway_ip | 192.168.3.254 |
| host_routes | |
| id | eb46a51b-c1b0-4df9-9046-a19612fa532f |
| ip_version | 4 |
| name | demo-subnet |
| network_id | 65c99acc-6438-493e-bbde-b3c0def3f575 |
| tenant_id | 7539436331ca4f9783bf93163e2a2e0f |
+------------------+--------------------------------------------------+
6.2.3 建立 router 作為外部網路與 tenant network 連結之用
所有 tenant virtual network 之間的流量,以及 tenant virtual network 到外部網路的流量,都必須由 virtual router 來處理 & 過濾。
因此這邊有三個步驟要完成:
- 建立 virtual router
- 將 tenant virtual network (demo-subnet) 附加到 virtual router
- 將 external network(ext-net) 附加到 virtual router
# 建立 virtual router
controller# neutron router-create demo-router
Created a new router:
+-----------------------+--------------------------------------+
| Field | Value |
+-----------------------+--------------------------------------+
| admin_state_up | True |
| external_gateway_info | |
| id | e74b7f9a-9ebe-4e88-8836-cbf558cfc05f |
| name | demo-router |
| status | ACTIVE |
| tenant_id | 7539436331ca4f9783bf93163e2a2e0f |
+-----------------------+--------------------------------------+
# 將 tenant virtual network (demo-subnet) 附加到 virtual router
controller# neutron router-interface-add demo-router demo-subnet
Added interface 5ea27e34-e45d-4a69-9fdb-59be55e07268 to router demo-router.
# 將 external network(ext-net) 附加到 virtual router
controller# neutron router-gateway-set demo-router ext-net
Set gateway for router demo-router
6.3 驗證網路服務是否設定成功
根據上面的設定,外部網路的網段為 192.168.20.0/24,我們分配了 192.168.20.[11-30] 給了外部網路。
其中 tenant router gateway 會自動使用最前面的 IP,也就是 192.168.20.11,若是有設定正確,嘗試 ping 這個 IP 就可以取得回應。
若把 OpenStack 安裝在 VM 的話,記得把虛擬交換器的 promiscuous mode 打開,網路才會通喔!
我的環境是在 VMware 裡面,就把 192.168.20.0/24 這個網段所在的 port group 的 promiscuous mode 開啟。(不需要開啟整個 vSwitch 的 promiscuous mode)


