文書の過去の版を表示しています。
複数のQEMU/KVMホストにまたがる仮想ネットワークをVXLANで構築
構成
libvirtが作成するデフォルト仮想ネットワークのブリッジvirbr0
はlibvirtが管理しているため、
それとは別に手動でブリッジを作成しブリッジ接続の仮想ネットワークを作成する。
ブリッジ接続の仮想ネットワークではNATやDHCPサーバが自動的に構成されないので手動で追加する。
ホストはCentOS 7.9で172.31.0.110(eth0)と172.31.0.120(eth0)の2台。
rhel8系はpolicycoreutils-python
のパッケージ名がpolicycoreutils-python-utils
に変更。
ブリッジbr0を作成し192.168.124.1と192.168.124.2を割り当て、VXLANで接続。 Open vSwitchではなくLinux標準のbridgeを使用する。
DHCP/DNSサーバのdnsmasqを192.168.124.1で実行。 192.168.124.1と192.168.124.2で外部にNAT接続。 NATはfirewalldのexternalゾーンとinternalゾーンで実現。 DHCPが公告するデフォルトゲートウェイは192.168.124.1。
参考:
Host#1 172.31.0.110
libvirtがインストールされているならip_forwardの設定は不要なはず。
echo "net.ipv4.ip_forward = 1" > /etc/sysctl.d/ip_forward echo 1 > /proc/sys/net/ipv4/ip_forward
まずはexternal
ゾーンにpublic
ゾーンと同等の設定とVXLANを許可してから
eth0のゾーンをexternal
移す。
internal
ゾーンはDHCPとDNSを許可。
firewall-cmd --get-active-zones firewall-cmd --info-zone=public firewall-cmd --info-zone=external firewall-cmd --zone=external --add-service=dhcpv6-client firewall-cmd --zone=external --add-port 8472/udp firewall-cmd --zone=external --change-interface=eth0 firewall-cmd --zone=internal --add-service dhcp firewall-cmd --zone=internal --add-service dns firewall-cmd --info-zone=public firewall-cmd --info-zone=external firewall-cmd --info-zone=internal firewall-cmd --runtime-to-permanent
internal
ゾーンにブリッジbr0と172.31.0.120とのVXLAN接続を作成。
nmcli connection add type bridge con-name br0 ifname br0 ipv4.method static ip4 192.168.124.1/24 ipv6.method link-local connection.zone internal nmcli connection add type vxlan slave-type bridge con-name br0-vxlan10 ifname vxlan10 id 10 local 172.31.0.110 remote 172.31.0.120 master br0 connection.zone internal
ここまでの設定状態確認。bridge
コマンドはiproute
パッケージが必要。
nmcli con nmcli dev status bridge fdb show dev vxlan10
br0
でdnsmasqを起動。
yum install dnsmasq policycoreutils-python semanage fcontext --add -t dnsmasq_lease_t '/var/lib/dnsmasq-br0/dhcp\.leasefile' semanage fcontext --add -t dnsmasq_etc_t '/var/lib/dnsmasq-br0(/.*)?' mkdir /var/lib/dnsmasq-br0 cat <<EOF > /var/lib/dnsmasq-br0/dnsmasq.conf strict-order pid-file=/var/run/dnsmasq-br0.pid except-interface=lo bind-dynamic interface=br0 dhcp-range=192.168.124.16,192.168.124.254 dhcp-no-override dhcp-authoritative dhcp-lease-max=253 dhcp-leasefile=/var/lib/dnsmasq-br0/dhcp.leasefile dhcp-hostsfile=/var/lib/dnsmasq-br0/dhcp.hostsfile dhcp-optsfile=/var/lib/dnsmasq-br0/dhcp.optsfile addn-hosts=/var/lib/dnsmasq-br0/addn.hosts EOF touch /var/lib/dnsmasq-br0/dhcp.leasefile touch /var/lib/dnsmasq-br0/dhcp.hostsfile touch /var/lib/dnsmasq-br0/addn.hosts touch /var/lib/dnsmasq-br0/dhcp.optsfile restorecon -r /var/lib/dnsmasq-br0 cat <<EOF > /etc/systemd/system/dnsmasq-br0.service [Unit] Description=DNS caching server for br0. After=network.target [Service] ExecStart=/usr/sbin/dnsmasq -k --conf-file=/var/lib/dnsmasq-br0/dnsmasq.conf [Install] WantedBy=multi-user.target EOF systemctl enable dnsmasq-br0 --now systemctl status dnsmasq-br0
br0
を使用する仮想ネットワークnorth
を作成。
cat <<EOF > /tmp/network-north.xml <network> <name>north</name> <forward mode='bridge' /> <bridge name="br0" /> </network> EOF virsh net-define /tmp/network-north.xml virsh net-dumpxml north virsh net-info north virsh net-start north virsh net-autostart north
Host#2 172.31.0.120
libvirtがインストールされているならip_forwardの設定は不要なはず。
echo "net.ipv4.ip_forward = 1" > /etc/sysctl.d/ip_forward echo 1 > /proc/sys/net/ipv4/ip_forward
まずはexternal
ゾーンにpublic
ゾーンと同等の設定とVXLANを許可してから
eth0のゾーンをexternal
移す。
こちらではdnsmasqを動かさないのでinternal
ゾーンはそのまま。
firewall-cmd --get-active-zones firewall-cmd --info-zone=public firewall-cmd --info-zone=external firewall-cmd --zone=external --add-service=dhcpv6-client firewall-cmd --zone=external --add-port 8472/udp firewall-cmd --zone=external --change-interface=eth0 firewall-cmd --info-zone=public firewall-cmd --info-zone=external firewall-cmd --info-zone=internal firewall-cmd --runtime-to-permanent
internal
ゾーンにブリッジbr0と172.31.0.110とのVXLAN接続を作成。
nmcli connection add type bridge con-name br0 ifname br0 ipv4.method static ip4 192.168.124.2/24 ipv6.method link-local connection.zone internal nmcli connection add type vxlan slave-type bridge con-name br0-vxlan10 ifname vxlan10 id 10 local 172.31.0.120 remote 172.31.0.110 master br0 connection.zone internal
ここまでの設定状態確認。
nmcli con nmcli dev status bridge fdb show dev vxlan10
br0
を使用する仮想ネットワークvxlan
を作成。
cat <<EOF > /tmp/network-vxlan.xml <network> <name>vxlan</name> <forward mode='bridge' /> <bridge name="br0" /> </network> EOF virsh net-define /tmp/network-vxlan.xml virsh net-dumpxml vxlan virsh net-info vxlan virsh net-start vxlan virsh net-autostart vxlan
ゲストOSのインストール
–network network=vxlan
で接続するネットワークを指定してインストールする。
virt-install --name centos7 --memory 2048 --vcpus 1 --disk size=8 --network network=vxlan --os-variant centos7.0 --location /var/lib/libvirt/images/CentOS-7-x86_64-Minimal-2009.iso --nographics --extra-args='console=tty0 console=ttyS0,115200n8'
DHCPを使用しない場合:
nmcli prop name | value |
---|---|
ip4 | 192.168.124.3-192.168.124.15 |
gw4 | 192.168.124.1 または 192.168.124.2 |
ipv4.dns | 192.168.124.1 |