在Ubuntu下编译安装GreatSQL
本次介绍如何利用Docker构建Ubuntu环境,并将GreatSQL源码编译成二进制文件。
1、准备工作
先创建本次Docker的workdir为 /data/docker-ubuntu:
[root@greatsql ~]# mdkir /data/docker-ubuntu
1.1、配置Ubuntu环境下的apt源配置文件
开始编译之前,建议先配置好apt源,这样后续部署环境下载软件包时速度更快。
以阿里、腾讯两大云主机为例,可以这样配置(两个apt源自行二选一):
#腾讯云
[root@greatsql ~]# cat /data/docker-ubuntu/ubuntu-20.4-sources.list
deb http://mirrors.cloud.tencent.com/ubuntu/ focal main restricted
deb http://mirrors.cloud.tencent.com/ubuntu/ focal-updates main restricted
deb http://mirrors.cloud.tencent.com/ubuntu/ focal universe
deb http://mirrors.cloud.tencent.com/ubuntu/ focal-updates universe
deb http://mirrors.cloud.tencent.com/ubuntu/ focal multiverse
deb http://mirrors.cloud.tencent.com/ubuntu/ focal-updates multiverse
deb http://mirrors.cloud.tencent.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.cloud.tencent.com/ubuntu/ focal-security main restricted
deb http://mirrors.cloud.tencent.com/ubuntu/ focal-security universe
deb http://mirrors.cloud.tencent.com/ubuntu/ focal-security multiverse
如果是阿里云的话换成下面的内容
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
deb http://mirrors.aliyun.com/ubuntu/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-security universe
deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse
这个文件先准备好,后面会在Dockerfile里用到它。
另外,从我自己测试的情况,在构建docker镜像的过程中,阿里云的源更容易出错,请自行测试选定。
安装Docker,下载boost、GreatSQL源码包等这些工作我直接略过了,可直接参考这篇文档:在Linux下源码编译安装GreatSQL。
我还准备了一份自动化编译GreatSQL的shell脚本,可以自取服用:
[root@greatsql ~]# cat /data/docker-ubuntu/greatsql-automake.sh
#!/bin/bash
MAJOR_VERSION=8
MINOR_VERSION=0
PATCH_VERSION=25
RELEASE=15
REVISION=`date +%Y%m%d%H%M`
BASE_DIR=/usr/local/GreatSQL-8.0.25
JOBS=16
#reversion=`echo $RANDOM | sha256sum | cut -c1-11` && echo $reversion;
cmake . -DBOOST_INCLUDE_DIR=../boost_1_73_0 -DCMAKE_INSTALL_PREFIX=${BASE_DIR} -DWITH_ZLIB=bundled \
-DWITH_NUMA=ON -DFORCE_INSOURCE_BUILD=1 -DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_CONFIG=mysql_release \
-DCOMPILATION_COMMENT="GreatSQL (GPL), Release ${RELEASE}, Revision ${REVISION}" \
-DWITH_TOKUDB=OFF -DWITH_ROCKSDB=OFF -DWITH_COREDUMPER=OFF \
-DMAJOR_VERSION=${MAJOR_VERSION} -DMINOR_VERSION=${MINOR_VERSION} -DPATCH_VERSION=${PATCH_VERSION} && \
make -j${JOBS} VERBOSE=1 && make install
1.2、构建docker镜像
用下面这份Dockerfile构建Ubuntu镜像:
FROM ubuntu
ENV LANG en_US.utf8
ARG UID=1001
ARG GID=1001
ARG UNAME=mysql
#ENV TZ Asia/Shanghai
ENV PATH="/usr/local/mysql/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/loca/mysql/lib:${LD_LIBRARY_PATH}"
ENV TERM=xterm
COPY ubuntu-20.4-sources.list /etc/apt/sources.list
#RUN apt-get update && apt-get install -y --no-install-recommends tzdata && rm -rf /var/lib/apt/lists/*
RUN apt update && apt install -y --no-install-recommends tzdata && rm -rf /var/lib/apt/lists/*
ENV TZ Asia/Shanghai
RUN apt update -y && apt upgrade -y && \
apt install -y --fix-missing gcc-10 cmake automake build-essential diffutils git lbzip2 libaio-dev libbison-dev \
libcurl4-openssl-dev libevent-dev libexpat1-dev libffi-dev libgflags-dev libgtest-dev libjemalloc-dev \
libldap2-dev liblz4-dev libncurses-dev libnuma-dev libreadline-dev libsnappy-dev libssh-dev libtirpc-dev \
libtool libxml2-dev libzstd-dev make net-tools numactl pkg-config psmisc vim wget \
&& groupadd -g $GID -o $UNAME && useradd -m -g $GID -u $UID -o -s /bin/bash $UNAME \
&& /usr/bin/install -m 0775 -o mysql -g root -d /var/lib/mysql /var/run/mysqld /docker-entrypoint-initdb.d \
&& /usr/bin/install -m 0664 -o mysql -g root /dev/null /etc/sysconfig/mysql
COPY patchelf-0.12.tar.gz /tmp/
RUN cd /tmp && tar -xzvf patchelf-0.12.tar.gz && cd patchelf-0.12 && ./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
COPY boost_1_73_0.tar.gz /opt/
COPY greatsql-automake.sh /opt/
RUN rm -fr /tmp/*
开始构建docker镜像,成功后再保存到本地并导入本地镜像:
[root@greatsql ~]# docker build -t docker-ubuntu .
... ...
[root@greatsql ~]# docker save -o docker-ubuntu.tar docker-ubuntu
[root@greatsql ~]# docker load -i docker-ubuntu.tar
创建一个docker容器,并将GreatSQL源码包copy进去:
[root@greatsql ~]# docker run -itd --name greatsql --hostname=greatsql docker-ubuntu
[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
-rw------- 1 1000 1000 526639994 Jul 27 05:59 greatsql-8.0.25-15.tar.gz
-rw-r--r-- 1 root root 751 Nov 12 15:25 greatsql-automake.sh
其他不同OS及架构平台下的Dockerfile可戳下面链接参考:
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/
可直接调用自动化编译脚本开始编译,也可以自行手动编译:
[root@greatsql /]# cd /opt/greatsql-8.0.25
[root@greatsql /]# /bin/bash /opt/greatsql-automake.sh
...
编译完成后,就会将二进制文件安装到 /usr/local/GreatSQL-8.0.25 目录下,执行下面的命令检查测试:
[root@greatsql /]# /usr/local/GreatSQL-8.0.25/bin/mysqld --verbose --version
/usr/local/GreatSQL-8.0.25/bin/mysqld Ver 8.0.25-15 for Linux on x86_64 (GreatSQL (GPL), Release 15, Revision 202111121536)
这就编译完成了。
全文完。
Enjoy GreatSQL :)
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦