编译源码安装


本次介绍如何利用Docker来编译GreatSQL源码。

1. 下载GeratSQL源码及Docker压缩包

1.1 下载Docker编译环境压缩包

戳此下载编译源码安装 - 图1 (opens new window)GreatSQL Docker编译环境压缩包greatsql_docker_build.tar.xz编译源码安装 - 图2 (opens new window)

将压缩包放在 /opt/ 目录下:

  1. $ cd /opt/
  2. $ tar xf greatsql_docker_build.tar.xz
  3. $ cd greatsql_docker_build
  4. $ ls
  5. Dockerfile greatsql-automake.sh greatsql-docker-build.sh patchelf-0.12.tar.gz rpcsvc-proto-1.4.tar.gz

下载 boost_1_73_0 源码包:

  1. $ pwd
  2. /opt/greatsql_docker_build
  3. $ curl -o boost_1_73_0.tar.gz https://nchc.dl.sourceforge.net/project/boost/boost/1.73.0/boost_1_73_0.tar.gz
  4. $ ls
  5. boost_1_73_0.tar.gz Dockerfile greatsql-automake.sh greatsql-docker-build.sh patchelf-0.12.tar.gz rpcsvc-proto-1.4.tar.gz

1.2 下载GreatSQL源码

戳此下载编译源码安装 - 图3 (opens new window)GreatSQL源码压缩包,解压缩后放在 /opt 目录下。

或者也可以直接用git下载,将源码放在 /opt/ 目录下:

  1. $ cd /opt/
  2. $ git clone https://gitee.com/GreatSQL/GreatSQL.git
  3. $ mv greatsql greatsql-8.0.25-16

2. 构建Docker编译环境

执行脚本 greatsql_docker_build.sh 开始构建Docker编译环境:

  1. $ cd /opt/greatsql_docker_build
  2. $ sh ./greatsql_docker_build.sh /opt/greatsql-8.0.25-16

执行脚本后面带的参数 /opt/greatsql-8.0.25-16 是指GreatSQL源码所在目录。 之后就会自动开始构建Docker环境了:

  1. $ sh ./greatsql_docker_build.sh /opt/greatsql-8.0.25-16
  2. Sending build context to Docker daemon 411.9MB
  3. Step 1/14 : FROM centos
  4. ---> 5d0da3dc9764
  5. Step 2/14 : ENV container docker
  6. ---> Using cache
  7. ---> 49a38409329a
  8. ...
  9. Step 14/14 : COPY boost_1_73_0.tar.gz /opt/
  10. ---> 55a506d50850
  11. Successfully built 55a506d50850
  12. Successfully tagged greatsql_build_env:latest
  13. Docker build success!you can run it:
  14. docker run -d -v /opt/greatsql-8.0.25-16:/opt/greatsql-8.0.25-16 greatsql_build_env

3. 进入Docker容器编译GreatSQL

根据上面的提示,创建一个新容器用于编译GreatSQL:

  1. $ docker run -d -v /opt/greatsql-8.0.25-16:/opt/greatsql-8.0.25-16 greatsql_build_env
  2. cc6500484dad5c905f00167e274f833bb722eff83269a51a2eb058013aaccfb4

找到正确的容器ID,进入该容器,准备开始编译:

  1. $ docker ps -a | grep greatsql_build
  2. cc6500484dad greatsql_build_env "/usr/sbin/init" 2 minutes ago Up 2 minutes strange_borg
  3. $ docker exec -it cc6500484dad bash
  4. [root@cc6500484dad /]#
  5. [root@cc6500484dad /]# cd /opt
  6. [root@cc6500484dad opt]# ls
  7. boost_1_73_0.tar.gz greatsql-8.0.25-16 greatsql-automake.sh rh
  8. [root@cc6500484dad opt]# tar zxf boost_1_73_0.tar.gz

编辑 /opt/greatsql_docker_build/greatsql-automake.sh 脚本,确认其中文件目录、版本号等信息是否正确:

  1. #!/bin/bash
  2. MAJOR_VERSION=8
  3. MINOR_VERSION=0
  4. PATCH_VERSION=25
  5. RELEASE=16
  6. REVISION=8bb0e5af297
  7. GLIBC=2.28
  8. ARCH=x86_64
  9. MYSQL=GreatSQL
  10. PKG_NAME=${MYSQL}-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}-${RELEASE}-Linux-glibc${GLIBC}-${ARCH}
  11. BASE_DIR=/usr/local/${PKG_NAME}
  12. BOOST_VERSION=1_73_0
  13. SOURCE_DIR=greatsql-8.0.25-16
  14. ...

确认都没问题的话,就可以执行该脚本开始编译源码了:

  1. # 记得执行这步,切换到gcc 10编译环境下
  2. $ source ~/.bash_profile
  3. $ time sh /opt/greatsql_docker_build/greatsql-automake.sh
  4. -- Running cmake version 3.20.2
  5. -- Found Git: /usr/bin/git (found version "2.27.0")
  6. CMake Deprecation Warning at cmake/cmake_policies.cmake:54 (CMAKE_POLICY):
  7. The OLD behavior for policy CMP0075 will be removed from a future version
  8. of CMake.
  9. ...
  10. -- Up-to-date: /usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64/man/man8/mysqld.8
  11. -- Up-to-date: /usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64/man/man1/mysqlrouter.1
  12. -- Up-to-date: /usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64/man/man1/mysqlrouter_passwd.1
  13. -- Up-to-date: /usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64/man/man1/mysqlrouter_plugin_info.1

编译过程中如果没问题,就会在 /usr/local 目录下生成GreatSQL二进制安装文件,例如:

  1. $ ls /usr/local/GreatSQL-8.0.25-16-Linux-glibc2.28-x86_64
  2. bin docs lib LICENSE.router man mysql-test README.md-test run support-files var
  3. cmake include LICENSE LICENSE-test mysqlrouter-log-rotate README.md README.router share usr

至此,GreatSQL二进制安装包就编译成功了,接下来可以参考文档二进制包安装并构建MGR集群继续进行数据库的初始化,以及MGR集群构建等工作,这里不赘述。

4. 相关资源

greatsql_docker_build 最新版本详见:https://gitee.com/GreatSQL/GreatSQL-Doc/tree/master/greatsql_docker_build编译源码安装 - 图4 (opens new window)

延伸阅读

问题反馈

联系我们

扫码关注微信公众号

输入图片说明