Centos7.9 qemu-6.2.0 编译安装

Centos7.9 qemu-6.2.0 编译安装

操作系统版本

CentOS Linux release 7.9.2009 (Core) 3.10.0-1160.el7.x86_64

操作系统已安装KVM
yum安装kvm qemu版本:qemu-img version 1.5.3

已尝试在CentOS7.9编译安装:qemu-8.1.0.tar.xzqemu-7.2.5.tar.xz 失败

qemu依赖版本要求

nettle >=3.4
Python >= 3.7
GCC >= v7.4
gnutls >=3.5.18
Ninja

在安装gnutls前,必须先安装nettle。
gnutls-3.8.1对应需要先安装nettle-3.6此版本

安装qemu相关依赖

yum安装依赖

yum -y install flex bison gcc gcc-c++ automake libtool zlib-devel glib2-devel bzip2-devel libuuid-devel spice-protocol spice-server-devel ncurses-devel usbredir-devel libaio-devel libseccomp-devel numactl-devel libcap-devel libiscsi-devel libnfs-devel SDL-devel libcap-ng-devel pixman pixman-devel libunistring-devel

安装nettle-3.6

卸载已安装nettle
yum remove nettle*

必须在升级gcc版本前,安装nettle-3.6

wget https://ftp.gnu.org/gnu/nettle/nettle-3.6.tar.gz
tar -zxvf nettle-3.6.tar.gz
cd nettle-3.6
./configure \
--prefix=/usr/local/nettle \
--disable-openssl \
--enable-shared \
--enable-mini-gmp

make
make install

# 定义库位置
echo /usr/local/nettle/lib64 > /etc/ld.so.conf.d/nettle.conf
ldconfig

export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/nettle/lib64/pkgconfig"
pkg-config --modversion nettle

# 显示如下信息,表示安装成功
3.6

安装gnutls-3.8.1

wget https://www.gnupg.org/ftp/gcrypt/gnutls/v3.8/gnutls-3.8.1.tar.xz
tar -xvJf gnutls-3.8.1.tar.xz
cd gnutls-3.8.1
./configure \
--prefix=/usr/local/gnutls \
--with-nettle-mini \
--without-p11-kit

make
make install

# 定义库位置
echo /usr/local/gnutls/lib > /etc/ld.so.conf.d/gnutls.conf
ldconfig

export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/gnutls/lib/pkgconfig"
pkg-config --modversion gnutls

# 显示如下信息,表示安装成功
3.8.1

安装过程中,如果出现错误提示安装对应的依赖包
configure: error:
Libunistring was not found. To use the included one, use --with-included-unistring
yum -y install libunistring-devel

安装 Python-3.9.0

yum安装Python依赖包
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel

下载Python3.9.0
Python下载地址
https://www.python.org/ftp/python/

wget http://npm.taobao.org/mirrors/python/3.9.0/Python-3.9.0.tgz
tar -zxvf Python-3.9.0.tgz
cd Python-3.9.0
./configure --prefix=/usr/local/python3
make && make install

rm -rf /usr/bin/python
rm -rf /usr/bin/pip
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

yum必须使用python2,需要修改yum配置
vim /usr/bin/yum
把 #! /usr/bin/python 修改为 #! /usr/bin/python2
vim /usr/libexec/urlgrabber-ext-down
把 #! /usr/bin/python 修改为 #! /usr/bin/python2
vim /usr/bin/yum-config-manager
#!/usr/bin/python 改为 #!/usr/bin/python2

安装Ninja

yum -y install re2c git

git clone git://github.com/ninja-build/ninja.git
cd ninja
./configure.py --bootstrap
cp ninja /usr/bin/
ninja --version

升级gcc

配置gcc yum源

cat > /etc/yum.repos.d/CentOS-SCLo-scl.repo << 'EOF'
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=http://mirror.centos.org/centos/7/sclo/$basearch/rh/
#mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-sclo
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
EOF

yum 安装gcc,并创建软连接

yum -y install devtoolset-11-gcc*
mv /usr/bin/gcc /usr/bin/gcc-4.8.5
mv /usr/bin/g++ /usr/bin/g++-4.8.5
ln -s /opt/rh/devtoolset-11/root/bin/gcc /usr/bin/gcc
ln -s /opt/rh/devtoolset-11/root/bin/g++ /usr/bin/g++

查看gcc版本

gcc --versio
g++ --version

#显示如下信息,表示安装成功
gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

编译安装qemu

qemu下载地址

https://www.qemu.org/download/#source

wget https://download.qemu.org/qemu-6.2.0.tar.xz

编译安装qemu

为了加快编译速度,架构只选择了x86_64-softmmu,i386-softmmu

#  如果不是同一个终端会话,需要先执行
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/nettle/lib64/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/gnutls/lib/pkgconfig"
tar -xvJf qemu-6.2.0.tar.xz
cd qemu-6.2.0
./configure \
--prefix=/usr/local/qemu \
--enable-kvm \
--enable-vnc \
--enable-modules \
--enable-virtfs \
--enable-libiscsi \
--enable-libnfs \
--enable-usb-redir \
--enable-libusb \
--enable-spice \
--enable-uuid \
--enable-bzip2 \
--enable-linux-aio \
--enable-system \
--enable-seccomp \
--enable-numa \
--enable-nettle \
--enable-gnutls \
--target-list="x86_64-softmmu,i386-softmmu"

#输出如下信息
qemu 6.2.0

  Directories
    Install prefix               : /usr/local/qemu
    BIOS directory               : share/qemu
    firmware path                : /usr/local/qemu/share/qemu-firmware
    binary directory             : bin
    library directory            : lib
    module directory             : lib/qemu
    libexec directory            : libexec
    include directory            : include
    config directory             : /usr/local/qemu/etc
    local state directory        : /usr/local/qemu/var
    Manual directory             : share/man
    Doc directory                : /usr/local/qemu/share/doc
    Build directory              : /root/qemu-6.2.0/build
    Source path                  : /root/qemu-6.2.0
    GIT submodules               : ui/keycodemapdb tests/fp/berkeley-testfloat-3 tests/fp/berkeley-softfloat-3 dtc capstone slirp

  Host binaries
    git                          : git
    make                         : make
    python                       : /usr/bin/python3 (version: 3.6)
    sphinx-build                 : NO
    genisoimage                  : /usr/bin/genisoimage
    smbd                         : "/usr/sbin/smbd"

  Configurable features
    Documentation                : NO
    system-mode emulation        : YES
    user-mode emulation          : NO
    block layer                  : YES
    Install blobs                : YES
    module support               : YES
    alternative module path      : NO
    fuzzing support              : NO
    Audio drivers                : oss
    Trace backends               : log
    QOM debugging                : YES
    vhost-kernel support         : YES
    vhost-net support            : YES
    vhost-crypto support         : YES
    vhost-scsi support           : YES
    vhost-vsock support          : YES
    vhost-user support           : YES
    vhost-user-blk server support: YES
    vhost-user-fs support        : YES
    vhost-vdpa support           : YES
    build guest agent            : YES

  Compilation
    host CPU                     : x86_64
    host endianness              : little
    C compiler                   : cc -m64 -mcx16
    Host C compiler              : cc -m64 -mcx16
    C++ compiler                 : NO
    CFLAGS                       : -O2 -g
    QEMU_CFLAGS                  : -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong
    QEMU_LDFLAGS                 : -Wl,--warn-common -Wl,-z,relro -Wl,-z,now  -fstack-protector-strong
    profiler                     : NO
    link-time optimization (LTO) : NO
    PIE                          : YES
    static build                 : NO
    malloc trim support          : YES
    membarrier                   : NO
    debug stack usage            : NO
    mutex debugging              : NO
    memory allocator             : system
    avx2 optimization            : YES
    avx512f optimization         : NO
    gprof enabled                : NO
    gcov                         : NO
    thread sanitizer             : NO
    CFI support                  : NO
    strip binaries               : YES
    sparse                       : NO
    mingw32 support              : NO
    x86_64 tests                 : cc

  Targets and accelerators
    KVM support                  : YES
    HAX support                  : NO
    HVF support                  : NO
    WHPX support                 : NO
    NVMM support                 : NO
    Xen support                  : NO
    TCG support                  : YES
    TCG backend                  : native (x86_64)
    TCG plugins                  : YES
    TCG debug enabled            : NO
    target list                  : x86_64-softmmu i386-softmmu
    default devices              : YES
    out of process emulation     : YES

  Block layer support
    coroutine backend            : ucontext
    coroutine pool               : YES
    Block whitelist (rw)         : 
    Block whitelist (ro)         : 
    Use block whitelist in tools : NO
    VirtFS support               : YES
    build virtiofs daemon        : YES
    Live block migration         : YES
    replication support          : YES
    bochs support                : YES
    cloop support                : YES
    dmg support                  : YES
    qcow v1 support              : YES
    vdi support                  : YES
    vvfat support                : YES
    qed support                  : YES
    parallels support            : YES
    FUSE exports                 : NO

  Crypto
    TLS priority                 : "NORMAL"
    GNUTLS support               : YES 3.8.1
      GNUTLS crypto              : NO
    libgcrypt                    : NO
    nettle                       : YES 3.6
      XTS                        : YES
    crypto afalg                 : NO
    rng-none                     : NO
    Linux keyring                : YES

  Dependencies
    SDL support                  : NO
    SDL image support            : NO
    GTK support                  : NO
    pixman                       : YES 0.34.0
    VTE support                  : NO
    slirp support                : internal
    libtasn1                     : YES 4.10
    PAM                          : NO
    iconv support                : YES
    curses support               : YES
    virgl support                : NO
    curl support                 : NO
    Multipath support            : NO
    VNC support                  : YES
    VNC SASL support             : NO
    VNC JPEG support             : NO
    VNC PNG support              : YES 1.5.13
    OSS support                  : YES
    ALSA support                 : YES 1.1.8
    PulseAudio support           : NO
    JACK support                 : NO
    brlapi support               : NO
    vde support                  : NO
    netmap support               : NO
    v3 support               : YES
    Linux AIO support            : YES
    Linux io_uring support       : NO
    ATTR/XATTR support           : YES
    RDMA support                 : NO
    PVRDMA support               : NO
    fdt support                  : internal
    libcap-ng support            : YES
    bpf support                  : NO
    spice protocol support       : YES 0.12.14
      spice server support       : YES 0.14.0
    rbd support                  : NO
    xfsctl support               : NO
    smartcard support            : YES 2.7.0
    U2F support                  : NO
    libusb                       : YES 1.0.21
    usb net redir                : YES 0.7.1
    OpenGL support               : NO
    GBM                          : NO
    libiscsi support             : YES 1.9.0
    libnfs support               : YES 1.11.0
    seccomp support              : YES 2.3.1
    GlusterFS support            : NO
    TPM support                  : YES
    libssh support               : NO
    lzo support                  : NO
    snappy support               : NO
    bzip2 support                : YES
    lzfse support                : NO
    zstd support                 : NO
    NUMA host support            : YES
    libxml2                      : NO
    capstone                     : internal
    libpmem support              : NO
    libdaxctl support            : NO
    libudev                      : NO
    FUSE lseek                   : NO
    selinux                      : YES 2.5

  Subprojects
    libvhost-user                : YES

Found ninja-1.10.2 at /usr/bin/ninja

如果执行./configure 后出错,根据提示yum安装对应的依赖包,再次执行,可根据输出的信息启用对应的模块。

# 执行编译时间比较久
make
make install

配置软连接

在配置软连接前,必须先确定以下事项:
1.关闭所有虚拟机运行
ps -ef |grep qemu

2.停止libvirtd服务
systemctl stop libvirtd

# 备份现使用qemu
mv /usr/libexec/qemu-kvm /usr/libexec/qemu-kvm.bak
mv /usr/bin/qemu-kvm /usr/bin/qemu-kvm.bak
mv /usr/bin/qemu-img /usr/bin/qemu-img.bak
mv /usr/bin/qemu-system-x86_64 /usr/bin/qemu-system-x86_64.bak

#配置软连接
ln -s /usr/local/qemu/bin/qemu-system-x86_64 /usr/libexec/qemu-kvm
ln -s /usr/local/qemu/bin/qemu-system-x86_64 /usr/bin/qemu-kvm
ln -s /usr/local/qemu/bin/qemu-system-x86_64 /usr/bin/qemu-system-x86_64 
ln -s /usr/local/qemu/bin/qemu-img /usr/bin/qemu-img

查看qemu版本

qemu-img --version
qemu-kvm --version
# 显示如下信息,表示安装成功
QEMU emulator version 6.2.0
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers

启动libvirtd服务

systemctl start libvirtd

测试启动虚拟机

你可能感兴趣的:(虚拟化,虚拟化,kvm,qemu)