升级MySQL Shell for GreatSQL版本
0. 写在前面
GreatSQL 8.0.32-24已发布,配套的MySQL Shell也需要跟着升级一波,MySQL Shell版本从8.0.25升级到8.0.32后,也引入了一些不错的新特性。
下面正式开始MySQL Shell编译工作。
1. 准备工作
1.1 准备Docker环境
参考编译环境要求 greatsql_docker_build(https://gitee.com/GreatSQL/GreatSQL-Doc/blob/master/greatsql_shell_docker_build/Dockerfile) ,构建好一个Docker镜像环境,基本上照着做就行,这里不赘述。
1.2 下载源码包
先下载准备好下列几个源码包:
- antlr4-cpp-runtime-4.10-source.zip, https://github.com/antlr/website-antlr4/blob/gh-pages/download/antlr4-cpp-runtime-4.10-source.zip
- boost_1_77_0.tar.gz, https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.gz
- mysql-8.0.32.tar.gz, https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.32.tar.gz
- mysql-shell-8.0.32-src.tar.gz, https://downloads.mysql.com/archives/get/p/43/file/mysql-shell-8.0.32-src.tar.gz
- patchelf-0.14.5.tar.gz, https://github.com/NixOS/patchelf/releases/download/0.14.5/patchelf-0.14.5.tar.gz
- protobuf-all-3.19.4.tar.gz, https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protobuf-all-3.19.4.tar.gz
- rpcsvc-proto-1.4.tar.gz, https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4/rpcsvc-proto-1.4.tar.gz
下载完后都放在 /opt/
目录下,并解压缩。
1.3 修改MySQL Shell源码包
打开链接:https://gitee.com/GreatSQL/GreatSQL-Doc/blob/master/greatsql_shell_docker_build/mysqlsh-for-greatsql-8.0.32.patch,下载GreatSQL补丁包文件 mysqlsh-for-greatsql-8.0.32.patch。
为了让MySQL Shell支持GreatSQL仲裁节点(ARBITRATOR)特性,需要打上补丁包:
代码语言:javascript复制$ cd /opt/mysql-shell-8.0.32-src
$ patch -p1 -f < /opt/mysqlsh-for-greatsql-8.0.32.patch
patching file mysqlshdk/libs/mysql/group_replication.cc
patching file mysqlshdk/libs/mysql/group_replication.h
1.4 编译相关软件包
1.43.1 antlr4-4.10
编译antlr4需要依赖 uuid
库,先安装上:
$ yum install -y libuuid libuuid-devel uuid
接着开始编译antlr4:
代码语言:javascript复制$ cd /opt/antlr4-4.10/runtime/Cpp/
$ mkdir bld && cd bld
$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/antlr4 && make -j16 && make -j16 install
1.4.2 patchelf-0.14.5
代码语言:javascript复制$ cd /opt/patchelf-0.14.5
$ ./bootstrap.sh && ./configure && make -j16 && make -j16 install
1.4.3 protobuf-3.19.4
代码语言:javascript复制$ cd /opt/protobuf-3.19.4
$ ./configure && make -j16 && make -j16 install
1.4.4 rpcsvc-proto-1.4
代码语言:javascript复制$ cd /opt/rpcsvc-proto-1.4
$ ./configure && make -j16 && make -j16 install
2. 准备编译MySQL Shell
2.1 编译MySQL 8.0.32
在MySQL 8.0.32源码目录中,编译生成MySQL客户端相关依赖库,这是编译MySQL Shell之前要先做的事:
代码语言:javascript复制$ cd /opt/mysql-8.0.32
$ mkdir bld && cd bld
$ cmake .. -DBOOST_INCLUDE_DIR=/opt/boost_1_77_0
-DLOCAL_BOOST_DIR=/opt/boost_1_77_0
-DWITH_SSL=system &&
cmake --build . --target mysqlclient -- -j16;
cmake --build . --target mysqlxclient -- -j16
P.S,在 cmake
后面加上 -- -j16
的作用是多线程并行编译,这样速度更快,不加的话只能单线程编译,速度比较慢。
2.2 编译MySQL Shell 8.0.32
编译完成后,切换到MySQL Shell源码目录下,准备继续编译:
代码语言:javascript复制$ cd /opt/mysql-shell-8.0.32-src/
$ mkdir bld && cd bld
$ cmake ..
-DCMAKE_INSTALL_PREFIX=/usr/local/greatsql-shell-8.0.32-24-Linux-glibc2.28-x86_64
-DMYSQL_SOURCE_DIR=/opt/mysql-8.0.32
-DMYSQL_BUILD_DIR=/opt/mysql-8.0.32/bld/
-DHAVE_PYTHON=1
-DWITH_PROTOBUF=bundled
-DBUILD_SOURCE_PACKAGE=0
-DBUNDLED_ANTLR_DIR=/usr/local/antlr4/
&& make && make install
测试提示错误信息:
代码语言:javascript复制CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
(Required is at least version "3.8")
这表示需要先安装Python 3.8相关软件包,因为还需要libssh,就一并安装:
代码语言:javascript复制$ yum install -y python38 python38-devel python38-libs python38-pyyaml libssh libssh-config libssh-devel
再次编译,并指定Python 3.8的相关路径:
代码语言:javascript复制$ cmake ..
-DCMAKE_INSTALL_PREFIX=/usr/local/greatsql-shell-8.0.32-24-Linux-glibc2.28-x86_64
-DMYSQL_SOURCE_DIR=/opt/mysql-8.0.32
-DMYSQL_BUILD_DIR=/opt/mysql-8.0.32/bld/
-DHAVE_PYTHON=1
-DWITH_PROTOBUF=bundled
-DBUILD_SOURCE_PACKAGE=0
-DBUNDLED_ANTLR_DIR=/usr/local/antlr4/
-DPYTHON_LIBRARIES=/usr/lib64/python3.8 -DPYTHON_INCLUDE_DIRS=/usr/include/python3.8/
&& make -j16 && make -j16 install
编译完成后,会把二进制文件安装到 /usr/local/greatsql-shell-8.0.32-24-Linux-glibc2.28-x86_64
目录下。
2.3 运行测试
运行 mysqlsh
,看是否能直接跑起来:
$ cd /usr/local/greatsql-shell-8.0.32-24-Linux-glibc2.28-x86_64
$ ./bin/mysqlsh
./bin/mysqlsh: error while loading shared libraries: libprotobuf.so.30: cannot open shared object file: No such file or directory
提示无法找到动态库文件 libprotobuf.so.30
。实际上这个动态库文件在 /usr/local/lib
目录下,只需将其拷贝一份到MySQL Shell的lib目录下即可:
$ cp /usr/local/lib/libprotobuf.so.30 lib/mysqlsh/
$ ldd bin/mysqlsh | grep libprotobuf.so
libprotobuf.so.30 => /usr/local/greatsql-shell-8.0.32-24-Linux-glibc2.28-x86_64/bin/../lib/mysqlsh/libprotobuf.so.30 (0x00007f60660a2000)
这次找到依赖库文件了。
运行 mysqlsh
,看能否正常使用:
$ ./bin/mysqlsh
MySQL Shell 8.0.32
...
Type 'help' or '?' for help; 'quit' to exit.
WARNING: Found errors loading plugins, for more details look at the log at: /root/.mysqlsh/mysqlsh.log
MySQL Py > q
Bye!
看到有 WARNING 提示,检查日志文件 /root/.mysqlsh/mysqlsh.log
,看到有了类似下面的内容:
ModuleNotFoundError: No module named 'certifi'
只需用pip安装相应模块即可:
代码语言:javascript复制$ pip3.8 install --user certifi
好了,开始感受GreatSQL 8.0.32-24新版本特性,以及MGR仲裁节点的魅力吧 O(∩_∩)O哈哈~
3. 写在最后
折腾完这些,是不是感觉还是有点麻烦?没关系,我已经把这些工作都封装到docker镜像中了,包括Dockerfile以及自动编译脚本。下面简单介绍下怎么用。
自行下载MySQL和MySQL Shell,以及boost源码包,上面已经给过下载地址了。
下载完后都放在 /opt/
目录下,并解压缩。
下载 MySQL Shell for GreatSQL编译辅助包(https://product.greatdb.com/GreatSQL/greatsql-shell-requirement-pkg.tar.xz),解压缩到 /opt/
目录下。
执行下面命令构建docker镜像:
代码语言:javascript复制$ cd /opt/greatsql_shell_docker_build
$ sh ./greatsql-shell-docker-build.sh /opt/mysql-8.0.32/ /opt/mysql-shell-8.0.32-src/ /opt/boost_1_77_0
说明: 上述命令中,脚本后面跟着三个目录参数,分别对应MySQL、MySQL Shell、boost源码全路径。
之后就可以自动完成MySQL Shell for GreatSQL编译docker容器环境,启动并进入该容器:
代码语言:javascript复制$ docker images | grep -i greatsql_shell
greatsql_shell_build_env latest 4db9dcd3c563 About an hour ago 4.1GB
$ docker run -d
-v /opt/mysql-8.0.32:/opt/mysql-8.0.32
-v /opt/mysql-shell-8.0.32-src:/opt/mysql-shell-8.0.32-src
-v /opt/boost_1_77_0:/opt/boost_1_77_0
--name greatsql_shell_build_env greatsql_shell_build_env
$ docker exec -it greatsql_shell_build_env bash
进入容器后,编辑 /opt/greatsql-shell-automake.sh
脚本,确认其中文件目录是否都正确,确认都没问题的话,就可以执行该脚本开始编译源码了。
# 加载环境变量,并切换到高版本gcc编译环境
[root@a5cebc4c0276 opt]# cd /opt
[root@a5cebc4c0276 opt]# source ~/.bash_profile
[root@a5cebc4c0276 opt]# ls -la
total 136
drwxr-xr-x 1 root root 110 Jul 11 08:56 .
drwxr-xr-x 1 root root 62 Jul 11 08:08 ..
drwxr-xr-x 8 root root 4096 Aug 5 2021 boost_1_77_0
-rwxr-xr-x 1 root root 910 Jul 11 08:15 greatsql-shell-automake.sh
drwxr-xr-x 32 7161 31415 65536 Jul 11 08:12 mysql-8.0.32
drwxr-xr-x 18 root root 65536 Jul 11 08:15 mysql-shell-8.0.32-src
drwxr-xr-x 3 root root 28 Jul 11 07:27 rh
# 开始自动编译
[root@a5cebc4c0276 opt]# sh ./greatsql-shell-automake.sh
编译结束后,试着运行 mysqlsh
客户端,确认可用:
/usr/local/greatsql-mysql-shell-8.0.32-centos-glibc2.28-x86_64/bin/mysqlsh
MySQL Shell 8.0.32
Copyright (c) 2016, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type 'help' or '?' for help; 'quit' to exit.
MySQL Py >
看起来挺顺利的哈 :)