入门见上一篇文章:sonic 云真机 linux 单机版部署
分布式部署过程中踩过的坑,尤其是数据库连接方面较多问题,这里做一下 Mark,便于其他同学参考,会详尽到配置文件层面
跟单机版本的明显区别,就是可以分布在各地,类似于 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 3月 25 17:14 ./
drwxrwxr-x 3 lixuefu2 lixuefu2 4096 3月 25 13:28 ../
drwxrwxrwx 2 lixuefu2 lixuefu2 4096 3月 25 17:03 config/
-rwxrwxrwx 1 lixuefu2 lixuefu2 5336 3月 25 17:14 docker-compose.yml*
drwxrwxrwx 8 lixuefu2 lixuefu2 4096 3月 25 10:55 .git/
drwxrwxrwx 2 lixuefu2 lixuefu2 4096 3月 25 11:02 imageFiles/
drwxrwxrwx 2 lixuefu2 lixuefu2 4096 3月 25 11:02 keepFiles/
drwxrwxrwx 2 lixuefu2 lixuefu2 4096 3月 25 16:02 logs/
drwxrwxrwx 3 root root 4096 3月 25 11:20 mysql/
drwxrwxrwx 2 lixuefu2 lixuefu2 4096 3月 25 11:02 packageFiles/
-rwxrwxrwx 1 lixuefu2 lixuefu2 111 3月 25 10:55 README.md*
drwxrwxrwx 2 lixuefu2 lixuefu2 4096 3月 25 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 3月 25 17:03 ./
drwxrwxrwx 10 lixuefu2 lixuefu2 4096 3月 25 17:14 ../
-rwxrwxrwx 1 lixuefu2 lixuefu2 137 3月 25 10:55 actuator-prod.yml*
-rwxrwxrwx 1 lixuefu2 lixuefu2 77 3月 25 11:09 common-prod.yml*
-rwxrwxrwx 1 lixuefu2 lixuefu2 299 3月 25 10:55 feign-prod.yml*
-rwxrwxrwx 1 lixuefu2 lixuefu2 777 3月 25 16:49 jdbc-prod.yml*
-rwxrwxrwx 1 lixuefu2 lixuefu2 309 3月 25 13:32 knife4j-prod.yml*
-rwxrwxrwx 1 lixuefu2 lixuefu2 149 3月 25 11:11 logging-prod.yml*
-rwxrwxrwx 1 lixuefu2 lixuefu2 160 3月 25 10:55 sonic-server-bus-prod.yml*
-rwxrwxrwx 1 lixuefu2 lixuefu2 344 3月 25 13:20 sonic-server-controller-prod.yml*
-rwxrwxrwx 1 lixuefu2 lixuefu2 167 3月 25 11:09 sonic-server-folder-prod.yml*
-rwxrwxrwx 1 lixuefu2 lixuefu2 872 3月 25 11:11 sonic-server-gateway-prod.yml*
-rwxrwxrwx 1 lixuefu2 lixuefu2 513 3月 25 11:09 sonic-server-task-prod.yml*
-rwxrwxrwx 1 lixuefu2 lixuefu2 50 3月 25 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 四大模块均配置进去了,便于大家直接调用即可,官方 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/! https://img-blog.csdnimg.cn/d3127289dc3445e6b52f4a29072922d2.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBATGlYdWVGdTcyNzIyNDIwNA==,size_20,color_FFFFFF,t_70,g_se,x_16)[在这里插入图片描述](
《sonic 集群版后端部署》:sonic 官方分布式部署
《Java:jdbc 连接 mysql 数据库》:Java:jdbc 连接 mysql 数据库