关于mysql:mysqlshell-for-GreatSQL-8027编译安装及使用

55次阅读

共计 7916 个字符,预计需要花费 20 分钟才能阅读完成。

[toc]

0. 前言

因为 GreatSQL 8.0.27 版本中引入 MGR 仲裁节点(投票节点,ARBITRATOR)个性,MySQL 提供的 mysql-shell 无奈辨认该个性,因而提供 mysql-shell for GreatSQL 版本。

1. 批改阐明

须要批改 mysql-shell 源码,减少对仲裁节点(投票节点)角色类型的反对,波及到两个文件:

  • mysqlshdk/libs/mysql/group_replication.h
  • mysqlshdk/libs/mysql/group_replication.cc
    Member_role 对象中减少 ARBITRATOR 角色类型即可。整个 patch 文件只有 35 行,很简略:
$ cat mysqlsh-for-greatsql-8.0.27.patch

diff --git a/mysqlshdk/libs/mysql/group_replication.cc b/mysqlshdk/libs/mysql/group_replication.cc
index ef6a8e1b9..9edbab628 100644
--- a/mysqlshdk/libs/mysql/group_replication.cc
+++ b/mysqlshdk/libs/mysql/group_replication.cc
@@ -108,6 +108,8 @@ std::string to_string(const Member_role role) {
       return "PRIMARY";
     case Member_role::SECONDARY:
       return "SECONDARY";
+    case Member_role::ARBITRATOR:
+      return "ARBITRATOR";
     case Member_role::NONE:
       return "NONE";
   }
@@ -119,6 +121,8 @@ Member_role to_member_role(const std::string &role) {return Member_role::PRIMARY;} else if (shcore::str_casecmp("SECONDARY", role.c_str()) == 0) {
     return Member_role::SECONDARY;
+  } else if (shcore::str_casecmp("ARBITRATOR", role.c_str()) == 0) {+    return Member_role::ARBITRATOR;} else if (role.empty()) {return Member_role::NONE;} else {
diff --git a/mysqlshdk/libs/mysql/group_replication.h b/mysqlshdk/libs/mysql/group_replication.h
index c76385e4b..1d957eae5 100644
--- a/mysqlshdk/libs/mysql/group_replication.h
+++ b/mysqlshdk/libs/mysql/group_replication.h
@@ -73,7 +73,7 @@ enum class Member_state {MISSING};

-enum class Member_role {PRIMARY, SECONDARY, NONE};
+enum class Member_role {PRIMARY, SECONDARY, ARBITRATOR, NONE};

 enum class Topology_mode {SINGLE_PRIMARY, MULTI_PRIMARY, NONE};

2. 编译 mysql-shell

从 MySQL 官网下载的 mysql-shell 8.0.27 源码包是有问题的,会导致编译失败,须要本人手动批改 CMakeLists.txt 文件。我曾经提交 bug(#106730)了,降级到 8.0.28 就能够了。

官网提供的参考文档 https://github.com/mysql/mysql-shell/blob/master/INSTALL 版本太老了(最初更新工夫 Aug 19, 2020),简直齐全不可用。

只好我本人摸索了。

2.1 环境筹备

下载几个相干的安装包:

  • protobuf-all-3.11.4.tar.gz,https://github.com/protocolbu…
  • mysql-8.0.27.tar.gz,https://downloads.mysql.com/a…
  • mysql-shell-8.0.27-src.tar.gz,https://downloads.mysql.com/a…
  • boost_1_73_0.tar.gz,https://boostorg.jfrog.io/art…
  • patchelf-0.14.5.tar.gz,https://github.com/NixOS/patc…
  • rpcsvc-proto, https://github.com/thkukuk/rp…

利用上面的 Dockerfile 构建一个 CentOS 8 的 docker 镜像,专门用于编译 mysql-shell:

FROM docker.io/arm64v8/centos

RUN rm -f /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Linux-AppStream.repo /etc/yum.repos.d/CentOS-Linux-BaseOS.repo && \
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
RUN yum install -y epel-release && \
yum clean all && \
yum makecache
RUN yum install -y --skip-broken yum-utils wget diffutils net-tools vim git gcc gcc-c++ automake libtool cmake cmake3 \
make psmisc openssl openssl-devel zlib-devel readline-devel bzip2-devel expat-devel  \
bison  flex wget unzip libcurl-devel libevent-devel libffi-devel lz4-devel \
file clang bzip2 libxml2-devel libtirpc libtirpc-devel numactl-devel numactl-libs \
numactl openldap-devel openldap-clients pam-devel valgrind boost-devel \
libzstd libzstd-devel patchelf perl perl-Env perl-JSON perl-Memoize perl-Time-HiRes time libaio-devel libarchive \
ncurses-devel ncurses-libs pam redhat-lsb-core scl-utils-build pkg-config ccache \
jemalloc jemalloc-devel libicu-devel re2-devel redhat-lsb-core rpm* tar libssh \
cyrus-sasl-devel cyrus-sasl-scram python36 python36-devel

RUN dnf install -y dnf
RUN dnf install -y gcc-toolset-10 && source /opt/rh/gcc-toolset-10/enable
RUN echo 'source /opt/rh/gcc-toolset-10/enable' >> /root/.bash_profile

#patchelf
COPY patchelf-0.14.5.tar.gz /tmp/

#rpcsvc-proto
COPY rpcsvc-proto-1.4.tar.gz /tmp/rpcsvc-proto-1.4.tar.gz

COPY boost_1_73_0.tar.gz /opt/

RUN rm -fr /tmp/*

接下来就是制作 docker 镜像包,而后再启动一个 docker 容器,具体过程办法可参考这篇文章:自制 GreatSQL Docker 镜像。

启动容器后,将之前下载的几个安装包都拷贝到容器中的 /opt/ 目录下并解压缩:

drwxr-xr-x  8 root   root      65536 Apr 22  2020 boost_1_73_0
-rw-------  1 root   root  128699082 Dec  7 08:34 boost_1_73_0.tar.gz
drwxr-xr-x 31   7161 31415     65536 Mar 15 06:30 mysql-8.0.27
-rw-r--r--  1 root   root  285550905 Mar 15 06:12 mysql-8.0.27.tar.gz
drwxr-xr-x 17 root   root      65536 Mar 15 07:12 mysql-shell-8.0.27-src
-rw-r--r--  1 root   root   81013338 Mar 15 06:12 mysql-shell-8.0.27-src.tar.gz
-rw-r--r--  1 root   root       1372 Mar 15 06:12 mysqlsh-for-greatsql-8.0.27.patch
-rw-r--r--  1 root   root     313132 Mar 16 09:26 patchelf-0.14.5-x86_64.tar.gz
drwxr-xr-x 18 411487 89939     65536 Mar 15 07:00 protobuf-3.11.4
-rw-r--r--  1 root   root    7408292 Mar 15 06:12 protobuf-all-3.11.4.tar.gz
drwxr-xr-x  3 root   root         28 Mar 15 06:01 rh
drwxr-xr-x  4   1000 users     65536 Mar 15 06:29 rpcsvc-proto-1.4
-rw-r--r--  1 root   root     149354 Dec  7 08:23 rpcsvc-proto-1.4.tar.gz

接下来先编译装置几个依赖包:

$ cd /opt/protobuf-3.11.4
./autogen.sh && ./configure && make && make install

$ cd /opt/rpcsvc-proto-1.4
./configure  && make && make install

2.2 开始编译 mysql & mysql-shell

复制执行上面的命令,一次性实现 mysql & mysql-shell 编译装置:

cd /opt/mysql-8.0.27 && \
rm -fr bld && \
mkdir bld && \
cd bld && \
cmake .. -DBOOST_INCLUDE_DIR=/opt/boost_1_73_0/ \
-DLOCAL_BOOST_DIR=/opt/boost_1_73_0/ \
-DWITH_SSL=system && \
cmake --build . --target mysqlclient; \
cmake --build . --target mysqlxclient && \
cd /opt/mysql-shell-8.0.27-src && \
rm -fr bld && \
mkdir bld && \
cd bld && \
cmake .. \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-shell-8.0.27-18-Linux-glibc2.28-x86_64 \
-DMYSQL_SOURCE_DIR=/opt/mysql-8.0.27 \
-DMYSQL_BUILD_DIR=/opt/mysql-8.0.27/bld/ \
-DHAVE_PYTHON=1 -DWITH_PROTOBUF=bundled && \
make -j64 && make install

编译实现后,会把二进制文件装置到 /usr/local/mysql-shell-8.0.27-18-Linux-glibc2.28-x86_64 目录下。

2.3 利用 patchelf 批改 mysqlsh 二进制文件

编译装置结束后,执行上面的命令,查看 mysqlsh 二进制文件的依赖关系是否都失常,会发现其中有个 so 依赖文件找不到:

$ cd /usr/local/mysql-shell-8.0.27-18-Linux-glibc2.28-x86_64
$ ldd bin/mysqlsh
        linux-vdso.so.1 (0x00007ffd3adce000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f96f73a8000)
...
        libprotobuf.so.22 => not found
...

这是因为 libprotobuf.so.22 这个动静库文件在 /usr/local/lib/ 目录下,所以找不到。

这时候,咱们能够利用 patchelf 批改 mysqlsh 文件,将依赖门路从绝对路径形式改成相对路径形式:

- 首先,新建一个目录
$ pwd
/usr/local/mysql-shell-8.0.27-18-Linux-glibc2.28-x86_64
$ mkdir -p lib/private
- 将 libprotobuf 动静库文件拷贝过去
$ cp /usr/local/lib/libprotobuf.so.22.0.4 lib/private
- 做一个软链接
$ cd lib/private/
$ ln -s libprotobuf.so.22.0.4 libprotobuf.so.22
- 再利用 patchelf 批改 mysqlsh
cd /usr/local/mysql-shell-8.0.27-18-Linux-glibc2.28-x86_64
$ patchelf --set-rpath '$ORIGIN/../lib/private' ./bin/mysqlsh
$ ldd bin/mysqlsh
cd ../..
[root@mysqlsh-c8 mysql-shell-8.0.27-18-Linux-glibc2.28-x86_64]# ldd bin/mysqlsh
        linux-vdso.so.1 (0x00007ffec77e1000)
...
        libprotobuf.so.22 => /usr/local/mysql-shell-8.0.27-18-Linux-glibc2.28-x86_64/bin/../lib/private/libprotobuf.so.22 (0x00007f2b8a5db000)

能够看到,mysqlsh 能找到 libprotobuf 这个动静库文件了,也就能够失常应用了。

3. 运行 mysql-shell for GreatSQL

如果想要让 mysql-shell 反对 JavaScript 语法,须要再编译时加上 libv8,但其难度太大了,我示意间接放弃。。。

尽管不反对 js 语法,但还是反对 Python 语法的呀,略有不同而已,上面举几个常见的例子作为参照比照:

js 语法 py 语法
$ var c=dba.getCluster() $c=dba.get_cluster()
c.status() c.statsu()
c.setPrimaryInstance() c.set_primary_instance()
c.switchToMultiPrimaryMode() c.switch_to_multi_primary_mode()
c.rebootClusterFromCompleteOutage() c.reboot_cluster_from_complete_outage()

看到了吧,其实也就是语法格调略有不同而已,没什么本质区别。

接下来能够玩转 GreatSQL 8.0.27 的仲裁节点新性能了:

 MySQL  172.16.16.12:33060+ ssl  Py > c.status()
{
    "clusterName": "GreatSQL8027",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "172.16.16.12:3306",
        "ssl": "REQUIRED",
        "status": "OK",
        "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
        "topology": {
            "172.16.16.10:3306": {
                "address": "172.16.16.10:3306",
                "memberRole": "ARBITRATOR",  <-- 仲裁节点
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": null,
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.27"
            },
            "172.16.16.11:3306": {
                "address": "172.16.16.11:3306",
                "memberRole": "SECONDARY",  <-- Secondary 节点
                "mode": "R/O",
                "readReplicas": {},
                "replicationLag": "00:00:00.001422",
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.27"
            },
            "172.16.16.12:3306": {
                "address": "172.16.16.12:3306",
                "memberRole": "PRIMARY",  <-- Primary 节点
                "mode": "R/W",
                "readReplicas": {},
                "replicationLag": null,
                "role": "HA",
                "status": "ONLINE",
                "version": "8.0.27"
            }
        },
        "topologyMode": "Single-Primary"
    },
    "groupInformationSourceMember": "172.16.16.12:3306"
}

对了,第一次启动 mysqlsh 时,可能会有相似上面的提醒:

WARNING: Found errors loading plugins, for more details look at the log at: /root/.mysqlsh/mysqlsh.log

只有执行上面的指令装置 certifi 这个 Python 模块即可:

$ pip3.6 install --user certifi

好了,开始感触 MGR 仲裁节点的魅力吧 O(∩_∩)O 哈哈~

P.S1:这是老叶长期抱佛脚的应急版本,可能还有诸多不欠缺的中央,前面会推出正式的版本。

PS2:GreatSQL 8.0.27 及 5.7.36 版本很快就会公布,请急躁期待。另外,如果是想应用 MGR 的话,强烈建议选用 8.0 版本,不要应用 5.7 版本,8.0 的 MGR 在性能和可靠性方面都要比 5.7 好太多。

本文完。

Enjoy GreatSQL :)

正文完
 0