首页 > 代码库 > neutron实现阿里云ecs网络

neutron实现阿里云ecs网络

一、neutron实现阿里云ecs网络

(1)环境准备

IP地址		主机名			操作系统
192.168.56.11	linux-node1		CentOS7
192.168.56.12	linux-node2		CentOS7

其中,linux-node1当作控制节点

linux-node2当作计算节点

(2)添加双网卡

阿里云主机,两个网卡,一个外网,一个内网网卡。

所以我们模拟阿里云云主机,需要添加在原有基础上再添加一块网卡。

打开wmware workstation,点“编辑”--“虚拟网络编辑器”,打开后,编辑VMnet1,类型选择仅主机,子网地址选择192.168.57.0,同时将“使用本地DHCP服务将IP地址分配给虚拟机”取消掉,单击确定按钮。

接下来为控制节点和计算节点添加网卡 选择linux-node1,“设置”--“网络适配器”,下一步添加网络连接,选择自定义特定虚拟网络--“VMnet1(仅主机模式)”,点击“完成”--“确定”

用同样的方式为linux-node2添加网卡。

(3)在虚拟机上添加网卡

[root@linux-node1 ~]# cd /etc/sysconfig/network-scripts/

[root@linux-node1 network-scripts]# cp ifcfg-eth0 ifcfg-eth1

[root@linux-node1 network-scripts]# cat ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR0=192.168.57.11
PREFIX0=24

启动并查看eth1

[root@linux-node1 network-scripts]# ifup eth1
[root@linux-node1 network-scripts]# ifconfig
eth0: flags=4163mtu 1500
        inet 192.168.56.11  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::20c:29ff:fe4c:a40b  prefixlen 64  scopeid 0x20
        ether 00:0c:29:4c:a4:0b  txqueuelen 1000  (Ethernet)
        RX packets 14383  bytes 3982904 (3.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 13871  bytes 9990604 (9.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163mtu 1500
        inet 192.168.57.11  netmask 255.255.255.0  broadcast 192.168.57.255
        inet6 fe80::20c:29ff:fe4c:a415  prefixlen 64  scopeid 0x20
        ether 00:0c:29:4c:a4:15  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12  bytes 888 (888.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10loop  txqueuelen 0  (Local Loopback)
        RX packets 74878  bytes 29270386 (27.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 74878  bytes 29270386 (27.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tap50360466-68: flags=4163mtu 1500
        ether 7e:24:2c:64:4f:0b  txqueuelen 1000  (Ethernet)
        RX packets 8  bytes 648 (648.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

使用同样的方法配置linux-node2

(4)修改ml2和linuxbridge的配置文件

在控制节点上修改linuxbridge_agent.ini

[root@linux-node1 network-scripts]# vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini 

physical_interface_mappings = public:eth0,internet:eth1

查看配置

[root@linux-node1 network-scripts]# grep ‘^[a-Z]‘ /etc/neutron/plugins/ml2/linuxbridge_agent.ini 
physical_interface_mappings = public:eth0,internet:eth1
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver 
enable_security_group = true
enable_vxlan = false

修改ml2_conf.ini

[root@linux-node1 network-scripts]# vim /etc/neutron/plugins/ml2/ml2_conf.ini

flat_networks = public,internet
查看配置
[root@linux-node1 network-scripts]# grep ‘^[a-Z]‘ /etc/neutron/plugins/ml2/ml2_conf.ini
type_drivers = flat,vlan,vxlan,gre,geneve
tenant_network_types = 
mechanism_drivers = linuxbridge,openvswitch
extension_drivers = port_security
flat_networks = public,internet
enable_ipset = true
[root@linux-node1 netwo

重启linuxbridge

[root@linux-node1 network-scripts]# systemctl restart neutron-linuxbridge-agent

在计算节点上配置linuxbridger_agent.ini

[root@linux-node2 ~]# grep ‘^[a-Z]‘ /etc/neutron/plugins/ml2/linuxbridge_agent.ini
physical_interface_mappings = public:eth0,internet:eth1
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver 
enable_security_group = True
enable_vxlan = True

重启linuxbridge

[root@linux-node2 network-scripts]# systemctl restart neutron-linuxbridge-agent

在控制节点上重启neutron-server

[root@linux-node1 network-scripts]# systemctl restart neutron-server

(5)创建虚拟网络

先执行一下环境变量

[root@linux-node1 ~]# source admin-openstack.sh

创建internet网络

[root@linux-node1 ~]# neutron net-create --shared --provider:physical_network internet --provider:network_type flat internet-net
Created a new network:
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2016-11-16T13:51:07                  |
| description               |                                      |
| id                        | 00c9b5e2-f29e-4afd-a7e2-f9c47a457644 |
| ipv4_address_scope        |                                      |
| ipv6_address_scope        |                                      |
| mtu                       | 1500                                 |
| name                      | internet-net                         |
| port_security_enabled     | True                                 |
| provider:network_type     | flat                                 |
| provider:physical_network | internet                             |
| provider:segmentation_id  |                                      |
| router:external           | False                                |
| shared                    | True                                 |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tags                      |                                      |
| tenant_id                 | 53f72af1420a4d098d48f2c82d7e9ec7     |
| updated_at                | 2016-11-16T13:51:07                  |
+---------------------------+--------------------------------------+

创建子网

[root@linux-node1 ~]# neutron subnet-create --name internet-subnet >   --allocation-pool start=192.168.57.100,end=192.168.57.200 >   --dns-nameserver 223.5.5.5 internet-net 192.168.57.0/24
Created a new subnet:
+-------------------+------------------------------------------------------+
| Field             | Value                                                |
+-------------------+------------------------------------------------------+
| allocation_pools  | {"start": "192.168.57.100", "end": "192.168.57.200"} |
| cidr              | 192.168.57.0/24                                      |
| created_at        | 2016-11-16T14:03:27                                  |
| description       |                                                      |
| dns_nameservers   | 223.5.5.5                                            |
| enable_dhcp       | True                                                 |
| gateway_ip        | 192.168.57.1                                         |
| host_routes       |                                                      |
| id                | 92311aff-245c-4663-aa93-a8b2e2b780a1                 |
| ip_version        | 4                                                    |
| ipv6_address_mode |                                                      |
| ipv6_ra_mode      |                                                      |
| name              | internet-subnet                                      |
| network_id        | 00c9b5e2-f29e-4afd-a7e2-f9c47a457644                 |
| subnetpool_id     |                                                      |
| tenant_id         | 53f72af1420a4d098d48f2c82d7e9ec7                     |
| updated_at        | 2016-11-16T14:03:27                                  |
+-------------------+------------------------------------------------------+

查看一下刚才创建的网络

[root@linux-node1 ~]# neutron net-list
+--------------------------------------+--------------+------------------------------------------------------+
| id                                   | name         | subnets                                              |
+--------------------------------------+--------------+------------------------------------------------------+
| 2cbfb54c-b760-41e1-ba69-83131220463b | public-net   | 80f2d649-7882-4625-9f07-03ad96e5be9a 192.168.57.0/24 |
|                                      |              | 
| 00c9b5e2-f29e-4afd-a7e2-f9c47a457644 | internet-net | 92311aff-245c-4663-aa93-a8b2e2b780a1 192.168.57.0/24 |
+--------------------------------------+--------------+------------------------------------------------------+

二、创建虚拟机

接下来就可以登录到192.168.56.11/dashboard,创建云主机了

用户名:demo

密码:demo

登录进去后,在页面左侧选择云主机,进入云主机管理页面,单击“创建云主机”,就可以开始创建主机了

技术分享

输入实例名称,即主机名

技术分享

选择引导源,这里我选择了一个小镜像,便于测试

技术分享

选择套餐,即给云主机配置cpu、磁盘和内存的大小

技术分享

选择网络,添加双网卡

技术分享

选择安全组

技术分享

选择密码对,用于后面登录云主机

技术分享

配置完成后,点击启动实例,就开始创建云主机了。

创建完成后,可以在云主机列表中查看云主机。

点击控制台,可以通过web界面登陆云主机。

技术分享

查看网络配置,可以看到网络配置成功,能连接外网

技术分享

查看网络拓扑

技术分享

综上,我们可以利用openstack neutron创建阿里云ecs网络


本文出自 “JackyWang” 博客,请务必保留此出处http://jackyxin.blog.51cto.com/1976631/1873761

neutron实现阿里云ecs网络