一、编译环境
- Linux version 3.10.0-327.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) )
- gpdb-5.16.0
二、编译过程
2.1、下载greenplum源码
可从该位置下载需要的版本:https://github.com/greenplum-db/gpdb/releases/(此处使用gpdb-5.16.0)
2.2、解压
下载后再centos中解压到指定目录,如/home/gpdb_src
2.3、安装必备的工具
- psutil
- lockfile (>= 0.9.1)
- paramiko
- setuptools
- conan
注意,以上工具使用pip(>=7.x.x)安装,如果没有pip,可以参考https://pip.pypa.io/en/stable/installing/步骤进行安装。
如果pip版本太低,可使用如下命令升级:
pip install --upgrade pip
2.4、配置ld.so.conf
由于我们使用的是CentOS系统, 所以一定要加上/usr/local/lib和/usr/local/lib64的路径到/etc/ld.so.conf文件中,这一步尤为重要,目的是将常用的动态函数库加载到内存中,可以提高函数库的访问效率。另外,如果不配置这一步,在后面编译的过程中会遇到一些奇奇怪怪的缺少引用的错误
修改后的文件内容类似如下:
修改完成后保存,之后运行ldconfig命令
2.5、创建gpadmin用户和配置ssh
这一步可以使用源码中自带的脚本完成,脚本位置如下:/home/gpdb_src/gpdb-5.16.0/concourse/scripts/setup_gpadmin_user.bash,执行如下命令:
cd /home
bash ./gpdb_src/concourse/scripts/setup_gpadmin_user.bash
这里说明下,这一步如果使用脚本操作,一定要把源码文件放到gpdb_src中,执行脚本时需要进入到与gpdb_src同级的目录执行,如果要手动配置也是可以的。具体的操作也不复杂,有兴趣的朋友可以读下setup_gpadmin_user.bash脚本。
执行完成后,进行如下两步操作验证:
如果切换账户正常并且ssh正常,不需要输入密码,这说明这一步成功
2.6、修改内核参数
sudo bash -c 'cat >> /etc/sysctl.conf <<-EOF
kernel.shmmax = 500000000
kernel.shmmni = 4096
kernel.shmall = 4000000000
kernel.sem = 500 1024000 200 4096
kernel.sysrq = 1
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.msgmni = 2048
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_forward = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.conf.all.arp_filter = 1
net.ipv4.ip_local_port_range = 1025 65535
net.core.netdev_max_backlog = 10000
net.core.rmem_max = 2097152
net.core.wmem_max = 2097152
vm.overcommit_memory = 2
EOF'
sudo bash -c 'cat >> /etc/security/limits.conf <<-EOF
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
EOF'
sudo bash -c 'cat >> /etc/ld.so.conf <<-EOF
/usr/local/lib
EOF'
这一步使用root账户操作,并且很重要,否则在后期使用greenplum的时候会遇到问题,详细的问题后面会解析。
2.7、编译GPORCA(可选)
这里提一下,如果不需要优化器这一步也可以跳过。毕竟greenplum在不安装orca的情况下使用的是legacy优化器。
GPORCA是postgresql新一代的优化器,在性能上有很大提升,至于为什么要有两个优化器,其实是有历史原因的,早期legacy是针对单节点PostgreSQL而构建的,主要应用于OLTP场景,现在的greenplum使用MPP,主要应用场景变为OLAP场景,legacy对此虽然进行了修改,但是从架构设计上,使得其维护和添加新的功能越来越困难,所以有了GPORCA优化器。
首先,编译gporca前需要安装如下必备工具:
- CMake(>=3.1)
- xerces-c(>=3.1.x)
- re2c(>= 0.11.3)
2.7.1、自动编译
cd /home/gpdb_src/gpdb-5.16.0/depends
./configure
make
make install_local
2.7.2 手工编译
特别注意,安装前一定要确认优化器当前的版本是否和greenplum版本相匹配,如果不匹配将无法编译greenplum,详情参见问题6
1) 下载安装cmake
进入https://cmake.org/download/页面下载自己需要的版本
2) 下载安装gp-xerces
可以使用git下载:https://github.com/greenplum-db/gp-xerces.git
3) 下载安装re2c
进入http://re2c.org/install/install.html页面下载自己需要的版本
安装re3c是由于配置ninja时需要
4) 下载安装Ninja
可以使用git下载:https://github.com/ninja-build/ninja.git
下载后进入ninja目录执行如下命令:
./configure.py --bootstrap
5) 下载安装gporca
可以使用git下载:https://github.com/greenplum-db/gporca.git
解压后进入目录执行如下命令安装:
cmake -GNinja -H. -Bbuild
ninja install -C build
待安装完成后,进入/gporca/build目录,执行ctest命令进行检查
如果最后输出类似如下结果:
100% tests passed, 0 tests failed out of 119
Total Test time (real) = 195.48 sec
这说明编译成功了。
2.8 编译greenplum
执行如下命令:
cd /home/gpdb_src/gpdb-5.16.0/gpdb-5.16.0
./configure --with-perl --with-python --with-libxml --with-gssapi --prefix=/usr/local/gpdb
make -j8 #代替make命令,并行的编译,提高编译速度
注意:这里如果跳过了第七步(不使用GPORCA优化器),则configure时需要使用如下命令:
./configure --with-perl --with-python --with-libxml --with-gssapi --disable-orca --prefix=/usr/local/gpdb
configure有很多的组件可以加上,如果需要添加自定义可以使用./configure --help查看,加上自己需要的组件即可
通过以上步骤,就完成了编译。虽然本人已经力求写的详细,但是还是略过了一些自认为大家一看到就能知道原因,同时环境的差异也会导致一些本人没有遇到过的错误,所以有理由相信大家编译的时候还是会遇到一些问题,如果遇到了本文没有涉及到的错误可以告诉我,大家一起讨论。
安装greenplum
cd /home/gpdb_src/gpdb-5.16.0
make -j8 install #安装
创建测试集群
如下命令需要使用之前创建的数据库管理员账户运行,否则会报如下错误:
su - gpadmin
source /usr/local/gpdb/greenplum_path.sh #将greenplum的运行信息加入到shell环境中
cd /home/gpdb_src/gpdb-5.16.0/gpAux/gpdemo
source gpdemo-env.sh
make create-demo-cluster
可以使用如下命令处理:
yum remove python-gssapi.x86_64
三、错误处理
1)
安装必备工具或者升级pip时可能报类似如下错误:
Could not fetch URL https://pypi.python.org/simple/conan/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:765) - skipping
可以执行如下命令:
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org XXXX
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org --upgrade pip
XXXX为你要安装的工具
如果以上都不解决问题,可是使用-i 参数指定国内的镜像来进行安装
如:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple psutil
出现如下错误则要修正系统时间:
当你没有pip,在2.3步安装pip本身都报类似如下错误:
Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:765) - skipping
Could not find a version that satisfies the requirement pip (from versions: )
No matching distribution found for pip
可以使用如下命令安装:
sudo yum -y install epel-release
sudo yum -y install python-pip
yum也不好使的情况下,可以尝试如下命令:
python get-pip.py --trusted-host pypi.org --trusted-host
2)
checking for xsltCleanupGlobals in -lxslt... no
configure: error: library 'xslt' is required for XSLT support
执行如下命令:yum install libxslt libxslt-devel
3)
/bin/ld: libpq/SUBSYS.o: undefined reference to symbol 'gss_delete_sec_context@@gssapi_krb5_2_MIT'
/bin/ld: note: 'gss_delete_sec_context@@gssapi_krb5_2_MIT' is defined in DSO /lib64/libgssapi_krb5.so.2 so try adding it to the linker command line
/lib64/libgssapi_krb5.so.2: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make[2]: *** [postgres] Error 1
make[2]: Leaving directory `/home/greenplum/src/backend'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/greenplum/src'
make: *** [all] Error 2
类似这种错误基本都是安装步骤中第4步没有配置导致的
4)
checking for flags to link embedded Perl... Can't locate ExtUtils/Embed.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.
no
configure: error: could not determine flags for linking embedded Perl.
This probably means that ExtUtils::Embed or ExtUtils::MakeMaker is not installed.
yum install perl-ExtUtils-Embed -y
5)
checking for xmlSaveToBuffer in -lxml2... no
configure: error: library 'xml2' (version >= 2.6.23) is required for XML support
yum install libxml2 libxml2-devel -y
6)
checking Checking ORCA version... configure: error: Your ORCA version is expected to be 2.51.XXX
这说明你装的orca的版本是不匹配的,需要安装匹配版本,那么如何在安装前知道需要什么版本,执行如下命令:
cd /home/gpdb_src/depends
cat conanfile_orca.txt
这里在文件中可以看到如下记录:
[requires]
orca/v2.51.0@gpdb/stable
到github上找到对应版本下载安装即可。
当需要更换版本时,需要清理掉之前已经安装的版本。默认情况下安装在/usr/local/
目录下,根据安装的路径,执行如下命令删除已经安装的版本
rm -rf build/*
rm -rf /usr/local/include/naucrates
rm -rf /usr/local/include/gpdbcost
rm -rf /usr/local/include/gpopt
rm -rf /usr/local/include/gpos
rm -rf /usr/local/lib/libnaucrates.so*
rm -rf /usr/local/lib/libgpdbcost.so*
rm -rf /usr/local/lib/libgpopt.so*
rm -rf /usr/local/lib/libgpos.so*
注意:
1、build位于gporca编译目录,其是编译时cmake产生的一些文件
2、如果重新安装了版本一定要执行ldconfig命令,否则新的版本不会在缓存中更新,会一直报上述错误
7)
unable to execute gcc: No such file or directory
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-4lu7Y0/psutil/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-YPgXFP-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-4lu7Y0/psutil/
yum install -y gcc
8)如果使用编译参数:--with-gssapi可能会报如下错误:
checking for library containing gss_init_sec_context... no
configure: error: could not find function 'gss_init_sec_context' required for GSSAPI
安装gssapi即可:pip install gssapi
而安装gssapi可能报如下错误:
Complete output from command python setup.py egg_info:
In distributed package, building from C files...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-CHeKis/gssapi/setup.py", line 98, in <module>
raise Exception("Could not find main GSSAPI shared library. Please "
Exception: Could not find main GSSAPI shared library. Please try setting GSSAPI_MAIN_LIB yourself or setting ENABLE_SUPPORT_DETECTION to 'false'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-CHeKis/gssapi/
需要安装如下工具:yum install -y krb5-devel.x86_64
9)
checking for apr-1-config... no
configure: error: apr-1-config is required for gpfdist, unable to find binary
yum install -y apr-devel
10)
checking for library containing event_add... no
configure: error: libevent is required for gpfdist
yum install -y libevent-devel
11)
checking for curl-config... no
*** The curl-config script could not be found. Make sure it is
*** in your path, and that curl is properly installed.
*** Or see http://curl.haxx.se/
configure: error: Library requirements (curl) not met.
yum install -y libcurl-devel.x86_64
12)
checking for bzlib.h... no
configure: error: header file <bzlib.h> is required for bzip2 support
yum install -y bzip2-devel
13)安装psutil时可能报如下错误:
psutil/_psutil_common.c:9:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-3gzCd8/psutil/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-EAY9ck-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-3gzCd8/psutil/
yum install -y python-devel.x86_64
14)
ERROR: orca/v3.21.0@gpdb/stable: Error in build() method, line 48
cmake.configure(defs=cmake_defines)
ConanException: Error 256 while executing cd '/home/gpdb_src/gpdb-5.16.0/depends/.conan/data/orca/v3.21.0/gpdb/stable/build/4f7d6d5032b1a188f98e0c149ef6bf91e76af63e' && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Release" -DCONAN_EXPORTED="1" -DCONAN_IN_LOCAL_CACHE="ON" -DCONAN_COMPILER="gcc" -DCONAN_COMPILER_VERSION="4.8" -DCONAN_CXX_FLAGS="-m64" -DCONAN_SHARED_LINKER_FLAGS="-m64" -DCONAN_C_FLAGS="-m64" -DCONAN_LIBCXX="libstdc++" -DBUILD_SHARED_LIBS="ON" -DCMAKE_INSTALL_PREFIX="/home/gpdb_src/gpdb-5.16.0/depends/.conan/data/orca/v3.21.0/gpdb/stable/package/4f7d6d5032b1a188f98e0c149ef6bf91e76af63e" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -Wno-dev '/home/gpdb_src/gpdb-5.16.0/depends/.conan/data/orca/v3.21.0/gpdb/stable/build/4f7d6d5032b1a188f98e0c149ef6bf91e76af63e'
make: *** [orca] Error 1
yum install gcc-c++
15)该问题可能出现在make阶段
***
ERROR: `bison' is missing on your system. It is needed to create the
file `gram.c'. You can either get bison from a GNU mirror site
or download an official distribution of PostgreSQL, which contains
pre-packaged bison output.
***
make[3]: *** [gram.c] Error 1
make[3]: Leaving directory `/home/gpdb_src/gpdb-5.16.0/src/backend/parser'
make[2]: *** [parser/gram.h] Error 2
make[2]: *** Waiting for unfinished jobs....
AWK='gawk' /bin/sh Gen_fmgrtab.sh pg_proc_combined.h.tmp
make[3]: Leaving directory `/home/gpdb_src/gpdb-5.16.0/src/backend/utils'
make[2]: Leaving directory `/home/gpdb_src/gpdb-5.16.0/src/backend'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/gpdb_src/gpdb-5.16.0/src'
make: *** [all] Error 2
同样的flex
也可能出现类似问题,解决稍微麻烦一点
yum install -y bison.x86_64 bison-devel.x86_64
之后需要make clean
重新执行安装流程
15)
In file included from include/reader.h:4:0,
from include/gpreader.h:4,
from src/gpreader.cpp:1:
include/s3common_headers.h:8:26: fatal error: openssl/hmac.h: No such file or directory
#include <openssl/hmac.h>
^
compilation terminated.
yum install -y openssl-devel
四、参考资料
https://github.com/greenplum-db/gpdb/tree/5.16.0