研究开源的C++的RTB广告系统,通过centos7镜像,解决各种环境问题,使用boost库
Posted freewebsys
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了研究开源的C++的RTB广告系统,通过centos7镜像,解决各种环境问题,使用boost库相关的知识,希望对你有一定的参考价值。
目录
前言
本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/108971807
未经博主允许不得转载。
博主CSDN地址是:https://blog.csdn.net/freewebsys
博主掘金地址是:https://juejin.cn/user/585379920479288
博主知乎地址是:https://www.zhihu.com/people/freewebsystem
1,项目地址RTB项目地址
https://github.com/vanilla-rtb/rapid-bidder
Real Time Bidding (RTB) - Demand Side Platform (DSP) - Model project
Open-source model application utilizing vanilla-rtb stack and Redis.
实时定价广告系统。使用C++ 进行开发的,同时相关的库要求比较高。
cmake要求3以上,gcc要求5.1以上,boost要求 1.60 的版本,光着几个依赖就折腾很长时间。
但是重要搞定了。推荐大家使用docker折腾,可以不断的重试。
好像是个公司写的,做学习参考使用。
# 下载代码在电脑本地
git clone https://github.com/vanilla-rtb/rapid-bidder.git
# 下载子模块项目,包括 framework 模块
git submodule update --init
# 启动docker 并且把项目代码映射到容器data 目录
docker run -itd --name cpp -p 11081:11081 -v `pwd`/rapid-bidder:/data/rapid-bidder centos:centos7
# 进入 docker 并且安装编译工具全家桶
docker exec -it cpp bash
2,给centos7 升级gcc 版本到7
默认使用 yum install gcc 的方式安装的是比较低的gcc 版本。
但是 centos 支持使用高版本的库,直接安装就可以。
yum install -y centos-release-scl
yum install -y devtoolset-7-gcc*
yum install -y make
ln -s /opt/rh/devtoolset-7/root/usr/bin/gcc /usr/bin/gcc
ln -s /opt/rh/devtoolset-7/root/usr/bin/g++ /usr/bin/g++
ln -s /opt/rh/devtoolset-7/root/usr/bin/cc /usr/bin/cc
ln -s /opt/rh/devtoolset-7/root/usr/bin/c++ /usr/bin/c++
## 查看gcc 版本就是 7 的版本了。
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER= ......
............
Thread model: posix
gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)
3,然后安装项目需要的cmake,要求3以上
默认使用 yu安装的 cmake 是2.8 的版本。但是项目需要使用3.1 以上的 cmake 。需要下载源码进行安装。
# 安装ssl,否则会报错: Could NOT find OpenSSL
yum install -y openssl-devel
cd /home
# 从cmake 官方网下载最新的 3.24 版本
curl -O https://cmake.org/files/v3.24/cmake-3.24.2.tar.gz
tar -zxvf cmake-3.24.2.tar.gz
cd cmake-3.24.2
# 安装编译工具
./configure --prefix=/usr/local/cmake
# 编译安装,比较慢,需要耐心等待
make && make install
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake
# 查看版本
# cmake --version
cmake version 3.24.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
4,编译项目,安装相关依赖boost库,要求1.60以上
Could NOT find Boost (missing: Boost_INCLUDE_DIR)
不能使用 yum 进行安装,不是最新的库。
CMake Error at /usr/local/cmake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Boost: Found unsuitable version "1.53.0", but required is at
least "1.60.0" (found /usr/include, )
从官网下载 boost 包,然后安装,特别注意,使用最新包1.60
https://sourceforge.net/projects/boost/files/boost/1.60.0/
下载 boost 进行安装
tar -zxvf boost_1_80_0.tar.gz
cd boost_1_80_0
# 设置参数:
./bootstrap.sh --with-libraries=all --with-toolset=gcc
# 开始编译:
./b2 toolset=gcc
# 安装
./b2 install --prefix=/usr
5,都准备好了之后,重要可以编译RTB项目了
特别推荐使用docker 进行折腾,因为以上记录的步骤可不是一次就成功的。
反复折腾了好几次。然后才把相关的库和依赖补齐。
同时编译又特别的费时间。只能慢慢等待、摸索。
# mkdir Debug
# cd Debug
# cmake -DCMAKE_BUILD_TYPE=Debug .. -G "Unix Makefiles"
CMAKE_INSTALL_PREFIX /usr/local
CMAKE_CURRENT_SOURCE_DIR /data/rapid-bidder
CMAKE_CURRENT_BIN_DIR /data/rapid-bidder/Debug
-- Found Boost: /usr/local/include (found version "1.60.0") found components: log program_options system serialization date_time log_setup filesystem thread regex chrono atomic
-- Found Boost: /usr/local/include (found suitable version "1.60.0", minimum required is "1.60.0")
CMAKE_INSTALL_PREFIX /usr/local
CMAKE_CURRENT_SOURCE_DIR /data/rapid-bidder/framework
CMAKE_CURRENT_BIN_DIR /data/rapid-bidder/Debug/framework
CMake Deprecation Warning at framework/jsonv/CMakeLists.txt:13 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- JSONV version: 1.2.0
-- Found Boost: /usr/local/include (found version "1.60.0")
-- RUNTIME_INSTALL_DIR == /usr/local/bin
-- LIBRARY_INSTALL_DIR == /usr/local/lib64
-- INCLUDE_INSTALL_DIR == /usr/local/include
-- CONFIG_INSTALL_DIR == /usr/local/lib64/cmake/jsonv
-- Found Boost: /usr/local/include (found version "1.60.0") found components: system regex
-- Found Boost: /usr/local/include (found version "1.60.0") found components: log system serialization program_options date_time log_setup filesystem thread regex chrono atomic
-- Found Boost: /usr/local/include (found version "1.60.0") found components: log serialization system date_time log_setup filesystem thread regex chrono atomic
-- Found Boost: /usr/local/include (found version "1.60.0") found components: log program_options system serialization date_time log_setup filesystem thread regex chrono atomic
-- benchmarks disabled (google.benchmark not found)
-- REDISCLIENT_LIBRARY:
-- Configuring done
-- Generating done
-- Build files have been written to: /data/rapid-bidder/Debug
然后就可以构建了:
make -j4 install
[ 2%] Creating directories for 'redisclient'
[ 4%] Building C object framework/parsers/CMakeFiles/parsers.dir/jsmn.c.o
[ 4%] Building CXX object framework/CRUD/service/CMakeFiles/crud_service.dir/mime_types.cpp.o
[ 5%] Building CXX object framework/jsonv/CMakeFiles/jsonv.dir/src/jsonv/algorithm_compare.cpp.o
[ 7%] No download step for 'redisclient'
[ 8%] No update step for 'redisclient'
[ 10%] No patch step for 'redisclient'
...... 省略日志、编译时间 ......
"$ORIGIN/../lib:$ORIGIN/../lib64:/usr/local/lib"
-- Installing: /usr/local/bin/cache_loader_service
-- Set runtime path of "/usr/local/bin/cache_loader_service" to "$ORIGIN/../lib:$ORIGIN/../lib64:/usr/local/lib"
6,启动项目
官方有很多测试的例子,都可以尝试下
这里只说启动 web 界面
cd /usr/local/bin/
# 有个界面,可以直接启动 端口 11081
# ./campaign_manager_test --config etc/config.cfg
[2022-10-09 15:06:22.692621] [0x00007ff44fa68780] [debug] campaign-manager.budget_source data/campaign_budget
campaign-manager.host 0.0.0.0
campaign-manager.ipc_name vanilla-campaign-budget-ipc
campaign-manager.log /tmp/campaign_manager_log
campaign-manager.port 11081
campaign-manager.root www
config etc/config.cfg
15:06:22.693360: <debug> File opened data/campaign_budget
15:06:22.767101: <debug> ad : elapsed_sec=0|elapsed_ms=73|elapsed_mu=73737|elapsed_ns=73737300|
15:09:18.035032: <info> Read HOME page received url=/campaign/index.html
15:09:38.109451: <info> Read HOME page received url=/campaign/scripts/app.js
15:09:38.110285: <info> Read HOME page received url=/campaign/scripts/services.js
15:10:06.786973: <info> Read HOME page received url=/campaign/index.html
15:10:13.574350: <info> Read HOME page received url=/campaign/index.html
.......
15:10:22.078144: <info> Read HOME page received url=/campaign/scripts/controllers.js
15:10:22.079155: <info> Read HOME page received url=/campaign/scripts/app.js
15:10:33.231837: <info> Read HOME page received url=/campaign/views/header.html
15:10:33.270781: <info> Read received event url=/campaign/budget
15:10:33.281295: <debug> all_compaign_ids : elapsed_sec=0|elapsed_ms=10|elapsed_mu=10231|elapsed_ns=10231500|
然后就可以打开浏览器地址了:可以看到各种 CPC,CPM 数据了。
7,总结
通过研究c++ 的代码可以很好的学习下 boost 相关库知识。
同时发现c++ 的环境搭建,项目编译还真的是复杂些,折腾环境花了不少时间。
通过 docker 可以随时把镜像清除掉,然后再重新测试,用的都是比较新的包。
但是 centos7 的系统确实老了些默认支持包比较旧,都需要单独升级,找到方法更新。
以上是关于研究开源的C++的RTB广告系统,通过centos7镜像,解决各种环境问题,使用boost库的主要内容,如果未能解决你的问题,请参考以下文章