一、編譯環境
- 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
四、參考資料
http://blog.csdn.net/luojinbai/article/details/44217551
https://www.cnblogs.com/codeblock/p/4730122.html
https://github.com/greenplum-db/gpdb/tree/5.16.0