Linux - 弯路系列3:安装和编译libvirt-4.5.0及虚拟网卡virbr0(virbr0-nic)创建

系统:Anolis8(离线)

目录

1、安装及编译步骤

感谢提供步骤和错误解决参考: https://www.codeleading.com/article/1288836853/

  • tar -xvf libvirt-4.5.0.tar.xz 【安装包:https://download.libvirt.org/
  • cd libvirt-4.5.0
  • ./autogen.sh
  • make
  • make install
  • 完成后检查:
    -- 查看:virsh list --all
    -- 开启libvirt:libvirtd -d
    -- 查看是否启动:ps -le | grep libvirtd

2、make过程中的错误

错误1:error: 'xdr_u_int64_t' undeclared (first use in this function)

java 复制代码
  CCLD     libvirt_secret.la
  CC       remote/libvirt_driver_remote_la-remote_driver.lo
  CC       remote/libvirt_driver_remote_la-remote_protocol.lo
In file included from remote/remote_protocol.h:18,
                 from remote/remote_protocol.c:7:
remote/remote_protocol.c: In function 'xdr_remote_vcpu_info':
./util/virxdrdefs.h:28:24: warning: implicit declaration of function 'xdr_u_int64_t'; did you mean 'xdr_uint64_t'? [-Wimplicit-function-declaration]
 #  define xdr_uint64_t xdr_u_int64_t
                        ^~~~~~~~~~~~~
remote/remote_protocol.c:272:15: note: in expansion of macro 'xdr_uint64_t'
          if (!xdr_uint64_t (xdrs, &objp->cpu_time))
               ^~~~~~~~~~~~
./util/virxdrdefs.h:28:24: warning: nested extern declaration of 'xdr_u_int64_t' [-Wnested-externs]
 #  define xdr_uint64_t xdr_u_int64_t
                        ^~~~~~~~~~~~~
remote/remote_protocol.c:272:15: note: in expansion of macro 'xdr_uint64_t'
          if (!xdr_uint64_t (xdrs, &objp->cpu_time))
               ^~~~~~~~~~~~
remote/remote_protocol.c: In function 'xdr_remote_node_get_cells_free_memory_ret':
./util/virxdrdefs.h:28:24: error: 'xdr_u_int64_t' undeclared (first use in this function); did you mean 'xdr_uint64_t'?
 #  define xdr_uint64_t xdr_u_int64_t
                        ^~~~~~~~~~~~~
remote/remote_protocol.c:664:48: note: in expansion of macro 'xdr_uint64_t'
                 sizeof (uint64_t), (xdrproc_t) xdr_uint64_t))
                                                ^~~~~~~~~~~~
./util/virxdrdefs.h:28:24: note: each undeclared identifier is reported only once for each function it appears in
 #  define xdr_uint64_t xdr_u_int64_t
                        ^~~~~~~~~~~~~
remote/remote_protocol.c:664:48: note: in expansion of macro 'xdr_uint64_t'
                 sizeof (uint64_t), (xdrproc_t) xdr_uint64_t))
                                                ^~~~~~~~~~~~
remote/remote_protocol.c: In function 'xdr_remote_node_get_free_pages_ret':
./util/virxdrdefs.h:28:24: error: 'xdr_u_int64_t' undeclared (first use in this function); did you mean 'xdr_uint64_t'?
 #  define xdr_uint64_t xdr_u_int64_t
                        ^~~~~~~~~~~~~
remote/remote_protocol.c:6825:48: note: in expansion of macro 'xdr_uint64_t'
                 sizeof (uint64_t), (xdrproc_t) xdr_uint64_t))
                                                ^~~~~~~~~~~~
remote/remote_protocol.c: In function 'xdr_remote_node_alloc_pages_args':
./util/virxdrdefs.h:28:24: error: 'xdr_u_int64_t' undeclared (first use in this function); did you mean 'xdr_uint64_t'?
 #  define xdr_uint64_t xdr_u_int64_t
                        ^~~~~~~~~~~~~
remote/remote_protocol.c:6840:48: note: in expansion of macro 'xdr_uint64_t'
                 sizeof (uint64_t), (xdrproc_t) xdr_uint64_t))
                                                ^~~~~~~~~~~~
make[3]: *** [Makefile:10507: remote/libvirt_driver_remote_la-remote_protocol.lo] Error 1
make[3]: Leaving directory '/home/software/libvirt-3.2.0/libvirt-4.5.0/src'
make[2]: *** [Makefile:6429: all] Error 2
make[2]: Leaving directory '/home/software/libvirt-3.2.0/libvirt-4.5.0/src'
make[1]: *** [Makefile:2107: all-recursive] Error 1
make[1]: Leaving directory '/home/software/libvirt-3.2.0/libvirt-4.5.0'
make: *** [Makefile:2000: all] Error 2

解决:

解决来源:https://listman.redhat.com/archives/libvir-list/2013-May/077764.html

但是这个作者好像不是这一个原因

  • 在"./autogen.sh"后进行操作
  • grep -rn "XDR_CFLAGS =" * 为了查看包含XDR_CFLAGS定义的文件
  • 分别打开Makefilesrc/Makefile文件,找到其中的XDR_CFLAGS = 定义行,添加上-I/usr/include/tirpc
    即:XDR_CFLAGS = -I/usr/include/tirpc
  • 再进行make即可

注:因为我是一起加的,所以不确定是不是只用添加Makefilesrc/Makefile这两个文件其中之一即可,可自行尝试。

3、make install的错误

错误1:/usr/bin/mkdir -p ""/usr/local/etc/libvirt/nwfilter""

解决:

  • **grep -rn "NWFILTER_DIR" *** 【找到nwfilter文件的生成路径】
  • 删除2149、2722行多出来的引号

4、检查过程中的错误

参考:https://blog.csdn.net/yang39921/article/details/103296169

非常感谢分享!

5、手动创建virbr0(若未自动创建情况下)

ifconfigip a 后未看到有virbr0网卡

参考操作:

  1. CentOS7配置virbr0虚拟网卡详解:提升网络环境模拟效率
  2. kvm虚拟化网卡、virbr0、网段修改

(1)创建新的虚拟网络

  • 用一个xml文件定义default网络

virsh net-define /etc/libvirt/qemu/networks/default.xml

注:这两个参考步骤中default文件所处文件夹不同,我用的是1的路径。

若default.xml文件不存在,则先创建:
<network>
<name>default</name>
<bridge name="virbr0"/>
<forward/>
<ip address="192.168.122.1" netmask="255.255.255.0">
	<dhcp>
 		<range start="192.168.122.2" end="192.168.122.254"/>
	</dhcp>
</ip>
</network>

(2)设置virbr0自启

virsh net-start default

virsh net-autostart default

(3)检查配置

ip a

查看是否有virbr0了

(4)关于创建桥接网络接口virbr0-nic

使用 ip 命令验证桥是否存在:

  • ip link show type virbr0 (完成上述步骤,输入这步可得到下述内容)
java 复制代码
5: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
   link/ether 52:54:00:9a:8c:49 brd ff:ff:ff:ff:ff:ff

使用 ip 命令,查询以 virbr0 网桥为主的接口:

  • ip link show master virbr0 (若无输出,则手动添加
java 复制代码
6: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN mode DEFAULT group default qlen 1000
  link/ether 52:54:00:48:3f:0c brd ff:ff:ff:ff:ff:ff
  • 生成virbr0-nic,并将此接口添加到网桥virbr0

sudo ip tuntap add dev virbr0-nic mode tap        % 创建一个 TAP 接口

sudo ip link set dev virbr0-nic down            % 设置接口状态为 DOWN

sudo ip link set dev virbr0-nic address 52:54:00:9a:8c:49  % virbr0-nic 的 MAC 地址设置为与 virbr0 相同

sudo ip link set dev virbr0-nic master virbr0        % 将 virbr0-nic 接口添加到 virbr0 网桥

检查:
- ip link show virbr0-nic
- ip link show master virbr0
相关推荐
麻花201332 分钟前
WPF学习之路,控件的只读、是否可以、是否可见属性控制
服务器·前端·学习
一只哒布刘1 小时前
RHCE-DNS域名解析服务器
运维·服务器
醇氧1 小时前
ab (Apache Bench)的使用
linux·学习·centos·apache
千城丶Y1 小时前
GoogleCloud服务器的SSH连接配置
服务器·ssh·googlecloud
华纳云IDC服务商1 小时前
怎么选择香港服务器的线路?解决方案
服务器·网络·香港服务器
sss-web12262 小时前
4.远程访问及控制
运维·服务器
EasyCVR2 小时前
GA/T1400视图库平台EasyCVR视频融合平台HLS视频协议是什么?
服务器·网络·人工智能·音视频
moneyxjj2 小时前
Linux各种解压命令汇总
linux·运维·服务器
白白♛~2 小时前
网络管理之---3种网络模式配置
linux·服务器·网络
GOTXX2 小时前
NAT、代理服务与内网穿透技术全解析
linux·网络·人工智能·计算机网络·智能路由器