openstack的M版本的neutron的实验

试验步骤:
1.创建内部网络
2.创建vm
3.创建路由
4.路由连接内部网络
5.创建外部网络
6.路由连接外部网络
7.测试vm ping baidu ,到此成功让vm访问互联网
8.创建floating ip,让互联网访问这台vm

注意,多观察
ip netns
brctl show的变化

★★★★★★★★★★★基础知识★★★★★★★★★★★★★★
三个概念:
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

★★★★★★★★★★★★创建内部网络★★★★★★★★★★★★:
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


★★★★★★★★★★创建vm的方式:[]表示可选参数 <>表示参数替换
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
★★★★★★★创建路由器★★★★★★★★★★
创建路由器:

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试验一下

★★★★★★★★★★★★★★
创建外部网络:

创建网络:
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 

其中★★★★★一定要注意一下最后一个参数一定不要写错
网络节点的:

--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


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


创建子网:
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一次,不要和其他人冲突了


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

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

★★★★★★★★创建floating ip★★★★★★★★★★
创建
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




★★★★★★★★★如果遇到问题★★★★★★★★★★★★★★★

如果不通的话,删掉外网,重新建
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

########################调试脚本####mysql_openstack.sh #######################
#!/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



猜你喜欢

转载自haoningabc.iteye.com/blog/2322169