Ceph 编译

Nautilus

编译环境

硬件

采用KVM虚拟机编译Ceph源码,具体配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 8
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 13
Model name: QEMU Virtual CPU version 2.5+
Stepping: 3
CPU MHz: 2394.454
BogoMIPS: 4788.90
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 4096K
NUMA node0 CPU(s): 0-7
Flags: fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pse36 clflush mmx fxsr sse sse2 syscall nx lm rep_good nopl cpuid tsc_known_freq pni cx16 x2apic hypervisor lahf_lm pti
1
2
3
4
# free -g
total used free shared buff/cache available
Mem: 15 7 5 0 2 7
Swap: 0 0 0

软件

OS:

1
2
# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

kernel:

1
2
# uname -a
Linux host-10-100-13-111 4.18.20 #1 SMP Tue Sep 17 11:21:39 CST 2019 x86_64 x86_64 x86_64 GNU/Linux

gcc:

1
2
3
4
5
6
7
8
# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-7/root/usr --mandir=/opt/rh/devtoolset-7/root/usr/share/man --infodir=/opt/rh/devtoolset-7/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/isl-install --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)

编译

pre-compile

执行install-deps.sh,安装编译ceph依赖的软件包。

cmake

安装官方文档的步骤可以正常编译,但默认的编译是含有调试信息的。所以编译后的bin文件比较大。

  1. 生成makefile文件
    使用do_cmake.sh脚本在build目录下生成Makefile文件
  2. 编译
    使用make命令编译,此过程时间较长。
  3. 瘦身
    编译后的binary文件包含有debug信息,所以文件较大。需要使用strip对其debug信息进行裁剪。裁剪有两个工具可以用一个是objcopy;另一个是strip
    eg:
    `objcopy --strip-debug ./radosgw`
    `strip --strip-debug --strip-unneeded ./radosgw`
    

rpmbuild

  1. 生成rpmbuild目录树
    使用rpmdev-setuptree命令创建rpmbuild目录树,该目录树会在$home目录下生成。可根据自己的需要将rpmbuildcopy到指定的目录,但后续build过程需要指定这个目录。本人将rpmbuild目录移动到/root/src目录下。
  2. 获取源码tar包到rpmbuild/SOURCES目录
    获取源码tar包可以到https://download.ceph.com/tarballs/ceph-14.2.3.tar.gz去下载。也可以将修改好的代码直接做成tar包。然后将tar包copy到rpmbuild/SOURCES目录下。
  3. 提取tar包中的ceph.spec
    从源码tar包中提取ceph.spec文件到rpmbuild/SPECS目录,用于后续rpmbuild使用。eg: tar --strip-components=1 -C /root/src/rpmbuild/SPECS/ --no-anchored -xvzf /root/src/rpmbuild/SOURCES/ceph-14.2.3.tar.gz "ceph.spec"
  4. build rpms
    rpmbuild具体使用-bb还是-ba根据个人需要而定吧。本人这里使用-bb只制作binary。eg: rpmbuild -D "_smp_mflags 4" -D "_topdir /root/src/rpmbuild" -bb /root/src/rpmbuild/SPECS/ceph.spec
    由于本人将rpmbuild移动到了/root/src目录下,所以需要使用-D "_topdir /root/src/rpmbuild"去指定rpmbuild目录。
    本人不希望rpmbuild自动推算使用几个核心去编译,需要指定4个核心编译需要指定-D "_smp_mflags 4"

此时,可以静静等待编译完成。

编译的过程中可能会遇到BuildArch:noarch错误

1
2
3
4
5
error: Arch dependent binaries in noarch package


RPM build errors:
Arch dependent binaries in noarch package

可以通过在spec文件中增加%define _binaries_in_noarch_packages_terminate_build 0来解决此问题。

Luminous

编译 Ceph luminous版本,luminous的改动还是蛮大的,而且改变了原有的configure为cmake。

编译环境

硬件

armv7l (Odroid XU4)

软件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ lsb_release  -a
LSB Version: 1.4
Distributor ID: Arch
Description: Arch Linux
Release: rolling
Codename: n/a

$ uname -a
Linux HomeCenter 4.14.29-1-ARCH #1 SMP PREEMPT Fri Mar 23 02:57:06 UTC 2018 armv7l GNU/Linux

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/armv7l-unknown-linux-gnueabihf/7.2.1/lto-wrapper
Target: armv7l-unknown-linux-gnueabihf
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://github.com/archlinuxarm/PKGBUILDs/issues --enable-languages=c,c++,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --host=armv7l-unknown-linux-gnueabihf --build=armv7l-unknown-linux-gnueabihf --with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16
Thread model: posix
gcc version 7.2.1 20180116 (GCC)

编译

按照官方的文档,编译总共分为4步。

  1. 安装编译需要的依赖包 ./install-deps.sh
  2. 使用cmake生成Makefile ./do_cmake.sh
  3. 使用Makefile编译源代码
  4. 安装包制作

由于本人使用的是archlinux,简单查看了一下install-deps.sh这个脚本,发现没有与我使用os相匹配的处理;所以本人决定跳过第一步,并且我也不打算制作安装包,所以第四部也省略了。

接下来就只剩下第2、3步了,那么ceph编译依赖的其他软件包怎么解决,就只能放倒编译过程中出现报错再去究其原因了。闲言少叙,我们开始编译。

cmake过程

从github上clone下来ceph代码,不需要取得submodule的代码,因为在do_cmake.sh中首先会做。执行do_cmake.sh后,先取submodule代码,然后创建build目录,并在build目录中执行cmake,生成Makefile。

在获取submodule这个过程由于网络问题会出现不只一次的中断,这个时候需要先删除build目录,然后在重新执行do_cmake.sh

make过程

ceph编译需要用到boost包,之前的版本都是需要用户手动安装,L版改为取源码自行编译了。可以先执行make Boost或直接执行make操作,我在编译boost的时候遇到了找不到pyconfig.h的编译错误,此时需要根据错误提示的文件及行数,找到对应的cxxflags并增加-I/usr/include/python2.7/这样再次执行make操作boost就能正常编译了。

1
2
3
4
5
6
7
8
9
Scanning dependencies of target ceph-dencoder
[ 0%] Building CXX object src/CMakeFiles/ceph-dencoder.dir/test/encoding/ceph_dencoder.cc.o
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://github.com/archlinuxarm/PKGBUILDs/issues> for instructions.
make[2]: *** [src/CMakeFiles/ceph-dencoder.dir/build.make:64: src/CMakeFiles/ceph-dencoder.dir/test/encoding/ceph_dencoder.cc.o] Error 4
make[1]: *** [CMakeFiles/Makefile2:1609: src/CMakeFiles/ceph-dencoder.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

由于我使用的是嵌入式设备,内存只有2g大小,并且没有配置swap,在编译过程中会遇到g++: internal compiler error: Killed (program cc1plus)错误,这种错误都是由于内存不足导致的。对于我的环境而言,只能通过增加swap来解决(关于增加swap的方法)。

问题解决了,就一路make下去吧。

参考&鸣谢