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
相关推荐
the丶only9 分钟前
单点登录平台Casdoor搭建与使用,集成gitlab同步创建删除账号
linux·运维·服务器·docker·gitlab
书生-w11 分钟前
Docker部署GitLab服务器
服务器·docker·gitlab
Ling_suu21 分钟前
SpringBoot3——Web开发
java·服务器·前端
alden_ygq22 分钟前
etcd网关
服务器·数据库·etcd
ccubee38 分钟前
docker 安装 ftp
运维·docker·容器
枫叶红花1 小时前
【Linux系统编程】:信号(2)——信号的产生
linux·运维·服务器
yaosheng_VALVE1 小时前
探究全金属硬密封蝶阀的奥秘-耀圣控制
运维·eclipse·自动化·pyqt·1024程序员节
_微风轻起1 小时前
linux下网络编程socket&select&epoll的底层实现原理
linux·网络
dami_king1 小时前
SSH特性|组成|SSH是什么?
运维·ssh·1024程序员节
启明真纳1 小时前
elasticache备份
运维·elasticsearch·云原生·kubernetes