openstack的M版本的neutron的实验

[b]试验步骤:
1.创建内部网络
2.创建vm
3.创建路由
4.路由连接内部网络
5.创建外部网络
6.路由连接外部网络
7.测试vm ping baidu ,到此成功让vm访问互联网
8.创建floating ip,让互联网访问这台vm
[/b]
注意,多观察
ip netns
brctl show的变化

[b]★★★★★★★★★★★基础知识★★★★★★★★★★★★★★[/b]
三个概念:
1.网络,子网:
如果是内网对应命名空间,桥接,dnsmasq进程(dhcp的)
如果是外网没有命名空间,只有桥
2.port
3.路由

neutron net-list
neutron subnet-list
neutron port-list
neutron router-list
neutron router-port-list <router-id>

查看命名空间
ip netns
查看桥
brctl show
查看命名空间里的ip
ip netns exec <netns-name> ip a

[b]★★★★★★★★★★★★创建内部网络★★★★★★★★★★★★:[/b]
neutron net-list
neutron net-create <网络名字>

neutron net-create hello-private

创建子网

neutron subnet-create --name <子网名字> <网络名字> 网段

neutron subnet-create --name hello-sub-private hello-private 10.1.0.0/28

验证:

neutron port-list
ip netns

qdhcp- 开头的就是网络,后面跟网络id,
brctl show
桥上的tap<port-id>对应命名空间里的ns-<port-id>
ip netns exec <qdhcp-netid> ip a
brctl show
查看
是一个veth pair

ps -ef|grep dnsmasq

对应网络id


[b]★★★★★★★★★★创建vm的方式:[]表示可选参数 <>表示参数替换[/b]
1.根据网络创建vm(这种方法了解,本试验不用):

nova boot [--availability-zone nova::网络节点] --image <镜像> --flavor <flavor> --nic net-id=<网络id> <vm-name>

nova boot --availability-zone nova::mcom2 --image cirros --flavor 1 --nic net-id=23fa78be-a22a-4946-b175-20b5e5b92b3c One

注意这里,不能指定子网,如果是多个子网,会自动分配ip
2.如果想给vm指定ip: 创建port,给port指定ip ,指定port再创建vm(这种方法连接):
neutron port-create --fixed-ip subnet_id=<subnet-id>,ip_address=<子网内的ip> --name <port名字> <网络名字>

neutron port-create --fixed-ip subnet_id=5bcc6a89-9d6e-4126-92f3-b6a12174c5a1,ip_address=10.1.0.6 --name hello-port hello-private

neutron port-list 查看已经有两个port了
一个是属于网络命名空间的,一个是空闲的,准备绑定到vm的,
ip netns
ip netns exec qdhcp-23fa78be-a22a-4946-b175-20b5e5b92b3c ip a
指定port创建vm:

nova boot --flavor 1 --image cirros --nic port-id=<port-id> <vm-name>

nova boot --flavor 1 --image cirros --nic port-id=b52bc9c9-e4c7-455b-aa55-5256a026aaea hello-vm

测试vm

openstack console url show hello-vm
nova get-vnc-console hello-vm novnc

进入vm:
ifconfig
[b]★★★★★★★创建路由器★★★★★★★★★★[/b]
创建路由器:

neutron router-create --distributed=false <路由名字>

neutron router-create --distributed=False hello-router


☆★linuxbridge支持非分布式路由,openvswitch支持分布式路由

网络子网添加到路由器上:
neutron router-interface-add <路由名字> <子网名字>

neutron router-interface-add hello-router hello-sub-private

验证:
ip netns
qrouter-开头的是路由器,后面是router-id
ip netns exec qrouter-d62d8aca-0b9e-4e59-8c79-37aca9fe6696 ip a
路由ip 为10.1.0.1
console进入vm ping试验一下

[b]★★★★★★★★★★★★★★
创建外部网络:[/b]
创建网络:
neutron net-create --shared <外网名字> --router:external=True --provider:network_type flat --provider:physical_network <★ml2配置的外网flat_networks的名字>
#neutron net-create --shared hello-public --router:external=True --provider:network_type flat --provider:physical_network provider


neutron net-create --shared hello-public --router:external=True --provider:network_type flat --provider:physical_network hello-provider

[color=red]其中★★★★★一定要注意一下最后一个参数一定不要写错[/color]
网络节点的:
[b][color=red]
--provider:physical_network
vim /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2_type_flat]
flat_networks = hello-provider
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = hello-provider:eth0
[/color][/b]

改成其他的不好使
这两个配置文件一定要对应,
*似乎不好使


创建子网:
neutron subnet-create --name <子网名字> <网络名字> --allocation-pool start=<开始ip>,end=<截止ip> --gateway=网关ip --enable_dhcp=False <网段>
例如


neutron subnet-create --name hello-subnet-public hello-public --allocation-pool start=192.168.139.114,end=192.168.139.116 --gateway=192.168.128.1 --enable_dhcp=False 192.168.128.0/20

注意:139是办公网段,一定要都ping一次,不要和其他人冲突了


[b]★★★★★★★★★★★★★★★★外网接口添加到路由器上:[/b]
把外部网络的网关设置到路由器上

neutron router-gateway-set hello-router hello-public


这步骤一定要检查网桥是否存在,如果
brctl show
没有路由器到外网的网桥,则没有建成功★★★★★

不要使用:
neutron router-interface-add <router-name> <外网子网名称>
neutron router-interface-add hello-router hello-subnet-public
neutron router-interface-delete hello-router hello-subnet-public

这个是内网绑定路由和网络使用的

验证:

neutron net-list
neutron subnet-list
neutron port-list
neutron router-list
neutorn help|grep router
neutron router-port-list <router-id>
neutron router-port-list hello-router
ip netns exec qrouter-d62d8aca-0b9e-4e59-8c79-37aca9fe6696 ip a

qr-d0b3aac4-65@if23的ip为 192.168.139.114/20
如果使用了内网的绑定方式来绑定外网则得到
qr-d0b3aac4-65@if23的ip为 192.168.128.1/20


测试vm,
console连接进去,
如果网络不对,需要在vm里面重启网络或重启vm

测试是否能ping到百度
先ping 114.114.114.114

vi /etc/resolv.conf
servername 114.114.114.114

再ping baidu

[b]★★★★★★★★创建floating ip★★★★★★★★★★[/b]
创建

neutron floatingip-create hello-public
nova floating-ip-associate hello-vm 192.168.139.115

nova get-vnc-console hello-vm novnc
连到vm,ifconfig是看不到115这个ip的,
但是从controller能ssh过来

如果不行就重启试试
#nova reboot hello-vm


[b]★★★★★★★★★如果遇到问题★★★★★★★★★★★★★★★[/b]

如果不通的话,删掉外网,重新建

neutron router-gateway-clear hello-router hello-public
neutron net-delete hello-public


查看历史记录的时候带时间
export HISTTIMEFORMAT="%F %T `whoami` "
history

清理环境:
删除vm

nova delete <vm_name>
neutron port-list
neutron help|grep router
neutron router-list
neutron router-port-list <router-id>
neutron help router-interface-delete

删除网络和路由的连接,
外网用:
neutron router-gateway-clear <router-name> <net-name>
内网用
neutron router-interface-delete <ROUTER> <INTERFACE>
外网删除和路由的连接
neutron router-gateway-clear hello-router hello-public

内网删除和路由的连接
neutron  router-interface-delete hello-router hello-sub-private

删除端口,网络,路由
neutron port-delete <port-name>
neutron net-delete <net-id>
neutron router-delete hello-router


再删网络和vm

[b]########################调试脚本####mysql_openstack.sh #######################[/b]

#!/bin/sh
#for i in `awk ' {if(NR>4 && NR<40)print $2};' a.log `

mysql_user=root
mysql_password=haoning
mysql_host=mcon

if [ "$1" = "" ]
then
echo "please use ./mysql_openstack.sh [dbname], for example: ./mysql_openstack.sh keystone";
echo "this will exit."
exit 0;
fi

echo "use db " $1

for i in ` mysql -u$mysql_user -h$mysql_host -p$mysql_password $1 -e "show tables" |awk ' {if(NR>1)print $1};'`
do
if [ $i != "ml2_vxlan_allocations" ]
then
echo "mysql -u$mysql_user -h$mysql_host -p$mysql_password $1 -e \"select * from \`$i\`\"";
mysql -u$mysql_user -h$mysql_host -p$mysql_password $1 -e "select * from \`$i\`";
fi
done


./mysql_openstack.sh neutron


l2poplation
bridge fdb
ip neigh
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值