KVM libvirt環境搭建

2021-09-25 09:58:18 字數 2580 閱讀 2571

virbr0是kvm預設建立的乙個bridge,其作用是為連線其上的虛機網絡卡提供nat訪問外網的功能。

流操作命令

檢視交換機switch上的流表(print all flow entries)

sudo ovs-ofctl dump-flows switch

新增流表(add flow described by flow)

sudo ovs-ofctl add-flow switch flow

顯示埠及對應埠號(show openflow information)

sudo ovs-ofctl show switch

刪除匹配的流表(delete matching flows)

sudo ovs-ofctl del-flows switch [flow]

拓撲:乙個網橋br-int連線兩個虛機vm1和vm2

兩個虛機的ip處於相同網段時,ovs流表配置如下:

vm1的ip: 10.0.0.10,vm2的ip: 10.0.0.11

sudo ovs-ofctl add-flow br-int "ip,nw_dst=10.0.0.10 actions=output:1"

sudo ovs-ofctl add-flow br-int "ip,nw_dst=10.0.0.11 actions=output:2"

sudo ovs-ofctl add-flow br-int "arp,arp_tpa=10.0.0.10 actions=output:1"

sudo ovs-ofctl add-flow br-int "arp,arp_tpa=10.0.0.11 actions=output:2"

兩個虛機的ip處於不同網段時,ovs流表配置如下:

vm1的ip: 10.0.0.10,閘道器: 10.0.0.1

vm2的ip: 10.0.10.11,閘道器: 10.0.10.1

sudo ovs-ofctl add-flow br-int "in_port=1,arp,arp_tpa=10.0.0.1,arp_op=1 actions=load:0x2->nxm_of_arp_op,move:nxm_nx_arp_sha->nxm_nx_arp_tha,load:0x5254008b9cb2->nxm_nx_arp_sha,move:nxm_of_arp_spa->nxm_of_arp_tpa,load:0x0a000001->nxm_of_arp_spa,in_port"

sudo ovs-ofctl add-flow br-int "in_port=2,arp,arp_tpa=10.0.10.1,arp_op=1 actions=load:0x2->nxm_of_arp_op,move:nxm_nx_arp_sha->nxm_nx_arp_tha,load:0x5254004aadc2->nxm_nx_arp_sha,move:nxm_of_arp_spa->nxm_of_arp_tpa,load:0x0a000a01->nxm_of_arp_spa,in_port"

(****** operation): sudo ovs-ofctl add-flow br-int "icmp,icmp_type=8,icmp_code=0 actions=push:nxm_of_eth_src,push:nxm_of_eth_dst,pop:nxm_of_eth_src,pop:nxm_of_eth_dst,push:nxm_of_ip_src,push:nxm_of_ip_dst,pop:nxm_of_ip_src,pop:nxm_of_ip_dst,load:0xff->nxm_nx_ip_ttl,load:0x0->nxm_of_icmp_type,in_port"

sudo ovs-ofctl add-flow br-int "in_port=1,icmp actions=push:nxm_of_eth_dst,pop:nxm_of_eth_src,mod_dl_dst:52:54:00:8b:9c:b2,output:2"

sudo ovs-ofctl add-flow br-int "in_port=2,icmp actions=push:nxm_of_eth_dst,pop:nxm_of_eth_src,mod_dl_dst:52:54:00:4a:ad:c2,output:1"

sudo ovs-ofctl dump-flows br-int

sudo ovs-ofctl del-flows br-int icmp

常用virsh指令

1)virsh list 列出當前虛擬機器列表,不包括未啟動的

2)virsh list --all 列出所有虛擬機器,包括所有已經定義的虛擬機器

3)virsh destroy vm-name 關閉虛擬機器

4)virsh start vm-name 啟動虛擬機器

5)virsh edit vm-name 編輯虛擬機器xml檔案

6)virsh undefine vm-name 刪除虛擬機器

7)virsh shutdown vm-name 停止虛擬機器

8)virsh reboot vm-name 重啟虛擬機器

9)virsh autostart vm-name 虛擬機器隨宿主機啟動

10)virsh console vm-name 登入虛擬機器

檢視arp快取

arp -a

arp -n

LAMP環境搭建 php環境搭建

yum groupinstall development tools y yum groupinstall desktop platform development y yum install cmake pcre devel ncurses devel openssl devel libcurl ...

環境搭建 二 Python環境搭建

工欲善其事,必先利其器 要想玩轉python,我們首先需要搭建一套可使用且方便的環境。對於初學者,笨飯糰建議使用 anaconda anaconda 簡介anaconda是python的乙個科學計算發行版,內建了數百個python經常會使用的庫,包括做機器學習或資料探勘的庫。anaconda提供了乙...

環境 lamp環境搭建

以下命令全部使用root執行,如果不用root記得sudo apt update 更新一下可用軟體包列表 apt upgrade 更新已安裝的軟體包 apt install apache2 安裝apache2 systemctl start apache2 啟動apache apt install ...