基于kvm+ovs+ryu构建一个SDN环境

-安装kvm
1.安装软件包

apt-get install qemu-kvm libvirt-bin Python-libvirt  virt-viewer virt-manager bridge-utils -y

2.配置网卡
启动kvm虚拟机时,先使用桥接模式到br0上,等安装完ovs后再桥接到ovs上。

cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
auto br0
iface br0 inet static
address 192.168.40.100
netmask 255.255.255.0
gateway 192.168.40.2
bridge_ports eth0

3.启动虚拟机

virt-install --connect=qemu:///system --name vm1 --ram 1024 --vcpus=1 --os-type=linux  --accelerate --hvm --disk path=/opt/image/vm1.img,size=6,bus=virtio --cdrom=/opt/os/ubuntu14.iso --extra-args='console=tty0 console=ttyS0' --network bridge=br0,model=virtio --vnc --vnclisten=0.0.0.0 --vncport=5901

4.利用vnc viewer登录kvm虚拟机上完成安装
登录地址为192.168.40.100:5901
- 安装ovs

1.安装软件包

apt-get -y install automake autoconf libssl-dev gcc uml-utilities libtool build-essential git pkg-config linux-headers-`uname -r`

2.下载 openvswitch-2.4.0.tar.gz

wget http://openvswitch.org/releases/openvswitch-2.4.0.tar.gz

3.解压安装包,编译安装ovs

tar zxvf openvswitch-2.4.0.tar.gz
cd openvswitch-2.4.0
./boot.sh
./configure --with-linux=/lib/modules/`uname -r`/build
make && make install

4.载入内核模块

modinfo ./datapath/linux/openvswitch.ko
modprobe libcrc32c
insmod ./datapath/linux/openvswitch.ko
lsmod|grep open

5.配置ovs数据并启动守护线程

mkdir -p /usr/local/etc/openvswitch
ovsdb-tool create /usr/local/etc/openvswitch/conf.db ./vswitchd/vswitch.ovsschema
ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --private-key=db:Open_vSwitch,SSL,private_key --certificate=db:Open_vSwitch,SSL,certificate --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert --pidfile --detach
ovs-vsctl --no-wait init
ovs-vswitchd --pidfile --detach

6.创建一个ovs网桥

ovs-vsctl add-br br-int

7.修改kvm的XML配置文件,使得其桥接到ovs

<interface type='bridge'>
      <mac address='52:54:00:88:8a:f8'/>
      <source bridge='br-int'/>
      <virtualport type='openvswitch'>
        <parameters interfaceid='8a0b9687-fd1c-4fdf-b11a-c179c1237780'/>
      virtualport>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    interface>

-安装ryu控制器
1.下载ryu源码

git clone https://github.com/osrg/ryu.git

2.编译安装

cd ryu
python setup.py install

3.连接至控制器

ovs-vsctl set-controller br-int tcp:192.168.40.100:6653

ryu的wsgi api和openflow监听端口可以在ryu.conf中配置

你可能感兴趣的:(SDN)