本文介紹如何在CentOS環境下編譯GreatSQL RPM包。 運行環境是docker中的CentOS 8 x86_64: $ docker -v Docker version 20.10.10, build b485636 $ docker run -itd --hostname c8 --na ...
本文介紹如何在CentOS環境下編譯GreatSQL RPM包。
運行環境是docker中的CentOS 8 x86_64:
$ docker -v
Docker version 20.10.10, build b485636
$ docker run -itd --hostname c8 --name c8 centos bash
a0a2128591335ef41e6faf46b7e79953c097500e9f033733c3ab37f915b69439
$ docker exec -it c8 bash
1、準備工作
1.1、配置yum源
開始編譯之前,需要先配置好yum源,方便安裝一些輔助工具。
在這裡採用阿裡雲的yum源:
[root@c8 /]# rm -f /etc/yum.repos.d/* && \
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo && \
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo && \
yum clean all && yum makecache
1.2、安裝編譯所需要的軟體包
安裝 rmp-build
包,它會附帶安裝其他必要的相關依賴包:
[root@c8 /]# dnf install -y rpm-build
1.3 創建構建RPM包所需的目錄
創建相應的目錄
[root@c8 /]# mkdir -p /root/rpmbuild/SOURCES
1.4 下載GreatSQL源碼包
戳此鏈接 https://gitee.com/GreatSQL/GreatSQL/releases/tag/GreatSQL-8.0.32-25,找到 greatsql-8.0.32-25.tar.xz
下載GreatSQL源碼包,放在上面創建的 /root/rpmbuild/SOURCES
目錄下,並解壓縮。
1.5 下載greatsql.spec文件
戳此鏈接 https://gitee.com/GreatSQL/GreatSQL-Doc/blob/master/build-gs/greatsql.spec,下載 greatsql.spec
文件,放在上面創建的 /root/rpmbuild/
目錄下。
1.6 下載boost源碼包
編譯GreatSQL 8.0.32-25版本需要配套的boost版本是1.77,戳此鏈接下載 https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.gz,放在上面創建的 /root/rpmbuild/SOURCES
目錄下。
1.7 下載rpcsvc-proto包並編譯安裝
編譯GreatSQL需要配套rpcsvc-proto
包,戳此鏈接下載 https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4/rpcsvc-proto-1.4.tar.gz,放在 /tmp/
目錄下。
2、開始準備編譯GreatSQL RPM包
從GreatSQL源碼包中拷貝幾個必要的文件
[root@c8 /]# cd /root/rpmbuild/SOURCES/greatsql-8.0.32-25/build-gs/rpm
[root@c8 rpm]# cp filter-*sh mysqld.cnf mysql-5.7-sharedlib-rename.patch mysql.init mysql_config.sh /root/rpmbuild/SOURCES/
修改 greatsql.spec
文件中的部分內容:
[root@c8 rpm]# vim /root/rpmbuild/greatsql.spec
...
%global greatsql_version 25
%global revision db07cc5cb73
...
SOURCE0: greatsql-8.0.32-25.tar.xz
...
SOURCE10: boost_1_77_0.tar.gz
...
%changelog
* Fri Dec 29 2023 GreatSQL <[email protected]> - 8.0.32-25.1
- Release GreatSQL-8.0.32-25.1
* Wed Jun 7 2023 GreatSQL <[email protected]> - 8.0.32-24.1
- Release GreatSQL-8.0.32-24.1
...
開始嘗試編譯RPM包
[root@c8 rpm]# cd /root/rpmbuild
[root@c8 rpmbuild]# rpmbuild --nodebuginfo --define "_smp_mflags -j14" --define 'dist .el8' --define "_topdir /root/rpmbuild/" -bb ./greatsql.spec
在使用 rpmbuild
編譯RPM包時,通常會選擇加上 -ba
或 -bb
參數,下麵是關於這兩個參數的註釋:
-ba Build binary and source packages (after doing the %prep, %build, and %install stages).
-bb Build a binary package (after doing the %prep, %build, and %install stages).
簡單說,-ba
會編譯出RPM包和SRPM包,而 -bb
只會編譯出RPM包。
第一次運行時,大概率會提示N多依賴包缺失,先耐心地逐個安裝上:
[root@c8 rpmbuild]# rpmbuild --nodebuginfo --define "_smp_mflags -j14" --define 'dist .el8' --define "_topdir /root/rpmbuild/" -bb ./greatsql.spec
...
warning: Macro expanded in comment on line 787: %{_mandir}/man1/mysql.server.1*
warning: Macro expanded in comment on line 956: %{_datadir}/mysql-*/audit_log_filter_linux_install.sql
...
warning: bogus date in %changelog: Wed Jun 6 2022 GreatSQL <[email protected]> - 8.0.25-16.1
error: Failed build dependencies:
bison is needed by greatsql-8.0.32-25.1.el8.x86_64
cmake >= 2.8.2 is needed by greatsql-8.0.32-25.1.el8.x86_64
cmake >= 3.6.1 is needed by greatsql-8.0.32-25.1.el8.x86_64
...
zlib-devel is needed by greatsql-8.0.32-25.1.el8.x86_64
這裡貼一下我用上述乾凈docker環境中安裝的一些依賴包:
[root@c8 rpmbuild]# dnf install -y bison cmake cyrus-sasl-devel gcc-c++ gcc-toolset-11 gcc-toolset-11-annobin-plugin-gcc yum krb5-devel 1libaio-devel libcurl-devel libtirpc-devel m4 make ncurses-devel numactl-devel openldap-devel openssl openssl-devel pam-devel perl perl-Carp perl-Data-Dumper perl-Errno perl-Exporter perl-File-Temp perl-Getopt-Long perl-JSON perl-Memoize perl-Time-HiRes readline-devel time zlib-devel
由於安裝了 gcc-toolset-11
包,需要執行下麵的命令才能切換到 gcc11 版本環境中,並確認gcc、cmake的版本是否符合要求:
[root@c8 rpmbuild]# source /opt/rh/gcc-toolset-11/enable
[root@c8 rpmbuild]# gcc --version
gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@c8 rpmbuild]# cmake --version
cmake version 3.20.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
還需要編譯安裝rpcsvc-proto
依賴包
[root@c8 rpmbuild]# cd /tmp/
[root@c8 tmp]# tar xf rpcsvc-proto-1.4.tar.gz
[root@c8 tmp]# cd rpcsvc-proto-1.4
[root@c8 rpcsvc-proto-1.4]# ./configure && make && make install
...
make[2]: Leaving directory '/tmp/rpcsvc-proto-1.4'
make[1]: Leaving directory '/tmp/rpcsvc-proto-1.4'
安裝完這些依賴包後,再次開始嘗試編譯RPM包。
[root@c8 rpcsvc-proto-1.4]# cd /root/rpmbuild/
# 將編譯過程輸出到日誌文件中,更方便觀察的排查錯誤
[root@c8 rpmbuild]# rpmbuild --nodebuginfo --define "_smp_mflags -j14" --define 'dist .el8' --define "_topdir /root/rpmbuild/" -bb ./greatsql.spec > ./rpmbuild.log 2>&1
warning: Macro expanded in comment on line 787: %{_mandir}/man1/mysql.server.1*
warning: Macro expanded in comment on line 956: %{_datadir}/mysql-*/audit_log_filter_linux_install.sql
...
warning: bogus date in %changelog: Wed Jun 6 2022 GreatSQL <[email protected]> - 8.0.25-16.1
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.jOIUMM
+ umask 022
+ cd /root/rpmbuild//BUILD
+ cd /root/rpmbuild/BUILD
+ rm -rf greatsql-8.0.32-25
...
如果編譯失敗了,會有類似這樣的結果:
bogus date in %changelog: Wed Jun 6 2022 GreatSQL <[email protected]> - 8.0.25-16.1
Bad exit status from /var/tmp/rpm-tmp.k8RLOL (%build)
只需打開 /root/rpmbuild/rpmbuild.log
文件,搜索 error/fail
等關鍵字(不區分大小寫)應該就能分析出錯誤原因了。
解決完錯誤原因,再一次重試編譯,這次應該順利了,耐心等著吧。在這過程中,我們還可以通過觀察 /root/rpmbuild/rpmbuild.log
文件瞭解編譯的進度情況,例如下麵這樣,可見進度大約到了91%,勝利在望 ~
...
[ 91%] Building CXX object sql/CMakeFiles/binlog.dir/changestreams/misc/column_filters/column_filter_outbound_func_indexes.cc.o
...
編譯GreatSQL RPM包的過程中要做兩遍,一次編譯出release包,一次編譯出debug包,所以會有一點點費時,正好泡杯好茶安心喝著就是了。
最後,查看編譯結果,會有類似下麵的日誌:
[root@c8 rpmbuild]# tail rpmbuild.log
Wrote: /root/rpmbuild/RPMS/x86_64/greatsql-client-debuginfo-8.0.32-25.1.el8.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/greatsql-test-debuginfo-8.0.32-25.1.el8.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/greatsql-shared-debuginfo-8.0.32-25.1.el8.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/greatsql-mysql-router-debuginfo-8.0.32-25.1.el8.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.Z174QT
+ umask 022
+ cd /root/rpmbuild//BUILD
+ cd greatsql-8.0.32-25
+ /usr/bin/rm -rf /root/rpmbuild/BUILDROOT/greatsql-8.0.32-25.1.el8.x86_64
+ exit 0
再看下編譯生成的RPM文件包:
[root@c8 rpmbuild]# du -sch *
45G BUILD #編譯工作目錄,產生大量編譯文件,所以特別大,可以清空
0 BUILDROOT
976M RPMS #編譯產生的RPM包
1.8G SOURCES
0 SPECS
0 SRPMS
37M rpmbuild.log
64K greatsql.spec
47G total
[root@c8 rpmbuild]# cd /root/rpmbuild/RPMS/x86_64
[root@c8 x86_64]# ls -la
total 998740
drwxr-xr-x 2 root root 4096 Dec 29 10:27 .
drwxr-xr-x 3 root root 20 Dec 29 10:21 ..
-rw-r--r-- 1 root root 19061972 Dec 29 10:22 greatsql-client-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 36091240 Dec 29 10:27 greatsql-client-debuginfo-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 4591912 Dec 29 10:25 greatsql-debuginfo-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 26174384 Dec 29 10:25 greatsql-debugsource-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 2241908 Dec 29 10:24 greatsql-devel-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 2145368 Dec 29 10:24 greatsql-icu-data-files-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 8100 Dec 29 10:24 greatsql-mysql-config-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 5259796 Dec 29 10:24 greatsql-mysql-router-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 37427440 Dec 29 10:28 greatsql-mysql-router-debuginfo-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 78317640 Dec 29 10:22 greatsql-server-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 379119548 Dec 29 10:27 greatsql-server-debuginfo-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 1502984 Dec 29 10:24 greatsql-shared-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 2805716 Dec 29 10:27 greatsql-shared-debuginfo-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 409911420 Dec 29 10:24 greatsql-test-8.0.32-25.1.el8.x86_64.rpm
-rw-r--r-- 1 root root 18017572 Dec 29 10:27 greatsql-test-debuginfo-8.0.32-25.1.el8.x86_64.rpm
大功告成。
3、安裝GreatSQL
將編譯產生的RPM包文件拷貝到另外一個全新的docker CentOS 8環境下,測試安裝是否順利。下麵略過拷貝文件以及新docker鏡像環境初始化過程,直接開始安裝:
[root@cc8 cc8]# rpm -ivh *rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:greatsql-shared-8.0.32-25.1.el8 ################################# [ 13%]
2:greatsql-client-8.0.32-25.1.el8 ################################# [ 25%]
3:greatsql-icu-data-files-8.0.32-25################################# [ 38%]
4:greatsql-server-8.0.32-25.1.el8 ################################# [ 50%]
5:greatsql-test-8.0.32-25.1.el8 ################################# [ 63%]
6:greatsql-mysql-router-8.0.32-25.1################################# [ 75%]
7:greatsql-mysql-config-8.0.32-25.1################################# [ 88%]
8:greatsql-devel-8.0.32-25.1.el8 ################################# [100%]
看起來一切都很順利,成功搞定。
延伸閱讀
- 玩轉MySQL 8.0源碼編譯
- 將GreatSQL添加到系統systemd服務
- 利用GreatSQL部署MGR集群
- InnoDB Cluster+GreatSQL部署MGR集群
- 在Docker中部署GreatSQL並構建MGR集群
全文完。
Enjoy GreatSQL