A tutorial on compiling, installing, and configuring Libvirt under KVM

Source: Internet
Author: User
Tags mkdir systemtap git clone


6.1.2 Libvirt compilation, installation, and configuration

1. Compiling and installing from source Libvirt

If only ordinary users use Libvirt, Generally do not need to compile libvirt from the source code, just install the corresponding Linux system on the Libvirt software package. Some advanced users or developers may want to learn more about libvirt, or even modify Libvirt source code to achieve their own functions, it is still necessary to understand the compilation and installation of Libvirt from the source process.

For an example of compiling Libvirt 1.0.0 on a Rhel 6.3 system, describe the Libvirt compilation and installation process.

(1) before you actually start compiling, you need to check and clean up the Libvirt installed on your system (if you've ever installed them) , and the command-line actions are as follows:


  code is as follows
 [root@jay-linux kvm_demo]# which LIBVIRTD
/USR/SBIN/LIBVIRTD
[Root@jay-linux kvm_demo]# rpm-q Libvirt
libvirt-0.9.10-21.el6.x86_64
[root@jay-linux kvm_demo]# rpm-e libvirt
[Root@jay-linux kvm_demo]# Libvirtd–version
-bash:/usr/sbin/libvirtd:no such file or directory




(2) Download Libvirt source code

You can choose to obtain its Libvirt source code installation package from the source code ISO of the Linux system release. You can also choose to download the Libvirt source tar.gz package from the Libvirt official website, or you can clone the development Libvirt source repository to local by using the Git tool. The Web page of the

Libvirt officially released source code is: http://libvirt.org/sources/. The Web page provides the most original libvirt versions of the source code tar.gz compression package, as well as the compiled Libvirt-devel, Libvirt-python, Libvirt-java, libvirt-php and other RPM package downloads. Libvirt official also provides FTP download source code site: ftp://libvirt.org/libvirt/. The command line to download the libvirt-1.0.0.tar.gz source Pack and unzip it is as follows:


  code is as follows
[root@jay-linux kvm_demo]# wget http://libvirt.org/sources/libvirt-1.0.0.tar.gz

–2012-11-25 22:58:24–   http://libvirt.org/sources/libvirt-1.0.0.tar.gz

HTTP request sent, awaiting response ... OK

length:21868950 (21M) [Application/x-gzip]

Saving to: "libvirt-1.0.0.tar.gz"

 

100%[=======================>] 21,868,950  67.6k/s   in 2m 29s

 

2012-11-2 5 23:00:54 (143 kb/s) – "Libvirt-1.0.0.tar.gz saved [21868950/21868950]

[root@jay-linux kvm_demo]# tar-zxf LIBV irt-1.0.0.tar.gz

The address of the



libvirt The latest GIT code warehouse in development is: Git://libvirt.org/libvirt.git. You can also browse the code warehouses in the development of Libvirt.git and Libvirt-java.git and libvirt-php.git through Web pages http://libvirt.org/git/. In addition, Libvirt Python-bound code is stored in the Libvirt source repository (libvirt.git), and there is no separate Libvirt-python code warehouse. The command line to download the Libvirt development Code warehouse is as follows:


The
  code is as follows
[root@jay-linux kvm_demo]# git clone git://libvirt.org/libvirt.git

Initialized empty Git repository in/root/kvm_demo/libvirt/.git/

remote:counting objects:96578, done.

remote:compressing objects:100% (15214/15214), done.

Receiving objects:  52% (50926/96578), 51.28 MiB | kib/s

Receiving objects:  52% (50927/96 578), 51.31 MiB | KIB/S

Remote:total 96578 (Delta 80940), reused 96578 (Delta 80940)

receiving objects:100% (96578/96 578), 91.22 MiB | KIB/S, done.

Resolving deltas:100% (80940/80940), done.




(3) Configure and compile Libvirt

The way to configure and compile Libvirt is similar to most open source projects on Linux, by running the Configure script to build the environment configuration and then compiling with the make command to install with the make install command.

See what configuration options are available for the command "./configure–help", which has the following command line operation:


The code is as follows
[Root@jay-linux kvm_demo]# CD libvirt-1.0.0

[Root@jay-linux libvirt-1.0.0]#./configure–help


' Configure ' configures Libvirt 1.0.0 to adapt to many kinds of systems.

Usage:./configure [OPTION] ... [Var=value] ...

To assign environment variables (e.g., CC, cflags ...), specify them as

Var=value. Below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:


-h,–help Display this Help and exit

–help=short display options specific to this package

–help=recursive display the short help of the included packages

-v,–version display version information and exit

-q,–quiet,–silent do not print ' checking ... ' messages

–cache-file=file cache test results in file [disabled]

-c,–config-cache alias for ' –cache-file=config.cache '

-n,–no-create do not create output files

–srcdir=dir Find the sources in dir [Configure Dir or ' ... ']

Installation directories:

–prefix=prefix install architecture-independent files in prefix

[/usr/local]

–exec-prefix=eprefix install architecture-dependent files in Eprefix



[PREFIX]


By default, ' make install ' would install all the files in

'/usr/local/bin ', '/usr/local/lib ' etc. You can specify

An installation prefix the other than '/usr/local ' using ' –prefix ',

For instance ' –prefix= $HOME '.




<!– the hundreds of-line help option information for the configuration Libvirt is omitted here –>

Depending on the configuration help above, if you do not specify a custom installation path without the "–prefix=prefix" parameter, the Libvirt-related files will be installed in directories such as/usr/local/bin and/usr/local/lib by default.

The command for configuring the Libvirt compilation Environment is "./configure", and the command line operation is as follows:


The code is as follows

Checking for a bsd-compatible install .../usr/bin/install-c[root@jay-linux libvirt-1.0.0]# ./configure

checking for a BSD-compatible install… /usr/bin/install -c

checking whether build environment is sane… yes

checking for a thread-safe mkdir -p… /bin/mkdir -p

checking for gawk… gawk

checking whether make sets $(MAKE)… yes

checking how to create a ustar tar archive… gnutar

<!– Here omit hundreds of lines of output information during the configuration process –>

configure: Readline: yes

configure: Python: yes

configure: DTrace: no

configure: numad: no

configure: XML Catalog: /etc/xml/catalog

configure: Init script: redhat

configure: Console locks: /var/lock

configure:

configure: Privileges

configure:

configure: QEMU: root:root

configure:




During the configuration process, you may be configured to fail because of a lack of software packages that you need to rely on at compile time, just follow the prompts to install the corresponding package, and then rerun the "./configure" Command configuration. By default, Libvirt configures QEMU/KVM, VMware Driver Support (if a dependent library program is found), LIBVIRTD and Virsh are configured, and Libvirt binds to Python is configured by default. For Xen, Hyper-V, and so on support, the configuration program will automatically check whether the current system contains these hypervisor related programs, if the detection is successful, it will compile the corresponding driver.

The command that really compiles libvirt is "make" and the command line operates as follows:


The code is as follows
[root@jay-linux libvirt-1.0.0]# make-j 4

make  all-recursive

Make[1]: Entering directory '/root/kvm_demo/libvirt- 1.0.0′

Making all in Gnulib/lib

Make[2]: Entering directory '/root/kvm_demo/libvirt-1.0.0/gnulib/lib ' br>
gen    alloca.h

gen    c++defs.h

gen    Warn-on-use.h

<!– This omits the hundreds of-line output information from the compilation process –>

making all in Examples/systemtap

Make[2]: Entering Directory '/root/kvm_demo/libvirt-1.0.0/examples/systemtap '

Make[2]: Nothing to is done as ' all '.

Make[2]: Leaving directory '/root/kvm_demo/libvirt-1.0.0/examples/systemtap '

Make[2]: Entering directory '/root/kvm_demo/libvirt-1.0.0′

Make[2]: Leaving directory '/root/kvm_demo/libvirt-1.0.0′

Make[1]: Leaving directory '/root/kvm_demo/libvirt-1.0.0′




(4) Installation Libvirt

Superuser (root) permissions are not required for configuration and compilation, but root user permissions are generally required when installing Libvirt. Execute the Make install command to complete the Libvirt installation, with the following command line operation:


The code is as follows
[root@jay-linux libvirt-1.0.0]# make install

making install in Gnulib/lib

Make[1]: Entering directory '/root/kvm_demo/li Bvirt-1.0.0/gnulib/lib '

make  install-am

Make[2]: Entering directory '/root/kvm_demo/ Libvirt-1.0.0/gnulib/lib '

Make[3]: Entering directory '/root/kvm_demo/libvirt-1.0.0/gnulib/lib '

If Test yes = no; Then

case ' Linux-gnu ' in

darwin[56]*)

Need_charset_alias=true;;

<!– The hundreds of-line output information from the installation process is omitted –>

Make[2]: Entering directory '/root/kvm_demo/libvirt-1.0.0′

Mak E[2]: Nothing is done for ' install-exec-am '.

/bin/mkdir-p '/usr/local/lib/pkgconfig '

/usr/bin/install-c-M 644 libvirt.pc '/usr/local/lib/pkgconf IG '

Make[2]: Leaving directory '/root/kvm_demo/libvirt-1.0.0′

Make[1]: Leaving directory '/root/kvm_ demo/libvirt-1.0.0′




(5) Check the installed Libvirt

Libvirt installation will be installed on the system LIBVIRTD, Virsh, and other executable programs, will also install the Libvirt API library, will also install the binding to Python, check these installed files, command line operation as follows:


The code is as follows
[root@jay-linux libvirt-1.0.0]# which libvirtd

/usr/local/sbin/libvirtd

[root@jay-linux libvirt-1.0.0]# libvirtd –version

libvirtd (libvirt) 1.0.0

[root@jay-linux libvirt-1.0.0]# which virsh

/usr/local/bin/virsh

[root@jay-linux libvirt-1.0.0]# virsh –version

1.0.0

 

[root@jay-linux libvirt-1.0.0]# ls /usr/local/include/libvirt/

libvirt.h  libvirt-qemu.h  virterror.h

 

[root@jay-linux libvirt-1.0.0]# ls /usr/local/lib/libvirt*

/usr/local/lib/libvirt.a        /usr/local/lib/libvirt-qemu.so           /usr/local/lib/libvirt.so.0

/usr/local/lib/libvirt.la       /usr/local/lib/libvirt-qemu.so.0         /usr/local/lib/libvirt.so.0.1000.0

/usr/local/lib/libvirt-qemu.a   /usr/local/lib/libvirt-qemu.so.0.1000.0

/usr/local/lib/libvirt-qemu.la  /usr/local/lib/libvirt.so

 

/usr/local/lib/libvirt:

connection-driver

 

[root@jay-linux libvirt-1.0.0]# ls /usr/local/lib64/python2.6/site-packages/*virt*

/usr/local/lib64/python2.6/site-packages/libvirtmod.la       /usr/local/lib64/python2.6/site-packages/libvirtmod.so

/usr/local/lib64/python2.6/site-packages/libvirtmod_qemu.la  /usr/local/lib64/python2.6/site-packages/libvirt.py

/usr/local/lib64/python2.6/site-packages/libvirtmod_qemu.so  /usr/local/lib64/python2.6/site-packages/libvirt_qemu.py




If you use libvirt these libraries immediately after installation and you encounter an error message that you cannot find a corresponding library file, you may need to run tools such as Ldconfig to update the shared library that you just installed.

(6) compiling libvirt from Libvirt git code warehouse

Compiling and installing Libvirt from the GIT source code warehouse is exactly the same as compiling the installation from the Libvirt source tar.gz package. Here are only some of the differences in the pre-compilation configuration (Configure). When using the Libvirt.git source warehouse configuration, you run its own autogen.sh script first, and it will download the Git://git.sv.gnu.org/gnulib.git by default. The Configure configuration script is then generated according to the template and some makefile files are initialized, and the Configure file is automatically run to the configuration of the compilation environment.

The basic Operations command line for installing Libvirt from the Git source repository is as follows (omitting the output information from the command execution):


The code is as follows


[Root@jay-linux libvirt.git]#./autogen.sh

[Root@jay-linux libvirt.git]# make

[Root@jay-linux libvirt.git]# make install




By default, the configured and compiled directories may be inconsistent with the default directory provided by the Linux operating system release, for example: RHEL 6.3 libvirtd, Virsh, and other executable programs installed in the system's RPM package are installed/usr/sbin/directory. Shared library files, such as libvirt.so, libvirt-qemu.so, are installed in the/usr/lib64/directory, and from the previous steps






5 in the installation of their own compilation , the default will be LIBVIRTD, Virsh, etc. installed in the/usr/local/sbin directory, and libvirt.so, libvirt-qemu.so, etc. are installed in the/usr/local/lib/ Table of Contents. If you want to maintain consistency in the directory where executable programs and shared libraries are installed in the operating system hairstyle version, the autogen.sh script provides the "–system" parameter, configured with this parameter, to ensure that the installation directory is consistent with the native system as much as possible. Its command-line operations are as follows (omitting the output information from partial command execution):


The code is as follows
[root@jay-linux libvirt.git]# ./autogen.sh –system

[root@jay-linux libvirt.git]# make

[root@jay-linux libvirt.git]# make install

[root@jay-linux libvirt.git]# which libvirtd

/usr/sbin/libvirtd

[root@jay-linux libvirt.git]# which virsh

/usr/bin/virsh

[root@jay-linux libvirt.git]# ls /usr/lib64/libvirt*

/usr/lib64/libvirt.a        /usr/lib64/libvirt-qemu.so           /usr/lib64/libvirt.so

/usr/lib64/libvirt.la       /usr/lib64/libvirt-qemu.so.0         /usr/lib64/libvirt.so.0

/usr/lib64/libvirt-qemu.a   /usr/lib64/libvirt-qemu.so.0.1000.0  /usr/lib64/libvirt.so.0.1000.0

/usr/lib64/libvirt-qemu.la  /usr/lib64/libvirt-qemu.so.0.9.10    /usr/lib64/libvirt.so.0.9.10

 

/usr/lib64/libvirt:

connection-driver



2. Install Libvirt with package

In many popular Linux hairstyles (such as Rhel 6.x, Fedora 17, Ubuntu 12.10, etc.) on the provision of Libvirt-related software packages, in accordance with the installation of ordinary software packages to install Libvirt-related packages. In the author's current use of RHEL 6.3 can be used yum or RPM tools to install the corresponding RPM package, to view the system has been installed in the Libvirt-related RPM package, the command line is as follows:


  code is as follows
[root@rhel6u3-ga ~]# Rpm-qa | grep libvirt

libvirt-python-0.9.10-21.el6.x86_64

Libvirt-java-javadoc-0.4.7-1.el6.noarch

libvirt-qmf-0.3.0-6.el6.x86_64

libvirt-client-0.9.10-21.el6.x86_64

libvirt-lock-sanlock-0.9.10-21.el6.x86_64

Libvirt-java-devel-0.4.7-1.el6.noarch

libvirt-0.9.10-21.el6.x86_64

libvirt-snmp-0.0.2-3.el6.x86_64

Libvirt-java-0.4.7-1.el6.noarch

libvirt-devel-0.9.10-21.el6.x86_64

libvirt-cim-0.6.1-3.el6.x86_64




Of course, RHEL 6.3 uses the QEMU/KVM virtualization scheme by default, so you should install QEMU-related packages to see the following command line operations for these packages:


The code is as follows
[Root@rhel6u3-ga ~]# Rpm-qa | grep QEMU

Qemu-img-0.12.1.2-2.295.el6.x86_64

Qemu-kvm-0.12.1.2-2.295.el6.x86_64

Gpxe-roms-qemu-0.9.7-6.9.el6.noarch




Because Libvirt is cross-platform and supports Microsoft's Hyper-V virtualization, you can also install Libvirt on Windows and even compile libvirt. You can view and download the Libvirt installer that runs on Windows on Libvirt's official web page, http://libvirt.org/sources/win32_experimental/. However, since Libvirt is primarily based on Linux and developers and personal developers in the companies that support it (Redhat) are mostly Linux programmers, the Libvirt version of Windows is still in development, Development progress is not as fast as Linux libvirt, and the previous mention of the Libvirt Windows version that can be downloaded is also an experimental version, rather than an official product release, whose functionality is not guaranteed to be perfect.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.