callus-corn / ansible-ovn

MIT License
0 stars 0 forks source link

メモ #1

Closed callus-corn closed 2 years ago

callus-corn commented 2 years ago

OVS

dnf update

ビルドに必要なパッケージのインストール

dnf install git gcc autoconf automake  libtool openssl-devel libcap-ng unbound python3 python3-pip
pip install flake8

ユーティリティ

dnf install wget nc curl net-tools
pip install pyftpdlib tftpy

ビルド

git clone https://github.com/openvswitch/ovs.git
cd ovs
git checkout v3.0.0
./boot.sh
./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc
make
make install
callus-corn commented 2 years ago

OVN

dnf update
dnf install git gcc autoconf automake  libtool openssl-devel libcap-ng unbound python3 python3-pip
pip install flake8
dnf install wget nc curl net-tools
pip install pyftpdlib tftpy
git clone https://github.com/ovn-org/ovn.git
cd ovn
git checkout v22.06.0
./boot.sh
./configure  --with-ovs-source=/tmp/ovs --prefix=/usr --localstatedir=/var --sysconfdir=/etc
make
make install
callus-corn commented 2 years ago

コントローラ側 DB(NorthDB, SouthDB)作成

mkdir -p /etc/ovn
ovsdb-tool create /etc/ovn/ovn_nb.db ovn-nb.ovsschema
ovsdb-tool create /etc/ovn/ovn_sb.db ovn-sb.ovsschema

起動

mkdir -p /var/log/ovn
mkdir -p /var/run/openvswitch
mkdir -p /var/run/ovn

ovsdb-server /etc/ovn/ovn_nb.db --remote=punix:/var/run/ovn/ovn_nb.sock --remote=ptcp:6641 --pidfile=/var/run/ovn/ovn_nb.pid --detach --log-file=/var/log/ovn/ovn_nb.log

ovsdb-server /etc/ovn/ovn_sb.db --remote=punix:/var/run/ovn/ovn_sb.sock --remote=ptcp:6642 --pidfile=/var/run/ovn/ovn_sb.pid --detach --log-file=/var/log/ovn/ovn_sb.log

初期化

ovn-nbctl --db unix:/var/run/ovn/ovn_nb.sock --no-wait init
ovn-sbctl --db unix:/var/run/ovn/ovn_sb.sock init

ovn-northd起動

ovn-northd --pidfile=/var/run/ovn/northd.pid --detach --log-file=/var/log/ovn/northd.log --ovnnb-db=unix:/var/run/ovn/ovn_nb.sock --ovnsb-db=unix:/var/run/ovn/ovn_sb.sock
callus-corn commented 2 years ago

ovn host

modprobe openvswitch

mkdir /etc/openvswitch
mkdir /var/run/openvswitch
mkdir /var/log/ovs

ovsdb-tool create /etc/openvswitch/vtep.db ovs/vtep/vtep.ovsschema
ovsdb-tool create /etc/openvswitch/conf.db ovs/vswitchd/vswitch.ovsschema
ovsdb-server --remote=punix:/var/run/openvswitch/vtep.sock --detach --pidfile=/var/run/vtep.pid --log-file=/var/log/ovs/vtep.log /etc/openvswitch/vtep.db
ovsdb-server --remote=punix:/var/run/openvswitch/conf.sock --detach --pidfile=/var/run/conf.pid --log-file=/var/log/ovs/conf.log /etc/openvswitch/conf.db
ovs-vsctl --db=unix:/var/run/openvswitch/vtep.sock --no-wait init
ovs-vsctl --db=unix:/var/run/openvswitch/conf.sock --no-wait init
ovs-vswitchd --pidfile=/var/run/openvswitch/vswitchd.pid --detach --log-file=/var/log/vswitchd.log
mkdir /var/run/ovn
mkdir /var/log/ovn

ovs-vsctl --db=unix:/var/run/openvswitch/conf.sock set Open_vSwitch . externaml-ids:system-id=
ovs-vsctl --db=unix:/var/run/openvswitch/conf.sock set Open_vSwitch . externaml-ids:ovn-remote=tcp:192.168.1.110:6642
ovs-vsctl --db=unix:/var/run/openvswitch/conf.sock set Open_vSwitch . externaml-ids:ovn-encap-id=192.168.1.111
ovs-vsctl --db=unix:/var/run/openvswitch/conf.sock set Open_vSwitch . externaml-ids:ovn-encap=type=geneve
ovn-controller --pidfile=/var/run/ovn/controller.pid --detach --log-file=/var/log/ovn/controller.log
callus-corn commented 2 years ago

動作確認

ovn-nbctl --db=unix:/var/run/ovn/ovn_nb.sock ls-add sw
ip netns add ns1
ip link add veth1 type veth peer name vtap1
ip link set veth1 netns ns1
ip link set dev vtap1 up
ip netns exec ns1 ip link set veth1 up
ip netns exec ns1 ip link set lo up
ip netns exec ns1 ip addr add 10.0.0.1/8 dev veth1

ip netns exec ns1 cat /sys/class/net/veth1/address
ovn-nbctl --db=tcp:192.168.1.110:6641 lsp-add sw sw-port1
ovn-nbctl --db=tcp:192.168.1.110:6641 lsp-set-addresses sw-port1 MAC IS HERE 42:8e:2e:77:f0:5b

ovs-vsctl --db=unix:/var/run/openvswitch/db.sock add-port br-int vtap1 -- set interface vtap1 external_ids:iface-id=sw-port1
ip netns add ns2
ip link add veth2 type veth peer name vtap2
ip link set veth2 netns ns2
ip link set dev vtap2 up
ip netns exec ns2 ip link set veth2 up
ip netns exec ns2 ip link set lo up
ip netns exec ns2 ip addr add 10.0.0.2/8 dev veth2

ip netns exec ns2 cat /sys/class/net/veth2/address
ovn-nbctl --db=tcp:192.168.1.110:6641 lsp-add sw sw-port2
ovn-nbctl --db=tcp:192.168.1.110:6641 lsp-set-addresses sw-port2 MAC IS HERE 42:8e:2e:77:f0:5b
ovs-vsctl --db=unix:/var/run/openvswitch/db.sock add-port br-int vtap2 -- set interface vtap2 external_ids:iface-id=sw-port2
callus-corn commented 2 years ago

public (switch)

ovn-nbctl ls-add public
ovn-nbctl lsp-add public public-port
ovn-nbctl lsp-set-type public-port localnet
ovn-nbctl lsp-set-addresses public-port unknown
ovn-nbctl lsp-set-options public-port network_name=phynet
sudo nmcli c del enp1s0
sudo ovs-vsctl add-br br-ext
sudo ovs-vsctl add-port br-ext enp1s0
sudo ip link set br-ext up
sudo ip address add 192.168.1.111/24 dev br-ext

sudo ovs-vsctl set open . external-ids:ovn-bridge-mappings=phynet:br-ext
sudo nmcli c del enp1s0
sudo ovs-vsctl add-br br-ext
sudo ovs-vsctl add-port br-ext enp1s0
sudo ip link set br-ext up
sudo ip address add 192.168.1.112/24 dev br-ext

sudo ovs-vsctl set open . external-ids:ovn-bridge-mappings=phynet:br-ext

router

ovn-nbctl lr-add rt
ovn-nbctl lr-route-add rt 0.0.0.0/0 192.168.1.254

ovn-nbctl lrp-add rt rt-sw 96:2a:9f:22:92:90 10.255.255.254/8

ovn-nbctl lsp-add sw sw-rt
ovn-nbctl lsp-set-type sw-rt router
ovn-nbctl lsp-set-addresses sw-rt router
ovn-nbctl lsp-set-options sw-rt router-port=rt-sw

ovn-nbctl lrp-add rt rt-public 6a:10:b5:75:18:3e 192.168.1.199/24

ovn-nbctl lsp-add public public-rt
ovn-nbctl lsp-set-type public-rt router
ovn-nbctl lsp-set-addresses public-rt router
ovn-nbctl lsp-set-options public-rt router-port=rt-public
sudo ovn-nbctl lrp-set-gateway-chassis rt-public 6c782f7d-c768-6480-4548-57fd477a746a
sudo ovn-nbctl lrp-set-gateway-chassis rt-public 7b4d647d-2fd9-0950-1125-fabb06be29b8

ovn-nbctl set logical_router_port rt-public options:redirect-chassis=7b4d647d-2fd9-0950-1125-fabb06be29b8,6c782f7d-c768-6480-4548-57fd477a746a
ovn-nbctl lr-nat-add rt snat 192.168.1.199 10.0.0.0/8