Apri vSwitch è uno switch software multilivello gratuito e open source, utilizzato per gestire il traffico tra macchine virtuali e reti fisiche o logiche. Fornisce funzionalità come l'isolamento del traffico nei tenant OpenStack utilizzando le tecniche di sovrapposizione come GRE , VXLAN e VLAN 802.1Q .
È possibile implementare l'utilizzo del motore di inoltro dei pacchetti vSwitch aperto nello spazio del kernel o nello spazio utente e l'aggregazione dei collegamenti può essere eseguita anche tramite LACP .
In questo articolo discuteremo come installare l'ultima versione di Open vSwitch 2.9.2 su CentOS 7 e RHEL 7 Server. Oltre a questo, vedremo come vSwitch aperto può essere utilizzato nelle macchine virtuali KVM per la loro rete.
Ulteriori informazioni su: Come installare e configurare KVM su Ubuntu 18.04 LTS Server
Presumo che tu abbia già un server CentOS 7 o RHEL 7 configurato con KVM. Open vSwitch (OVS) 2.0 è disponibile nei repository yum predefiniti di CentOS 7 e RHEL 7, ma se installi l'ultima versione di open vSwitch, fai riferimento ai passaggi seguenti.
Fase 1) Installa i pacchetti richiesti usando il comando yum
Accedi al tuo server CentOS 7 o RHEL 7 ed esegui il comando yum sottostante,
[[email protected] ~]# yum install wget openssl-devel python-sphinx gcc make python-devel openssl-devel kernel-devel graphviz kernel-debug-devel autoconf automake rpm-build redhat-rpm-config libtool python-twisted-core python-zope-interface PyQt4 desktop-file-utils libcap-ng-devel groff checkpolicy selinux-policy-devel -y
Passaggio 2) Crea un utente ovs e scarica Open vSwitch 2.9
Crea un utente con nome ovs usando il comando sotto
[[email protected] ~]# useradd ovs [[email protected] ~]# su - ovs [[email protected] ~]$
Scarica il file tar di OVS 2.9 e crea openvswitch rpm usando i comandi sotto,
[email protected] ~]$ mkdir -p ~/rpmbuild/SOURCES [[email protected] ~]$ wget http://openvswitch.org/releases/openvswitch-2.9.2.tar.gz [[email protected] ~]$ cp openvswitch-2.9.2.tar.gz ~/rpmbuild/SOURCES/ [[email protected] ~]$ tar xfz openvswitch-2.9.2.tar.gz [[email protected] ~]$ rpmbuild -bb --nocheck openvswitch-2.9.2/rhel/openvswitch-fedora.spec [[email protected] ~]$ exit logout [[email protected] ~]#
Ora installa Open vSwitch rpm usando il comando yum sotto,
[[email protected] ~]# yum localinstall /home/ovs/rpmbuild/RPMS/x86_64/openvswitch-2.9.2-1.el7.x86_64.rpm -y
Passaggio 3) Avvia e abilita il servizio Open vSwitch
Utilizza i seguenti comandi systemctl per avviare e abilitare il servizio vSwitch aperto
[[email protected] ~]# systemctl start openvswitch.service [[email protected] ~]# systemctl enable openvswitch.service Created symlink from /etc/systemd/system/multi-user.target.wants/openvswitch.service to /usr/lib/systemd/system/openvswitch.service. [[email protected] ~]# systemctl status openvswitch.service ● openvswitch.service - Open vSwitch Loaded: loaded (/usr/lib/systemd/system/openvswitch.service; enabled; vendor preset: disabled) Active: active (exited) since Sun 2018-08-05 10:16:12 EDT; 17s ago Main PID: 73958 (code=exited, status=0/SUCCESS) Aug 05 10:16:12 compute02 systemd[1]: Starting Open vSwitch... Aug 05 10:16:12 compute02 systemd[1]: Started Open vSwitch. [[email protected] ~]#
Utilizzare il comando seguente per verificare la versione di OVS
[[email protected] ~]# ovs-vsctl -V ovs-vsctl (Open vSwitch) 2.9.2 DB Schema 7.15.1 [[email protected] ~]#
Fase:4 Crea il bridge OVS e aggiungi le interfacce.
Usa il comando seguente per creare ovs bridge,
[[email protected] ~]# ovs-vsctl add-br ovs-br0
Ora svuota o rimuovi IP dall'interfaccia, nel mio caso IP assegnato a eno16777736
[[email protected] ~]# ip addr flush dev eno16777736
Ora assegna questo indirizzo IP a ovs bridge(ovs-br0)
[[email protected] ~]# ip addr add 192.168.1.4/24 dev ovs-br0
Aggiungi l'interfaccia come porta in ovs-br0 usando il comando seguente,
[[email protected] ~]# ovs-vsctl add-port ovs-br0 eno16777736
Ora apri il bridge usando il comando "ip link" sotto,
[[email protected] ~]# ip link set dev ovs-br0 up
Nota : Le modifiche sopra non sono persistenti, quindi rendi queste modifiche persistenti durante il riavvio, dobbiamo creare il file ovs bridge, i passaggi sono mostrati di seguito
[[email protected] ~]# cd /etc/sysconfig/network-scripts/ [[email protected] network-scripts]# cp ifcfg-eno16777736 ifcfg-ovs-br0 [[email protected] network-scripts]# [[email protected] network-scripts]# vi ifcfg-eno16777736 DEVICE=eno16777736 HWADDR="00:0c:29:c1:c3:4e" TYPE=OVSPort DEVICETYPE=ovs OVS_BRIDGE=ovs-br0 ONBOOT=yes
Salva ed esci dal file
[[email protected] network-scripts]# vi ifcfg-ovs-br0 DEVICE=ovs-br0 DEVICETYPE=ovs TYPE=OVSBridge BOOTPROTO=static IPADDR=192.168.1.4 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 ONBOOT=yes
Salva ed esci dal file
Riavvia il servizio di rete utilizzando il comando seguente,
[[email protected] network-scripts]# systemctl restart network
Ora verifica ovs bridge e le sue porte usando "ovs-vsctl comando ”
[[email protected] ~]# ovs-vsctl show 8dc5f8e7-0e54-4d9d-ba7a-cd6b9b94f470 Bridge "ovs-br0" Port "ovs-br0" Interface "ovs-br0" type: internal Port "eno16777736" Interface "eno16777736" ovs_version: "2.9.2" [[email protected] ~]#
Passaggio:5) Crea e definisci la rete virsh ovs
Crea un file di rete ovs con i seguenti contenuti ,
[[email protected] ~]# vi /tmp/ovs-network.xml <network> <name>ovs-network</name> <forward mode='bridge'/> <bridge name='ovs-br0'/> <virtualport type='openvswitch'/> </network>
Ora definisci la rete ovs usando il comando virsh sotto,
[[email protected] ~]# virsh net-define /tmp/ovs-network.xml Network ovs-network defined from /tmp/ovs-network.xml [[email protected] ~]# virsh net-start ovs-network Network ovs-network started [[email protected] ~]# virsh net-autostart ovs-network Network ovs-network marked as autostarted [[email protected] ~]#
Ora verifica la rete virsh usando il comando sotto,
[[email protected] ~]# virsh net-list Name State Autostart Persistent ---------------------------------------------------------- default active yes yes ovs-network active yes yes [[email protected] ~]#
Fase:6) Crea macchine virtuali e collega ovs-network
Creiamo due VM di prova usando il comando virt-install di seguito, specifichiamo la rete per queste VM come ovs-network,
[[email protected] ~]# virt-install -n testvm1 --description "Test VM1 for OVS " --os-type=Linux --os-variant=rhel7 --ram=1096 --vcpus=1 --disk path=/var/lib/libvirt/images/testvm1.img,bus=virtio,size=10 --network network:ovs-network --graphics none --location /root/CentOS-7-x86_64-DVD-1511.iso --extra-args console=ttyS0
Allo stesso modo crea una seconda macchina virtuale di prova con il nome "testvm2"
[[email protected] ~]# virt-install -n testvm2 --description "Test VM2 for OVS " --os-type=Linux --os-variant=rhel7 --ram=1096 --vcpus=1 --disk path=/var/lib/libvirt/images/testvm2.img,bus=virtio,size=10 --network network:ovs-network --graphics none --location /root/CentOS-7-x86_64-DVD-1511.iso --extra-args console=ttyS0
Una volta create le VM, le loro interfacce dovrebbero essere aggiunte automaticamente in ovs bridge (ov-br0) e possiamo verificarlo dal comando ovs-vsctl,
[[email protected] ~]# ovs-vsctl show 8dc5f8e7-0e54-4d9d-ba7a-cd6b9b94f470 Bridge "ovs-br0" Port "ovs-br0" Interface "ovs-br0" type: internal Port "eno16777736" Interface "eno16777736" Port "vnet0" Interface "vnet0" Port "vnet1" Interface "vnet1" ovs_version: "2.9.2" [[email protected] ~]# ovs-vsctl list-ports ovs-br0 eno16777736 vnet0 vnet1 [[email protected] ~]#
Nel comando precedente vnet0 e vnet1 sono l'interfaccia tap delle macchine virtuali. Quando spegniamo questi VMS, queste porte verranno rimosse automaticamente da OVS Bridge (ovs-br0). I file di registro per ovs (openvswitch) sono conservati nella cartella "/var/log/openvswitch “.
Con questo concludo questo articolo, spero che tu abbia un'idea su come installare e utilizzare Open vSwitch 2.9 con KVM sui server CentOS 7 e RHEL 7. Se ti piace l'articolo, condividi il tuo feedback e commenti.