OpenStack之安装kvm+编译安装libvirt+解决遇到的问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenStack之安装kvm+编译安装libvirt+解决遇到的问题相关的知识,希望对你有一定的参考价值。


http://libvirt.org/sources/ 下载libvirt进行编译安装

1.简单编译安装libvirt

[email protected]:/tool#tar -xf libvirt-1.3.4.tar.gz

[email protected]:/tool# cd libvirt-1.3.4

[email protected]:/tool/libvirt-1.3.4#

Ubuntu缺省情况下,没有提供C/C++的编译环境,所以还需手动安装如下包
[email protected]:/tool/libvirt-1.3.4#apt-get install build-essential

[email protected]:/tool/libvirt-1.3.4#apt-get install libpciaccess-dev libyajl-dev libxml2 libxml2-dev gnutls-bin libgnutls-dev


因为libvirt中包含有支持python 的库

[email protected]:/tool/libvirt-1.3.4#apt-get install libdevmapper  libdevmapper-dev python-dev libnl-dev pkg-config

编译安装libvirt-1.3.4,这样在执行./configure时就不会报错了

[email protected]:/tool/libvirt-1.3.4#./configure --prefix=/usr --localstatedir=/var  --sysconfdir=/etc


..............

..............

onfig.status: creating po/Makefile

configure: 

configure: Configuration summary

configure: =====================

configure: 

configure: Drivers

configure: 

configure:       Xen: no

configure:      QEMU: yes

configure:       UML: yes

configure:    OpenVZ: yes

configure:    VMware: yes

configure:      VBox: yes

configure:    XenAPI: no

configure:  xenlight: no

configure:       LXC: yes

configure:      PHYP: no

configure:       ESX: no

configure:   Hyper-V: no

configure:        vz: no

configure:     Bhyve: no

configure:      Test: yes

configure:    Remote: yes

configure:   Network: yes

configure:  Libvirtd: yes

configure: Interface: yes

configure:   macvtap: yes

configure:  virtport: yes

configure: 

configure: Storage Drivers

configure: 

configure:      Dir: yes

configure:       FS: yes

configure:    NetFS: yes

configure:      LVM: yes

configure:    iSCSI: no

configure:     SCSI: yes

configure:    mpath: yes

configure:     Disk: no

configure:      RBD: no

configure: Sheepdog: no

configure:  Gluster: no

configure:      ZFS: no

configure: 

configure: Security Drivers

configure: 

configure:  SELinux: yes (/selinux)

configure: AppArmor: no (install profiles: no)

configure: 

configure: Driver Loadable Modules

configure: 

configure:   dlopen:  -ldl

configure: 

configure: Libraries

configure: 

configure:   apparmor: no 

configure:       attr: no 

configure:      audit: no 

configure:      avahi: no 

configure:      blkid: no 

configure:      capng: no 

configure:       curl: no 

configure:       dbus: no 

configure:       fuse: no 

configure:  glusterfs: no 

configure:        hal: no 

configure:      netcf: no 

configure:    numactl: no 

configure:  openwsman: no 

configure:  pciaccess: yes (CFLAGS=‘ ‘ LIBS=‘-lpciaccess  ‘)

configure:   readline: no 

configure:    sanlock: no 

configure:       sasl: no 

configure:    selinux: yes (CFLAGS=‘‘ LIBS=‘-lselinux‘)

configure:       ssh2: no 

configure: systemd_daemon: no 

configure:       udev: yes (CFLAGS=‘ ‘ LIBS=‘-ludev  ‘)

configure: wireshark_dissector: no 

configure:        nss: yes

configure:       yajl: yes (CFLAGS=‘‘ LIBS=‘-lyajl‘)

configure:   libxml: -I/usr/include/libxml2   -lxml2  

configure:   dlopen: -ldl

configure: openwsman: no

configure:   gnutls: -I/usr/include/p11-kit-1   -DGCRYPT_NO_DEPRECATED -lgnutls   -lgcrypt

configure: firewalld: no

configure:   polkit: no

configure:      xen: no

configure:   xenapi: no

configure: xenlight: no

configure:     pcap: no

configure:       nl:   -lnl  

configure:    mscom: no

configure:      xdr: 

configure:      rbd: no

configure: pm-utils: yes

configure: 

configure: Test suite

configure: 

configure:          Coverage: no

configure:         Alloc OOM: no

configure: 

configure: Miscellaneous

configure: 

configure:              Debug: yes

configure:        Use -Werror: no

configure:      Warning Flags:  -W -Waddress -Wall -Wattributes -Wbad-function-cast -Wbuiltin-macro-redefined -Wcast-align -Wchar-subscripts -Wclobbered -Wcomment -Wcomments -Wcoverage-mismatch -Wcpp -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wdouble-promotion -Wempty-body -Wendif-labels -Wextra -Wformat-contains-nul -Wformat-extra-args -Wformat-security -Wformat-y2k -Wformat-zero-length -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Winline -Wint-to-pointer-cast -Winvalid-pch -Wjump-misses-init -Wlogical-op -Wmain -Wmissing-braces -Wmissing-declarations -Wmissing-field-initializers -Wmissing-include-dirs -Wmissing-parameter-type -Wmissing-prototypes -Wmultichar -Wnested-externs -Wnonnull -Wold-style-declaration -Wold-style-definition -Woverflow -Woverride-init -Wpacked-bitfield-compat -Wparentheses -Wpointer-arith -Wpointer-sign -Wpointer-to-int-cast -Wpragmas -Wreturn-type -Wsequence-point -Wshadow -Wstrict-aliasing -Wstrict-prototypes -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wswitch -Wsync-nand -Wtrampolines -Wtrigraphs -Wtype-limits -Wuninitialized -Wunknown-pragmas -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wnormalized=nfc -Wno-missing-field-initializers -Wno-sign-compare -Wjump-misses-init -Wno-format-nonliteral -Wframe-larger-than=4096 -fexceptions -fasynchronous-unwind-tables -fipa-pure-const -Wno-suggest-attribute=pure -Wno-suggest-attribute=const -fstack-protector-all

configure:             DTrace: no

configure:              numad: no

configure:        XML Catalog: /etc/xml/catalog

configure:        Init script: check

configure:  Char device locks: /var/lock

configure:     Default Editor: vi

configure:       Loader/NVRAM: 

configure:   virt-login-shell: yes

configure: virt-host-validate: yes

configure: 

configure: Developer Tools

configure: 

configure: Wireshark dissector: no

configure: 

configure: Privileges

configure: 

configure:       QEMU: root:root

configure: 


[email protected]:make &&make install

[email protected]:/tool/libvirt-1.3.4# virsh list
p11-kit: invalid config filename, will be ignored in the future: /etc/pkcs11/modules/gnome-keyring-module
error: failed to connect to the hypervisor
error: no valid connection
error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘: No such file or directory

发现报错:p11-kit:无效的配置文件名将来会被忽略:/ etc / pkcs11 / modules / gnome-keyring-module,及libvirtd没有启动


[email protected]:/tool/libvirt-1.3.4# ps -aux |grep "libvirtd"
Warning: bad ps syntax, perhaps a bogus ‘-‘? See http://procps.sf.net/faq.html
root     129786  0.0  0.0   9432   940 pts/2    S+   10:30   0:00 grep --color=auto libvirtd


[email protected]:/tool/libvirt-1.3.4# libvirtd -d
p11-kit: invalid config filename, will be ignored in the future: /etc/pkcs11/modules/gnome-keyring-module


[email protected]:/tool/libvirt-1.3.4# rm -rf  /etc/pkcs11/modules/gnome-keyring-module


[email protected]:/tool/libvirt-1.3.4# ps -aux |grep "libvirtd"
root     129792  1.6  0.3 307788  6948 ?        Sl   10:30   0:00 libvirtd -d
root     129911  0.0  0.0   9432   940 pts/2    S+   10:31   0:00 grep --color=auto libvirtd

[email protected]:/tool/libvirt-1.3.4# virsh list
 Id    Name                           State
----------------------------------------------------

这样则显示libvirt安装成功



2.下面的是根据openstack结合kvm进行编译安装libvirt的环境,需要的模块比较多也比较完善,但有的可以根据需求去掉。


[email protected]:/home/zxl#vim /etc/apt/sources.list

 deb http://mirrors.sohu.com/ubuntu/ precise main restricted
 deb-src http://mirrors.sohu.com/ubuntu/ precise main restricted
 deb http://mirrors.sohu.com/ubuntu/ precise-updates main restricted
 deb-src http://mirrors.sohu.com/ubuntu/ precise-updates main restricted
 deb http://mirrors.sohu.com/ubuntu/ precise universe
 deb-src http://mirrors.sohu.com/ubuntu/ precise universe
 deb http://mirrors.sohu.com/ubuntu/ precise-updates universe
 deb-src http://mirrors.sohu.com/ubuntu/ precise-updates universe
 deb http://mirrors.sohu.com/ubuntu/ precise multiverse
 deb-src http://mirrors.sohu.com/ubuntu/ precise multiverse
 deb http://mirrors.sohu.com/ubuntu/ precise-updates multiverse
 deb-src http://mirrors.sohu.com/ubuntu/ precise-updates multiverse
 deb http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse
 deb-src http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse
 deb http://mirrors.sohu.com/ubuntu/ precise-security main restricted
 deb-src http://mirrors.sohu.com/ubuntu/ precise-security main restricted
 deb http://mirrors.sohu.com/ubuntu/ precise-security universe
 deb-src http://mirrors.sohu.com/ubuntu/ precise-security universe
 deb http://mirrors.sohu.com/ubuntu/ precise-security multiverse
 deb-src http://mirrors.sohu.com/ubuntu/ precise-security multiverse
 deb http://extras.ubuntu.com/ubuntu precise main
 deb-src http://extras.ubuntu.com/ubuntu precise main


[email protected]:/home/zxl# apt-get update

[email protected]:/home/zxl# apt-get install qemu-kvm ubuntu-vm-builder bridge-utils

[email protected]:/home/zxl# modprobe kvm

[email protected]:/home/zxl# modprobe kvm-intel

[email protected]:/home/zxl# modprobe kvm-amd

检测kvm是否正常运行

[email protected]:/home/zxl# kvm-ok

INFO: /dev/kvm exists

KVM acceleration can be used

则kvm安装成功,下面编译安装libvirt



[email protected]:/tool# tar -xf libvirt-1.3.4.tar.gz 

[email protected]:/tool# cd libvirt-1.3.4

[email protected]:/tool/libvirt-1.3.4# apt-get install build-essential python-dev libxml2-dev libxslt-dev tgt lvm2 python-lxml unzip python-mysqldb mysql-client memcached openssl expect iputils-arping python-xattr python-lxml kvm gawk iptables ebtables sqlite3 sudo kvm vlan curl socat python-libxml2 iscsitarget iscsitarget-dkms open-iscsi build-essential libxml2 libxml2-dev make fakeroot dkms openvswitch-switch openvswitch-datapath-dkms libxslt1.1 libxslt1-dev vlan gnutls-bin libgnutls-dev cdbs debhelper libncurses5-dev libreadline-dev libavahi-client-dev libparted0-dev libdevmapper-dev libudev-dev libpciaccess-dev libcap-ng-dev libnl-3-dev libapparmor-dev python-all-dev libxen-dev policykit-1 libyajl-dev libpcap0.8-dev libnuma-dev radvd libxml2-utils libnl-route-3-200 libnl-route-3-dev libnuma1 numactl libnuma-dbg libnuma-dev dh-buildinfo expect ebtables iptables iputils-ping iputils-arping sudo dnsmasq-base dnsmasq-utils

 

[email protected]:/tool/libvirt-1.3.4# ./configure --prefix=/usr --localstatedir=/var  --sysconfdir=/etc

看见下面的内容则说明环境准备好了

config.status: creating po/Makefile

configure: 

configure: Configuration summary

configure: =====================

configure: 

configure: Drivers

configure: 

configure:       Xen: yes

configure:      QEMU: yes

configure:       UML: yes

configure:    OpenVZ: yes

configure:    VMware: yes

configure:      VBox: yes

configure:    XenAPI: no

configure:  xenlight: no

configure:       LXC: yes

configure:      PHYP: no

configure:       ESX: no

configure:   Hyper-V: no

configure:        vz: no

configure:     Bhyve: no

configure:      Test: yes

configure:    Remote: yes

configure:   Network: yes

configure:  Libvirtd: yes

configure: Interface: yes

configure:   macvtap: yes

configure:  virtport: yes

configure: 

configure: Storage Drivers

configure: 

configure:      Dir: yes

configure:       FS: yes

configure:    NetFS: yes

configure:      LVM: yes

configure:    iSCSI: yes

configure:     SCSI: yes

configure:    mpath: yes

configure:     Disk: yes

configure:      RBD: no

configure: Sheepdog: no

configure:  Gluster: no

configure:      ZFS: no

configure: 

configure: Security Drivers

configure: 

configure:  SELinux: yes (/selinux)

configure: AppArmor: yes (install profiles: no)

configure: 

configure: Driver Loadable Modules

configure: 

configure:   dlopen:  -ldl

configure: 

configure: Libraries

configure: 

configure:   apparmor: yes (CFLAGS=‘‘ LIBS=‘-lapparmor‘)

configure:       attr: no 

configure:      audit: no 

configure:      avahi: yes (CFLAGS=‘-D_REENTRANT  ‘ LIBS=‘-lavahi-common -lavahi-client  ‘)

configure:      blkid: yes (CFLAGS=‘-I/usr/include/blkid -I/usr/include/uuid  ‘ LIBS=‘-lblkid  ‘)

configure:      capng: yes (CFLAGS=‘‘ LIBS=‘-lcap-ng‘)

configure:       curl: no 

configure:       dbus: yes (CFLAGS=‘-I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include  ‘ LIBS=‘-ldbus-1 -lpthread -lrt  ‘)

configure:       fuse: no 

configure:  glusterfs: no 

configure:        hal: no 

configure:      netcf: no 

configure:    numactl: yes (CFLAGS=‘‘ LIBS=‘-lnuma‘)

configure:  openwsman: no 

configure:  pciaccess: yes (CFLAGS=‘ ‘ LIBS=‘-lpciaccess  ‘)

configure:   readline: yes (CFLAGS=‘‘ LIBS=‘-lreadline‘)

configure:    sanlock: no 

configure:       sasl: no 

configure:    selinux: yes (CFLAGS=‘‘ LIBS=‘-lselinux‘)

configure:       ssh2: no 

configure: systemd_daemon: no 

configure:       udev: yes (CFLAGS=‘ ‘ LIBS=‘-ludev -lrt  ‘)

configure: wireshark_dissector: no 

configure:        nss: yes

configure:       yajl: yes (CFLAGS=‘‘ LIBS=‘-lyajl‘)

configure:   libxml: -I/usr/include/libxml2   -lxml2  

configure:   dlopen: -ldl

configure: openwsman: no

configure:   gnutls: -I/usr/include/p11-kit-1   -DGCRYPT_NO_DEPRECATED -lgnutls   -lgcrypt

configure: firewalld: yes

configure:   polkit: /usr/bin/pkcheck (version 1)

configure:      xen:   -lxenstore

configure:   xenapi: no

configure: xenlight: no

configure:     pcap: -I/usr/include -L/usr/lib/x86_64-linux-gnu  -lpcap

configure:       nl: -I/usr/include/libnl3   -I/usr/include/libnl3   -lnl-3   -lnl-route-3 -lnl-3  

configure:    mscom: no

configure:      xdr: 

configure:      rbd: no

configure: pm-utils: yes

configure: 

configure: Test suite

configure: 

configure:          Coverage: no

configure:         Alloc OOM: no

configure: 

configure: Miscellaneous

configure: 

configure:              Debug: yes

configure:        Use -Werror: no

configure:      Warning Flags:  -W -Waddress -Wall -Wattributes -Wbad-function-cast -Wbuiltin-macro-redefined -Wcast-align -Wchar-subscripts -Wclobbered -Wcomment -Wcomments -Wcoverage-mismatch -Wcpp -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wdouble-promotion -Wempty-body -Wendif-labels -Wextra -Wformat-contains-nul -Wformat-extra-args -Wformat-security -Wformat-y2k -Wformat-zero-length -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Winline -Wint-to-pointer-cast -Winvalid-pch -Wjump-misses-init -Wlogical-op -Wmain -Wmissing-braces -Wmissing-declarations -Wmissing-field-initializers -Wmissing-include-dirs -Wmissing-parameter-type -Wmissing-prototypes -Wmultichar -Wnested-externs -Wnonnull -Wold-style-declaration -Wold-style-definition -Woverflow -Woverride-init -Wpacked-bitfield-compat -Wparentheses -Wpointer-arith -Wpointer-sign -Wpointer-to-int-cast -Wpragmas -Wreturn-type -Wsequence-point -Wshadow -Wstrict-aliasing -Wstrict-prototypes -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wswitch -Wsync-nand -Wtrampolines -Wtrigraphs -Wtype-limits -Wuninitialized -Wunknown-pragmas -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wnormalized=nfc -Wno-missing-field-initializers -Wno-sign-compare -Wjump-misses-init -Wno-format-nonliteral -Wframe-larger-than=4096 -fexceptions -fasynchronous-unwind-tables -fipa-pure-const -Wno-suggest-attribute=pure -Wno-suggest-attribute=const -fstack-protector-all

configure:             DTrace: no

configure:              numad: no

configure:        XML Catalog: /etc/xml/catalog

configure:        Init script: check

configure:  Char device locks: /var/lock

configure:     Default Editor: vi

configure:       Loader/NVRAM: 

configure:   virt-login-shell: yes

configure: virt-host-validate: yes

configure: 

configure: Developer Tools

configure: 

configure: Wireshark dissector: no

configure: 

configure: Privileges

configure: 

configure:       QEMU: root:root

configure: 

这样就同时安装了许多以后可能需要的模块,且没有报错

[email protected]:/tool/libvirt-1.3.4# make &&make install


libvirt安装完毕,看能不能正常运行

[email protected]:/tool/libvirt-1.3.4# virsh list

。。。。。。。一直卡住不动。

[email protected]:/tool/libvirt-1.3.4# ps -aux |grep "libvirtd"

Warning: bad ps syntax, perhaps a bogus ‘-‘? See http://procps.sf.net/faq.html

root       9762  0.0  0.2 264836  5496 ?        Sl   12:02   0:00 /usr/sbin/libvirtd -d

root      81512  0.0  0.0   9396   932 pts/4    S+   12:20   0:00 grep --color=auto libvirtd

关闭后,再重启!!!!!!

[email protected]:/tool/libvirt-1.3.4# /etc/init.d/libvirt-bin stop

Rather than invoking init scripts through /etc/init.d, use the service(8)

utility, e.g. service libvirt-bin stop

Since the script you are attempting to invoke has been converted to an

Upstart job, you may also use the stop(8) utility, e.g. stop libvirt-bin

libvirt-bin stop/waiting


[email protected]:/tool/libvirt-1.3.4# libvirtd -d

[email protected]:/tool/libvirt-1.3.4# ps -aux |grep "libvirtd"

Warning: bad ps syntax, perhaps a bogus ‘-‘? See http://procps.sf.net/faq.html

root      81542  5.6  0.3 315720  7380 ?        Sl   12:20   0:00 libvirtd -d

root      81658  0.0  0.0   9396   936 pts/4    S+   12:21   0:00 grep --color=auto libvirtd

[email protected]:/tool/libvirt-1.3.4# 

[email protected]:/tool/libvirt-1.3.4# virsh list

 Id    Name                           State

----------------------------------------------------


[email protected]:/tool/libvirt-1.3.4# virsh list

 Id    Name                           State

----------------------------------------------------


OK这样就完美编译libvirt成功!



3.管理界面

[email protected]:/tool/libvirt-1.3.4# apt-get install qemu virt-manager

[email protected]:/home/zxl# virt-manager

可能会报错,No DBUS daemon Running,则采用下面的进程启动dbus进程

[email protected]:/home/zxl# eval `dbus-launch --auto-syntax`

[email protected]:/home/zxl# virt-manager

技术分享


技术分享


则表明安装成功(但用Xsell远程连接好像不能打开,没有反应)




本文出自 “11097124” 博客,请务必保留此出处http://11107124.blog.51cto.com/11097124/1957742

以上是关于OpenStack之安装kvm+编译安装libvirt+解决遇到的问题的主要内容,如果未能解决你的问题,请参考以下文章

KVM虚拟化之安装KVM虚拟机

OpenStack之安装4网卡ubuntu-14.04及网络详细配置

OpenStack之安装4网卡ubuntu-14.04及网络详细配置

Git详解之安装

Django之安装与部署

安全性测试之安装包测试