1. 程式人生 > >OpenStack之安裝kvm+編譯安裝libvirt+解決遇到的問題

OpenStack之安裝kvm+編譯安裝libvirt+解決遇到的問題

編譯安裝libvirt kvm openstack


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+解決遇到的問題