共计 12171 个字符,预计需要花费 31 分钟才能阅读完成。
欢送来到 GreatSQL 社区分享的 MySQL 技术文章,如有疑难或想学习的内容,能够在下方评论区留言,看到后会进行解答
- GreatSQL 社区原创内容未经受权不得随便应用,转载请分割小编并注明起源。
本次介绍如何利用 Docker 来将 GreatSQL 源码编译成二进制文件,以及制作二进制包、RPM 包等。
本文介绍的运行环境是 CentOS 7.9:
[root@greatsql ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@greatsql ~]# uname -a
Linux greatsql 3.10.0-1160.11.1.el7.x86_64 #1 SMP Fri Dec 18 16:34:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
1、筹备工作
1.1、配置 yum 源
开始编译之前,倡议先配置好 yum 源,不便装置一些工具。
以阿里、腾讯两大云主机为例,能够这样配置(两个 yum 源自行二选一):
[root@greatsql ~]# mv /etc/yum.repos.d/CentOS-Base.repo{,.orig}
#阿里云
[root@greatsql ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#腾讯云
[root@greatsql ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
#替换完后,更新缓存
[root@greatsql ~]# yum clean all
[root@greatsql ~]# yum makecache
1.2、装置 docker
[root@greatsql]# yum install -y docker
[root@greatsql]# systemctl start docker
1.3、提前下载几个必要的安装包
别离下载几个编译过程中须要的依赖包:
boost, https://boostorg.jfrog.io/artifactory/main/release/1.73.0/source/boost_1_73_0.tar.gz
git, https://github.com/git/git/archive/v2.27.0.tar.gz, 下载后重命名为 git-v2.27.0.tar.gz
patchelf, https://github.com/NixOS/patchelf/archive/refs/tags/0.12.tar.gz, 下载后重命名为 patchelf-0.12.tar.gz
rpcsvc-proto, https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4/rpcsvc-proto-1.4.tar.gz
下载 GreatSQL 源码包:https://gitee.com/GreatSQL/GreatSQL/archive/greatsql-8.0.25-15.tar.gz
1.4、构建 docker 镜像
用上面这份 Dockerfile 构建镜像,这里以 CentOS 7 为例:
FROM centos:7
ENV LANG en_US.utf8
RUN yum install -y epel-release && \
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo && \
yum clean all && \
yum makecache
RUN yum install -y yum-utils && \
yum install -y wget diffutils net-tools vim git gcc gcc-c++ automake libtool cmake cmake3 \
make psmisc openssl-devel zlib-devel readline-devel bzip2-devel expat-devel gflags-devel \
bison bison-devel flex wget unzip libcurl-devel libevent-devel libffi-devel lz4-devel lz4-static \
file clang bzip2 snappy-devel libxml2-devel libtirpc libtirpc-devel numactl-devel numactl-libs \
numactl gtest-devel openldap-devel openldap-clients rpcgen pam-devel valgrind boost-devel rpm* tar \
centos-release-scl libzstd libzstd-static libzstd-devel perl-Env perl-JSON time libaio-devel \
ncurses-devel ncurses-libs pam python-devel redhat-lsb-core scl-utils-build pkg-config ccache
RUN yum install -y devtoolset-10-gcc*
RUN echo 'scl enable devtoolset-10 bash' >> /root/.bash_profile
# update git
COPY git-v2.27.0.tar.gz /tmp/
RUN cd /tmp/ && tar -xzvf git-v2.27.0.tar.gz && cd git-2.27.0 && make prefix=/opt/git/ all && make prefix=/opt/git/ install
RUN mv /usr/bin/git /usr/bin/git.bk && ln -s /opt/git/bin/git /usr/bin/git
# update patchelf 0.12
COPY patchelf-0.12.tar.gz /tmp/
RUN cd /tmp && tar -xzvf patchelf-0.12.tar.gz && cd patchelf && ./bootstrap.sh && ./configure && make && make install
COPY rpcsvc-proto-1.4.tar.gz /tmp/rpcsvc-proto-1.4.tar.gz
RUN tar zxvf /tmp/rpcsvc-proto-1.4.tar.gz -C /tmp && cd /tmp/rpcsvc-proto-1.4/ && ./configure && make && make install
RUN rm -fr /tmp/*
COPY boost_1_73_0.tar.gz /opt/
RUN ln -fs /usr/bin/cmake3 /usr/bin/cmake
开始构建 docker 镜像,胜利后再保留到本地并导入本地镜像:
[root@greatsql ~]# docker build -t centos7-greatsql .
... ...
[root@greatsql ~]# docker save -o centos7-greatsql.tar centos7-greatsql
[root@greatsql ~]# docker load -i centos7-greatsql.tar
创立一个 docker 容器,并将 GreatSQL 源码包 copy 进去:
[root@greatsql ~]# docker run -itd --name greatsql --hostname=greatsql centos7-greatsql bash
[root@greatsql ~]# docker cp /opt/greatsql-8.0.25-15.tar.gz greatsql:/opt/
[root@greatsql ~]# docker exec -it greatsql bash
[root@greatsql /]# ls -l /opt/
-rw------- 1 root root 128699082 Jul 27 06:56 boost_1_73_0.tar.gz
drwxr-xr-x 5 root root 4096 Jul 28 06:38 git
-rw------- 1 1000 1000 526639994 Jul 27 05:59 greatsql-8.0.25-15.tar.gz
drwxr-xr-x 3 root root 4096 Jul 28 06:34 rh
2、编译 GreatSQL
进入容器后,解压 GreatSQL 和 boost 源码包:
[root@greatsql /]# tar zxf /opt/greatsql-8.0.25-15.tar.gz -C /opt
[root@greatsql /]# tar zxf /opt/boost_1_73_0.tar.gz -C /opt/greatsql-8.0.25-15/
2.1、只编译二进制文件
如果只是想在本机应用,则能够只编译出二进制文件即可,无需打包或制作 RPM 包。用上面的命令进行编译:
[root@greatsql /]# cmake3 /opt/greatsql-8.0.25-15 \
-DBUILD_TESTING=OFF -DUSE_GTAGS=OFF -DUSE_CTAGS=OFF \
-DUSE_ETAGS=OFF \-DUSE_CSCOPE=OFF -DWITH_TOKUDB=OFF \
-DBUILD_CONFIG=mysql_release -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DFEATURE_SET=community \
-DCMAKE_INSTALL_PREFIX=/usr/local/GreatSQL-8.0.25-15-Linux \
-DMYSQL_DATADIR=/usr/local/GreatSQL-8.0.25-15-Linux/data \
-DROUTER_INSTALL_LIBDIR=/usr/local/GreatSQL-8.0.25-15-Linux/lib/mysqlrouter/private \
-DROUTER_INSTALL_PLUGINDIR=/usr/local/GreatSQL-8.0.25-15-Linux/lib/mysqlrouter/plugin \
-DCOMPILATION_COMMENT='GreatSQL (GPL), Release 15, Revision e36e91b7242' \
-DWITH_PAM=ON -DWITH_ROCKSDB=ON -DROCKSDB_DISABLE_AVX2=1 -DROCKSDB_DISABLE_MARCH_NATIVE=1 \
-DWITH_INNODB_MEMCACHED=ON -DWITH_ZLIB=bundled -DWITH_NUMA=ON -DWITH_LDAP=system \
-DFORCE_INSOURCE_BUILD=1 -DWITH_LIBEVENT=bundled -DWITH_ZSTD=bundled \
-DWITH_BOOST=/opt/greatsql-8.0.25-15/boost_1_73_0
cmake 过程如果没报错,就会输入相似上面的后果:
... ...
-- Build files have been written to: /opt/greatsql-8.0.25-15
接下来能够开始正式编译了:
[root@greatsql ~]# make -j30 VERBOSE=1 && make install
参数 -j30 设定为并行编译的逻辑 CPU 数量,能够指定为比逻辑 CPU 总数少一点,不要把所有 CPU 都跑满。
编译实现后,就会将二进制文件装置到 /usr/local/GreatSQL-8.0.25-15-Linux.x86_64 目录下。
2.2、编译并打包成二进制文件包或 RPM 包
如果是想要在编译完后也能拷贝到其余服务器上应用,也能够间接编译生成二进制包或 RPM 包,能够用上面的命令编译:
[root@greatsql ~]# cd /opt/greatsql-8.0.25-15/build-gs/
[root@greatsql ~]# export your_processors=30 #同上,批改并行 CPU 数量
[root@greatsql ~]# export TAR_PROCESSORS=-T$your_processors
[root@greatsql ~]# export MAKE_JFLAG=-j$your_processors
[root@greatsql ~]# mkdir -p workdir
[root@greatsql ~]# cp /opt/boost_1_73_0.tar.gz /opt/greatsql-8.0.25-15/build-gs/
[root@greatsql ~]# cp /opt/greatsql-8.0.25-15.tar.gz /opt/greatsql-8.0.25-15/build-gs/workdir/
# 抉择 1:编译并打包成二进制包
[root@greatsql ~]# bash -xe ./percona-server-8.0_builder.sh --builddir=`pwd`/workdir --get_sources=0 --install_deps=0 --with_ssl=1 --build_tarball=1 --build_src_rpm=0 --build_rpm=0 --no_git_info=1 --local_boost=1
# 抉择 2:编译并打包成 RPM 包
[root@greatsql ~]# bash -xe ./percona-server-8.0_builder.sh --builddir=`pwd`/workdir --get_sources=0 --install_deps=0 --with_ssl=1 --build_tarball=0 --build_src_rpm=1 --build_rpm=1 --no_git_info=1 --local_boost=1
编译过程中如果遇到相似上面的 patchelf 报错:
+ patchelf --replace-needed libreadline.so.7 libreadline.so bin/mysql
patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections
能够参考这个 patch:patchelf: Fix alignment issues with contiguous note sections #275,批改下源码,在容器里从新手动编译 patchelf。
编译完结后,就会在 /opt/greatsql-8.0.25-15/build-gs/workdir/ 目录下生成相应的二进制包、RPM 包:
[root@greatsql build-gs]# du -sh workdir/TARGET/
40M workdir/TARGET/GreatSQL-8.0.25-15-Linux-glibc2.17-x86_64-minimal.tar.xz
500M workdir/TARGET/GreatSQL-8.0.25-15-Linux-glibc2.17-x86_64.tar.xz
[root@greatsql build-gs]# du -sh workdir/rpm/greatsql-*
14M workdir/rpm/greatsql-client-8.0.25-15.1.el8.x86_64.rpm
30M workdir/rpm/greatsql-client-debuginfo-8.0.25-15.1.el8.x86_64.rpm
3.4M workdir/rpm/greatsql-debuginfo-8.0.25-15.1.el8.x86_64.rpm
23M workdir/rpm/greatsql-debugsource-8.0.25-15.1.el8.x86_64.rpm
2.1M workdir/rpm/greatsql-devel-8.0.25-15.1.el8.x86_64.rpm
4.6M workdir/rpm/greatsql-mysql-router-8.0.25-15.1.el8.x86_64.rpm
27M workdir/rpm/greatsql-mysql-router-debuginfo-8.0.25-15.1.el8.x86_64.rpm
13M workdir/rpm/greatsql-rocksdb-8.0.25-15.1.el8.x86_64.rpm
204M workdir/rpm/greatsql-rocksdb-debuginfo-8.0.25-15.1.el8.x86_64.rpm
60M workdir/rpm/greatsql-server-8.0.25-15.1.el8.x86_64.rpm
343M workdir/rpm/greatsql-server-debuginfo-8.0.25-15.1.el8.x86_64.rpm
1.4M workdir/rpm/greatsql-shared-8.0.25-15.1.el8.x86_64.rpm
2.5M workdir/rpm/greatsql-shared-debuginfo-8.0.25-15.1.el8.x86_64.rpm
440M workdir/rpm/greatsql-test-8.0.25-15.1.el8.x86_64.rpm
18M workdir/rpm/greatsql-test-debuginfo-8.0.25-15.1.el8.x86_64.rpm
这就能够用在 copy 到其余服务器上安装应用了。
3、初始化 GreatSQL
本次打算在上面 3 台服务器上部署 MGR 集群:
先在 nodeA 服务器上执行上面的初始化工作,另外两个服务器也照做一遍即可。
首先编辑 /etc/my.cnf 配置文件,可参考采纳上面的配置参数:
#my.cnf
[mysqld]
user = mysql
port = 3306
#主从复制或 MGR 集群中,server_id 记得要不同
#另外,实例启动时会生成 auto.cnf,外面的 server_uuid 值也要不同
#server_uuid 的值还能够本人手动指定,只有合乎 uuid 的格局规范就能够
server_id = 3306
basedir=/usr/local/GreatSQL-8.0.25-15-Linux.x86_64
datadir = /data/GreatSQL
socket = /data/GreatSQL/mysql.sock
pid-file = mysql.pid
character-set-server = UTF8MB4
skip_name_resolve = 1
#若你的 MySQL 数据库次要运行在境外,请务必依据理论状况调整本参数
default_time_zone = "+8:00"
#performance setttings
lock_wait_timeout = 3600
open_files_limit = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
thread_stack = 512K
sort_buffer_size = 4M
join_buffer_size = 4M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
thread_cache_size = 768
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
#log settings
log_timestamps = SYSTEM
log_error = /data/GreatSQL/error.log
log_error_verbosity = 3
slow_query_log = 1
log_slow_extra = 1
slow_query_log_file = /data/GreatSQL/slow.log
long_query_time = 0.1
log_queries_not_using_indexes = 1
log_throttle_queries_not_using_indexes = 60
min_examined_row_limit = 100
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_bin = /data/GreatSQL/binlog
binlog_format = ROW
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
binlog_rows_query_log_events = 1
binlog_expire_logs_seconds = 604800
#MySQL 8.0.22 前,想启用 MGR 的话,须要设置 binlog_checksum=NONE 才行
binlog_checksum = CRC32
gtid_mode = ON
enforce_gtid_consistency = TRUE
#myisam settings
key_buffer_size = 32M
myisam_sort_buffer_size = 128M
#replication settings
master_info_repository = TABLE
relay_log_info_repository = TABLE
relay_log_recovery = 1
slave_parallel_type = LOGICAL_CLOCK
#能够设置为逻辑 CPU 数量的 2 倍
slave_parallel_workers = 64
binlog_transaction_dependency_tracking = WRITESET
slave_preserve_commit_order = 1
slave_checkpoint_period = 2
#mgr settings
loose-plugin_load_add = 'mysql_clone.so'
loose-plugin_load_add = 'group_replication.so'
loose-group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1"
#MGR 本地节点 IP:PORT,请自行替换
loose-group_replication_local_address = "172.16.16.10:33061"
#MGR 集群所有节点 IP:PORT,请自行替换
loose-group_replication_group_seeds = "172.16.16.10:33061,172.16.16.11:33061,172.16.16.12:33061"
loose-group_replication_start_on_boot = OFF
loose-group_replication_bootstrap_group = OFF
loose-group_replication_exit_state_action = READ_ONLY
loose-group_replication_flow_control_mode = "DISABLED"
loose-group_replication_single_primary_mode = ON
#innodb settings
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 64G
innodb_buffer_pool_instances = 8
innodb_data_file_path = ibdata1:12M:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 3
innodb_max_undo_log_size = 4G
# 依据您的服务器 IOPS 能力适当调整
# 个别配一般 SSD 盘的话,能够调整到 10000 - 20000
# 配置高端 PCIe SSD 卡的话,则能够调整的更高,比方 50000 - 80000
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_open_files = 65535
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_online_alter_log_max_size = 4G
innodb_print_ddl_logs = 1
innodb_status_file = 1
#留神: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致 log_error 文件增长较快
innodb_status_output = 0
innodb_status_output_locks = 1
innodb_sort_buffer_size = 67108864
#innodb monitor settings
innodb_monitor_enable = "module_innodb"
innodb_monitor_enable = "module_server"
innodb_monitor_enable = "module_dml"
innodb_monitor_enable = "module_ddl"
innodb_monitor_enable = "module_trx"
innodb_monitor_enable = "module_os"
innodb_monitor_enable = "module_purge"
innodb_monitor_enable = "module_log"
innodb_monitor_enable = "module_lock"
innodb_monitor_enable = "module_buffer"
innodb_monitor_enable = "module_index"
innodb_monitor_enable = "module_ibuf_system"
innodb_monitor_enable = "module_buffer_page"
innodb_monitor_enable = "module_adaptive_hash"
#pfs settings
performance_schema = 1
#performance_schema_instrument = '%memory%=on'
performance_schema_instrument = '%lock%=on'
执行上面的命令进行初始化:
[root@greatsql ~]# /usr/local/GreatSQL-8.0.25-15-Linux.x86_64/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure
初始化时可选项有 –initialize 和 –initialize-insecure 两种,前者会为 root 账号生成一个随机明码,后者不会。在这里为了省事,选用后者,生产环境里请务必要为 root 用户设置平安明码。
之后就能够启动 mysqld 过程了:
[root@greatsql ~]# /usr/local/GreatSQL-8.0.25-15-Linux.x86_64/bin/mysqld --defaults-file=/etc/my.cnf &
GreatSQL 是基于 Percona Server 的分支版本,默认状况下须要用到 jemalloc 这个库,如果启动过程中报告相似上面的谬误,只须要再装置 jemalloc 或者 libaio 等相干的软件包即可:
/usr/local/GreatSQL-8.0.25-15/bin/mysqld: error while loading shared libraries: libjemalloc.so.1: cannot open shared object file: No such file or directory
补充装置 libjemalloc 库即可:
[root@greatsql ~]# yum install -y jemalloc jemalloc-devel
如果想要敞开 mysqld 过程,执行上面的命令即可:
# 假如此时 root 还是空明码
[root@greatsql ~]# /usr/local/GreatSQL-8.0.25-15-Linux.x86_64/bin/mysql -uroot -S/data/GreatSQL/mysql.sock shutdown
查看版本号:
root@GreatSQL [(none)]> \s
...
Server version: 8.0.25-15 GreatSQL, Release 15, Revision 80bbf22abbd
...
Enjoy GreatSQL :)
本文由博客一文多发平台 OpenWrite 公布!