符号说明
$ 表示在用户模式下执行命令
# 表示在root模式下执行命令
### 表示注释用于解释接下来一条命令的作用
更新环境源
- 设置阿里源
$ sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
$ sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
$ sudo yum clean all
$ sudo yum makecache
编译spice
- 安装编译依赖
$ sudo yum install -y libxml2-devel.x86_64 zlib-devel.x86_64 libffi-devel.x86_64 pixman-devel.x86_64 openssl-devel.x86_64 celt051-devel.x86_64 libjpeg-turbo-devel.x86_64 libmpc-devel.x86_64 mpfr-devel.x86_64 gmp-devel.x86_64
- 编译python
$ wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz
$ tar zJf Python-2.7.12.tar.xz
$ cd Python-2.7.12
$ ./configure --enable-shared --with-zlib
$ make -j8
$ sudo make install
$ sudo ldconfig
### 修改yum使用的python
$ sudo mv /usr/bin/python /usr/bin/python2.6.6
$ sudo ln -s /usr/local/bin/python2.7 /usr/bin/python
$ sudo sed -i 's/#!/usr/bin/python$/#!/usr/bin/python2.6.6/g' /usr/bin/yum
$ python -V
### 如果出现error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory需要重新ldconfig
$ sudo echo "/usr/local/lib" >> /etc/ld.so.conf
$ sudo ldconfig
$ sudo /sbin/ldconfig -v
### 安装pip
$ wget https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py
### 安装依赖
$ sudo pip install six pyparsing
- 设置环境变量(二选一)
### 直接安装到当前系统的环境变量设定
$ export PREFIX="/usr/local/gnome"
$ export ACLOCAL="aclocal -I $PREFIX/share/aclocal"
$ export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PREFIX/share/pkgconfig:$PREFIX/lib64/pkgconfig"
$ export CFLAGS=" -I$PREFIX/include"
$ export CPPFLAGS=" -I$PREFIX/include"
### 需要安装到其他系统的环境变量设定,打包$HOME/gnome下的usr目录即生成安装包
$ export PREFIX="$HOME/gnome/usr/local/gnome"
$ export ACLOCAL="aclocal -I $PREFIX/share/aclocal"
$ export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PREFIX/share/pkgconfig:$PREFIX/lib64/pkgconfig"
$ export CFLAGS=" -I$PREFIX/include"
$ export CPPFLAGS=" -I$PREFIX/include"
$export LDFLAGS=" -L$PREFIX/lib -L$PREFIX/lib -Wl,--rpath -Wl,/usr/local/gnome/lib -L$PREFIX/lib64 -Wl,--rpath -Wl,/usr/local/gnome/lib64"
### 请保证后续所有操作都在设置了环境变量的shell中执行
- 编译gcc
### 编译gcc需要内存大于1G,交换分区要大于1G,磁盘要大于10G,否则容易失败,失败后重新make即可
$ wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.0/gcc-4.8.0.tar.gz
$ tar zxf gcc-4.8.0.tar.gz
$ cd gcc-4.8.0
$ ./configure --prefix=$PREFIX --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++ --with-ppl --with-cloog --with-tune=generic --build=x86_64-redhat-linux --disable-multilib
$ make -j8
$ make install
$ export PATH="$PREFIX/bin/:$PATH"
- 编译glib
$ wget ftp://ftp.gnome.org/pub/gnome/sources/glib/2.42/glib-2.42.2.tar.xz
$ tar zJf glib-2.42.2.tar.xz
$ cd glib-2.42.2
$ ./configure --prefix=$PREFIX
$ make -j8
$ make install
- 编译spice-protocol
$ git clone https://anongit.freedesktop.org/git/spice/spice-protocol.git
$ ./autogen.sh --prefix=$PREFIX
$ make -j8
$ make install
- 编译spice
### gcc版本要升级到4.5以上不然编译最新spice会出现typedef struct重复定义的情况
$ ./autogen.sh --prefix=$PREFIX
$ make -j8
$ make install
编译qemu
- 安装编译依赖
$ sudo yum install -y libudev-devel.x86_64
- 设置环境变量
和spice的保持一致
- 编译autoconf
$ wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.xz
$ tar xJf autoconf-2.69.tar.xz
$ cd autoconf-2.69.tar.xz
$ ./configure --prefix=$PREFIX
- 编译libusb
$ git clone https://github.com/libusb/libusb.git
$ cd libusb
$ ./autogen.sh --prefix=$PREFIX
$ make -j8
$ make install
- 编译usbredir
$ git clone git://anongit.freedesktop.org/spice/usbredir
$ cd usbredir
$ ./autogen.sh --prefix=$PREFIX
$ make -j8
$ make install
- 编译qemu
$ git clone git://git.qemu-project.org/qemu.git
$ cd qemu
$ ./configure --prefix=$PREFIX --target-list=x86_64-softmmu --enable-vnc --enable-kvm --enable-libusb --enable-usb-redir --enable-spice
$ make -j8
$ make install