sonic云真机linux分布式部署

  • Post author:
  • Post category:linux




一、关于sonic

入门见上一篇文章:

sonic云真机linux单机版部署


分布式部署过程中踩过的坑,尤其是数据库连接方面较多问题,这里做一下Mark,便于其他同学参考,会详尽到配置文件层面



二、sonic分布式版本

跟单机版本的明显区别,就是可以分布在各地,类似于jenkins的从节点

官方推荐:集群版后端部署(推荐接入设备50+时使用)

官方部署:

sonic分布式部署


建议先观看官方文档,这里作为补充用



三、部署机器

服务器及前端:ubuntu21.04

agent:这里直接部署在本机,ubuntu21.04

手机:华为 Nova7 欧派



四、具体部署过程

1、【目录】配置目录:参考官方

在这里插入图片描述

笔者最终可运行版本的目录:

工作目录:sonic-server-config-yml

root@ubuntu:/home/lixuefu2/sonic-cluster/sonic-server-config-yml# ll
总用量 52
drwxrwxrwx 10 lixuefu2 lixuefu2 4096  325 17:14 ./
drwxrwxr-x  3 lixuefu2 lixuefu2 4096  325 13:28 ../
drwxrwxrwx  2 lixuefu2 lixuefu2 4096  325 17:03 config/
-rwxrwxrwx  1 lixuefu2 lixuefu2 5336  325 17:14 docker-compose.yml*
drwxrwxrwx  8 lixuefu2 lixuefu2 4096  325 10:55 .git/
drwxrwxrwx  2 lixuefu2 lixuefu2 4096  325 11:02 imageFiles/
drwxrwxrwx  2 lixuefu2 lixuefu2 4096  325 11:02 keepFiles/
drwxrwxrwx  2 lixuefu2 lixuefu2 4096  325 16:02 logs/
drwxrwxrwx  3 root     root     4096  325 11:20 mysql/
drwxrwxrwx  2 lixuefu2 lixuefu2 4096  325 11:02 packageFiles/
-rwxrwxrwx  1 lixuefu2 lixuefu2  111  325 10:55 README.md*
drwxrwxrwx  2 lixuefu2 lixuefu2 4096  325 11:02 recordFiles/
root@ubuntu:/home/lixuefu2/sonic-cluster/sonic-server-config-yml# pwd
/home/lixuefu2/sonic-cluster/sonic-server-config-yml

config文件夹:

root@ubuntu:/home/lixuefu2/sonic-cluster/sonic-server-config-yml/config# ll
总用量 56
drwxrwxrwx  2 lixuefu2 lixuefu2 4096  325 17:03 ./
drwxrwxrwx 10 lixuefu2 lixuefu2 4096  325 17:14 ../
-rwxrwxrwx  1 lixuefu2 lixuefu2  137  325 10:55 actuator-prod.yml*
-rwxrwxrwx  1 lixuefu2 lixuefu2   77  325 11:09 common-prod.yml*
-rwxrwxrwx  1 lixuefu2 lixuefu2  299  325 10:55 feign-prod.yml*
-rwxrwxrwx  1 lixuefu2 lixuefu2  777  325 16:49 jdbc-prod.yml*
-rwxrwxrwx  1 lixuefu2 lixuefu2  309  325 13:32 knife4j-prod.yml*
-rwxrwxrwx  1 lixuefu2 lixuefu2  149  325 11:11 logging-prod.yml*
-rwxrwxrwx  1 lixuefu2 lixuefu2  160  325 10:55 sonic-server-bus-prod.yml*
-rwxrwxrwx  1 lixuefu2 lixuefu2  344  325 13:20 sonic-server-controller-prod.yml*
-rwxrwxrwx  1 lixuefu2 lixuefu2  167  325 11:09 sonic-server-folder-prod.yml*
-rwxrwxrwx  1 lixuefu2 lixuefu2  872  325 11:11 sonic-server-gateway-prod.yml*
-rwxrwxrwx  1 lixuefu2 lixuefu2  513  325 11:09 sonic-server-task-prod.yml*
-rwxrwxrwx  1 lixuefu2 lixuefu2   50  325 11:12 sonic-server-transport-prod.yml*

2、【配置文件】

2.1、从官方下载配置文件:

部署文章


yml目录及docker-compose.yml

git clone https://github.com/SonicCloudOrg/sonic-server-config-yml.git

2.2、配置docker-compose.yml,这里把mysql、agent、web、server四大模块均配置进去了(本机即包含服务端、agent端时),便于大家直接调用即可,官方docker-compose.yml默认没包含mysql、agent、web三块配置。

其中sonic-agent中的配置值AGENT_KEY见下取值:

在这里插入图片描述

version: '3'
services:
  sonic-agent:
    #下方为Docker Hub镜像,推荐海外用户使用,默认使用国内加速镜像
    #image: "sonicorg/sonic-agent-linux:v1.3.2-release"
    image: "registry.cn-hangzhou.aliyuncs.com/sonic-cloud/sonic-agent-linux:v1.3.2-release"
    environment:
      # 替换为部署Agent机器的ipv4
      - AGENT_HOST=192.168.213.130
      # 替换为Agent服务的端口,可以自行更改
      - AGENT_PORT=7777
      # 替换为前端新增Agent生成的key
      - AGENT_KEY=359e3ace-a9f9-4b49-8228-15167163deaa
      # 这个host改成后端的host
      - SERVER_HOST=192.168.213.130
      # 这个port改成后端文件中心的port(一般不变)
      - SERVER_FOLDER_PORT=8094
      # 这个port改成后端传输中心的port(一般不变)
      - SERVER_TRANSPORT_PORT=8095
      # 是否使用安卓模块
      - ANDROID_ENABLE=true
      # 是否开启远程adb调试功能
      - USE_ADBKIT=true
      # 是否使用iOS模块
      - IOS_ENABLE=true
      # 替换为你自己使用的wda的bundleId,如果没有.xctrunner后缀会自动补全,建议使用公司的开发者证书
      - WDA_BUNDLE_ID=com.facebook.WebDriverAgentRunner.xctrunner
      # 是否启用Appium
      - APPIUM_ENABLE=true
      # 默认为0会自动寻找随机端口启动,如果需要指定appium server端口,请在这里设置
      - APPIUM_PORT=0
      # 是否启用webview调试功能
      - WEBVIEW_ENABLE=true
      # 谷歌调试端口,一般不需要修改(默认0使用随机端口,如果需要开启防火墙给外部使用,请设置固定端口如7778)
      - CHROME_DRIVER_PORT=0
    network_mode: "host"
    privileged: true
    volumes:
      - /dev/bus/usb:/dev/bus/usb
      - /var/run/usbmuxd:/var/run/usbmuxd

  sonic-mysql:
    image: "mysql:5.7"
    hostname: sonic-mysql
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    environment:
      - MYSQL_ROOT_PASSWORD=Sonic!@#123
      - MYSQL_DATABASE=sonic
    volumes:
      - ./mysql/data:/var/lib/mysql
    ports:
      - "3307:3306"
    networks:
      - sonic-network

  sonic-client-web:
    image: "sonicorg/sonic-client-web:v1.3.2-release"
    environment:
      #192.168.1.1改为你的ipv4,port更改为sonic-server-simple暴露的port(一般不变)
      - SONIC_API_HOST=192.168.213.130
      - SONIC_API_PORT=8094
    networks:
      - sonic-network
    ports:
      - "3000:80"

  sonic-server-eureka:
    image: "sonicorg/sonic-server-eureka:v1.3.2-release"
    hostname: sonic-server-eureka
    environment:
      - SEC_NAME=sonic #eureka用户名
      - SEC_PASSWORD=sonic #eureka密码
      - EUREKA_HOST=sonic-server-eureka
    volumes:
      - ./logs/:/logs/
    networks:
      - sonic-network
    ports:
      - "9090:9090"

  sonic-server-bus:
    image: "sonicorg/sonic-server-bus:v1.3.2-release"
    environment:
      - PROFILE=prod
      - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
    networks:
      - sonic-network
    volumes:
      - ./config:/config
      - ./logs/:/logs/
    depends_on:
      - sonic-server-eureka
    restart: on-failure

  sonic-server-gateway:
    image: "sonicorg/sonic-server-gateway:v1.3.2-release"
    environment:
      - PROFILE=prod
      - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
    networks:
      - sonic-network
    volumes:
      - ./logs/:/logs/
    depends_on:
      - sonic-server-bus
      - sonic-server-eureka
    ports:
      - "8094:8094"
    restart: on-failure

  sonic-server-controller:
    image: "sonicorg/sonic-server-controller:v1.3.2-release"
    environment:
      - PROFILE=prod
      - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
    networks:
      - sonic-network
    volumes:
      - ./logs/:/logs/
    depends_on:
      - sonic-server-bus
      - sonic-server-eureka
      - sonic-server-gateway
    restart: on-failure

  sonic-server-folder:
    image: "sonicorg/sonic-server-folder:v1.3.2-release"
    environment:
      - PROFILE=prod
      - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
    networks:
      - sonic-network
    volumes:
      - ./keepFiles/:/keepFiles/
      - ./imageFiles/:/imageFiles/
      - ./recordFiles/:/recordFiles/
      - ./packageFiles/:/packageFiles/
      - ./logs/:/logs/
    depends_on:
      - sonic-server-bus
      - sonic-server-eureka
      - sonic-server-gateway
    restart: on-failure

  sonic-server-task:
    image: "sonicorg/sonic-server-task:v1.3.2-release"
    environment:
      - PROFILE=prod
      - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
    networks:
      - sonic-network
    volumes:
      - ./logs/:/logs/
    depends_on:
      - sonic-server-bus
      - sonic-server-eureka
      - sonic-server-gateway
    restart: on-failure

  sonic-server-transport:
    image: "sonicorg/sonic-server-transport:v1.3.2-release"
    environment:
      - PROFILE=prod
      - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
    networks:
      - sonic-network
    volumes:
      - ./logs/:/logs/
    depends_on:
      - sonic-server-bus
      - sonic-server-eureka
      - sonic-server-gateway
    ports:
      - "8095:8095"
    restart: on-failure

networks:
  sonic-network:
    driver: bridge

2.3、actuator-prod.yml、feign-prod.yml、sonic-server-bus-prod.yml、sonic-server-task-prod.yml、common-prod.yml、logging-prod.yml、sonic-server-gateway-prod.yml、sonic-server-transport-prod.yml默认同官方即可,无需修改

2.4、knife4j-prod.yml,这里域名需要改成服务器所在域名

knife4j:
  enable: true
  setting:
    enableHost: true
    enableHostText: "http://192.168.213.130:8094"
    enableFooter: false
    enableFooterCustom: true
    footerCustomContent: MIT License | Copyright 2021 - [SonicCloudOrg/sonic-server](https://github.com/SonicCloudOrg/sonic-server/blob/main/LICENSE)

2.5、sonic-server-folder-prod.yml,这里域名需要改成服务器所在域名

server:
  port: 0

spring:
  servlet:
    multipart:
      maxFileSize: -1
      maxRequestSize: -1

gateway:
  #替换localhost
  host: "http://192.168.213.130:8094"

2.6、jdbc-prod.yml,

这里需要注意jdbc连接的域名,需要用docker-compose.yml中启动的mysql域名,否则会前端会一直提示“系统异常”,后台日志显示数据库连接不上,账号密码默认同官方即可

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://sonic-mysql:3306/sonic?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC&autoReconnect=true&serverTimezone=GMT%2b8
    username: root
    password: Sonic!@#123
    # 会用到广播的事件
    initialization-mode: always
    schema:
      - classpath:data.sql
# mybatis-plus配置
mybatis-plus:
  mapper-locations: classpath:mapping/*.xml, classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml
  global-config:
    # 是否显示mybatis-plus图标
    banner: false
  configuration:
    # 关闭二级缓存
    cache-enabled: false
    # 关闭一级缓存
    localCacheScope: STATEMENT
    # sql日志
    # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

2.7、sonic-server-controller-prod.yml,这里域名需要改成服务器所在域名

server:
  port: 0

robot:
  client:
    host: "http://192.168.213.130:3000"
  img:
    success: "https://gitee.com/sonic-cloud/sonic-cloud/raw/master/src/assets/suc.png"
    warning: "https://gitee.com/sonic-cloud/sonic-cloud/raw/master/src/assets/warn.png"
    error: "https://gitee.com/sonic-cloud/sonic-cloud/raw/master/src/assets/fail.png"
~                                                                                        

3、【启动】以上配置完毕后,回到docker-compose.yml所在目录,启动

docker-compose up -d

过程如果修改过config中配置,则

docker-compose down
docker-compose up -d

4、验证启动成功,登陆Eureka:http://localhost:9090/,存在以上任务算成功,Eureka启动以上6个实例,可能需要几十秒秒,需要稍等下,这里只有sonic-server-controller(v1.3.2-release)-172.28.0.6、sonic-server-task(v1.3.2-release)-172.28.0.10实例成功,才能往后验证

在这里插入图片描述

进入云真机页面,连接手机:http://localhost:3000/
在这里插入图片描述

实际部署过程中,服务器跟agent都是分开的,所以这里:

服务器端部署docker-compose.yml:

version: '3'
services:
  sonic-mysql:
    image: "mysql:5.7"
    hostname: sonic-mysql
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    environment:
      - MYSQL_ROOT_PASSWORD=Sonic!@#123
      - MYSQL_DATABASE=sonic
    volumes:
      - ./mysql/data:/var/lib/mysql
    ports:
      - "3307:3306"
    networks:
      - sonic-network

  sonic-client-web:
    image: "sonicorg/sonic-client-web:v1.3.2-release"
    environment:
      #192.168.1.1改为你的ipv4,port更改为sonic-server-simple暴露的port(一般不变)
      - SONIC_API_HOST=10.16.0.###
      - SONIC_API_PORT=8094
    networks:
      - sonic-network
    ports:
      - "3000:80"

  sonic-server-eureka:
    image: "sonicorg/sonic-server-eureka:v1.3.2-release"
    hostname: sonic-server-eureka
    environment:
      - SEC_NAME=sonic #eureka用户名
      - SEC_PASSWORD=sonic #eureka密码
      - EUREKA_HOST=sonic-server-eureka
    volumes:
      - ./logs/:/logs/
    networks:
      - sonic-network
    ports:
      - "9090:9090"

  sonic-server-bus:
    image: "sonicorg/sonic-server-bus:v1.3.2-release"
    environment:
      - PROFILE=prod
      - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
    networks:
      - sonic-network
    volumes:
      - ./config:/config
      - ./logs/:/logs/
    depends_on:
      - sonic-server-eureka
    restart: on-failure

  sonic-server-gateway:
    image: "sonicorg/sonic-server-gateway:v1.3.2-release"
    environment:
      - PROFILE=prod
      - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
    networks:
      - sonic-network
    volumes:
      - ./logs/:/logs/
    depends_on:
      - sonic-server-bus
      - sonic-server-eureka
    ports:
      - "8094:8094"
    restart: on-failure

  sonic-server-controller:
    image: "sonicorg/sonic-server-controller:v1.3.2-release"
    environment:
      - PROFILE=prod
      - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
    networks:
      - sonic-network
    volumes:
      - ./logs/:/logs/
    depends_on:
      - sonic-server-bus
      - sonic-server-eureka
      - sonic-server-gateway
    restart: on-failure

  sonic-server-folder:
    image: "sonicorg/sonic-server-folder:v1.3.2-release"
    environment:
      - PROFILE=prod
      - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
    networks:
      - sonic-network
    volumes:
      - ./keepFiles/:/keepFiles/
      - ./imageFiles/:/imageFiles/
      - ./recordFiles/:/recordFiles/
      - ./packageFiles/:/packageFiles/
      - ./logs/:/logs/
    depends_on:
      - sonic-server-bus
      - sonic-server-eureka
      - sonic-server-gateway
    restart: on-failure

  sonic-server-task:
    image: "sonicorg/sonic-server-task:v1.3.2-release"
    environment:
      - PROFILE=prod
      - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
    networks:
      - sonic-network
    volumes:
      - ./logs/:/logs/
    depends_on:
      - sonic-server-bus
      - sonic-server-eureka
      - sonic-server-gateway
    restart: on-failure

  sonic-server-transport:
    image: "sonicorg/sonic-server-transport:v1.3.2-release"
    environment:
      - PROFILE=prod
      - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
    networks:
      - sonic-network
    volumes:
      - ./logs/:/logs/
    depends_on:
      - sonic-server-bus
      - sonic-server-eureka
      - sonic-server-gateway
    ports:
      - "8095:8095"
    restart: on-failure

networks:
  sonic-network:
    driver: bridge

agent端docker-compose.yml:

version: '3'
services:
  sonic-agent:
    #下方为Docker Hub镜像,推荐海外用户使用,默认使用国内加速镜像
    #image: "sonicorg/sonic-agent-linux:v1.3.2-release"
    image: "registry.cn-hangzhou.aliyuncs.com/sonic-cloud/sonic-agent-linux:v1.3.2-release"
    environment:
      # 替换为部署Agent机器的ipv4
      - AGENT_HOST=192.168.213.130
      # 替换为Agent服务的端口,可以自行更改
      - AGENT_PORT=7777
      # 替换为前端新增Agent生成的key
      - AGENT_KEY=b8381f7d-f983-4f0d-a45a-9b9d7c2421d2
      # 这个host改成后端的host
      - SERVER_HOST=10.16.0.###
      # 这个port改成后端文件中心的port(一般不变)
      - SERVER_FOLDER_PORT=8094
      # 这个port改成后端传输中心的port(一般不变)
      - SERVER_TRANSPORT_PORT=8095
      # 是否使用安卓模块
      - ANDROID_ENABLE=true
      # 是否开启远程adb调试功能
      - USE_ADBKIT=true
      # 是否使用iOS模块
      - IOS_ENABLE=true
      # 替换为你自己使用的wda的bundleId,如果没有.xctrunner后缀会自动补全,建议使用公司的开发者证书
      - WDA_BUNDLE_ID=com.facebook.WebDriverAgentRunner.xctrunner
      # 是否启用Appium
      - APPIUM_ENABLE=true
      # 默认为0会自动寻找随机端口启动,如果需要指定appium server端口,请在这里设置
      - APPIUM_PORT=0
      # 是否启用webview调试功能
      - WEBVIEW_ENABLE=true
      # 谷歌调试端口,一般不需要修改(默认0使用随机端口,如果需要开启防火墙给外部使用,请设置固定端口如7778)
      - CHROME_DRIVER_PORT=0
    network_mode: "host"
    privileged: true
    volumes:
      - /dev/bus/usb:/dev/bus/usb
      - /var/run/usbmuxd:/var/run/usbmuxd

备注,笔者是用虚拟机部署,需要配置宿主机7777端口转入到对应虚拟机OS的ip

在这里插入图片描述

在这里插入图片描述



五、参考资料

《sonic集群版后端部署》:

sonic官方分布式部署


《Java:jdbc连接mysql数据库》:

Java:jdbc连接mysql数据库



版权声明:本文为LiXueFu727224204原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。