1.前言 吐槽
openGauss于6月30号开源,继承于原来的GaussDB300的内核,最初源于pg9.2.4内核,但是对pg内核做了很多改动,具体可以参考我这篇文章《华为GaussDB相比PostgreSQL做了哪些内核优化?》。其实从参数也可以看出来华为对内核的改造,在pg11.3版本数据库中共有290个参数,openGauss里目前有515个参数,我们知道数据库参数都是涉及到非常内核的东西,所以华为的研发能力还是很强的。比如说前两天刚刚看到一个参数enable_increment_checkpoint,在openGauss里支持了增量检查点,默认使用double write双写机制来确保不会出现断页的问题,代替了full_page_writes带来的性能开销和wal容量开销。
openGauss的开源对pg社区是一件好事,因为他的一些优秀特性pg社区也可以借鉴采纳,当然也对openGauss的发展是利好,因为可以吸引一些国内外的开发者将pg新版本的优秀特性引入,也可以转变华为做软件的思路,将openGauss做成一款跟pg一样易用的产品。
具体看看编译的过程,编译过程较复杂,不要自己去下载gcc8.2编译,因为可能到最后编译opengauss-server的make阶段的时候发现报错,因为还有一些依赖包需要编译,具体就是dependency和platform目录需要编译,所以尽量使用华为提供的gcc8.2.0及cmake源码编译,python3可以自行下载编译。整个过程为了编译opengauss编译了接近一百个外部软件,过程中坑还是比较多的,可能编译数据库没问题,但是编译这些依赖包各种问题,反观pg就很nice,试过很多类型的平台,都是三条命令直接编译成功,很方便。
华为现在做软件的思路总是给自己竖立一座座高墙,什么脚本都给你写好,给软件整成一个黑盒,出了问题你也不知道出在哪里。华为如果不简化编译流程,这么复杂的编译过程在生产上就是不可用的状态。
我大概花了好几天时间才编译成功,中间主要是在社区提issue耽误很多时间,如果提前把坑都填了,中途不报任何错误,可能完整编译下来也得四个小时以上。
整个编译过程分为下面几个部分:
①准备操作系统环境及相关依赖包
②编译华为第三方工具,包含操作系统依赖包、python3、gcc8.2.0、cmake、dependency、platform
③编译openGauss数据库
2.准备环境及相关安装包
操作系统:centos7.5
用户:omm
组:dbgrp
软件目录:/gaussdb 30G
数据目录:/gaussdata 100G
归档日志目录:/gaussarch 50G
openGauss源码包(社区下载):opengauss-openGauss-server-master.zip
第三方gcc工具源码包(社区下载):openGauss-third_party.zip
gcc8.2.0源码包(镜像网站下载):gcc-8.2.0.tar.gz
其他依赖包(系统yum源自带):libaio-devel、ncurses-devel、pam-devel、libffi-devel、python3-devel、libtool、readline-devel、zlib-devel
python3(镜像网站下载):python3-devel-3.6.8-13.el7.x86_64.rpm
3.编译第三方工具
3.1安装其他依赖包
代码语言:javascript复制[root@DB03 package]# yum install libaio-devel ncurses-devel pam-devel libffi-devel libtool readline-devel zlib-devel -y
3.2编译python3
代码语言:javascript复制[root@DB03 package]# xz -d Python-3.7.0.tar.xz
[root@DB03 package]# tar xf Python-3.7.0.tar
[root@DB03 package]# cd Python-3.7.0/
[root@DB03 Python-3.7.0]# ./configure --prefix=/usr/local/python-3.7.0
[root@DB03 Python-3.7.0]# make -j 20
[root@DB03 Python-3.7.0]# make install
修改python软链接至python3
代码语言:javascript复制[root@DB03 build]# rm -rf /usr/bin/python
[root@DB03 build]# ln -s /usr/local/python-3.7.0/bin/python3 /usr/bin/python
[omm@DB03 ~]$ python --version
Python 3.7.0
3.3安装python3-devel
必须安装,脚本会强制rpm -qa|grep pyrhon3-devel检查,没安装会build失败。可以去百度搜索python3-devel,第一个就是,但是版本是python3.6.8的,没关系,选择强制安装,装完之后yum命令可能会有问题,需要改一下yum命令的第一行/usr/bin/python为/usr/bin/python2.7
代码语言:javascript复制[root@DB03 package]# rpm -ivh python3-devel-3.6.8-13.el7.x86_64.rpm --nodeps --force
warning: python3-devel-3.6.8-13.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:python3-devel-3.6.8-13.el7 ################################# [100%]
3.4编译gcc8.2.0 cmake
拷贝gcc8.2.0源码包到buildtools/gcc目录下
代码语言:javascript复制[omm@DB03 package]$ unzip openGauss-third_party.zip
[omm@DB03 package]$ cp gcc-8.2.0.tar.gz openGauss-third_party/buildtools/gcc
开始编译
代码语言:javascript复制[omm@DB03 package]$ cd openGauss-third_party/build/
[omm@DB03 build]$ sh build_all.sh
[BUILD] buildtools ....................
过了四十分钟左右报错,看日志是编译cmake报错。
buildtools_build.log
代码语言:javascript复制[BUILD] gmp ........................... OK [ 53.55s]
[BUILD] mpfr .......................... OK [ 136.21s]
[BUILD] mpc ........................... OK [ 29.66s]
[BUILD] isl ........................... OK [ 143.45s]
[BUILD] gcc ........................... OK [1650.43s]
[BUILD] cmake ......................... FAILED [ 271.04s]
华为建议自行编译cmake
[omm@DB03 openGauss-third_party]$ cd buildtools/cmake/
添加环境变量:(其中/gaussdb/package/openGauss-third_party目录改为你实际的目录路径)
vi build.sh
代码语言:javascript复制export CC=/gaussdb/package/openGauss-third_party/buildtools/gcc/install_comm/bin/gcc
export CXX=/gaussdb/package/openGauss-third_party/buildtools/gcc/install_comm/bin/g
export LD_LIBRARY_PATH=/gaussdb/package/openGauss-third_party/buildtools/gcc/install_comm/lib64:/gaussdb/package/openGauss-third_party/buildtools/isl/install_comm/lib:/gaussdb/package/openGauss-third_party/buildtools/mpc/install_comm/lib/:/gaussdb/package/openGauss-third_party/buildtools/mpfr/install_comm/lib/:/gaussdb/package/openGauss-third_party/buildtools/gmp/install_comm/lib/:$LD_LIBRARY_PATH
export PATH=/gaussdb/package/openGauss-third_party/buildtools/gcc/install_comm/bin:$PATH
单独编译cmake
代码语言:javascript复制[omm@DB03 cmake]$ sh build.sh -m all
3.5编译dependency目录
编译dependency目录,这一步可能失败,原因是无法分配内存,一定要保证内存足够再进行编译。同时建议放在后台编译,编译时间很长。
代码语言:javascript复制[omm@DB03 package]$ cd openGauss-third_party/dependency/build
[omm@DB03 build]$ sh build_dependency.sh
[BUILD] boost ......................... OK [ 155.72s]
[BUILD] cJSON ......................... OK [ 0.52s]
[BUILD] zlib .......................... OK [ 6.77s]
[BUILD] openssl ....................... OK [ 174.65s]
[BUILD] libevent ...................... OK [ 21.07s]
[BUILD] jemalloc ...................... OK [ 83.03s]
[BUILD] kerberos ...................... OK [ 63.97s]
[BUILD] libcurl ....................... OK [ 49.14s]
[BUILD] libedit ....................... OK [ 10.35s]
[BUILD] lz4 ........................... OK [ 10.61s]
[BUILD] llvm .......................... OK [1529.44s]
[BUILD] ncurses ....................... OK [ 48.81s]
[BUILD] protobuf ...................... OK [ 292.68s]
[BUILD] libxml2 ....................... FAILED [ 0.03s]
查看报错日志:
代码语言:javascript复制[omm@DB03 build]$ cat libxml2_build.log
tar: This does not look like a tar archive
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
发现包的格式不对
代码语言:javascript复制[omm@DB03 libxml2]$ file libxml2-2.9.9.tar.gz
libxml2-2.9.9.tar.gz: ASCII text
这里经过确认总共有两个包的由于大文件的关系直接下载会造成格式不对,所以再次去git网站下载这两个包,并上传到相应目录,注意,需要先删除原理的包再上传。心情十分尴尬:
libxml2-2.9.9.tar.gz
snappy-1.1.7.tar.gz
重新执行build_dependency.sh,它竟然又从头开始build了,之前build好的又build了一遍,一上午又没了,试想如果我没确认snappy包也有这个问题的话,再来一遍发现到snappy又报错,那我真的要崩溃了,汗颜!
代码语言:javascript复制[omm@DB03 build]$ sh build_dependency.sh
[BUILD] boost ......................... OK [ 98.70s]
[BUILD] cJSON ......................... OK [ 0.57s]
[BUILD] zlib .......................... OK [ 6.82s]
[BUILD] openssl ....................... OK [ 175.11s]
[BUILD] libevent ...................... OK [ 20.87s]
[BUILD] jemalloc ...................... OK [ 82.74s]
[BUILD] kerberos ...................... OK [ 63.94s]
[BUILD] libcurl ....................... OK [ 44.83s]
[BUILD] libedit ....................... OK [ 10.36s]
[BUILD] lz4 ........................... OK [ 10.90s]
[BUILD] llvm .......................... OK [1544.08s]
[BUILD] ncurses ....................... OK [ 49.08s]
[BUILD] protobuf ...................... OK [ 292.11s]
[BUILD] libxml2 ....................... OK [ 42.27s]
[BUILD] libcgroup ..................... OK [ 11.67s]
[BUILD] libthrift ..................... FAILED [ 93.63s]
检查日志,报下面的错误,omm用户没有权限。
代码语言:javascript复制 /bin/mkdir -p '/usr/lib/php/'
/bin/mkdir: cannot create directory ‘/usr/lib/php/’: Permission denied
make[4]: *** [install-phpDATA] Error 1
make[4]: Leaving directory `/gaussdb/package/openGauss-third_party/dependency/libthrift/thrift-0.13.0/lib/php'
make[3]: *** [install-am] Error 2
make[3]: Leaving directory `/gaussdb/package/openGauss-third_party/dependency/libthrift/thrift-0.13.0/lib/php'
make[2]: *** [install-recursive] Error 1
make[2]: Leaving directory `/gaussdb/package/openGauss-third_party/dependency/libthrift/thrift-0.13.0/lib/php'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/gaussdb/package/openGauss-third_party/dependency/libthrift/thrift-0.13.0/lib'
make: *** [install-recursive] Error 1
这次换root用户来编译,并且注释掉build_dependency.sh中已经编译过的项目。
vi build_dependency.sh
重新使用root用户编译
代码语言:javascript复制[root@DB03 build]# sh build_dependency.sh
[BUILD] libthrift ..................... OK [ 93.06s]
[BUILD] double-conversion ............. OK [ 4.32s]
[BUILD] brotli ........................ OK [ 9.07s]
[BUILD] snappy ........................ OK [ 11.64s]
[BUILD] zstd .......................... OK [ 19.68s]
[BUILD] glog .......................... OK [ 26.95s]
[BUILD] flatbuffers ................... OK [ 21.49s]
[BUILD] rapidjson ..................... OK [ 0.15s]
[BUILD] arrow ......................... OK [ 74.01s]
[BUILD] orc ........................... OK [ 21.87s]
[BUILD] c-ares ........................ OK [ 56.98s]
[BUILD] grpc .......................... OK [ 51.27s]
[BUILD] pcre .......................... OK [ 10.52s]
[BUILD] libiconv ...................... OK [ 36.42s]
[BUILD] nghttp2 ....................... OK [ 17.04s]
[BUILD] esdk_obs_api .................. OK [ 99.60s]
[BUILD] numactl ....................... OK [ 5.09s]
[BUILD] memcheck ...................... OK [ 0.54s]
[BUILD] six ........................... OK [ 1.33s]
[BUILD] pycparser ..................... OK [ 1.27s]
[BUILD] cffi .......................... OK [ 7.28s]
[BUILD] bcrypt ........................ OK [ 2.73s]
[BUILD] idna .......................... OK [ 1.07s]
[BUILD] ipaddress ..................... OK [ 0.88s]
[BUILD] netifaces ..................... OK [ 3.56s]
[BUILD] pynacl ........................ OK [ 172.97s]
[BUILD] asn1crypto .................... OK [ 1.13s]
[BUILD] cryptography .................. OK [ 32.37s]
[BUILD] pyOpenSSL ..................... OK [ 1.12s]
[BUILD] paramiko ...................... OK [ 1.29s]
[BUILD] psutil ........................ OK [ 3.10s]
[BUILD] pyasn1 ........................ OK [ 1.13s]
total time:975.71
总算build完了。
3.6编译platform目录
代码语言:javascript复制[root@DB03 openGauss-third_party]# cd platform/build/
[root@DB03 build]# sh build_platform.sh
[BUILD] securec ....................... OK [ 4.65s]
total time:10.42
这个倒是很顺利。
3.7目录检查
第三方工具编译完成后会出现下面这几个目录:
代码语言:javascript复制/gaussdb/package/binarylibs/buildtools/centos7.6_x86_64/cmake
/gaussdb/package/binarylibs/buildtools/centos7.6_x86_64/gcc8.2
/gaussdb/package/binarylibs/dependency/centos7.6_x86_64/xxx
/gaussdb/package/binarylibs/platform/centos7.6_x86_64/xxx
4.编译安装openGauss数据库
4.1编辑omm环境变量
代码语言:javascript复制[omm@DB03 package]$ vi ~/.bashrc
export CODE_BASE=/gaussdb/package/openGauss-server # Path of the openGauss-server file
export BINARYLIBS=$CODE_BASE/../binarylibs # Path of the binarylibs file
export GAUSSHOME=/gaussdb/software/
export GCC_PATH=$BINARYLIBS/buildtools/centos7.6_x86_64/gcc8.2
export CC=$GCC_PATH/gcc/bin/gcc
export CXX=$GCC_PATH/gcc/bin/g
export LD_LIBRARY_PATH=$GAUSSHOME/lib:$GCC_PATH/gcc/lib64:$GCC_PATH/isl/lib:$GCC_PATH/mpc/lib/:$GCC_PATH/mpfr/lib/:$GCC_PATH/gmp/lib/:$LD_LIBRARY_PATH
export PATH=$GAUSSHOME/bin:$GCC_PATH/gcc/bin:$PATH
4.2编译openGauss数据库
代码语言:javascript复制[omm@DB03 package]$ unzip opengauss-openGauss-server-master.zip
[omm@DB03 package]$ cd openGauss-server/
[omm@DB03 openGauss-server]$ ./configure --gcc-version=8.2.0 CC=g CFLAGS="-O2 -g3" --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-thread-safety --enable-thread-safety
make阶段,注意不要用gauss文档里面的make -sj会报内存不够的错误,直接使用make -j
代码语言:javascript复制[omm@DB03 openGauss-server]$ make -j40
关注最后几行,表示编译成功:
代码语言:javascript复制make[2]: Leaving directory `/gaussdb/package/openGauss-server/src/test/regress'
make[1]: Leaving directory `/gaussdb/package/openGauss-server/src'
All of openGauss successfully made. Ready to install.
代码语言:javascript复制[omm@DB03 openGauss-server]$ make install
关注下面这行,表示编译成功:
代码语言:javascript复制openGauss installation complete.
4.3目录检查
openGauss编译完成后会出现下面这几个目录:
代码语言:javascript复制/gaussdb/software/bin
/gaussdb/software/etc
/gaussdb/software/include
/gaussdb/software/lib
/gaussdb/software/share
5.创建数据库
5.1初始化数据库
代码语言:javascript复制[omm@DB03 ~]$ gs_initdb --pgdata=/gaussdata/ --nodename=dn_6001 --encoding=utf-8
The files belonging to this database system will be owned by user "omm".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".
fixing permissions on existing directory /gaussdata ... ok
creating subdirectories ... ok
selecting default max_connections ... 10
selecting default shared_buffers ... 400kB
creating configuration files ... ok
creating template1 database in /gaussdata/base/1 ... [GUC] FATAL: invalid value for parameter "max_stack_depth": 2048
[GUC] DETAIL: "max_stack_depth" must not exceed 384kB.
[GUC] HINT: Increase the platform's stack depth limit via "ulimit -s" or local equivalent.
child process exited with exit code 1
gs_initdb: removing contents of data directory "/gaussdata"
发现报错,原因是max_stack_depth的大小应该小于操作系统stack的限制,目前操作系统stack限制是1024,将其改为8192
代码语言:javascript复制[root@DB03 ~]# vi /etc/security/limits.conf
* soft stack 8192
* hard stack 8192
再次查看发现stack size已经改过来了
代码语言:javascript复制[omm@DB03 ~]$ ulimit -s
8192
再次初始化,输入admin用户密码,要求三种八位以上的字符
代码语言:javascript复制[omm@DB03 ~]$ gs_initdb --pgdata=/gaussdata/ --nodename=dn_6001 --encoding=utf-8
The files belonging to this database system will be owned by user "omm".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".
fixing permissions on existing directory /gaussdata ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /gaussdata/base/1 ... ok
initializing pg_authid ... ok
Enter new system admin password:
Enter it again:
Password must contain at least three kinds of characters.
Enter new system admin password:
Enter it again:
setting password ... ok
initializing dependencies ... ok
loading PL/pgSQL server-side language ... ok
creating system views ... ok
creating performance views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading foreign-data wrapper for MOT access ... ok
update system tables ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
freezing database template0 ... ok
freezing database template1 ... ok
freezing database postgres ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run gs_initdb.
Success. You can now start the database server of single node using:
gaussdb -D /gaussdata
or
gs_ctl start -D /gaussdata -l logfile
5.2启动数据库
第一次启动会报:file "/gaussdata/gaussdb.state" is not exist
代码语言:javascript复制[omm@DB03 ~]$ gs_ctl start -D /gaussdata -l logfile
[2020-07-10 14:58:39.964][38149][][gs_ctl]: gs_ctl started,datadir is -D "/gaussdata"
[2020-07-10 14:58:40.081][38149][][gs_ctl]: waiting for server to start...
[2020-07-10 14:58:40.081][38149][][gs_ctl]: file "/gaussdata/gaussdb.state" is not exist
重启一下
代码语言:javascript复制[omm@DB03 ~]$ gs_ctl restart -D /gaussdata -l logfile
[2020-07-10 14:59:38.065][38717][][gs_ctl]: gs_ctl restarted ,datadir is -D "/gaussdata"
waiting for server to shut down... done
server stopped
[2020-07-10 14:59:41.075][38717][][gs_ctl]: waiting for server to start...
.
[2020-07-10 14:59:42.086][38717][][gs_ctl]: done
[2020-07-10 14:59:42.086][38717][][gs_ctl]: server started (/gaussdata)
查看进程,可以看到openGauss为单进程数据库
代码语言:javascript复制[omm@DB03 ~]$ ps -ef |grep gaussdb
omm 38727 1 7 14:59 pts/2 00:00:02 /gaussdb/software/bin/gaussdb -D /gaussdata
5.3连接测试
代码语言:javascript复制[omm@DB03 gaussdata]$ gsql postgres
gsql ((openGauss 1.0.0 build ) compiled at 2020-07-10 10:56:07 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
postgres=#
当然装完还需要调整很多参数,比如默认装完shared_buffers只有32M。
6.总结
编译安装过程中的坑总结如下:
①编译高斯数据库之前的依赖包很多,而且版本很固定,并不是操作系统默认版本,比如gcc8.2.0,还有接近一百个依赖包需要分别编译,编译过程十分繁杂耗时,如果开始把坑都填好,完整编译下来也得四个小时以上。
②不要自己下载gcc8.2.0进行编译,可能到make阶段会报某个函数错误,因为除了gcc8.2.0还有很多依赖包,要使用华为提供的第三方编译工具进行编译。
③编译open强制检查python3-devel包,该包不包含在python3源码包中,只能自己去下载,能下载到的只有python3-devel-3.6.8-13.el7.x86_64.rpm版本的rpm包,该包安装还有很多依赖,只能使用--nodeps --force的方式强制安装。这种方式安装完成后yum命令还会有问题,需要修改/usr/bin/yum命令脚本。
④编译cmake时会报错,需要强制将上一步编译完成的gcc的环境变量放在omm环境变量中,然后对cmake进行单独编译。
⑤编译dependency目录需要使用root用户进行编译。
⑥编译dependency目录时可能会报无法分配内存的错误,要保证操作系统内存足够。
⑦编译dependency目录时,在libxml2和snappy两个包时候可能会报错,因为这两个文件是ascii text文件,只是一个链接,所以需要使用git lfs方式下载,或者直接去网站重新下载这两个文件进行替换,再进行编译。
⑧编译dependency目录失败时无法跳过已经编译成功的子目录,需要重头开始编译,可以通过修改build_dependency.sh脚本跳过。
⑨编译openGauss数据库的make阶段,不要使用华为文档中提供的make -sj静默编译,会报无法分配内存的错误,直接使用make -j40进行编译。