X86

安装依赖

安装所需要的依赖

  • gcc
  • cmake
  • libaio 库

安装 gcc(11.2.0,可支持 从c++20和部分c++23)

  • 源码安装 11.2.0
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
wget http://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.gz
tar -zxvf gcc-11.2.0.tar.gz

# 安装依赖
sudo yum install bzip2
cd gcc-11.2.0
sudo ./contrib/download_prerequisites

# 配置
mkdir build
cd build/
../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
# –enable-languages 表示你要让你的gcc支持哪些语言
# –disable-multilib 不生成编译为其他平台可执行代码的交叉编译器
# –disable-checking 生成的编译器在编译过程中不做额外检查,
#也可以使用 *–enable-checking=xxx* 来增加一些检查

# 编译
# 比如有 128个cpu 核,就填 128,也就是 128线程编译,可以加速
sudo make -j 128

# 安装
sudo make install

# 验证
gcc -v
g++ -v
  • yum 安装 gcc 11.2
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 安装并启用 SCL 仓库
sudo yum install centos-release-scl

# 安装 gcc 11
sudo yum install devtoolset-11-gcc devtoolset-11-gcc-c++

# 启用
scl enable devtoolset-9 bash

# 可能要再手动配置下 /etc/profile

# 验证
gcc -v
g++ -v
  • 麒麟v10 安装 gcc 参考这篇文章
    安装好后替换下 LD_LIBRARY_PATH
1
export LD_LIBRARY_PATH=/usr/local/gcc-9.3.0/lib64/:$LD_LIBRARY_PATH
  • 安装 cmake
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 安装依赖
sudo yum groupinstall -y "Development Tools"
sudo yum install -y openssl-devel

wget https://github.com/Kitware/CMake/releases/download/v3.16.9/cmake-3.16.9.tar.gz
tar -zxvf cmake-3.16.9.tar.gz
cd cmake-3.16.9

# 编译安装
./bootstrap
make
sudo make install

# 检查
cmake --version
  • 安装 gdb(用于调试,实际部署时不需要
1
2
3
4
5
6
wget http://ftp.gnu.org/gnu/gdb/gdb-10.1.tar.gz
tar -xzf gdb-10.1.tar.gz
cd gdb-10.1
./configure
make
sudo make install

编译项目

项目的依赖

  • rapid-join
  • oracle client
  • lib-kafka
  • protobuf

下载依赖

  • 安装 rapidjson
1
2
3
RAPIDJSON_VERSION=1.1.0
wget https://github.com/Tencent/rapidjson/archive/refs/tags/v${RAPIDJSON_VERSION}.tar.gz
tar -xzf v1.1.0.tar.gz
  • 安装 oracle 客户端
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
ORACLE_MAJOR=19
ORACLE_MINOR=18

wget https://download.oracle.com/otn_software/linux/instantclient/${ORACLE_MAJOR}${ORACLE_MINOR}000/instantclient-basic-linux.x64-${ORACLE_MAJOR}.${ORACLE_MINOR}.0.0.0dbru.zip

unzip instantclient-basic-linux.x64-${ORACLE_MAJOR}.${ORACLE_MINOR}.0.0.0dbru.zip

wget https://download.oracle.com/otn_software/linux/instantclient/${ORACLE_MAJOR}${ORACLE_MINOR}000/instantclient-sdk-linux.x64-${ORACLE_MAJOR}.${ORACLE_MINOR}.0.0.0dbru.zip

unzip instantclient-sdk-linux.x64-${ORACLE_MAJOR}.${ORACLE_MINOR}.0.0.0dbru.zip
cd instantclient_${ORACLE_MAJOR}_${ORACLE_MINOR}
ln -s libclntshcore.so.${ORACLE_MAJOR}.1 libclntshcore.so

可选依赖

Kfaka
这个依赖不是必须的

1
2
3
4
5
6
7
8
wget https://github.com/confluentinc/librdkafka/archive/refs/tags/v1.9.2.tar.gz .
tar -zxvf v1.9.2.tar.gz

cd librdkafka-1.9.2/
# 编译
./configure --prefix=/opt/librdkafka
make
make install

promethes:
github 编译

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# fetch third-party dependencies
git submodule init
git submodule update

mkdir _build
cd _build

# run cmake
cmake .. -DBUILD_SHARED_LIBS=ON -DENABLE_PUSH=OFF -DENABLE_COMPRESSION=OFF

# build
cmake --build . --parallel 4

# run tests
ctest -V

# install the libraries and headers
cmake --install .

编译项目

进入到 根目录

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
mkdir build
cd build

# 执行 cmake 把这里的 rapidjson 和 oracle 的替换成实际的路径
cmake -DWITH_RAPIDJSON=/open_log/dependency/rapidjson -DWITH_OCI=/open_log/dependency/oracle/instantclient_19_18 ..

# 编译
make

# 上面两段也可以连起来
cmake -DWITH_RAPIDJSON=/open_log/dependency/rapidjson -DWITH_OCI=/open_log/dependency/oracle/instantclient_19_18 ..; make

运行

配置文件

非闪回权限

增加一个配置即可
参考 ->这里

disable-checks 的解释
A sum of numbers:

  • 0x0001 — During startup, don’t check if the database user has appropriate grants to system tables.
  • 0x0002 — During startup, don’t check if listed tables contain supplemental logging for primary keys.
  • 0x0004 — Disable CRC check for read blocks.

online模式的配置文件

如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{
  "version": "1.5.0",
  "source": [
    {
      "alias": "S1",
      "name": "O112A",
      "reader": {
        "type": "online",
        "user": "用户名",
        "password": "密码",
        "server": "//IP:port/实例名",
        "disable-checks": 1
      },
      "format": {
        "type": "json"
      },

      "state": {
                        "type": "disk",
                        "path": "/opt/OpenLogReplicator/checkpoint"
      },
      "filter": {
        "table": [
          {"owner": "TEST", "table": ".*"}
        ]
      },

      "memory": {
        "min-mb": 64,
        "max-mb": 1024
      }
      
    }
  ],
  "target": [
    {
      "alias": "K1",
      "source": "S1",
      "writer": {
        "type": "file",
        "output": "/open_log/OpenLogReplicator/build/output/output-%t.json",
        "new-line": 1,
        "max-file-size": 1073741824,
        "append": 0
      }
    }
  ]
}

state 指向的:/opt/OpenLogReplicator/checkpoint,是checkpoint 目录,需要提前创建
/open_log/OpenLogReplicator/build/output/output-%t.json 这个是输出目录,需要提前创建

一些问题

用户授权

创建新用户

1
2
3
4
5
create user openlogtest  identified by "123456";

# 增加权限
grant create session to openlogtest;
ALTER USER openlogtest QUOTA UNLIMITED ON USERS;

libaio

  • libaio
    缺少这个库会报错:
1
error while loading shared libraries: libaio.so.1: cannot open shared object file

安装

1
2
3
4
5
6
7
8
sudo yum install -y libaio libaio-devel


# 确认安装
ldconfig -p | grep libaio

# 输出类似
# libaio.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libaio.so.1

ARM

安装依赖

  • 安装 gcc
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 下载
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz
tar -xvf gcc-9.3.0.tar.gz

# 下载gcc依赖
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gmp/gmp-6.1.0.tar.xz
tar -xvf gmp-6.1.0.tar.xz
mv gmp-6.1.0 gmp
 
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/mpfr/mpfr-3.1.4.tar.gz
tar -xvf mpfr-3.1.4.tar.gz
mv mpfr-3.1.4 mpfr
 
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/mpc/mpc-1.0.3.tar.gz
tar -xvf mpc-1.0.3.tar.gz
mv mpc-1.0.3 mpc
 

cd gcc-9.3.0
# yum install -y gcc-c++ glibc-static gcc //为避免出错建议安装此包

# 编译
mkdir gcc-build
cd gcc-build
../configure --prefix=/usr/local/gcc-9.3.0 --disable-multilib --enable-languages=c,c++

# make这步会非常长
make -j 128   # 这里根据实际机器核数修改,
make install
/usr/local/gcc-9.3.0目录下就是9.3版本的编译器

export CC=/usr/local/gcc-9.3.0/bin/gcc
export CXX=/usr/local/gcc-9.3.0/bin/g++

验证

1
2
gcc --version
g++ --version

麒麟v10 安装 gcc 参考这篇文章


yum 安装

1
2
yum -y install make gcc gcc-c++ clang texinfo automake
yum install cmake
  • 安装 libaio
1
yum install -y libaio libaio-devel
  • 安装 cmake
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 安装依赖
sudo yum groupinstall -y "Development Tools"
sudo yum install -y openssl-devel

wget https://github.com/Kitware/CMake/releases/download/v3.16.9/cmake-3.16.9.tar.gz
tar -zxvf cmake-3.16.9.tar.gz
cd cmake-3.16.9

# 编译安装
./bootstrap
make
sudo make install

# 检查
cmake --version

编译项目

  • 安装 rapidjson
1
2
3
RAPIDJSON_VERSION=1.1.0
wget https://github.com/Tencent/rapidjson/archive/refs/tags/v${RAPIDJSON_VERSION}.tar.gz
tar -xzf v1.1.0.tar.gz

rac 需要安装 libcurl

1
yum install libcurl-devel
  • 安装 oracle 客户端
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basic-linux-arm64.zip 
unzip instantclient-basic-linux-arm64.zip 

wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-sdk-linux-arm64.zip
unzip instantclient-sdk-linux-arm64.zip

ORACLE_MAJOR=19
ORACLE_MINOR=22
cd instantclient_19_22
ln -s libclntshcore.so.${ORACLE_MAJOR}.1 libclntshcore.so
  • 编译项目
1
2
3
4
5
6
7
mkdir build
cd build

# 执行 cmake 把这里的 rapidjson 和 oracle 的替换成实际的路径
cmake -DWITH_RAPIDJSON=/open_log/rapidjson-1.1.0 -DWITH_OCI=/open_log/oracle/arm/instantclient_19_22  ..
# 64 线程编译
make -j 64

参考