简介

这只是一个操作步骤,背景知识参考 STF 正式环境 docker 化集群部署

环境

软件版本

IP 地址

Hosts

10.8.8.128 stf.ovwane.com
10.8.8.128 devside.stf.ovwane.com
10.8.8.131 provider1.stf.ovwane.com

安装 Docker


apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# 添加 Docker 源
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

# 安装 Docker
apt-get install -y docker-ce

# 启动 Docker
systemctl start docker.service

安装 Docker Compose

# 下载 Docker Compose
curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# 添加执行权限
chmod +x /usr/local/bin/docker-compose

部署 OpenSTF 服务端

拉取镜像

for name in nginx:1.15.7-alpine rethinkdb:2.3.6  openstf/stf:v3.4.0; do
    docker pull $name
done

新建目录

mkdir -p /data/stf/nginx/
mkdir stf_app

nginx.conf 配置文件

请修改 IP 地址和域名

vim /data/stf/nginx/nginx.conf

#daemon off
worker_processes 4;

events {
  worker_connections 1024;
}

http {
  upstream stf_app {
    server 10.8.8.128:3100 max_fails=0;
  }

  upstream stf_auth {
    server 10.8.8.128:3101 max_fails=0;
  }

  upstream stf_storage_apk {
    server 10.8.8.128:3102 max_fails=0;
  }

  upstream stf_storage_image {
    server 10.8.8.128:3103 max_fails=0;
  }

  upstream stf_storage {
    server 10.8.8.128:3104 max_fails=0;
  }

  upstream stf_websocket {
    server 10.8.8.128:3105 max_fails=0;
  }

  upstream stf_api {
    server 10.8.8.128:3106 max_fails=0;
  }

  types {
    application/javascript  js;
    image/gif               gif;
    image/jpeg              jpg;
    text/css                css;
    text/html               html;
  }

  map $http_upgrade $connection_upgrade {
    default  upgrade;
    ''       close;
  }

  server {
    listen 80;
    server_name stf.ovwane.com;
    keepalive_timeout 70; 
#    resolver 114.114.114.114 8.8.8.8 valid=300s;
#    resolver_timeout 10s;

    location ~ "^/d/provider1/([^/]+)/(?<port>[0-9]{5})/$" {
      proxy_pass http://10.8.8.131:$port/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header X-Real-IP $remote_addr;
    }

    location ~ "^/d/provider2/([^/]+)/(?<port>[0-9]{5})/$" {
      proxy_pass http://10.8.8.132:$port/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header X-Real-IP $remote_addr;
    }

    location /auth/ {
      proxy_pass http://stf_auth/auth/;
    }

    location /api/ {
      proxy_pass http://stf_api/api/;
    }

    location /s/image/ {
      proxy_pass http://stf_storage_image;
    }

    location /s/apk/ {
      proxy_pass http://stf_storage_apk;
    }

    location /s/ {
      client_max_body_size 1024m;
      client_body_buffer_size 128k;
      proxy_pass http://stf_storage;
    }

    location /socket.io/ {
      proxy_pass http://stf_websocket;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Real-IP $http_x_real_ip;
    }

    location / {
      proxy_pass http://stf_app;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Real-IP $http_x_real_ip;
    }
  }
}

进入 stf_app 目录

cd stf_app

配置文件

vim .env

STF_VERSION=3.4.0
STF_HOST=stf.ovwane.com
STF_URL=http://stf.ovwane.com
STF_IMAGE=openstf/stf:v3.4.0
STF_SECRET=RETHINKDBAUTHKEYANY

STF_VERSION=3.4.0 # OpenSTF 版本
STF_HOST=stf.ovwane.com # 域名
STF_URL=http://stf.ovwane.com # http 或者 https
STF_IMAGE=openstf/stf:v3.4.0 # OpenSTF 镜像版本

Docker Compose 配置文件

vim docker-compose.yml

如果使用 IP 访问,需要修改 stf-log-rethinkdb 处 devside.$STF_HOST 为你的 IP。

version: '3'
services:
  nginx:
    image: nginx:1.15.7-alpine
    volumes:
      - /data/stf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
    network_mode: "host"

  rethinkdb:
    depends_on:
      - nginx
    image: rethinkdb:2.3.6
    command: rethinkdb --bind all --cache-size 8192 --http-port 8090 --no-update-check
    volumes:
      - /data/stf/rethinkdb:/data
    network_mode: "host"

  stf-migrate:
    depends_on:
      - rethinkdb
    image: $STF_IMAGE
    command: stf migrate
    network_mode: "host"

  stf-app:
    depends_on:
      - stf-migrate
    image: $STF_IMAGE
    command: stf app --port 3100 --auth-url ${STF_URL}/auth/mock/ --websocket-url ws://${STF_HOST}/
    network_mode: "host"
    environment:
      SECRET: $STF_SECRET

  stf-auth:
    depends_on:
      - stf-app
    image: $STF_IMAGE
    command: stf auth-mock --port 3101 --app-url ${STF_URL}
    network_mode: "host"
    environment:
      SECRET: $STF_SECRET

  stf-storage-plugin-apk:
    depends_on:
      - stf-api
    image: $STF_IMAGE
    command: stf storage-plugin-apk --port 3102 --storage-url ${STF_URL}
    network_mode: "host"

  stf-storage-plugin-image:
    depends_on:
      - stf-storage-plugin-apk
    image: $STF_IMAGE
    command: stf storage-plugin-image --port 3103 --storage-url $STF_URL
    network_mode: "host"

  stf-storage-temp:
    depends_on:
      - stf-storage-plugin-image
    image: $STF_IMAGE
    command: stf storage-temp --port 3104 --save-dir /tmp
    network_mode: "host"

  stf-websocket:
    depends_on:
      - stf-auth
    image: $STF_IMAGE
    command: stf websocket --port 3105 --storage-url $STF_URL --connect-sub tcp://$STF_HOST:7150 --connect-push tcp://$STF_HOST:7170
    network_mode: "host"
    environment:
      SECRET: $STF_SECRET

  stf-api:
    depends_on:
      - stf-websocket
    image: $STF_IMAGE
    command: stf api --port 3106 --connect-sub tcp://$STF_HOST:7150 --connect-push tcp://$STF_HOST:7170
    network_mode: "host"
    environment:
      SECRET: $STF_SECRET

  stf-triproxy-app:
    depends_on:
      - stf-storage-temp
    image: $STF_IMAGE
    command: stf triproxy app --bind-pub "tcp://*:7150" --bind-dealer "tcp://*:7160" --bind-pull "tcp://*:7170"
    network_mode: "host"

  stf-processor:
    depends_on:
      - stf-triproxy-app
    image: $STF_IMAGE
    command: stf processor stf-processer --connect-app-dealer tcp://$STF_HOST:7160 --connect-dev-dealer tcp://$STF_HOST:7260
    network_mode: "host"

  stf-triproxy-dev:
    depends_on:
      - stf-processor
    image: $STF_IMAGE
    command: stf triproxy dev --bind-pub "tcp://*:7250" --bind-dealer "tcp://*:7260" --bind-pull "tcp://*:7270"
    network_mode: "host"

  stf-reaper:
    depends_on:
      - stf-triproxy-dev
    image: $STF_IMAGE
    command: stf reaper dev --connect-push tcp://$STF_HOST:7270 --connect-sub tcp://$STF_HOST:7150 --heartbeat-timeout 30000
    network_mode: "host"

  stf-log-rethinkdb:
    depends_on:
      - stf-reaper
    image: $STF_IMAGE
    command: stf log-rethinkdb --connect-sub tcp://devside.$STF_HOST:7150
    network_mode: "host"

启动

docker-compose up -d

部署 OpenSTF 设备提供端

安装 ADB

apt -y install adb

编辑 adbd.service
vim /etc/systemd/system/adbd.service

[Unit]
Description=Android Debug Bridge daemon
After=network.target
[Service]
Restart=always
RestartSec=2s
Type=forking
User=root
ExecStartPre=/usr/bin/adb kill-server
ExecStart=/usr/bin/adb start-server
ExecStop=/usr/bin/adb kill-server

[Install]
WantedBy=multi-user.target

启动 ADB

# 开机自启动
systemctl enable adbd.service

# 启动
systemctl start adbd.service

部署 OpenSTF

拉取镜像

docker pull  openstf/stf:v3.4.0

新建目录

mkdir stf_provider

进入 stf_provider 目录

cd stf_provider

配置文件

vim .env

STF_VERSION=3.4.0
STF_HOST=stf.ovwane.com
STF_URL=http://stf.ovwane.com
STF_IMAGE=openstf/stf:v3.4.0
STF_PROVIDER=provider1

STF_VERSION=3.4.0 # OpenSTF 版本
STF_HOST=stf.ovwane.com # 域名
STF_URL=http://stf.ovwane.com # http 或者 https
STF_IMAGE=openstf/stf:v3.4.0 # OpenSTF 镜像版本
STF_PROVIDER=provider1 # provider 编号

Docker Compose 配置文件

vim docker-compose.yml

如果使用 IP 访问,需要修改 devside.$STF_HOST 为你的 IP。
如果使用 IP 访问,需要修改 $STF_PROVIDER.$STF_HOST 为你的 IP。如果此处使用 IP 不能访问,请用域名的方式,然后所有主机绑定 hosts。

version: '3'
services:
  stf-provider:
    image: $STF_IMAGE
    command: stf provider --name "${STF_PROVIDER}" --connect-sub tcp://devside.$STF_HOST:7250 --connect-push tcp://devside.$STF_HOST:7270 --storage-url $STF_URL --public-ip $STF_PROVIDER.$STF_HOST --min-port=15000 --max-port=25000 --heartbeat-interval 20000 --screen-ws-url-pattern "ws://${STF_HOST}/d/${STF_PROVIDER}/<%= serial %>/<%= publicPort %>/"
    network_mode: "host"

启动

docker-compose up -d

参考


↙↙↙阅读原文可查看相关链接,并与作者交流