CentOS 7源码安装 Xen跟Centos 6稍微有点不一样,这里记录下来以便以后查阅。
安装前的配置和安装需要的软件包
CentOS7系统安装以后,首先查看有没有开启SELinux,如果开启了要关闭SELinux的功能:
[root@centos ~]# vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
也可以考虑配一个速度快的
yum源。
之后,更新系统,并且安装编译 Xen 所需要的编译器、工具、软件库等:
# yum update
# yum groupinstall "Development Tools"
# yum install -y gcc gcc-c++ git patch texinfo
# yum install -y python-devel acpica-tools libuuid-devel ncurses-devel glib2 glib2-devel libaio-devel openssl-devel yajl-devel glibc-devel glibc-devel.i686 pixman-devel
# wget http://mirror.centos.org/centos/6/os/x86_64/Packages/dev86-0.16.17-15.1.el6.x86_64.rpm
# rpm -ivh dev86-0.16.17-15.1.el6.x86_64.rpm
安装Xen
到Xen官网下载相应的源码包后编译、安装:# tar zxvf xen-4.9.1.tar.gz
# cd xen-4.9.1
# ./configure --libdir=/usr/lib
# make -j4 dist
# make install
更新内核
CentOS 7使用的是Linux-3.10的内核,Xen 4.9无法启动这个内核,这里考虑更新为最新的长期支持版本:
# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
# yum --enablerepo=elrepo-kernel install kernel-lt -y
详情可以参考<CentOS 6升级Linux内核>
配置 Grub
在这之前安装的Xen和Linux内核是没有任何联系的,所以修改Grub使Linux内核以支持Xen的方式启动,其实就是添加一个含有Xen的启动项。
如果是Linux4.4的内核,直接更新Grub2即可:
# grub2-mkconfig -o /etc/grub2.cfg
如果是其他内核,可能还需要手动配置 grub2,加上带 Xen 的 Linux dom0 内核:
# grub2-mkconfig -o /etc/grub2.cfg
# vi /etc/grub2.cfg
# vi /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry 'CentOS Linux, with Linux 3.15.4 Xen' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.15.4-advanced-aa64a6a3-518e-4a7c-9e88-2f3f33c8c700' {
load_video
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' 6bc61a5c-12e3-4711-9532-61760367e0dc
else
search --no-floppy --fs-uuid --set=root 6bc61a5c-12e3-4711-9532-61760367e0dc
fi
multiboot /xen.gz
module /vmlinuz-3.15.4 root=UUID=aa64a6a3-518e-4a7c-9e88-2f3f33c8c700 ro rd.lvm.lv=cl/root vconsole.font=latarcyrheb-sun16 crashkernel=auto vconsole.keymap=us rd.lvm.lv=cl/swap rhgb quiet
module /initramfs-3.15.4.img
}
# grub2-mkconfig -o /etc/grub2.cfg
上述操作是复制/etc/grub2.cfg中相应内核的引导配置,在 /etc/grub.d/40_custom 内加入自定Xen引导项目。
配置完Grub2后可以修改默认启动内核为Xen引导的内核:
# cat /boot/grub2/grub.cfg |grep menuentry
if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
menuentry_id_option=""
export menuentry_id_option
menuentry 'CentOS Linux (4.4.135-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-4.4.135-1.el7.elrepo.x86_64-advanced-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
menuentry 'CentOS Linux (3.10.0-862.3.2.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-862.3.2.el7.x86_64-advanced-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
menuentry 'CentOS Linux (3.10.0-862.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-862.el7.x86_64-advanced-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
menuentry 'CentOS Linux (0-rescue-06f363a00b5c41c4920e89af9cbfcc21) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-06f363a00b5c41c4920e89af9cbfcc21-advanced-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
menuentry 'CentOS Linux, with Xen hypervisor' --class centos --class gnu-linux --class gnu --class os --class xen $menuentry_id_option 'xen-gnulinux-simple-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
submenu 'Advanced options for CentOS Linux (with Xen hypervisor)' $menuentry_id_option 'gnulinux-advanced-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
submenu 'Xen hypervisor, version 4.9.1' $menuentry_id_option 'xen-hypervisor-4.9.1-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
menuentry 'CentOS Linux, with Xen 4.9.1 and Linux 4.4.135-1.el7.elrepo.x86_64' --class centos --class gnu-linux --class gnu --class os --class xen $menuentry_id_option 'xen-gnulinux-4.4.135-1.el7.elrepo.x86_64-advanced-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
submenu 'Xen hypervisor, version 4.9.1.config' $menuentry_id_option 'xen-hypervisor-4.9.1.config-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
menuentry 'CentOS Linux, with Xen 4.9.1.config and Linux 4.4.135-1.el7.elrepo.x86_64' --class centos --class gnu-linux --class gnu --class os --class xen $menuentry_id_option 'xen-gnulinux-4.4.135-1.el7.elrepo.x86_64-advanced-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
submenu 'Xen hypervisor, version 4.9' $menuentry_id_option 'xen-hypervisor-4.9-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
menuentry 'CentOS Linux, with Xen 4.9 and Linux 4.4.135-1.el7.elrepo.x86_64' --class centos --class gnu-linux --class gnu --class os --class xen $menuentry_id_option 'xen-gnulinux-4.4.135-1.el7.elrepo.x86_64-advanced-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
submenu 'Xen hypervisor, version 4' $menuentry_id_option 'xen-hypervisor-4-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
menuentry 'CentOS Linux, with Xen 4 and Linux 4.4.135-1.el7.elrepo.x86_64' --class centos --class gnu-linux --class gnu --class os --class xen $menuentry_id_option 'xen-gnulinux-4.4.135-1.el7.elrepo.x86_64-advanced-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
submenu 'Xen hypervisor, version xen' $menuentry_id_option 'xen-hypervisor-xen-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
menuentry 'CentOS Linux, with Xen xen and Linux 4.4.135-1.el7.elrepo.x86_64' --class centos --class gnu-linux --class gnu --class os --class xen $menuentry_id_option 'xen-gnulinux-4.4.135-1.el7.elrepo.x86_64-advanced-263cd610-0e5b-4e48-a3b4-c9a751ecf5e8' {
# grub2-set-default 'CentOS Linux, with Xen hypervisor'
安装后的操作
安装Xen后首先重启运行 ldconfig命令导入动态共享库:
# ldconfig
之后运行xl info可能还是会报错的:
# xl info
xc: error: Could not obtain handle on privileged command interface (2 = No such file or directory): Internal error
libxl: error: libxl.c:99:libxl_ctx_alloc: cannot open libxc handle: No such file or directory
cannot init xl context
这是因为没有挂载 xenfs ,挂载一下就可以了:
# modprobe xenfs
# mount -t xenfs xenfs /proc/xen
# ls /proc/xen/
capabilities privcmd xenbus xsd_kva xsd_port
还有,运行xl list无响应是因为xencommons服务未开启,开启一下:
# /etc/init.d/xencommons start
将init.d下面的三个xen服务设成开机启动
# chkconfig xencommons on
# chkconfig xendomains on
# chkconfig xen-watchdog on
可能遇到的问题
如果在创建DomU时出现如下错误:
Traceback (most recent call last):
File “/usr/lib/xen/bin/pygrub”, line 20, in
import xen.lowlevel.xc ImportError: No module named xen.lowlevel.xc
可以通过重新编译和安装xen kernel来解决:
make dist PYTHON_PREFIX_ARG=
make install PYTHON_PREFIX_ARG=