搭建 Docker 环境下的 nadx-exchange

安装 Centos 7 镜像

下载镜像
docker pull centos
启动容器
docker run --name nadx-exchange -v /data:/data -p 9200:9200 -d -i -t centos:latest /bin/bash
进入容器
docker exec -it nadx-exchange bash

接下来的所有操作都是在容器中执行。

安装 JDK8

通过 yum 命令安装 jdk8

yum install java-1.8.0-openjdk* -y

配置 java 环境变量

vi  ~/.bashrc
#在该文件底部追加:
JAVA_HOME=/usr/lib/jvm/java
PATH=$PATH:$JAVA_HOME/bin

安装 git

yum install -y git

安装 wget

yum install wget -y

安装文件上传与下载工具

yum install lrzsz -y

安装 which(镜像没自带, 而 maven 中需用到)

yum install which -y

安装 maven

wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo

yum -y install apache-maven

安装 Redis

# Docker 安装 Redis

安装 MySql

# Centos 7 上使用 Docker 安装 Mysql

部署 nadx-exchange

从 git 资源库拉取

mkdir /apps
cd /apps
git clone https://gitlab.fuseclick.com/sz-nadx/sz-nadx-exchange.git
cd sz-nadx-exchange
# git checkout $tag
git checkout 1.10.3.20190215a.sz

上传依赖包:2019/02/fuseadziab10120190108a-c0ed688a.jar

mkdir -p /root/.m2/repository/com/fuseadz/fuseadz-iab/1.0.1.20190108a
cd /root/.m2/repository/com/fuseadz/fuseadz-iab/1.0.1.20190108a
rz -y ...

结果:
2019/02/image-8f16fd39.png

添加 redis 节点 ip/ 域名映射

vi /etc/hosts
# 追加内容:
172.22.226.47 redis.nadx.iifab.com

修改项目配置

vi /apps/sz-nadx-exchange/src/main/resources/nadx-exchange.json

完整配置为:

{
  "app.env":"test",
  "app.http.port" : 9200,
  "app.server.region": "use",
  "app.server.node" : 110000001,

  "app.server.protocol" : "http",
  "app.server.domain" : "0.0.0.0:9200",
  "app.notify.max.second" : 3600,
  "cdn.server.domain" : "assets.filextech.com",

  "ip.trust" : "127.0.0.1,192.168.0.0/16",

  "event.thread.pool.size" : 100,
  "worker.thread.pool.size" : 500,
  "async.thread.pool.size": 500,

  "http.instance" : 16,
  "rtb.instance" : 100,
  "bid.instance" : 200,
  "bid.mode.impl" : 3,
  "bid.connection.pool.size" : 100,
  "bid.pipeline.size": 1,

  "stub.supply.token":"SU7Z4JR5B9F3AF8B",
  "stub.demand.id":98000,

  "header.country.key" : "COUNTRY",
  "header.region.key" : "REGION",
  "header.city.key" : "CITY",
  "header.carrier.key" : "ISP",
  "header.device.key" : "x-device",
  "exchange.cache.host" : "redis.nadx.iifab.com",
  "exchange.cache.port" : 6379,
  "exchange.cache.pool.max.total" : 3000,
  "currency.hash" : "hash_currency_exchange",

  "ip.geo.city.mmdb.file" : "/apps/sz-nadx-exchange/run/conf/GeoLite2-City.mmdb",
  "countries.csv.file" : "/apps/sz-nadx-exchange/run/conf/countries.csv",

  "data.path" : "/data/sz-nadx-exchange/data",
  "log.path" : "/data/sz-nadx-exchange/log",
  "log.max.file.size.mb": 1000,
  "log.level" : "DEBUG"
}

重点关注的配置项:
exchange.cache.host
ip.geo.city.mmdb.file
countries.csv.file
data.path
log.path

编译打包

cd /apps/sz-nadx-exchange
mvn clean install -Dmaven.test.skip=true

部署

mkdir -p /data/sz-nadx-exchange/data
mkdir -p /data/sz-nadx-exchange/log

cd /apps/sz-nadx-exchange
mkdir run
mkdir run/conf
cp /apps/sz-nadx-exchange/target/nadx-exchange-1.10.3.20190215a.sz-fat.jar  /apps/sz-nadx-exchange/run/
cp /apps/sz-nadx-exchange/target/classes/nadx-exchange.json /apps/sz-nadx-exchange/run/conf
cp /apps/sz-nadx-exchange/target/classes/logback.xml /apps/sz-nadx-exchange/run/conf
cp /apps/sz-nadx-exchange/target/classes/GeoLite2-City.mmdb /apps/sz-nadx-exchange/run/conf  
cp /apps/sz-nadx-exchange/target/classes/countries.csv /apps/sz-nadx-exchange/run/conf

部署后的程序目录结构如下:

/apps/sz-nadx-exchange/run/

├── conf
│ ├── logback.xml
│ ├── nadx-exchange.json
│ ├── GeoLite2-City.mmdb
│ └── countries.csv
├── nadx-exchange-1.10.3.20190215a.sz-fat.jar

启动

cd /apps/sz-nadx-exchange/run
nohup java -jar nadx-exchange-1.10.3.20190215a.sz-fat.jar -conf conf/nadx-exchange.json > /dev/null  2>&1 &
tail -f /data/sz-nadx-exchange/log/nadx-exchange.log

验证

curl exchange.nadx.iifab.com:9200